Passed
Push — develop ( ecbe19...f5d3ab )
by Jens
02:58
created
cloudcontrol/library/storage/Repository.php 2 patches
Indentation   +343 added lines, -343 removed lines patch added patch discarded remove patch
@@ -21,134 +21,134 @@  discard block
 block discarded – undo
21 21
  */
22 22
 class Repository
23 23
 {
24
-    protected $storagePath;
25
-
26
-    protected $fileBasedSubsets = array('sitemap', 'applicationComponents', 'documentTypes', 'bricks', 'imageSet', 'images', 'files', 'users');
27
-
28
-    protected $sitemap;
29
-    protected $sitemapChanges = false;
30
-
31
-    protected $applicationComponents;
32
-    protected $applicationComponentsChanges = false;
33
-
34
-    protected $documentTypes;
35
-    protected $documentTypesChanges = false;
36
-
37
-    protected $bricks;
38
-    protected $bricksChanges = false;
39
-
40
-    protected $imageSet;
41
-    protected $imageSetChanges = false;
42
-
43
-    protected $images;
44
-    protected $imagesChanges = false;
45
-
46
-    protected $files;
47
-    protected $filesChanges = false;
48
-
49
-    protected $users;
50
-    protected $usersChanges = false;
51
-
52
-    protected $contentDbHandle;
53
-
54
-    /**
55
-     * Repository constructor.
56
-     * @param $storagePath
57
-     * @throws \Exception
58
-     */
59
-    public function __construct($storagePath)
60
-    {
61
-        $storagePath = realpath($storagePath);
62
-        if (is_dir($storagePath) && $storagePath !== false) {
63
-            $this->storagePath = $storagePath;
64
-        } else {
65
-            throw new \Exception('Repository not yet initialized.');
66
-        }
67
-    }
68
-
69
-    /**
70
-     * Creates the folder in which to create all storage related files
71
-     *
72
-     * @param $storagePath
73
-     * @return bool
74
-     */
75
-    public static function create($storagePath)
76
-    {
77
-        return mkdir($storagePath);
78
-    }
79
-
80
-    /**
81
-     * Initiates default storage
82
-     * @throws \Exception
83
-     */
84
-    public function init()
85
-    {
86
-        $storageDefaultPath = realpath('../library/cc/install/_storage.json');
87
-        $contentSqlPath = realpath('../library/cc/install/content.sql');
88
-
89
-        $this->initConfigStorage($storageDefaultPath);
90
-        $this->initContentDb($contentSqlPath);
91
-
92
-        $this->save();
93
-    }
94
-
95
-    /**
96
-     * Load filebased subset and return it's contents
97
-     *
98
-     * @param $name
99
-     * @return mixed|string
100
-     * @throws \Exception
101
-     */
102
-    public function __get($name)
103
-    {
104
-        if (isset($this->$name)) {
105
-            if (in_array($name, $this->fileBasedSubsets)) {
106
-                return $this->$name;
107
-            } else {
108
-                throw new \Exception('Trying to get undefined property from Repository: ' . $name);
109
-            }
110
-        } else {
111
-            if (in_array($name, $this->fileBasedSubsets)) {
112
-                return $this->loadSubset($name);
113
-            } else {
114
-                throw new \Exception('Trying to get undefined property from Repository: ' . $name);
115
-            }
116
-        }
117
-    }
118
-
119
-    /**
120
-     * Set filebased subset contents
121
-     * @param $name
122
-     * @param $value
123
-     * @throws \Exception
124
-     */
125
-    public function __set($name, $value)
126
-    {
127
-        if (in_array($name, $this->fileBasedSubsets)) {
128
-            $this->$name = $value;
129
-            $changes = $name . 'Changes';
130
-            $this->$changes = true;
131
-        } else {
132
-            throw new \Exception('Trying to persist unknown subset in repository: ' . $name . ' <br /><pre>' . print_r($value, true) . '</pre>');
133
-        }
134
-    }
135
-
136
-    /**
137
-     * Persist all subsets
138
-     */
139
-    public function save()
140
-    {
141
-        array_map(function ($value) {
142
-        	$this->saveSubset($value);
24
+	protected $storagePath;
25
+
26
+	protected $fileBasedSubsets = array('sitemap', 'applicationComponents', 'documentTypes', 'bricks', 'imageSet', 'images', 'files', 'users');
27
+
28
+	protected $sitemap;
29
+	protected $sitemapChanges = false;
30
+
31
+	protected $applicationComponents;
32
+	protected $applicationComponentsChanges = false;
33
+
34
+	protected $documentTypes;
35
+	protected $documentTypesChanges = false;
36
+
37
+	protected $bricks;
38
+	protected $bricksChanges = false;
39
+
40
+	protected $imageSet;
41
+	protected $imageSetChanges = false;
42
+
43
+	protected $images;
44
+	protected $imagesChanges = false;
45
+
46
+	protected $files;
47
+	protected $filesChanges = false;
48
+
49
+	protected $users;
50
+	protected $usersChanges = false;
51
+
52
+	protected $contentDbHandle;
53
+
54
+	/**
55
+	 * Repository constructor.
56
+	 * @param $storagePath
57
+	 * @throws \Exception
58
+	 */
59
+	public function __construct($storagePath)
60
+	{
61
+		$storagePath = realpath($storagePath);
62
+		if (is_dir($storagePath) && $storagePath !== false) {
63
+			$this->storagePath = $storagePath;
64
+		} else {
65
+			throw new \Exception('Repository not yet initialized.');
66
+		}
67
+	}
68
+
69
+	/**
70
+	 * Creates the folder in which to create all storage related files
71
+	 *
72
+	 * @param $storagePath
73
+	 * @return bool
74
+	 */
75
+	public static function create($storagePath)
76
+	{
77
+		return mkdir($storagePath);
78
+	}
79
+
80
+	/**
81
+	 * Initiates default storage
82
+	 * @throws \Exception
83
+	 */
84
+	public function init()
85
+	{
86
+		$storageDefaultPath = realpath('../library/cc/install/_storage.json');
87
+		$contentSqlPath = realpath('../library/cc/install/content.sql');
88
+
89
+		$this->initConfigStorage($storageDefaultPath);
90
+		$this->initContentDb($contentSqlPath);
91
+
92
+		$this->save();
93
+	}
94
+
95
+	/**
96
+	 * Load filebased subset and return it's contents
97
+	 *
98
+	 * @param $name
99
+	 * @return mixed|string
100
+	 * @throws \Exception
101
+	 */
102
+	public function __get($name)
103
+	{
104
+		if (isset($this->$name)) {
105
+			if (in_array($name, $this->fileBasedSubsets)) {
106
+				return $this->$name;
107
+			} else {
108
+				throw new \Exception('Trying to get undefined property from Repository: ' . $name);
109
+			}
110
+		} else {
111
+			if (in_array($name, $this->fileBasedSubsets)) {
112
+				return $this->loadSubset($name);
113
+			} else {
114
+				throw new \Exception('Trying to get undefined property from Repository: ' . $name);
115
+			}
116
+		}
117
+	}
118
+
119
+	/**
120
+	 * Set filebased subset contents
121
+	 * @param $name
122
+	 * @param $value
123
+	 * @throws \Exception
124
+	 */
125
+	public function __set($name, $value)
126
+	{
127
+		if (in_array($name, $this->fileBasedSubsets)) {
128
+			$this->$name = $value;
129
+			$changes = $name . 'Changes';
130
+			$this->$changes = true;
131
+		} else {
132
+			throw new \Exception('Trying to persist unknown subset in repository: ' . $name . ' <br /><pre>' . print_r($value, true) . '</pre>');
133
+		}
134
+	}
135
+
136
+	/**
137
+	 * Persist all subsets
138
+	 */
139
+	public function save()
140
+	{
141
+		array_map(function ($value) {
142
+			$this->saveSubset($value);
143 143
 		}, $this->fileBasedSubsets);
144
-    }
145
-
146
-    /**
147
-     * Persist subset to disk
148
-     * @param $subset
149
-     */
150
-    protected function saveSubset($subset)
151
-    {
144
+	}
145
+
146
+	/**
147
+	 * Persist subset to disk
148
+	 * @param $subset
149
+	 */
150
+	protected function saveSubset($subset)
151
+	{
152 152
 		$changes = $subset . 'Changes';
153 153
 		if ($this->$changes === true) {
154 154
 			$json = json_encode($this->$subset, JSON_PRETTY_PRINT);
@@ -157,89 +157,89 @@  discard block
 block discarded – undo
157 157
 
158 158
 			$this->$changes = false;
159 159
 		}
160
-    }
161
-
162
-    /**
163
-     * Load subset from disk
164
-     * @param $subset
165
-     * @return mixed|string
166
-     */
167
-    protected function loadSubset($subset)
168
-    {
169
-        $subsetStoragePath = $this->storagePath . DIRECTORY_SEPARATOR . $subset . '.json';
170
-        $json = file_get_contents($subsetStoragePath);
171
-        $json = json_decode($json);
172
-        $this->$subset = $json;
173
-        return $json;
174
-    }
175
-
176
-    /**
177
-     * @param $contentSqlPath
178
-     */
179
-    protected function initContentDb($contentSqlPath)
180
-    {
181
-        $db = $this->getContentDbHandle();
182
-        $sql = file_get_contents($contentSqlPath);
183
-        $db->exec($sql);
184
-    }
185
-
186
-    /**
187
-     * @param $storageDefaultPath
188
-     */
189
-    protected function initConfigStorage($storageDefaultPath)
190
-    {
191
-        $json = file_get_contents($storageDefaultPath);
192
-        $json = json_decode($json);
193
-        $this->sitemap = $json->sitemap;
194
-        $this->sitemapChanges = true;
195
-        $this->applicationComponents = $json->applicationComponents;
196
-        $this->applicationComponentsChanges = true;
197
-        $this->documentTypes = $json->documentTypes;
198
-        $this->documentTypesChanges = true;
199
-        $this->bricks = $json->bricks;
200
-        $this->bricksChanges = true;
201
-        $this->imageSet = $json->imageSet;
202
-        $this->imageSetChanges = true;
203
-        $this->images = $json->images;
204
-        $this->imagesChanges = true;
205
-        $this->files = $json->files;
206
-        $this->filesChanges = true;
207
-        $this->users = $json->users;
208
-        $this->usersChanges = true;
209
-    }
210
-
211
-    /**
212
-     * @return \PDO
213
-     */
214
-    public function getContentDbHandle()
215
-    {
216
-        if ($this->contentDbHandle === null) {
217
-            $this->contentDbHandle = new \PDO('sqlite:' . $this->storagePath . DIRECTORY_SEPARATOR . 'content.db');
218
-        }
219
-        return $this->contentDbHandle;
220
-    }
221
-
222
-    /**
223
-     * Get all documents
224
-     * @return array
225
-     */
226
-    public function getDocuments()
227
-    {
228
-        return $this->getDocumentsByPath('/');
229
-    }
230
-
231
-    /**
232
-     * Get all documents and folders in a certain path
233
-     * @param $folderPath
234
-     * @return array
235
-     * @throws \Exception
236
-     */
237
-    public function getDocumentsByPath($folderPath)
238
-    {
239
-        $db = $this->getContentDbHandle();
240
-        $folderPathWithWildcard = $folderPath . '%';
241
-
242
-        $stmt = $this->getDbStatement('
160
+	}
161
+
162
+	/**
163
+	 * Load subset from disk
164
+	 * @param $subset
165
+	 * @return mixed|string
166
+	 */
167
+	protected function loadSubset($subset)
168
+	{
169
+		$subsetStoragePath = $this->storagePath . DIRECTORY_SEPARATOR . $subset . '.json';
170
+		$json = file_get_contents($subsetStoragePath);
171
+		$json = json_decode($json);
172
+		$this->$subset = $json;
173
+		return $json;
174
+	}
175
+
176
+	/**
177
+	 * @param $contentSqlPath
178
+	 */
179
+	protected function initContentDb($contentSqlPath)
180
+	{
181
+		$db = $this->getContentDbHandle();
182
+		$sql = file_get_contents($contentSqlPath);
183
+		$db->exec($sql);
184
+	}
185
+
186
+	/**
187
+	 * @param $storageDefaultPath
188
+	 */
189
+	protected function initConfigStorage($storageDefaultPath)
190
+	{
191
+		$json = file_get_contents($storageDefaultPath);
192
+		$json = json_decode($json);
193
+		$this->sitemap = $json->sitemap;
194
+		$this->sitemapChanges = true;
195
+		$this->applicationComponents = $json->applicationComponents;
196
+		$this->applicationComponentsChanges = true;
197
+		$this->documentTypes = $json->documentTypes;
198
+		$this->documentTypesChanges = true;
199
+		$this->bricks = $json->bricks;
200
+		$this->bricksChanges = true;
201
+		$this->imageSet = $json->imageSet;
202
+		$this->imageSetChanges = true;
203
+		$this->images = $json->images;
204
+		$this->imagesChanges = true;
205
+		$this->files = $json->files;
206
+		$this->filesChanges = true;
207
+		$this->users = $json->users;
208
+		$this->usersChanges = true;
209
+	}
210
+
211
+	/**
212
+	 * @return \PDO
213
+	 */
214
+	public function getContentDbHandle()
215
+	{
216
+		if ($this->contentDbHandle === null) {
217
+			$this->contentDbHandle = new \PDO('sqlite:' . $this->storagePath . DIRECTORY_SEPARATOR . 'content.db');
218
+		}
219
+		return $this->contentDbHandle;
220
+	}
221
+
222
+	/**
223
+	 * Get all documents
224
+	 * @return array
225
+	 */
226
+	public function getDocuments()
227
+	{
228
+		return $this->getDocumentsByPath('/');
229
+	}
230
+
231
+	/**
232
+	 * Get all documents and folders in a certain path
233
+	 * @param $folderPath
234
+	 * @return array
235
+	 * @throws \Exception
236
+	 */
237
+	public function getDocumentsByPath($folderPath)
238
+	{
239
+		$db = $this->getContentDbHandle();
240
+		$folderPathWithWildcard = $folderPath . '%';
241
+
242
+		$stmt = $this->getDbStatement('
243 243
             SELECT *
244 244
               FROM documents
245 245
              WHERE `path` LIKE ' . $db->quote($folderPathWithWildcard) . '
@@ -248,56 +248,56 @@  discard block
 block discarded – undo
248 248
           ORDER BY `type` DESC, `path` ASC
249 249
         ');
250 250
 
251
-        $documents = $stmt->fetchAll(\PDO::FETCH_CLASS, '\library\storage\Document');
252
-        foreach ($documents as $key => $document) {
253
-            if ($document->type === 'folder') {
254
-                $document->dbHandle = $db;
255
-                $documents[$key] = $document;
256
-            }
257
-        }
258
-        return $documents;
259
-    }
260
-
261
-
262
-    /**
263
-     * @param $path
264
-     * @return bool|Document
265
-     */
266
-    public function getDocumentContainerByPath($path)
267
-    {
268
-        $document = $this->getDocumentByPath($path);
269
-        if ($document === false) {
270
-            return false;
271
-        }
272
-        $slugLength = strlen($document->slug);
273
-        $containerPath = substr($path, 0, -$slugLength);
274
-        if ($containerPath === '/') {
275
-            return $this->getRootFolder();
276
-        }
277
-        if (substr($containerPath, -1) === '/'){
251
+		$documents = $stmt->fetchAll(\PDO::FETCH_CLASS, '\library\storage\Document');
252
+		foreach ($documents as $key => $document) {
253
+			if ($document->type === 'folder') {
254
+				$document->dbHandle = $db;
255
+				$documents[$key] = $document;
256
+			}
257
+		}
258
+		return $documents;
259
+	}
260
+
261
+
262
+	/**
263
+	 * @param $path
264
+	 * @return bool|Document
265
+	 */
266
+	public function getDocumentContainerByPath($path)
267
+	{
268
+		$document = $this->getDocumentByPath($path);
269
+		if ($document === false) {
270
+			return false;
271
+		}
272
+		$slugLength = strlen($document->slug);
273
+		$containerPath = substr($path, 0, -$slugLength);
274
+		if ($containerPath === '/') {
275
+			return $this->getRootFolder();
276
+		}
277
+		if (substr($containerPath, -1) === '/'){
278 278
 			$containerPath = substr($containerPath, 0, -1);
279 279
 		}
280
-        $containerFolder = $this->getDocumentByPath($containerPath);
281
-        return $containerFolder;
282
-    }
283
-
284
-    /**
285
-     * @param $path
286
-     * @return bool|Document
287
-     */
288
-    public function getDocumentByPath($path)
289
-    {
290
-        $db = $this->getContentDbHandle();
291
-        $document = $this->fetchDocument('
280
+		$containerFolder = $this->getDocumentByPath($containerPath);
281
+		return $containerFolder;
282
+	}
283
+
284
+	/**
285
+	 * @param $path
286
+	 * @return bool|Document
287
+	 */
288
+	public function getDocumentByPath($path)
289
+	{
290
+		$db = $this->getContentDbHandle();
291
+		$document = $this->fetchDocument('
292 292
             SELECT *
293 293
               FROM documents
294 294
              WHERE path = ' . $db->quote($path) . '
295 295
         ');
296
-        if ($document instanceof Document && $document->type === 'folder') {
297
-            $document->dbHandle = $db;
298
-        }
299
-        return $document;
300
-    }
296
+		if ($document instanceof Document && $document->type === 'folder') {
297
+			$document->dbHandle = $db;
298
+		}
299
+		return $document;
300
+	}
301 301
 
302 302
 	/**
303 303
 	 * Returns the count of all documents stored in the db
@@ -319,70 +319,70 @@  discard block
 block discarded – undo
319 319
 	}
320 320
 
321 321
 	/**
322
-     * Return the results of the query as array of Documents
323
-     * @param $sql
324
-     * @return array
325
-     * @throws \Exception
326
-     */
327
-    protected function fetchAllDocuments($sql)
328
-    {
329
-        $stmt = $this->getDbStatement($sql);
330
-        return $stmt->fetchAll(\PDO::FETCH_CLASS, '\library\storage\Document');
331
-    }
332
-
333
-    /**
334
-     * Return the result of the query as Document
335
-     * @param $sql
336
-     * @return mixed
337
-     * @throws \Exception
338
-     */
339
-    protected function fetchDocument($sql)
340
-    {
341
-        $stmt = $this->getDbStatement($sql);
342
-        return $stmt->fetchObject('\library\storage\Document');
343
-    }
344
-
345
-    /**
346
-     * Prepare the sql statement
347
-     * @param $sql
348
-     * @return \PDOStatement
349
-     * @throws \Exception
350
-     */
351
-    protected function getDbStatement($sql)
352
-    {
353
-        $db = $this->getContentDbHandle();
354
-        $stmt = $db->query($sql);
355
-        if ($stmt === false) {
356
-            $errorInfo = $db->errorInfo();
357
-            $errorMsg = $errorInfo[2];
358
-            throw new \Exception('SQLite Exception: ' . $errorMsg . ' in SQL: <br /><pre>' . $sql . '</pre>');
359
-        }
360
-        return $stmt;
361
-    }
362
-
363
-    /**
364
-     * Create a (non-existent) root folder Document and return it
365
-     * @return Document
366
-     */
367
-    protected function getRootFolder()
368
-    {
369
-        $rootFolder = new Document();
370
-        $rootFolder->path = '/';
371
-        $rootFolder->type = 'folder';
372
-        return $rootFolder;
373
-    }
374
-
375
-    /**
376
-     * Save the document to the database
377
-     * @param Document $documentObject
378
-     * @return bool
379
-     * @throws \Exception
380
-     * @internal param $path
381
-     */
382
-    public function saveDocument($documentObject)
383
-    {
384
-        $db = $this->getContentDbHandle();
385
-        $stmt = $this->getDbStatement('
322
+	 * Return the results of the query as array of Documents
323
+	 * @param $sql
324
+	 * @return array
325
+	 * @throws \Exception
326
+	 */
327
+	protected function fetchAllDocuments($sql)
328
+	{
329
+		$stmt = $this->getDbStatement($sql);
330
+		return $stmt->fetchAll(\PDO::FETCH_CLASS, '\library\storage\Document');
331
+	}
332
+
333
+	/**
334
+	 * Return the result of the query as Document
335
+	 * @param $sql
336
+	 * @return mixed
337
+	 * @throws \Exception
338
+	 */
339
+	protected function fetchDocument($sql)
340
+	{
341
+		$stmt = $this->getDbStatement($sql);
342
+		return $stmt->fetchObject('\library\storage\Document');
343
+	}
344
+
345
+	/**
346
+	 * Prepare the sql statement
347
+	 * @param $sql
348
+	 * @return \PDOStatement
349
+	 * @throws \Exception
350
+	 */
351
+	protected function getDbStatement($sql)
352
+	{
353
+		$db = $this->getContentDbHandle();
354
+		$stmt = $db->query($sql);
355
+		if ($stmt === false) {
356
+			$errorInfo = $db->errorInfo();
357
+			$errorMsg = $errorInfo[2];
358
+			throw new \Exception('SQLite Exception: ' . $errorMsg . ' in SQL: <br /><pre>' . $sql . '</pre>');
359
+		}
360
+		return $stmt;
361
+	}
362
+
363
+	/**
364
+	 * Create a (non-existent) root folder Document and return it
365
+	 * @return Document
366
+	 */
367
+	protected function getRootFolder()
368
+	{
369
+		$rootFolder = new Document();
370
+		$rootFolder->path = '/';
371
+		$rootFolder->type = 'folder';
372
+		return $rootFolder;
373
+	}
374
+
375
+	/**
376
+	 * Save the document to the database
377
+	 * @param Document $documentObject
378
+	 * @return bool
379
+	 * @throws \Exception
380
+	 * @internal param $path
381
+	 */
382
+	public function saveDocument($documentObject)
383
+	{
384
+		$db = $this->getContentDbHandle();
385
+		$stmt = $this->getDbStatement('
386 386
             INSERT OR REPLACE INTO documents (`path`,`title`,`slug`,`type`,`documentType`,`documentTypeSlug`,`state`,`lastModificationDate`,`creationDate`,`lastModifiedBy`,`fields`,`bricks`,`dynamicBricks`)
387 387
             VALUES(
388 388
               ' . $db->quote($documentObject->path) . ',
@@ -400,37 +400,37 @@  discard block
 block discarded – undo
400 400
               ' . $db->quote(json_encode($documentObject->dynamicBricks)) . '
401 401
             )
402 402
         ');
403
-        $result = $stmt->execute();
404
-        return $result;
405
-    }
406
-
407
-    /**
408
-     * Delete the document from the database
409
-     * If it's a folder, also delete it's contents
410
-     * @param $path
411
-     * @throws \Exception
412
-     */
413
-    public function deleteDocumentByPath($path)
414
-    {
415
-        $db = $this->getContentDbHandle();
416
-        $documentToDelete = $this->getDocumentByPath($path);
417
-        if ($documentToDelete instanceof Document) {
418
-            if ($documentToDelete->type == 'document') {
419
-                $stmt = $this->getDbStatement('
403
+		$result = $stmt->execute();
404
+		return $result;
405
+	}
406
+
407
+	/**
408
+	 * Delete the document from the database
409
+	 * If it's a folder, also delete it's contents
410
+	 * @param $path
411
+	 * @throws \Exception
412
+	 */
413
+	public function deleteDocumentByPath($path)
414
+	{
415
+		$db = $this->getContentDbHandle();
416
+		$documentToDelete = $this->getDocumentByPath($path);
417
+		if ($documentToDelete instanceof Document) {
418
+			if ($documentToDelete->type == 'document') {
419
+				$stmt = $this->getDbStatement('
420 420
                     DELETE FROM documents
421 421
                           WHERE path = ' . $db->quote($path) . '
422 422
                 ');
423
-                $stmt->execute();
424
-            } elseif ($documentToDelete->type == 'folder') {
425
-                $folderPathWithWildcard = $path . '%';
426
-                $stmt = $this->getDbStatement('
423
+				$stmt->execute();
424
+			} elseif ($documentToDelete->type == 'folder') {
425
+				$folderPathWithWildcard = $path . '%';
426
+				$stmt = $this->getDbStatement('
427 427
                     DELETE FROM documents
428 428
                           WHERE (path LIKE ' . $db->quote($folderPathWithWildcard) . '
429 429
                             AND substr(`path`, ' . (strlen($path) + 1) . ', 1) = "/")
430 430
                             OR path = ' . $db->quote($path) . '
431 431
                 ');
432
-                $stmt->execute();
433
-            }
434
-        }
435
-    }
432
+				$stmt->execute();
433
+			}
434
+		}
435
+	}
436 436
 }
437 437
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +35 added lines, -35 removed lines patch added patch discarded remove patch
@@ -105,13 +105,13 @@  discard block
 block discarded – undo
105 105
             if (in_array($name, $this->fileBasedSubsets)) {
106 106
                 return $this->$name;
107 107
             } else {
108
-                throw new \Exception('Trying to get undefined property from Repository: ' . $name);
108
+                throw new \Exception('Trying to get undefined property from Repository: '.$name);
109 109
             }
110 110
         } else {
111 111
             if (in_array($name, $this->fileBasedSubsets)) {
112 112
                 return $this->loadSubset($name);
113 113
             } else {
114
-                throw new \Exception('Trying to get undefined property from Repository: ' . $name);
114
+                throw new \Exception('Trying to get undefined property from Repository: '.$name);
115 115
             }
116 116
         }
117 117
     }
@@ -126,10 +126,10 @@  discard block
 block discarded – undo
126 126
     {
127 127
         if (in_array($name, $this->fileBasedSubsets)) {
128 128
             $this->$name = $value;
129
-            $changes = $name . 'Changes';
129
+            $changes = $name.'Changes';
130 130
             $this->$changes = true;
131 131
         } else {
132
-            throw new \Exception('Trying to persist unknown subset in repository: ' . $name . ' <br /><pre>' . print_r($value, true) . '</pre>');
132
+            throw new \Exception('Trying to persist unknown subset in repository: '.$name.' <br /><pre>'.print_r($value, true).'</pre>');
133 133
         }
134 134
     }
135 135
 
@@ -138,7 +138,7 @@  discard block
 block discarded – undo
138 138
      */
139 139
     public function save()
140 140
     {
141
-        array_map(function ($value) {
141
+        array_map(function($value) {
142 142
         	$this->saveSubset($value);
143 143
 		}, $this->fileBasedSubsets);
144 144
     }
@@ -149,10 +149,10 @@  discard block
 block discarded – undo
149 149
      */
150 150
     protected function saveSubset($subset)
151 151
     {
152
-		$changes = $subset . 'Changes';
152
+		$changes = $subset.'Changes';
153 153
 		if ($this->$changes === true) {
154 154
 			$json = json_encode($this->$subset, JSON_PRETTY_PRINT);
155
-			$subsetStoragePath = $this->storagePath . DIRECTORY_SEPARATOR . $subset . '.json';
155
+			$subsetStoragePath = $this->storagePath.DIRECTORY_SEPARATOR.$subset.'.json';
156 156
 			file_put_contents($subsetStoragePath, $json);
157 157
 
158 158
 			$this->$changes = false;
@@ -166,7 +166,7 @@  discard block
 block discarded – undo
166 166
      */
167 167
     protected function loadSubset($subset)
168 168
     {
169
-        $subsetStoragePath = $this->storagePath . DIRECTORY_SEPARATOR . $subset . '.json';
169
+        $subsetStoragePath = $this->storagePath.DIRECTORY_SEPARATOR.$subset.'.json';
170 170
         $json = file_get_contents($subsetStoragePath);
171 171
         $json = json_decode($json);
172 172
         $this->$subset = $json;
@@ -214,7 +214,7 @@  discard block
 block discarded – undo
214 214
     public function getContentDbHandle()
215 215
     {
216 216
         if ($this->contentDbHandle === null) {
217
-            $this->contentDbHandle = new \PDO('sqlite:' . $this->storagePath . DIRECTORY_SEPARATOR . 'content.db');
217
+            $this->contentDbHandle = new \PDO('sqlite:'.$this->storagePath.DIRECTORY_SEPARATOR.'content.db');
218 218
         }
219 219
         return $this->contentDbHandle;
220 220
     }
@@ -237,14 +237,14 @@  discard block
 block discarded – undo
237 237
     public function getDocumentsByPath($folderPath)
238 238
     {
239 239
         $db = $this->getContentDbHandle();
240
-        $folderPathWithWildcard = $folderPath . '%';
240
+        $folderPathWithWildcard = $folderPath.'%';
241 241
 
242 242
         $stmt = $this->getDbStatement('
243 243
             SELECT *
244 244
               FROM documents
245
-             WHERE `path` LIKE ' . $db->quote($folderPathWithWildcard) . '
246
-               AND substr(`path`, ' . (strlen($folderPath) + 1) . ') NOT LIKE "%/%"
247
-               AND path != ' . $db->quote($folderPath) . '
245
+             WHERE `path` LIKE ' . $db->quote($folderPathWithWildcard).'
246
+               AND substr(`path`, ' . (strlen($folderPath) + 1).') NOT LIKE "%/%"
247
+               AND path != ' . $db->quote($folderPath).'
248 248
           ORDER BY `type` DESC, `path` ASC
249 249
         ');
250 250
 
@@ -274,7 +274,7 @@  discard block
 block discarded – undo
274 274
         if ($containerPath === '/') {
275 275
             return $this->getRootFolder();
276 276
         }
277
-        if (substr($containerPath, -1) === '/'){
277
+        if (substr($containerPath, -1) === '/') {
278 278
 			$containerPath = substr($containerPath, 0, -1);
279 279
 		}
280 280
         $containerFolder = $this->getDocumentByPath($containerPath);
@@ -291,7 +291,7 @@  discard block
 block discarded – undo
291 291
         $document = $this->fetchDocument('
292 292
             SELECT *
293 293
               FROM documents
294
-             WHERE path = ' . $db->quote($path) . '
294
+             WHERE path = ' . $db->quote($path).'
295 295
         ');
296 296
         if ($document instanceof Document && $document->type === 'folder') {
297 297
             $document->dbHandle = $db;
@@ -312,7 +312,7 @@  discard block
 block discarded – undo
312 312
 			 WHERE `type` != "folder"
313 313
 		');
314 314
 		$result = $stmt->fetch(\PDO::FETCH_ASSOC);
315
-		if (!is_array($result )) {
315
+		if (!is_array($result)) {
316 316
 			return 0;
317 317
 		}
318 318
 		return intval(current($result));
@@ -355,7 +355,7 @@  discard block
 block discarded – undo
355 355
         if ($stmt === false) {
356 356
             $errorInfo = $db->errorInfo();
357 357
             $errorMsg = $errorInfo[2];
358
-            throw new \Exception('SQLite Exception: ' . $errorMsg . ' in SQL: <br /><pre>' . $sql . '</pre>');
358
+            throw new \Exception('SQLite Exception: '.$errorMsg.' in SQL: <br /><pre>'.$sql.'</pre>');
359 359
         }
360 360
         return $stmt;
361 361
     }
@@ -385,19 +385,19 @@  discard block
 block discarded – undo
385 385
         $stmt = $this->getDbStatement('
386 386
             INSERT OR REPLACE INTO documents (`path`,`title`,`slug`,`type`,`documentType`,`documentTypeSlug`,`state`,`lastModificationDate`,`creationDate`,`lastModifiedBy`,`fields`,`bricks`,`dynamicBricks`)
387 387
             VALUES(
388
-              ' . $db->quote($documentObject->path) . ',
389
-              ' . $db->quote($documentObject->title) . ',
390
-              ' . $db->quote($documentObject->slug) . ',
391
-              ' . $db->quote($documentObject->type) . ',
392
-              ' . $db->quote($documentObject->documentType) . ',
393
-              ' . $db->quote($documentObject->documentTypeSlug) . ',
394
-              ' . $db->quote($documentObject->state) . ',
395
-              ' . $db->quote($documentObject->lastModificationDate) . ',
396
-              ' . $db->quote($documentObject->creationDate) . ',
397
-              ' . $db->quote($documentObject->lastModifiedBy) . ',
398
-              ' . $db->quote(json_encode($documentObject->fields)) . ',
399
-              ' . $db->quote(json_encode($documentObject->bricks)) . ',
400
-              ' . $db->quote(json_encode($documentObject->dynamicBricks)) . '
388
+              ' . $db->quote($documentObject->path).',
389
+              ' . $db->quote($documentObject->title).',
390
+              ' . $db->quote($documentObject->slug).',
391
+              ' . $db->quote($documentObject->type).',
392
+              ' . $db->quote($documentObject->documentType).',
393
+              ' . $db->quote($documentObject->documentTypeSlug).',
394
+              ' . $db->quote($documentObject->state).',
395
+              ' . $db->quote($documentObject->lastModificationDate).',
396
+              ' . $db->quote($documentObject->creationDate).',
397
+              ' . $db->quote($documentObject->lastModifiedBy).',
398
+              ' . $db->quote(json_encode($documentObject->fields)).',
399
+              ' . $db->quote(json_encode($documentObject->bricks)).',
400
+              ' . $db->quote(json_encode($documentObject->dynamicBricks)).'
401 401
             )
402 402
         ');
403 403
         $result = $stmt->execute();
@@ -418,16 +418,16 @@  discard block
 block discarded – undo
418 418
             if ($documentToDelete->type == 'document') {
419 419
                 $stmt = $this->getDbStatement('
420 420
                     DELETE FROM documents
421
-                          WHERE path = ' . $db->quote($path) . '
421
+                          WHERE path = ' . $db->quote($path).'
422 422
                 ');
423 423
                 $stmt->execute();
424 424
             } elseif ($documentToDelete->type == 'folder') {
425
-                $folderPathWithWildcard = $path . '%';
425
+                $folderPathWithWildcard = $path.'%';
426 426
                 $stmt = $this->getDbStatement('
427 427
                     DELETE FROM documents
428
-                          WHERE (path LIKE ' . $db->quote($folderPathWithWildcard) . '
429
-                            AND substr(`path`, ' . (strlen($path) + 1) . ', 1) = "/")
430
-                            OR path = ' . $db->quote($path) . '
428
+                          WHERE (path LIKE ' . $db->quote($folderPathWithWildcard).'
429
+                            AND substr(`path`, ' . (strlen($path) + 1).', 1) = "/")
430
+                            OR path = ' . $db->quote($path).'
431 431
                 ');
432 432
                 $stmt->execute();
433 433
             }
Please login to merge, or discard this patch.
cloudcontrol/library/storage/Document.php 2 patches
Indentation   +63 added lines, -63 removed lines patch added patch discarded remove patch
@@ -18,58 +18,58 @@  discard block
 block discarded – undo
18 18
  */
19 19
 class Document
20 20
 {
21
-    public $id;
22
-    public $path;
23
-    public $title;
24
-    public $slug;
25
-    public $type;
26
-    public $documentType;
27
-    public $documentTypeSlug;
28
-    public $state;
29
-    public $lastModificationDate;
30
-    public $creationDate;
31
-    public $lastModifiedBy;
32
-    protected $fields;
33
-    protected $bricks;
34
-    protected $dynamicBricks;
35
-    protected $content;
21
+	public $id;
22
+	public $path;
23
+	public $title;
24
+	public $slug;
25
+	public $type;
26
+	public $documentType;
27
+	public $documentTypeSlug;
28
+	public $state;
29
+	public $lastModificationDate;
30
+	public $creationDate;
31
+	public $lastModifiedBy;
32
+	protected $fields;
33
+	protected $bricks;
34
+	protected $dynamicBricks;
35
+	protected $content;
36 36
 
37
-    protected $dbHandle;
37
+	protected $dbHandle;
38 38
 
39
-    protected $jsonEncodedFields = array('fields', 'bricks', 'dynamicBricks');
40
-    protected $orderableFields = array('title', 'slug', 'type', 'documentType', 'documentTypeSlug', 'state', 'lastModificationDate', 'creationDate', 'lastModifiedBy');
39
+	protected $jsonEncodedFields = array('fields', 'bricks', 'dynamicBricks');
40
+	protected $orderableFields = array('title', 'slug', 'type', 'documentType', 'documentTypeSlug', 'state', 'lastModificationDate', 'creationDate', 'lastModifiedBy');
41 41
 
42
-    public function __get($name) {
43
-        if (in_array($name, $this->jsonEncodedFields)) {
44
-            if (is_string($this->$name)) {
45
-                return json_decode($this->$name);
46
-            } else {
47
-                return $this->$name;
48
-            }
49
-        } elseif ($name === 'content') {
50
-            if ($this->dbHandle === null) {
51
-                throw new \Exception('Document doesnt have a dbHandle handle. (path: ' . $this->path . ')');
52
-            } else {
53
-                if ($this->content === null) {
54
-                    return $this->getContent();
55
-                }
56
-            }
57
-        } elseif ($name === 'dbHandle') {
58
-            throw new \Exception('Trying to get protected property repository.');
59
-        }
60
-        return $this->$name;
61
-    }
42
+	public function __get($name) {
43
+		if (in_array($name, $this->jsonEncodedFields)) {
44
+			if (is_string($this->$name)) {
45
+				return json_decode($this->$name);
46
+			} else {
47
+				return $this->$name;
48
+			}
49
+		} elseif ($name === 'content') {
50
+			if ($this->dbHandle === null) {
51
+				throw new \Exception('Document doesnt have a dbHandle handle. (path: ' . $this->path . ')');
52
+			} else {
53
+				if ($this->content === null) {
54
+					return $this->getContent();
55
+				}
56
+			}
57
+		} elseif ($name === 'dbHandle') {
58
+			throw new \Exception('Trying to get protected property repository.');
59
+		}
60
+		return $this->$name;
61
+	}
62 62
 
63
-    public function __set($name, $value) {
64
-        if (in_array($name, $this->jsonEncodedFields)) {
65
-            $this->$name = json_encode($value);
66
-        } elseif ($name === 'content') {
67
-            // Dont do anything for now..
68
-            return;
69
-        }
63
+	public function __set($name, $value) {
64
+		if (in_array($name, $this->jsonEncodedFields)) {
65
+			$this->$name = json_encode($value);
66
+		} elseif ($name === 'content') {
67
+			// Dont do anything for now..
68
+			return;
69
+		}
70 70
 
71
-        $this->$name = $value;
72
-    }
71
+		$this->$name = $value;
72
+	}
73 73
 
74 74
 	/**
75 75
 	 * @param string $orderBy
@@ -78,10 +78,10 @@  discard block
 block discarded – undo
78 78
 	 * @return array
79 79
 	 * @throws \Exception
80 80
 	 */
81
-    public function getContent($orderBy = 'title', $order = 'ASC')
82
-    {
83
-        $folderPathWithWildcard = $this->path . '%';
84
-        $sql = '    SELECT *
81
+	public function getContent($orderBy = 'title', $order = 'ASC')
82
+	{
83
+		$folderPathWithWildcard = $this->path . '%';
84
+		$sql = '    SELECT *
85 85
                       FROM documents
86 86
                      WHERE `path` LIKE ' . $this->dbHandle->quote($folderPathWithWildcard) . '
87 87
                        AND substr(`path`, ' . (strlen($this->path) + 2) . ') NOT LIKE "%/%"
@@ -89,24 +89,24 @@  discard block
 block discarded – undo
89 89
                        AND path != ' . $this->dbHandle->quote($this->path) . '
90 90
                   ORDER BY ' . (in_array($orderBy, $this->orderableFields) ? $orderBy : 'title') . ' ' . ($order === 'ASC' ? 'ASC' : 'DESC') . '
91 91
                     ';
92
-        $stmt = $this->dbHandle->prepare($sql);
92
+		$stmt = $this->dbHandle->prepare($sql);
93 93
 		if ($stmt === false) {
94 94
 			$errorInfo = $this->dbHandle->errorInfo();
95 95
 			$errorMsg = $errorInfo[2];
96 96
 			throw new \Exception('SQLite Exception: ' . $errorMsg . ' in SQL: <br /><pre>' . $sql . '</pre>');
97 97
 		}
98
-        $stmt->bindColumn(':orderBy', $orderBy, \PDO::PARAM_STMT);
98
+		$stmt->bindColumn(':orderBy', $orderBy, \PDO::PARAM_STMT);
99 99
 		$stmt->execute();
100
-        $contents = $stmt->fetchAll(\PDO::FETCH_CLASS, '\library\storage\Document');
101
-        foreach ($contents as $key => $document) {
102
-            if ($document->type === 'folder') {
103
-                $document->dbHandle = $this->dbHandle;
104
-                $contents[$key] = $document;
105
-            }
106
-        }
107
-        $this->content = $contents;
108
-        return $this->content;
109
-    }
100
+		$contents = $stmt->fetchAll(\PDO::FETCH_CLASS, '\library\storage\Document');
101
+		foreach ($contents as $key => $document) {
102
+			if ($document->type === 'folder') {
103
+				$document->dbHandle = $this->dbHandle;
104
+				$contents[$key] = $document;
105
+			}
106
+		}
107
+		$this->content = $contents;
108
+		return $this->content;
109
+	}
110 110
 
111 111
 	/**
112 112
 	 * @return string
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -48,7 +48,7 @@  discard block
 block discarded – undo
48 48
             }
49 49
         } elseif ($name === 'content') {
50 50
             if ($this->dbHandle === null) {
51
-                throw new \Exception('Document doesnt have a dbHandle handle. (path: ' . $this->path . ')');
51
+                throw new \Exception('Document doesnt have a dbHandle handle. (path: '.$this->path.')');
52 52
             } else {
53 53
                 if ($this->content === null) {
54 54
                     return $this->getContent();
@@ -80,20 +80,20 @@  discard block
 block discarded – undo
80 80
 	 */
81 81
     public function getContent($orderBy = 'title', $order = 'ASC')
82 82
     {
83
-        $folderPathWithWildcard = $this->path . '%';
83
+        $folderPathWithWildcard = $this->path.'%';
84 84
         $sql = '    SELECT *
85 85
                       FROM documents
86
-                     WHERE `path` LIKE ' . $this->dbHandle->quote($folderPathWithWildcard) . '
87
-                       AND substr(`path`, ' . (strlen($this->path) + 2) . ') NOT LIKE "%/%"
88
-                       AND substr(`path`, ' . (strlen($this->path) + 1) . ', 1) = "/"
89
-                       AND path != ' . $this->dbHandle->quote($this->path) . '
90
-                  ORDER BY ' . (in_array($orderBy, $this->orderableFields) ? $orderBy : 'title') . ' ' . ($order === 'ASC' ? 'ASC' : 'DESC') . '
86
+                     WHERE `path` LIKE ' . $this->dbHandle->quote($folderPathWithWildcard).'
87
+                       AND substr(`path`, ' . (strlen($this->path) + 2).') NOT LIKE "%/%"
88
+                       AND substr(`path`, ' . (strlen($this->path) + 1).', 1) = "/"
89
+                       AND path != ' . $this->dbHandle->quote($this->path).'
90
+                  ORDER BY ' . (in_array($orderBy, $this->orderableFields) ? $orderBy : 'title').' '.($order === 'ASC' ? 'ASC' : 'DESC').'
91 91
                     ';
92 92
         $stmt = $this->dbHandle->prepare($sql);
93 93
 		if ($stmt === false) {
94 94
 			$errorInfo = $this->dbHandle->errorInfo();
95 95
 			$errorMsg = $errorInfo[2];
96
-			throw new \Exception('SQLite Exception: ' . $errorMsg . ' in SQL: <br /><pre>' . $sql . '</pre>');
96
+			throw new \Exception('SQLite Exception: '.$errorMsg.' in SQL: <br /><pre>'.$sql.'</pre>');
97 97
 		}
98 98
         $stmt->bindColumn(':orderBy', $orderBy, \PDO::PARAM_STMT);
99 99
 		$stmt->execute();
@@ -113,7 +113,7 @@  discard block
 block discarded – undo
113 113
 	 */
114 114
 	public function __toString()
115 115
 	{
116
-		return 'Document:' . $this->title;
116
+		return 'Document:'.$this->title;
117 117
 	}
118 118
 
119 119
 
Please login to merge, or discard this patch.
cloudcontrol/library/search/indexer/TermCount.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -46,7 +46,7 @@  discard block
 block discarded – undo
46 46
 	protected function applyFilters($tokens)
47 47
 	{
48 48
 		foreach ($this->filters as $filterName) {
49
-			$filterClassName = '\library\search\filters\\' . $filterName;
49
+			$filterClassName = '\library\search\filters\\'.$filterName;
50 50
 			$filter = new $filterClassName($tokens);
51 51
 			$tokens = $filter->getFilterResults();
52 52
 		}
@@ -66,7 +66,7 @@  discard block
 block discarded – undo
66 66
 		foreach ($documentTermCount as $field => $countArray) {
67 67
 			$quotedField = $db->quote($field);
68 68
 			foreach ($countArray as $term => $count) {
69
-				$values[] = $quotedDocumentPath . ', ' . $db->quote($term) . ', ' . $db->quote($count) . ', ' . $quotedField;
69
+				$values[] = $quotedDocumentPath.', '.$db->quote($term).', '.$db->quote($count).', '.$quotedField;
70 70
 				$i += 1;
71 71
 				if ($i >= Indexer::SQLITE_MAX_COMPOUND_SELECT) {
72 72
 					$this->executeStoreDocumentTermCount($values, $sql, $db);
@@ -90,13 +90,13 @@  discard block
 block discarded – undo
90 90
 	 */
91 91
 	protected function executeStoreDocumentTermCount($values, $sql, $db)
92 92
 	{
93
-		$sql .= '(' . implode('),' . PHP_EOL . '(', $values) . ');';
93
+		$sql .= '('.implode('),'.PHP_EOL.'(', $values).');';
94 94
 
95 95
 		$stmt = $db->prepare($sql);
96 96
 		if ($stmt === false || !$stmt->execute()) {
97 97
 			$errorInfo = $db->errorInfo();
98 98
 			$errorMsg = $errorInfo[2];
99
-			throw new \Exception('SQLite Exception: ' . $errorMsg . ' in SQL: <br /><pre>' . $sql . '</pre>');
99
+			throw new \Exception('SQLite Exception: '.$errorMsg.' in SQL: <br /><pre>'.$sql.'</pre>');
100 100
 		}
101 101
 	}
102 102
 
Please login to merge, or discard this patch.