Passed
Push — master ( 4e76b5...cec725 )
by Morris
13:28 queued 17s
created
apps/dav/lib/Migration/RemoveOrphanEventsAndContacts.php 1 patch
Indentation   +51 added lines, -51 removed lines patch added patch discarded remove patch
@@ -30,65 +30,65 @@
 block discarded – undo
30 30
 
31 31
 class RemoveOrphanEventsAndContacts implements IRepairStep {
32 32
 
33
-	/** @var IDBConnection */
34
-	private $connection;
33
+    /** @var IDBConnection */
34
+    private $connection;
35 35
 
36
-	public function __construct(IDBConnection $connection) {
37
-		$this->connection = $connection;
38
-	}
36
+    public function __construct(IDBConnection $connection) {
37
+        $this->connection = $connection;
38
+    }
39 39
 
40
-	/**
41
-	 * @inheritdoc
42
-	 */
43
-	public function getName(): string {
44
-		return 'Clean up orphan event and contact data';
45
-	}
40
+    /**
41
+     * @inheritdoc
42
+     */
43
+    public function getName(): string {
44
+        return 'Clean up orphan event and contact data';
45
+    }
46 46
 
47
-	/**
48
-	 * @inheritdoc
49
-	 */
50
-	public function run(IOutput $output) {
51
-		$orphanItems = $this->removeOrphanChildren('calendarobjects', 'calendars',  'calendarid');
52
-		$output->info(sprintf('%d events without a calendar have been cleaned up', $orphanItems));
53
-		$orphanItems = $this->removeOrphanChildren('calendarobjects_props', 'calendarobjects',  'objectid');
54
-		$output->info(sprintf('%d properties without an events have been cleaned up', $orphanItems));
55
-		$orphanItems = $this->removeOrphanChildren('calendarchanges', 'calendars',  'calendarid');
56
-		$output->info(sprintf('%d changes without a calendar have been cleaned up', $orphanItems));
47
+    /**
48
+     * @inheritdoc
49
+     */
50
+    public function run(IOutput $output) {
51
+        $orphanItems = $this->removeOrphanChildren('calendarobjects', 'calendars',  'calendarid');
52
+        $output->info(sprintf('%d events without a calendar have been cleaned up', $orphanItems));
53
+        $orphanItems = $this->removeOrphanChildren('calendarobjects_props', 'calendarobjects',  'objectid');
54
+        $output->info(sprintf('%d properties without an events have been cleaned up', $orphanItems));
55
+        $orphanItems = $this->removeOrphanChildren('calendarchanges', 'calendars',  'calendarid');
56
+        $output->info(sprintf('%d changes without a calendar have been cleaned up', $orphanItems));
57 57
 
58
-		$orphanItems = $this->removeOrphanChildren('cards', 'addressbooks',  'addressbookid');
59
-		$output->info(sprintf('%d contacts without an addressbook have been cleaned up', $orphanItems));
60
-		$orphanItems = $this->removeOrphanChildren('cards_properties', 'cards',  'cardid');
61
-		$output->info(sprintf('%d properties without a contact have been cleaned up', $orphanItems));
62
-		$orphanItems = $this->removeOrphanChildren('addressbookchanges', 'addressbooks',  'addressbookid');
63
-		$output->info(sprintf('%d changes without an addressbook have been cleaned up', $orphanItems));
64
-	}
58
+        $orphanItems = $this->removeOrphanChildren('cards', 'addressbooks',  'addressbookid');
59
+        $output->info(sprintf('%d contacts without an addressbook have been cleaned up', $orphanItems));
60
+        $orphanItems = $this->removeOrphanChildren('cards_properties', 'cards',  'cardid');
61
+        $output->info(sprintf('%d properties without a contact have been cleaned up', $orphanItems));
62
+        $orphanItems = $this->removeOrphanChildren('addressbookchanges', 'addressbooks',  'addressbookid');
63
+        $output->info(sprintf('%d changes without an addressbook have been cleaned up', $orphanItems));
64
+    }
65 65
 
66
-	protected function removeOrphanChildren($childTable, $parentTable, $parentId): int {
67
-		$qb = $this->connection->getQueryBuilder();
66
+    protected function removeOrphanChildren($childTable, $parentTable, $parentId): int {
67
+        $qb = $this->connection->getQueryBuilder();
68 68
 
69
-		$qb->select('c.id')
70
-			->from($childTable, 'c')
71
-			->leftJoin('c', $parentTable, 'p', $qb->expr()->eq('c.' . $parentId, 'p.id'))
72
-			->where($qb->expr()->isNull('p.id'));
73
-		$result = $qb->execute();
69
+        $qb->select('c.id')
70
+            ->from($childTable, 'c')
71
+            ->leftJoin('c', $parentTable, 'p', $qb->expr()->eq('c.' . $parentId, 'p.id'))
72
+            ->where($qb->expr()->isNull('p.id'));
73
+        $result = $qb->execute();
74 74
 
75
-		$orphanItems = array();
76
-		while ($row = $result->fetch()) {
77
-			$orphanItems[] = (int) $row['id'];
78
-		}
79
-		$result->closeCursor();
75
+        $orphanItems = array();
76
+        while ($row = $result->fetch()) {
77
+            $orphanItems[] = (int) $row['id'];
78
+        }
79
+        $result->closeCursor();
80 80
 
81
-		if (!empty($orphanItems)) {
82
-			$qb->delete($childTable)
83
-				->where($qb->expr()->in('id', $qb->createParameter('ids')));
81
+        if (!empty($orphanItems)) {
82
+            $qb->delete($childTable)
83
+                ->where($qb->expr()->in('id', $qb->createParameter('ids')));
84 84
 
85
-			$orphanItemsBatch = array_chunk($orphanItems, 200);
86
-			foreach ($orphanItemsBatch as $items) {
87
-				$qb->setParameter('ids', $items, IQueryBuilder::PARAM_INT_ARRAY);
88
-				$qb->execute();
89
-			}
90
-		}
85
+            $orphanItemsBatch = array_chunk($orphanItems, 200);
86
+            foreach ($orphanItemsBatch as $items) {
87
+                $qb->setParameter('ids', $items, IQueryBuilder::PARAM_INT_ARRAY);
88
+                $qb->execute();
89
+            }
90
+        }
91 91
 
92
-		return count($orphanItems);
93
-	}
92
+        return count($orphanItems);
93
+    }
94 94
 }
Please login to merge, or discard this patch.