Completed
Push — stable10 ( b85e94...1e5021 )
by
unknown
23:18 queued 12:32
created
lib/private/Repair/SearchLuceneTables.php 1 patch
Indentation   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -29,37 +29,37 @@  discard block
 block discarded – undo
29 29
 
30 30
 class SearchLuceneTables implements IRepairStep {
31 31
 
32
-	public function getName() {
33
-		return 'Repair duplicate entries in oc_lucene_status';
34
-	}
32
+    public function getName() {
33
+        return 'Repair duplicate entries in oc_lucene_status';
34
+    }
35 35
 
36
-	/**
37
-	 * Fix duplicate entries in oc_lucene_status
38
-	 *
39
-	 * search_lucene prior to v0.5.0 did not have a primary key on the lucene_status table. Newer versions do, which
40
-	 * causes the migration check to fail because it tries to insert duplicate rows into the new schema.
41
-	 *
42
-	 * FIXME Currently, apps don't have a way of repairing anything before the migration check:
43
-	 * @link https://github.com/owncloud/core/issues/10980
44
-	 *
45
-	 * As a result this repair step needs to live in the core repo, although it belongs into search_lucene:
46
-	 * @link https://github.com/owncloud/core/issues/10205#issuecomment-54957557
47
-	 *
48
-	 * It will completely remove any rows that make a file id have more than one status:
49
-	 *  fileid | status                       fileid | status
50
-	 * --------+--------     will become     --------+--------
51
-	 *     2   |   E                             3   |   E
52
-	 *     2   |   I
53
-	 *     3   |   E
54
-	 *
55
-	 * search_lucene will then reindex the fileids without a status when the next indexing job is executed
56
-	 */
57
-	public function run(IOutput $out) {
58
-		$connection = \OC::$server->getDatabaseConnection();
59
-		if ($connection->tableExists('lucene_status')) {
60
-			$out->info('removing duplicate entries from lucene_status');
36
+    /**
37
+     * Fix duplicate entries in oc_lucene_status
38
+     *
39
+     * search_lucene prior to v0.5.0 did not have a primary key on the lucene_status table. Newer versions do, which
40
+     * causes the migration check to fail because it tries to insert duplicate rows into the new schema.
41
+     *
42
+     * FIXME Currently, apps don't have a way of repairing anything before the migration check:
43
+     * @link https://github.com/owncloud/core/issues/10980
44
+     *
45
+     * As a result this repair step needs to live in the core repo, although it belongs into search_lucene:
46
+     * @link https://github.com/owncloud/core/issues/10205#issuecomment-54957557
47
+     *
48
+     * It will completely remove any rows that make a file id have more than one status:
49
+     *  fileid | status                       fileid | status
50
+     * --------+--------     will become     --------+--------
51
+     *     2   |   E                             3   |   E
52
+     *     2   |   I
53
+     *     3   |   E
54
+     *
55
+     * search_lucene will then reindex the fileids without a status when the next indexing job is executed
56
+     */
57
+    public function run(IOutput $out) {
58
+        $connection = \OC::$server->getDatabaseConnection();
59
+        if ($connection->tableExists('lucene_status')) {
60
+            $out->info('removing duplicate entries from lucene_status');
61 61
 
62
-			$query = $connection->prepare('
62
+            $query = $connection->prepare('
63 63
 				DELETE FROM `*PREFIX*lucene_status`
64 64
 				WHERE `fileid` IN (
65 65
 					SELECT `fileid`
@@ -70,11 +70,11 @@  discard block
 block discarded – undo
70 70
 						HAVING count(`fileid`) > 1
71 71
 					) AS `mysqlerr1093hack`
72 72
 				)');
73
-			$query->execute();
74
-		} else {
75
-			$out->info('lucene_status table does not exist -> nothing to do');
76
-		}
77
-	}
73
+            $query->execute();
74
+        } else {
75
+            $out->info('lucene_status table does not exist -> nothing to do');
76
+        }
77
+    }
78 78
 
79 79
 }
80 80
 
Please login to merge, or discard this patch.
lib/private/Repair/SqliteAutoincrement.php 1 patch
Indentation   +52 added lines, -52 removed lines patch added patch discarded remove patch
@@ -36,66 +36,66 @@
 block discarded – undo
36 36
  * altered in order to retrigger SQL schema generation through OCSqlitePlatform.
37 37
  */
38 38
 class SqliteAutoincrement implements IRepairStep {
39
-	/**
40
-	 * @var \OC\DB\Connection
41
-	 */
42
-	protected $connection;
39
+    /**
40
+     * @var \OC\DB\Connection
41
+     */
42
+    protected $connection;
43 43
 
44
-	/**
45
-	 * @param \OC\DB\Connection $connection
46
-	 */
47
-	public function __construct($connection) {
48
-		$this->connection = $connection;
49
-	}
44
+    /**
45
+     * @param \OC\DB\Connection $connection
46
+     */
47
+    public function __construct($connection) {
48
+        $this->connection = $connection;
49
+    }
50 50
 
51
-	public function getName() {
52
-		return 'Repair SQLite autoincrement';
53
-	}
51
+    public function getName() {
52
+        return 'Repair SQLite autoincrement';
53
+    }
54 54
 
55
-	/**
56
-	 * Fix mime types
57
-	 */
58
-	public function run(IOutput $out) {
59
-		if (!$this->connection->getDatabasePlatform() instanceof SqlitePlatform) {
60
-			return;
61
-		}
55
+    /**
56
+     * Fix mime types
57
+     */
58
+    public function run(IOutput $out) {
59
+        if (!$this->connection->getDatabasePlatform() instanceof SqlitePlatform) {
60
+            return;
61
+        }
62 62
 
63
-		$sourceSchema = $this->connection->getSchemaManager()->createSchema();
63
+        $sourceSchema = $this->connection->getSchemaManager()->createSchema();
64 64
 
65
-		$schemaDiff = new SchemaDiff();
65
+        $schemaDiff = new SchemaDiff();
66 66
 
67
-		foreach ($sourceSchema->getTables() as $tableSchema) {
68
-			$primaryKey = $tableSchema->getPrimaryKey();
69
-			if (!$primaryKey) {
70
-				continue;
71
-			}
67
+        foreach ($sourceSchema->getTables() as $tableSchema) {
68
+            $primaryKey = $tableSchema->getPrimaryKey();
69
+            if (!$primaryKey) {
70
+                continue;
71
+            }
72 72
 
73
-			$columnNames = $primaryKey->getColumns();
73
+            $columnNames = $primaryKey->getColumns();
74 74
 
75
-			// add a column diff for every primary key column,
76
-			// but do not actually change anything, this will
77
-			// force the generation of SQL statements to alter
78
-			// those tables, which will then trigger the
79
-			// specific SQL code from OCSqlitePlatform
80
-			try {
81
-				$tableDiff = new TableDiff($tableSchema->getName());
82
-				$tableDiff->fromTable = $tableSchema;
83
-				foreach ($columnNames as $columnName) {
84
-					$columnSchema = $tableSchema->getColumn($columnName);
85
-					$columnDiff = new ColumnDiff($columnSchema->getName(), $columnSchema);
86
-					$tableDiff->changedColumns[] = $columnDiff;
87
-					$schemaDiff->changedTables[] = $tableDiff;
88
-				}
89
-			} catch (SchemaException $e) {
90
-				// ignore
91
-			}
92
-		}
75
+            // add a column diff for every primary key column,
76
+            // but do not actually change anything, this will
77
+            // force the generation of SQL statements to alter
78
+            // those tables, which will then trigger the
79
+            // specific SQL code from OCSqlitePlatform
80
+            try {
81
+                $tableDiff = new TableDiff($tableSchema->getName());
82
+                $tableDiff->fromTable = $tableSchema;
83
+                foreach ($columnNames as $columnName) {
84
+                    $columnSchema = $tableSchema->getColumn($columnName);
85
+                    $columnDiff = new ColumnDiff($columnSchema->getName(), $columnSchema);
86
+                    $tableDiff->changedColumns[] = $columnDiff;
87
+                    $schemaDiff->changedTables[] = $tableDiff;
88
+                }
89
+            } catch (SchemaException $e) {
90
+                // ignore
91
+            }
92
+        }
93 93
 
94
-		$this->connection->beginTransaction();
95
-		foreach ($schemaDiff->toSql($this->connection->getDatabasePlatform()) as $sql) {
96
-			$this->connection->query($sql);
97
-		}
98
-		$this->connection->commit();
99
-	}
94
+        $this->connection->beginTransaction();
95
+        foreach ($schemaDiff->toSql($this->connection->getDatabasePlatform()) as $sql) {
96
+            $this->connection->query($sql);
97
+        }
98
+        $this->connection->commit();
99
+    }
100 100
 }
101 101
 
Please login to merge, or discard this patch.
lib/private/Repair/OldGroupMembershipShares.php 2 patches
Indentation   +84 added lines, -84 removed lines patch added patch discarded remove patch
@@ -31,88 +31,88 @@
 block discarded – undo
31 31
 
32 32
 class OldGroupMembershipShares implements IRepairStep {
33 33
 
34
-	/** @var \OCP\IDBConnection */
35
-	protected $connection;
36
-
37
-	/** @var \OCP\IGroupManager */
38
-	protected $groupManager;
39
-
40
-	/**
41
-	 * @var array [gid => [uid => (bool)]]
42
-	 */
43
-	protected $memberships;
44
-
45
-	/**
46
-	 * @param IDBConnection $connection
47
-	 * @param IGroupManager $groupManager
48
-	 */
49
-	public function __construct(IDBConnection $connection, IGroupManager $groupManager) {
50
-		$this->connection = $connection;
51
-		$this->groupManager = $groupManager;
52
-	}
53
-
54
-	/**
55
-	 * Returns the step's name
56
-	 *
57
-	 * @return string
58
-	 */
59
-	public function getName() {
60
-		return 'Remove shares of old group memberships';
61
-	}
62
-
63
-	/**
64
-	 * Run repair step.
65
-	 * Must throw exception on error.
66
-	 *
67
-	 * @throws \Exception in case of failure
68
-	 */
69
-	public function run(IOutput $output) {
70
-		$deletedEntries = 0;
71
-
72
-		$query = $this->connection->getQueryBuilder();
73
-		$query->select('s1.id')->selectAlias('s1.share_with', 'user')->selectAlias('s2.share_with', 'group')
74
-			->from('share', 's1')
75
-			->where($query->expr()->isNotNull('s1.parent'))
76
-				// \OC\Share\Constant::$shareTypeGroupUserUnique === 2
77
-				->andWhere($query->expr()->eq('s1.share_type', $query->expr()->literal(2)))
78
-				->andWhere($query->expr()->isNotNull('s2.id'))
79
-				->andWhere($query->expr()->eq('s2.share_type', $query->expr()->literal(Share::SHARE_TYPE_GROUP)))
80
-			->leftJoin('s1', 'share', 's2', $query->expr()->eq('s1.parent', 's2.id'));
81
-
82
-		$deleteQuery = $this->connection->getQueryBuilder();
83
-		$deleteQuery->delete('share')
84
-			->where($query->expr()->eq('id', $deleteQuery->createParameter('share')));
85
-
86
-		$result = $query->execute();
87
-		while ($row = $result->fetch()) {
88
-			if (!$this->isMember($row['group'], $row['user'])) {
89
-				$deletedEntries += $deleteQuery->setParameter('share', (int) $row['id'])
90
-					->execute();
91
-			}
92
-		}
93
-		$result->closeCursor();
94
-
95
-		if ($deletedEntries) {
96
-			$output->info('Removed ' . $deletedEntries . ' shares where user is not a member of the group anymore');
97
-		}
98
-	}
99
-
100
-	/**
101
-	 * @param string $gid
102
-	 * @param string $uid
103
-	 * @return bool
104
-	 */
105
-	protected function isMember($gid, $uid) {
106
-		if (isset($this->memberships[$gid][$uid])) {
107
-			return $this->memberships[$gid][$uid];
108
-		}
109
-
110
-		$isMember = $this->groupManager->isInGroup($uid, $gid);
111
-		if (!isset($this->memberships[$gid])) {
112
-			$this->memberships[$gid] = [];
113
-		}
114
-		$this->memberships[$gid][$uid] = $isMember;
115
-
116
-		return $isMember;
117
-	}
34
+    /** @var \OCP\IDBConnection */
35
+    protected $connection;
36
+
37
+    /** @var \OCP\IGroupManager */
38
+    protected $groupManager;
39
+
40
+    /**
41
+     * @var array [gid => [uid => (bool)]]
42
+     */
43
+    protected $memberships;
44
+
45
+    /**
46
+     * @param IDBConnection $connection
47
+     * @param IGroupManager $groupManager
48
+     */
49
+    public function __construct(IDBConnection $connection, IGroupManager $groupManager) {
50
+        $this->connection = $connection;
51
+        $this->groupManager = $groupManager;
52
+    }
53
+
54
+    /**
55
+     * Returns the step's name
56
+     *
57
+     * @return string
58
+     */
59
+    public function getName() {
60
+        return 'Remove shares of old group memberships';
61
+    }
62
+
63
+    /**
64
+     * Run repair step.
65
+     * Must throw exception on error.
66
+     *
67
+     * @throws \Exception in case of failure
68
+     */
69
+    public function run(IOutput $output) {
70
+        $deletedEntries = 0;
71
+
72
+        $query = $this->connection->getQueryBuilder();
73
+        $query->select('s1.id')->selectAlias('s1.share_with', 'user')->selectAlias('s2.share_with', 'group')
74
+            ->from('share', 's1')
75
+            ->where($query->expr()->isNotNull('s1.parent'))
76
+                // \OC\Share\Constant::$shareTypeGroupUserUnique === 2
77
+                ->andWhere($query->expr()->eq('s1.share_type', $query->expr()->literal(2)))
78
+                ->andWhere($query->expr()->isNotNull('s2.id'))
79
+                ->andWhere($query->expr()->eq('s2.share_type', $query->expr()->literal(Share::SHARE_TYPE_GROUP)))
80
+            ->leftJoin('s1', 'share', 's2', $query->expr()->eq('s1.parent', 's2.id'));
81
+
82
+        $deleteQuery = $this->connection->getQueryBuilder();
83
+        $deleteQuery->delete('share')
84
+            ->where($query->expr()->eq('id', $deleteQuery->createParameter('share')));
85
+
86
+        $result = $query->execute();
87
+        while ($row = $result->fetch()) {
88
+            if (!$this->isMember($row['group'], $row['user'])) {
89
+                $deletedEntries += $deleteQuery->setParameter('share', (int) $row['id'])
90
+                    ->execute();
91
+            }
92
+        }
93
+        $result->closeCursor();
94
+
95
+        if ($deletedEntries) {
96
+            $output->info('Removed ' . $deletedEntries . ' shares where user is not a member of the group anymore');
97
+        }
98
+    }
99
+
100
+    /**
101
+     * @param string $gid
102
+     * @param string $uid
103
+     * @return bool
104
+     */
105
+    protected function isMember($gid, $uid) {
106
+        if (isset($this->memberships[$gid][$uid])) {
107
+            return $this->memberships[$gid][$uid];
108
+        }
109
+
110
+        $isMember = $this->groupManager->isInGroup($uid, $gid);
111
+        if (!isset($this->memberships[$gid])) {
112
+            $this->memberships[$gid] = [];
113
+        }
114
+        $this->memberships[$gid][$uid] = $isMember;
115
+
116
+        return $isMember;
117
+    }
118 118
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -93,7 +93,7 @@
 block discarded – undo
93 93
 		$result->closeCursor();
94 94
 
95 95
 		if ($deletedEntries) {
96
-			$output->info('Removed ' . $deletedEntries . ' shares where user is not a member of the group anymore');
96
+			$output->info('Removed '.$deletedEntries.' shares where user is not a member of the group anymore');
97 97
 		}
98 98
 	}
99 99
 
Please login to merge, or discard this patch.
lib/private/Repair/Preview.php 2 patches
Indentation   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -28,21 +28,21 @@
 block discarded – undo
28 28
 
29 29
 class Preview implements IRepairStep {
30 30
 
31
-	public function getName() {
32
-		return 'Cleaning-up broken previews';
33
-	}
31
+    public function getName() {
32
+        return 'Cleaning-up broken previews';
33
+    }
34 34
 
35
-	public function run(IOutput $out) {
36
-		$view = new View('/');
37
-		$children = $view->getDirectoryContent('/');
35
+    public function run(IOutput $out) {
36
+        $view = new View('/');
37
+        $children = $view->getDirectoryContent('/');
38 38
 
39
-		foreach ($children as $child) {
40
-			if ($view->is_dir($child->getPath())) {
41
-				$thumbnailsFolder = $child->getPath() . '/thumbnails';
42
-				if ($view->is_dir($thumbnailsFolder)) {
43
-					$view->rmdir($thumbnailsFolder);
44
-				}
45
-			}
46
-		}
47
-	}
39
+        foreach ($children as $child) {
40
+            if ($view->is_dir($child->getPath())) {
41
+                $thumbnailsFolder = $child->getPath() . '/thumbnails';
42
+                if ($view->is_dir($thumbnailsFolder)) {
43
+                    $view->rmdir($thumbnailsFolder);
44
+                }
45
+            }
46
+        }
47
+    }
48 48
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -38,7 +38,7 @@
 block discarded – undo
38 38
 
39 39
 		foreach ($children as $child) {
40 40
 			if ($view->is_dir($child->getPath())) {
41
-				$thumbnailsFolder = $child->getPath() . '/thumbnails';
41
+				$thumbnailsFolder = $child->getPath().'/thumbnails';
42 42
 				if ($view->is_dir($thumbnailsFolder)) {
43 43
 					$view->rmdir($thumbnailsFolder);
44 44
 				}
Please login to merge, or discard this patch.
lib/private/Repair/FillETags.php 1 patch
Indentation   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -29,29 +29,29 @@
 block discarded – undo
29 29
 
30 30
 class FillETags implements IRepairStep {
31 31
 
32
-	/** @var \OCP\IDBConnection */
33
-	protected $connection;
34
-
35
-	/**
36
-	 * @param \OCP\IDBConnection $connection
37
-	 */
38
-	public function __construct($connection) {
39
-		$this->connection = $connection;
40
-	}
41
-
42
-	public function getName() {
43
-		return 'Generate ETags for file where no ETag is present.';
44
-	}
45
-
46
-	public function run(IOutput $output) {
47
-		$qb = $this->connection->getQueryBuilder();
48
-		$qb->update('filecache')
49
-			->set('etag', $qb->expr()->literal('xxx'))
50
-			->where($qb->expr()->eq('etag', $qb->expr()->literal('')))
51
-			->orWhere($qb->expr()->isNull('etag'));
52
-
53
-		$result = $qb->execute();
54
-		$output->info("ETags have been fixed for $result files/folders.");
55
-	}
32
+    /** @var \OCP\IDBConnection */
33
+    protected $connection;
34
+
35
+    /**
36
+     * @param \OCP\IDBConnection $connection
37
+     */
38
+    public function __construct($connection) {
39
+        $this->connection = $connection;
40
+    }
41
+
42
+    public function getName() {
43
+        return 'Generate ETags for file where no ETag is present.';
44
+    }
45
+
46
+    public function run(IOutput $output) {
47
+        $qb = $this->connection->getQueryBuilder();
48
+        $qb->update('filecache')
49
+            ->set('etag', $qb->expr()->literal('xxx'))
50
+            ->where($qb->expr()->eq('etag', $qb->expr()->literal('')))
51
+            ->orWhere($qb->expr()->isNull('etag'));
52
+
53
+        $result = $qb->execute();
54
+        $output->info("ETags have been fixed for $result files/folders.");
55
+    }
56 56
 }
57 57
 
Please login to merge, or discard this patch.
lib/private/Repair/CleanTags.php 2 patches
Indentation   +167 added lines, -167 removed lines patch added patch discarded remove patch
@@ -37,171 +37,171 @@
 block discarded – undo
37 37
  */
38 38
 class CleanTags implements IRepairStep {
39 39
 
40
-	/** @var IDBConnection */
41
-	protected $connection;
42
-
43
-	/** @var IUserManager */
44
-	protected $userManager;
45
-
46
-	protected $deletedTags = 0;
47
-
48
-	/**
49
-	 * @param IDBConnection $connection
50
-	 * @param IUserManager $userManager
51
-	 */
52
-	public function __construct(IDBConnection $connection, IUserManager $userManager) {
53
-		$this->connection = $connection;
54
-		$this->userManager = $userManager;
55
-	}
56
-
57
-	/**
58
-	 * @return string
59
-	 */
60
-	public function getName() {
61
-		return 'Clean tags and favorites';
62
-	}
63
-
64
-	/**
65
-	 * Updates the configuration after running an update
66
-	 */
67
-	public function run(IOutput $output) {
68
-		$this->deleteOrphanTags($output);
69
-		$this->deleteOrphanFileEntries($output);
70
-		$this->deleteOrphanTagEntries($output);
71
-		$this->deleteOrphanCategoryEntries($output);
72
-	}
73
-
74
-	/**
75
-	 * Delete tags for deleted users
76
-	 */
77
-	protected function deleteOrphanTags(IOutput $output) {
78
-		$offset = 0;
79
-		while ($this->checkTags($offset)) {
80
-			$offset += 50;
81
-		}
82
-
83
-		$output->info(sprintf('%d tags of deleted users have been removed.', $this->deletedTags));
84
-	}
85
-
86
-	protected function checkTags($offset) {
87
-		$query = $this->connection->getQueryBuilder();
88
-		$query->select('uid')
89
-			->from('vcategory')
90
-			->groupBy('uid')
91
-			->orderBy('uid')
92
-			->setMaxResults(50)
93
-			->setFirstResult($offset);
94
-		$result = $query->execute();
95
-
96
-		$users = [];
97
-		$hadResults = false;
98
-		while ($row = $result->fetch()) {
99
-			$hadResults = true;
100
-			if (!$this->userManager->userExists($row['uid'])) {
101
-				$users[] = $row['uid'];
102
-			}
103
-		}
104
-		$result->closeCursor();
105
-
106
-		if (!$hadResults) {
107
-			// No more tags, stop looping
108
-			return false;
109
-		}
110
-
111
-		if (!empty($users)) {
112
-			$query = $this->connection->getQueryBuilder();
113
-			$query->delete('vcategory')
114
-				->where($query->expr()->in('uid', $query->createNamedParameter($users, IQueryBuilder::PARAM_STR_ARRAY)));
115
-			$this->deletedTags += $query->execute();
116
-		}
117
-		return true;
118
-	}
119
-
120
-	/**
121
-	 * Delete tag entries for deleted files
122
-	 */
123
-	protected function deleteOrphanFileEntries(IOutput $output) {
124
-		$this->deleteOrphanEntries(
125
-			$output,
126
-			'%d tags for delete files have been removed.',
127
-			'vcategory_to_object', 'objid',
128
-			'filecache', 'fileid', 'path_hash'
129
-		);
130
-	}
131
-
132
-	/**
133
-	 * Delete tag entries for deleted tags
134
-	 */
135
-	protected function deleteOrphanTagEntries(IOutput $output) {
136
-		$this->deleteOrphanEntries(
137
-			$output,
138
-			'%d tag entries for deleted tags have been removed.',
139
-			'vcategory_to_object', 'categoryid',
140
-			'vcategory', 'id', 'uid'
141
-		);
142
-	}
143
-
144
-	/**
145
-	 * Delete tags that have no entries
146
-	 */
147
-	protected function deleteOrphanCategoryEntries(IOutput $output) {
148
-		$this->deleteOrphanEntries(
149
-			$output,
150
-			'%d tags with no entries have been removed.',
151
-			'vcategory', 'id',
152
-			'vcategory_to_object', 'categoryid', 'type'
153
-		);
154
-	}
155
-
156
-	/**
157
-	 * Deletes all entries from $deleteTable that do not have a matching entry in $sourceTable
158
-	 *
159
-	 * A query joins $deleteTable.$deleteId = $sourceTable.$sourceId and checks
160
-	 * whether $sourceNullColumn is null. If it is null, the entry in $deleteTable
161
-	 * is being deleted.
162
-	 *
163
-	 * @param string $repairInfo
164
-	 * @param string $deleteTable
165
-	 * @param string $deleteId
166
-	 * @param string $sourceTable
167
-	 * @param string $sourceId
168
-	 * @param string $sourceNullColumn	If this column is null in the source table,
169
-	 * 								the entry is deleted in the $deleteTable
170
-	 */
171
-	protected function deleteOrphanEntries(IOutput $output, $repairInfo, $deleteTable, $deleteId, $sourceTable, $sourceId, $sourceNullColumn) {
172
-		$qb = $this->connection->getQueryBuilder();
173
-
174
-		$qb->select('d.' . $deleteId)
175
-			->from($deleteTable, 'd')
176
-			->leftJoin('d', $sourceTable, 's', $qb->expr()->eq('d.' . $deleteId, ' s.' . $sourceId))
177
-			->where(
178
-				$qb->expr()->eq('d.type', $qb->expr()->literal('files'))
179
-			)
180
-			->andWhere(
181
-				$qb->expr()->isNull('s.' . $sourceNullColumn)
182
-			);
183
-		$result = $qb->execute();
184
-
185
-		$orphanItems = array();
186
-		while ($row = $result->fetch()) {
187
-			$orphanItems[] = (int) $row[$deleteId];
188
-		}
189
-
190
-		if (!empty($orphanItems)) {
191
-			$orphanItemsBatch = array_chunk($orphanItems, 200);
192
-			foreach ($orphanItemsBatch as $items) {
193
-				$qb->delete($deleteTable)
194
-					->where(
195
-						$qb->expr()->eq('type', $qb->expr()->literal('files'))
196
-					)
197
-					->andWhere($qb->expr()->in($deleteId, $qb->createParameter('ids')));
198
-				$qb->setParameter('ids', $items, IQueryBuilder::PARAM_INT_ARRAY);
199
-				$qb->execute();
200
-			}
201
-		}
202
-
203
-		if ($repairInfo) {
204
-			$output->info(sprintf($repairInfo, sizeof($orphanItems)));
205
-		}
206
-	}
40
+    /** @var IDBConnection */
41
+    protected $connection;
42
+
43
+    /** @var IUserManager */
44
+    protected $userManager;
45
+
46
+    protected $deletedTags = 0;
47
+
48
+    /**
49
+     * @param IDBConnection $connection
50
+     * @param IUserManager $userManager
51
+     */
52
+    public function __construct(IDBConnection $connection, IUserManager $userManager) {
53
+        $this->connection = $connection;
54
+        $this->userManager = $userManager;
55
+    }
56
+
57
+    /**
58
+     * @return string
59
+     */
60
+    public function getName() {
61
+        return 'Clean tags and favorites';
62
+    }
63
+
64
+    /**
65
+     * Updates the configuration after running an update
66
+     */
67
+    public function run(IOutput $output) {
68
+        $this->deleteOrphanTags($output);
69
+        $this->deleteOrphanFileEntries($output);
70
+        $this->deleteOrphanTagEntries($output);
71
+        $this->deleteOrphanCategoryEntries($output);
72
+    }
73
+
74
+    /**
75
+     * Delete tags for deleted users
76
+     */
77
+    protected function deleteOrphanTags(IOutput $output) {
78
+        $offset = 0;
79
+        while ($this->checkTags($offset)) {
80
+            $offset += 50;
81
+        }
82
+
83
+        $output->info(sprintf('%d tags of deleted users have been removed.', $this->deletedTags));
84
+    }
85
+
86
+    protected function checkTags($offset) {
87
+        $query = $this->connection->getQueryBuilder();
88
+        $query->select('uid')
89
+            ->from('vcategory')
90
+            ->groupBy('uid')
91
+            ->orderBy('uid')
92
+            ->setMaxResults(50)
93
+            ->setFirstResult($offset);
94
+        $result = $query->execute();
95
+
96
+        $users = [];
97
+        $hadResults = false;
98
+        while ($row = $result->fetch()) {
99
+            $hadResults = true;
100
+            if (!$this->userManager->userExists($row['uid'])) {
101
+                $users[] = $row['uid'];
102
+            }
103
+        }
104
+        $result->closeCursor();
105
+
106
+        if (!$hadResults) {
107
+            // No more tags, stop looping
108
+            return false;
109
+        }
110
+
111
+        if (!empty($users)) {
112
+            $query = $this->connection->getQueryBuilder();
113
+            $query->delete('vcategory')
114
+                ->where($query->expr()->in('uid', $query->createNamedParameter($users, IQueryBuilder::PARAM_STR_ARRAY)));
115
+            $this->deletedTags += $query->execute();
116
+        }
117
+        return true;
118
+    }
119
+
120
+    /**
121
+     * Delete tag entries for deleted files
122
+     */
123
+    protected function deleteOrphanFileEntries(IOutput $output) {
124
+        $this->deleteOrphanEntries(
125
+            $output,
126
+            '%d tags for delete files have been removed.',
127
+            'vcategory_to_object', 'objid',
128
+            'filecache', 'fileid', 'path_hash'
129
+        );
130
+    }
131
+
132
+    /**
133
+     * Delete tag entries for deleted tags
134
+     */
135
+    protected function deleteOrphanTagEntries(IOutput $output) {
136
+        $this->deleteOrphanEntries(
137
+            $output,
138
+            '%d tag entries for deleted tags have been removed.',
139
+            'vcategory_to_object', 'categoryid',
140
+            'vcategory', 'id', 'uid'
141
+        );
142
+    }
143
+
144
+    /**
145
+     * Delete tags that have no entries
146
+     */
147
+    protected function deleteOrphanCategoryEntries(IOutput $output) {
148
+        $this->deleteOrphanEntries(
149
+            $output,
150
+            '%d tags with no entries have been removed.',
151
+            'vcategory', 'id',
152
+            'vcategory_to_object', 'categoryid', 'type'
153
+        );
154
+    }
155
+
156
+    /**
157
+     * Deletes all entries from $deleteTable that do not have a matching entry in $sourceTable
158
+     *
159
+     * A query joins $deleteTable.$deleteId = $sourceTable.$sourceId and checks
160
+     * whether $sourceNullColumn is null. If it is null, the entry in $deleteTable
161
+     * is being deleted.
162
+     *
163
+     * @param string $repairInfo
164
+     * @param string $deleteTable
165
+     * @param string $deleteId
166
+     * @param string $sourceTable
167
+     * @param string $sourceId
168
+     * @param string $sourceNullColumn	If this column is null in the source table,
169
+     * 								the entry is deleted in the $deleteTable
170
+     */
171
+    protected function deleteOrphanEntries(IOutput $output, $repairInfo, $deleteTable, $deleteId, $sourceTable, $sourceId, $sourceNullColumn) {
172
+        $qb = $this->connection->getQueryBuilder();
173
+
174
+        $qb->select('d.' . $deleteId)
175
+            ->from($deleteTable, 'd')
176
+            ->leftJoin('d', $sourceTable, 's', $qb->expr()->eq('d.' . $deleteId, ' s.' . $sourceId))
177
+            ->where(
178
+                $qb->expr()->eq('d.type', $qb->expr()->literal('files'))
179
+            )
180
+            ->andWhere(
181
+                $qb->expr()->isNull('s.' . $sourceNullColumn)
182
+            );
183
+        $result = $qb->execute();
184
+
185
+        $orphanItems = array();
186
+        while ($row = $result->fetch()) {
187
+            $orphanItems[] = (int) $row[$deleteId];
188
+        }
189
+
190
+        if (!empty($orphanItems)) {
191
+            $orphanItemsBatch = array_chunk($orphanItems, 200);
192
+            foreach ($orphanItemsBatch as $items) {
193
+                $qb->delete($deleteTable)
194
+                    ->where(
195
+                        $qb->expr()->eq('type', $qb->expr()->literal('files'))
196
+                    )
197
+                    ->andWhere($qb->expr()->in($deleteId, $qb->createParameter('ids')));
198
+                $qb->setParameter('ids', $items, IQueryBuilder::PARAM_INT_ARRAY);
199
+                $qb->execute();
200
+            }
201
+        }
202
+
203
+        if ($repairInfo) {
204
+            $output->info(sprintf($repairInfo, sizeof($orphanItems)));
205
+        }
206
+    }
207 207
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -171,14 +171,14 @@
 block discarded – undo
171 171
 	protected function deleteOrphanEntries(IOutput $output, $repairInfo, $deleteTable, $deleteId, $sourceTable, $sourceId, $sourceNullColumn) {
172 172
 		$qb = $this->connection->getQueryBuilder();
173 173
 
174
-		$qb->select('d.' . $deleteId)
174
+		$qb->select('d.'.$deleteId)
175 175
 			->from($deleteTable, 'd')
176
-			->leftJoin('d', $sourceTable, 's', $qb->expr()->eq('d.' . $deleteId, ' s.' . $sourceId))
176
+			->leftJoin('d', $sourceTable, 's', $qb->expr()->eq('d.'.$deleteId, ' s.'.$sourceId))
177 177
 			->where(
178 178
 				$qb->expr()->eq('d.type', $qb->expr()->literal('files'))
179 179
 			)
180 180
 			->andWhere(
181
-				$qb->expr()->isNull('s.' . $sourceNullColumn)
181
+				$qb->expr()->isNull('s.'.$sourceNullColumn)
182 182
 			);
183 183
 		$result = $qb->execute();
184 184
 
Please login to merge, or discard this patch.
lib/private/Repair/DropOldJobs.php 2 patches
Indentation   +47 added lines, -47 removed lines patch added patch discarded remove patch
@@ -30,59 +30,59 @@
 block discarded – undo
30 30
 
31 31
 class DropOldJobs implements IRepairStep {
32 32
 
33
-	/** @var IJobList */
34
-	protected $jobList;
33
+    /** @var IJobList */
34
+    protected $jobList;
35 35
 
36
-	/**
37
-	 * @param IJobList $jobList
38
-	 */
39
-	public function __construct(IJobList $jobList) {
40
-		$this->jobList = $jobList;
41
-	}
36
+    /**
37
+     * @param IJobList $jobList
38
+     */
39
+    public function __construct(IJobList $jobList) {
40
+        $this->jobList = $jobList;
41
+    }
42 42
 
43
-	/**
44
-	 * Returns the step's name
45
-	 *
46
-	 * @return string
47
-	 */
48
-	public function getName() {
49
-		return 'Drop old background jobs';
50
-	}
43
+    /**
44
+     * Returns the step's name
45
+     *
46
+     * @return string
47
+     */
48
+    public function getName() {
49
+        return 'Drop old background jobs';
50
+    }
51 51
 
52
-	/**
53
-	 * Run repair step.
54
-	 * Must throw exception on error.
55
-	 *
56
-	 * @throws \Exception in case of failure
57
-	 */
58
-	public function run(IOutput $output) {
59
-		$oldJobs = $this->oldJobs();
60
-		foreach($oldJobs as $job) {
61
-			if($this->jobList->has($job['class'], $job['arguments'])) {
62
-				$this->jobList->remove($job['class'], $job['arguments']);
63
-			}
64
-		}
65
-	}
52
+    /**
53
+     * Run repair step.
54
+     * Must throw exception on error.
55
+     *
56
+     * @throws \Exception in case of failure
57
+     */
58
+    public function run(IOutput $output) {
59
+        $oldJobs = $this->oldJobs();
60
+        foreach($oldJobs as $job) {
61
+            if($this->jobList->has($job['class'], $job['arguments'])) {
62
+                $this->jobList->remove($job['class'], $job['arguments']);
63
+            }
64
+        }
65
+    }
66 66
 
67
-	/**
68
-	 * returns a list of old jobs as an associative array with keys 'class' and
69
-	 * 'arguments'.
70
-	 *
71
-	 * @return array
72
-	 */
73
-	public function oldJobs() {
74
-		return [
75
-			['class' => 'OC_Cache_FileGlobalGC', 'arguments' => null],
76
-			['class' => 'OC\Cache\FileGlobalGC', 'arguments' => null],
77
-			['class' => 'OCA\Files\BackgroundJob\DeleteOrphanedTagsJob', 'arguments' => null],
67
+    /**
68
+     * returns a list of old jobs as an associative array with keys 'class' and
69
+     * 'arguments'.
70
+     *
71
+     * @return array
72
+     */
73
+    public function oldJobs() {
74
+        return [
75
+            ['class' => 'OC_Cache_FileGlobalGC', 'arguments' => null],
76
+            ['class' => 'OC\Cache\FileGlobalGC', 'arguments' => null],
77
+            ['class' => 'OCA\Files\BackgroundJob\DeleteOrphanedTagsJob', 'arguments' => null],
78 78
 
79
-			['class' => 'OCA\Files_sharing\Lib\DeleteOrphanedSharesJob', 'arguments' => null],
80
-			['class' => 'OCA\Files_sharing\ExpireSharesJob', 'arguments' => null],
79
+            ['class' => 'OCA\Files_sharing\Lib\DeleteOrphanedSharesJob', 'arguments' => null],
80
+            ['class' => 'OCA\Files_sharing\ExpireSharesJob', 'arguments' => null],
81 81
 
82
-			['class' => 'OCA\user_ldap\lib\Jobs', 'arguments' => null],
83
-			['class' => '\OCA\User_LDAP\Jobs\CleanUp', 'arguments' => null],
84
-		];
85
-	}
82
+            ['class' => 'OCA\user_ldap\lib\Jobs', 'arguments' => null],
83
+            ['class' => '\OCA\User_LDAP\Jobs\CleanUp', 'arguments' => null],
84
+        ];
85
+    }
86 86
 
87 87
 
88 88
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -57,8 +57,8 @@
 block discarded – undo
57 57
 	 */
58 58
 	public function run(IOutput $output) {
59 59
 		$oldJobs = $this->oldJobs();
60
-		foreach($oldJobs as $job) {
61
-			if($this->jobList->has($job['class'], $job['arguments'])) {
60
+		foreach ($oldJobs as $job) {
61
+			if ($this->jobList->has($job['class'], $job['arguments'])) {
62 62
 				$this->jobList->remove($job['class'], $job['arguments']);
63 63
 			}
64 64
 		}
Please login to merge, or discard this patch.
lib/private/Repair/UpdateOutdatedOcsIds.php 2 patches
Indentation   +60 added lines, -60 removed lines patch added patch discarded remove patch
@@ -36,71 +36,71 @@
 block discarded – undo
36 36
  * @package OC\Repair
37 37
  */
38 38
 class UpdateOutdatedOcsIds implements IRepairStep {
39
-	/** @var IConfig */
40
-	private $config;
39
+    /** @var IConfig */
40
+    private $config;
41 41
 
42
-	/**
43
-	 * @param IConfig $config
44
-	 */
45
-	public function __construct(IConfig $config) {
46
-		$this->config = $config;
47
-	}
42
+    /**
43
+     * @param IConfig $config
44
+     */
45
+    public function __construct(IConfig $config) {
46
+        $this->config = $config;
47
+    }
48 48
 
49
-	/**
50
-	 * {@inheritdoc}
51
-	 */
52
-	public function getName() {
53
-		return 'Repair outdated OCS IDs';
54
-	}
49
+    /**
50
+     * {@inheritdoc}
51
+     */
52
+    public function getName() {
53
+        return 'Repair outdated OCS IDs';
54
+    }
55 55
 
56
-	/**
57
-	 * @param string $appName
58
-	 * @param string $oldId
59
-	 * @param string $newId
60
-	 * @return bool True if updated, false otherwise
61
-	 */
62
-	public function fixOcsId($appName, $oldId, $newId) {
63
-		$existingId = $this->config->getAppValue($appName, 'ocsid');
56
+    /**
57
+     * @param string $appName
58
+     * @param string $oldId
59
+     * @param string $newId
60
+     * @return bool True if updated, false otherwise
61
+     */
62
+    public function fixOcsId($appName, $oldId, $newId) {
63
+        $existingId = $this->config->getAppValue($appName, 'ocsid');
64 64
 
65
-		if($existingId === $oldId) {
66
-			$this->config->setAppValue($appName, 'ocsid', $newId);
67
-			return true;
68
-		}
65
+        if($existingId === $oldId) {
66
+            $this->config->setAppValue($appName, 'ocsid', $newId);
67
+            return true;
68
+        }
69 69
 
70
-		return false;
71
-	}
70
+        return false;
71
+    }
72 72
 
73
-	/**
74
-	 * {@inheritdoc}
75
-	 */
76
-	public function run(IOutput $output) {
77
-		$appsToUpdate = [
78
-			'contacts' => [
79
-				'old' => '166044',
80
-				'new' => '168708',
81
-			],
82
-			'calendar' => [
83
-				'old' => '166043',
84
-				'new' => '168707',
85
-			],
86
-			'bookmarks' => [
87
-				'old' => '166042',
88
-				'new' => '168710',
89
-			],
90
-			'search_lucene' => [
91
-				'old' => '166057',
92
-				'new' => '168709',
93
-			],
94
-			'documents' => [
95
-				'old' => '166045',
96
-				'new' => '168711',
97
-			]
98
-		];
73
+    /**
74
+     * {@inheritdoc}
75
+     */
76
+    public function run(IOutput $output) {
77
+        $appsToUpdate = [
78
+            'contacts' => [
79
+                'old' => '166044',
80
+                'new' => '168708',
81
+            ],
82
+            'calendar' => [
83
+                'old' => '166043',
84
+                'new' => '168707',
85
+            ],
86
+            'bookmarks' => [
87
+                'old' => '166042',
88
+                'new' => '168710',
89
+            ],
90
+            'search_lucene' => [
91
+                'old' => '166057',
92
+                'new' => '168709',
93
+            ],
94
+            'documents' => [
95
+                'old' => '166045',
96
+                'new' => '168711',
97
+            ]
98
+        ];
99 99
 
100
-		foreach($appsToUpdate as $appName => $ids) {
101
-			if ($this->fixOcsId($appName, $ids['old'], $ids['new'])) {
102
-				$output->info("Fixed invalid $appName OCS id");
103
-			}
104
-		}
105
-	}
100
+        foreach($appsToUpdate as $appName => $ids) {
101
+            if ($this->fixOcsId($appName, $ids['old'], $ids['new'])) {
102
+                $output->info("Fixed invalid $appName OCS id");
103
+            }
104
+        }
105
+    }
106 106
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -62,7 +62,7 @@  discard block
 block discarded – undo
62 62
 	public function fixOcsId($appName, $oldId, $newId) {
63 63
 		$existingId = $this->config->getAppValue($appName, 'ocsid');
64 64
 
65
-		if($existingId === $oldId) {
65
+		if ($existingId === $oldId) {
66 66
 			$this->config->setAppValue($appName, 'ocsid', $newId);
67 67
 			return true;
68 68
 		}
@@ -97,7 +97,7 @@  discard block
 block discarded – undo
97 97
 			]
98 98
 		];
99 99
 
100
-		foreach($appsToUpdate as $appName => $ids) {
100
+		foreach ($appsToUpdate as $appName => $ids) {
101 101
 			if ($this->fixOcsId($appName, $ids['old'], $ids['new'])) {
102 102
 				$output->info("Fixed invalid $appName OCS id");
103 103
 			}
Please login to merge, or discard this patch.
lib/private/Repair/RemoveGetETagEntries.php 2 patches
Indentation   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -29,30 +29,30 @@
 block discarded – undo
29 29
 
30 30
 class RemoveGetETagEntries implements IRepairStep {
31 31
 
32
-	/**
33
-	 * @var IDBConnection
34
-	 */
35
-	protected $connection;
36
-
37
-	/**
38
-	 * @param IDBConnection $connection
39
-	 */
40
-	public function __construct(IDBConnection $connection) {
41
-		$this->connection = $connection;
42
-	}
43
-
44
-	public function getName() {
45
-		return 'Remove getetag entries in properties table';
46
-	}
47
-
48
-	/**
49
-	 * Removes all entries with the key "{DAV:}getetag" from the table properties
50
-	 */
51
-	public function run(IOutput $out) {
52
-		$sql = 'DELETE FROM `*PREFIX*properties`'
53
-			. ' WHERE `propertyname` = ?';
54
-		$deletedRows = $this->connection->executeUpdate($sql, ['{DAV:}getetag']);
55
-
56
-		$out->info('Removed ' . $deletedRows . ' unneeded "{DAV:}getetag" entries from properties table.');
57
-	}
32
+    /**
33
+     * @var IDBConnection
34
+     */
35
+    protected $connection;
36
+
37
+    /**
38
+     * @param IDBConnection $connection
39
+     */
40
+    public function __construct(IDBConnection $connection) {
41
+        $this->connection = $connection;
42
+    }
43
+
44
+    public function getName() {
45
+        return 'Remove getetag entries in properties table';
46
+    }
47
+
48
+    /**
49
+     * Removes all entries with the key "{DAV:}getetag" from the table properties
50
+     */
51
+    public function run(IOutput $out) {
52
+        $sql = 'DELETE FROM `*PREFIX*properties`'
53
+            . ' WHERE `propertyname` = ?';
54
+        $deletedRows = $this->connection->executeUpdate($sql, ['{DAV:}getetag']);
55
+
56
+        $out->info('Removed ' . $deletedRows . ' unneeded "{DAV:}getetag" entries from properties table.');
57
+    }
58 58
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -53,6 +53,6 @@
 block discarded – undo
53 53
 			. ' WHERE `propertyname` = ?';
54 54
 		$deletedRows = $this->connection->executeUpdate($sql, ['{DAV:}getetag']);
55 55
 
56
-		$out->info('Removed ' . $deletedRows . ' unneeded "{DAV:}getetag" entries from properties table.');
56
+		$out->info('Removed '.$deletedRows.' unneeded "{DAV:}getetag" entries from properties table.');
57 57
 	}
58 58
 }
Please login to merge, or discard this patch.