Passed
Push — master ( dc7e2f...19e521 )
by Julius
26:25 queued 13s
created
lib/private/Preview/BackgroundCleanupJob.php 2 patches
Indentation   +116 added lines, -116 removed lines patch added patch discarded remove patch
@@ -35,100 +35,100 @@  discard block
 block discarded – undo
35 35
 use OCP\IDBConnection;
36 36
 
37 37
 class BackgroundCleanupJob extends TimedJob {
38
-	/** @var IDBConnection */
39
-	private $connection;
40
-
41
-	/** @var Root */
42
-	private $previewFolder;
43
-
44
-	/** @var bool */
45
-	private $isCLI;
46
-
47
-	/** @var IMimeTypeLoader */
48
-	private $mimeTypeLoader;
49
-
50
-	public function __construct(ITimeFactory $timeFactory,
51
-								IDBConnection $connection,
52
-								Root $previewFolder,
53
-								IMimeTypeLoader $mimeTypeLoader,
54
-								bool $isCLI) {
55
-		parent::__construct($timeFactory);
56
-		// Run at most once an hour
57
-		$this->setInterval(3600);
58
-
59
-		$this->connection = $connection;
60
-		$this->previewFolder = $previewFolder;
61
-		$this->isCLI = $isCLI;
62
-		$this->mimeTypeLoader = $mimeTypeLoader;
63
-	}
64
-
65
-	public function run($argument) {
66
-		foreach ($this->getDeletedFiles() as $fileId) {
67
-			try {
68
-				$preview = $this->previewFolder->getFolder((string)$fileId);
69
-				$preview->delete();
70
-			} catch (NotFoundException $e) {
71
-				// continue
72
-			} catch (NotPermittedException $e) {
73
-				// continue
74
-			}
75
-		}
76
-	}
77
-
78
-	private function getDeletedFiles(): \Iterator {
79
-		yield from $this->getOldPreviewLocations();
80
-		yield from $this->getNewPreviewLocations();
81
-	}
82
-
83
-	private function getOldPreviewLocations(): \Iterator {
84
-		$qb = $this->connection->getQueryBuilder();
85
-		$qb->select('a.name')
86
-			->from('filecache', 'a')
87
-			->leftJoin('a', 'filecache', 'b', $qb->expr()->eq(
88
-				$qb->expr()->castColumn('a.name', IQueryBuilder::PARAM_INT), 'b.fileid'
89
-			))
90
-			->where(
91
-				$qb->expr()->isNull('b.fileid')
92
-			)->andWhere(
93
-				$qb->expr()->eq('a.parent', $qb->createNamedParameter($this->previewFolder->getId()))
94
-			)->andWhere(
95
-				$qb->expr()->like('a.name', $qb->createNamedParameter('__%'))
96
-			);
97
-
98
-		if (!$this->isCLI) {
99
-			$qb->setMaxResults(10);
100
-		}
101
-
102
-		$cursor = $qb->execute();
103
-
104
-		while ($row = $cursor->fetch()) {
105
-			yield $row['name'];
106
-		}
107
-
108
-		$cursor->closeCursor();
109
-	}
110
-
111
-	private function getNewPreviewLocations(): \Iterator {
112
-		$qb = $this->connection->getQueryBuilder();
113
-		$qb->select('path', 'mimetype')
114
-			->from('filecache')
115
-			->where($qb->expr()->eq('fileid', $qb->createNamedParameter($this->previewFolder->getId())));
116
-		$cursor = $qb->execute();
117
-		$data = $cursor->fetch();
118
-		$cursor->closeCursor();
119
-
120
-		if ($data === null) {
121
-			return [];
122
-		}
123
-
124
-		/*
38
+    /** @var IDBConnection */
39
+    private $connection;
40
+
41
+    /** @var Root */
42
+    private $previewFolder;
43
+
44
+    /** @var bool */
45
+    private $isCLI;
46
+
47
+    /** @var IMimeTypeLoader */
48
+    private $mimeTypeLoader;
49
+
50
+    public function __construct(ITimeFactory $timeFactory,
51
+                                IDBConnection $connection,
52
+                                Root $previewFolder,
53
+                                IMimeTypeLoader $mimeTypeLoader,
54
+                                bool $isCLI) {
55
+        parent::__construct($timeFactory);
56
+        // Run at most once an hour
57
+        $this->setInterval(3600);
58
+
59
+        $this->connection = $connection;
60
+        $this->previewFolder = $previewFolder;
61
+        $this->isCLI = $isCLI;
62
+        $this->mimeTypeLoader = $mimeTypeLoader;
63
+    }
64
+
65
+    public function run($argument) {
66
+        foreach ($this->getDeletedFiles() as $fileId) {
67
+            try {
68
+                $preview = $this->previewFolder->getFolder((string)$fileId);
69
+                $preview->delete();
70
+            } catch (NotFoundException $e) {
71
+                // continue
72
+            } catch (NotPermittedException $e) {
73
+                // continue
74
+            }
75
+        }
76
+    }
77
+
78
+    private function getDeletedFiles(): \Iterator {
79
+        yield from $this->getOldPreviewLocations();
80
+        yield from $this->getNewPreviewLocations();
81
+    }
82
+
83
+    private function getOldPreviewLocations(): \Iterator {
84
+        $qb = $this->connection->getQueryBuilder();
85
+        $qb->select('a.name')
86
+            ->from('filecache', 'a')
87
+            ->leftJoin('a', 'filecache', 'b', $qb->expr()->eq(
88
+                $qb->expr()->castColumn('a.name', IQueryBuilder::PARAM_INT), 'b.fileid'
89
+            ))
90
+            ->where(
91
+                $qb->expr()->isNull('b.fileid')
92
+            )->andWhere(
93
+                $qb->expr()->eq('a.parent', $qb->createNamedParameter($this->previewFolder->getId()))
94
+            )->andWhere(
95
+                $qb->expr()->like('a.name', $qb->createNamedParameter('__%'))
96
+            );
97
+
98
+        if (!$this->isCLI) {
99
+            $qb->setMaxResults(10);
100
+        }
101
+
102
+        $cursor = $qb->execute();
103
+
104
+        while ($row = $cursor->fetch()) {
105
+            yield $row['name'];
106
+        }
107
+
108
+        $cursor->closeCursor();
109
+    }
110
+
111
+    private function getNewPreviewLocations(): \Iterator {
112
+        $qb = $this->connection->getQueryBuilder();
113
+        $qb->select('path', 'mimetype')
114
+            ->from('filecache')
115
+            ->where($qb->expr()->eq('fileid', $qb->createNamedParameter($this->previewFolder->getId())));
116
+        $cursor = $qb->execute();
117
+        $data = $cursor->fetch();
118
+        $cursor->closeCursor();
119
+
120
+        if ($data === null) {
121
+            return [];
122
+        }
123
+
124
+        /*
125 125
 		 * This lovely like is the result of the way the new previews are stored
126 126
 		 * We take the md5 of the name (fileid) and split the first 7 chars. That way
127 127
 		 * there are not a gazillion files in the root of the preview appdata.
128 128
 		 */
129
-		$like = $this->connection->escapeLikeParameter($data['path']) . '/_/_/_/_/_/_/_/%';
129
+        $like = $this->connection->escapeLikeParameter($data['path']) . '/_/_/_/_/_/_/_/%';
130 130
 
131
-		/*
131
+        /*
132 132
 		 * Deleting a file will not delete related previews right away.
133 133
 		 *
134 134
 		 * A delete request is usually an HTTP request.
@@ -143,31 +143,31 @@  discard block
 block discarded – undo
143 143
 		 *
144 144
 		 * If the related file is deleted, b.fileid will be null and the preview folder can be deleted.
145 145
 		 */
146
-		$qb = $this->connection->getQueryBuilder();
147
-		$qb->select('a.name')
148
-			->from('filecache', 'a')
149
-			->leftJoin('a', 'filecache', 'b', $qb->expr()->eq(
150
-				$qb->expr()->castColumn('a.name', IQueryBuilder::PARAM_INT), 'b.fileid'
151
-			))
152
-			->where(
153
-				$qb->expr()->andX(
154
-					$qb->expr()->eq('a.storage', $qb->createNamedParameter($this->previewFolder->getStorageId())),
155
-					$qb->expr()->isNull('b.fileid'),
156
-					$qb->expr()->like('a.path', $qb->createNamedParameter($like)),
157
-					$qb->expr()->eq('a.mimetype', $qb->createNamedParameter($this->mimeTypeLoader->getId('httpd/unix-directory')))
158
-				)
159
-			);
160
-
161
-		if (!$this->isCLI) {
162
-			$qb->setMaxResults(10);
163
-		}
164
-
165
-		$cursor = $qb->execute();
166
-
167
-		while ($row = $cursor->fetch()) {
168
-			yield $row['name'];
169
-		}
170
-
171
-		$cursor->closeCursor();
172
-	}
146
+        $qb = $this->connection->getQueryBuilder();
147
+        $qb->select('a.name')
148
+            ->from('filecache', 'a')
149
+            ->leftJoin('a', 'filecache', 'b', $qb->expr()->eq(
150
+                $qb->expr()->castColumn('a.name', IQueryBuilder::PARAM_INT), 'b.fileid'
151
+            ))
152
+            ->where(
153
+                $qb->expr()->andX(
154
+                    $qb->expr()->eq('a.storage', $qb->createNamedParameter($this->previewFolder->getStorageId())),
155
+                    $qb->expr()->isNull('b.fileid'),
156
+                    $qb->expr()->like('a.path', $qb->createNamedParameter($like)),
157
+                    $qb->expr()->eq('a.mimetype', $qb->createNamedParameter($this->mimeTypeLoader->getId('httpd/unix-directory')))
158
+                )
159
+            );
160
+
161
+        if (!$this->isCLI) {
162
+            $qb->setMaxResults(10);
163
+        }
164
+
165
+        $cursor = $qb->execute();
166
+
167
+        while ($row = $cursor->fetch()) {
168
+            yield $row['name'];
169
+        }
170
+
171
+        $cursor->closeCursor();
172
+    }
173 173
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -65,7 +65,7 @@  discard block
 block discarded – undo
65 65
 	public function run($argument) {
66 66
 		foreach ($this->getDeletedFiles() as $fileId) {
67 67
 			try {
68
-				$preview = $this->previewFolder->getFolder((string)$fileId);
68
+				$preview = $this->previewFolder->getFolder((string) $fileId);
69 69
 				$preview->delete();
70 70
 			} catch (NotFoundException $e) {
71 71
 				// continue
@@ -126,7 +126,7 @@  discard block
 block discarded – undo
126 126
 		 * We take the md5 of the name (fileid) and split the first 7 chars. That way
127 127
 		 * there are not a gazillion files in the root of the preview appdata.
128 128
 		 */
129
-		$like = $this->connection->escapeLikeParameter($data['path']) . '/_/_/_/_/_/_/_/%';
129
+		$like = $this->connection->escapeLikeParameter($data['path']).'/_/_/_/_/_/_/_/%';
130 130
 
131 131
 		/*
132 132
 		 * Deleting a file will not delete related previews right away.
Please login to merge, or discard this patch.