Passed
Branch develop (96efe9)
by Jens
02:38
created
src/storage/Repository.php 1 patch
Indentation   +174 added lines, -174 removed lines patch added patch discarded remove patch
@@ -152,7 +152,7 @@  discard block
 block discarded – undo
152 152
         $host = $this;
153 153
         array_map(function ($value) use ($host) {
154 154
             $host->saveSubset($value);
155
-		}, $this->fileBasedSubsets);
155
+        }, $this->fileBasedSubsets);
156 156
     }
157 157
 
158 158
     /**
@@ -161,18 +161,18 @@  discard block
 block discarded – undo
161 161
      */
162 162
     public function saveSubset($subset)
163 163
     {
164
-		$changes = $subset . 'Changes';
165
-		if ($this->$changes === true) {
164
+        $changes = $subset . 'Changes';
165
+        if ($this->$changes === true) {
166 166
             if (!defined('JSON_PRETTY_PRINT')) {
167 167
                 $json = json_encode($this->$subset);
168 168
             } else {
169 169
                 $json = json_encode($this->$subset, JSON_PRETTY_PRINT);
170 170
             }
171
-			$subsetStoragePath = $this->storagePath . DIRECTORY_SEPARATOR . $subset . '.json';
172
-			file_put_contents($subsetStoragePath, $json);
171
+            $subsetStoragePath = $this->storagePath . DIRECTORY_SEPARATOR . $subset . '.json';
172
+            file_put_contents($subsetStoragePath, $json);
173 173
 
174
-			$this->$changes = false;
175
-		}
174
+            $this->$changes = false;
175
+        }
176 176
     }
177 177
 
178 178
     /**
@@ -229,33 +229,33 @@  discard block
 block discarded – undo
229 229
         return $this->contentDbHandle;
230 230
     }
231 231
 
232
-	/**
233
-	 * Get all documents
234
-	 *
235
-	 * @param string $state
236
-	 *
237
-	 * @return array
238
-	 * @throws \Exception
239
-	 */
232
+    /**
233
+     * Get all documents
234
+     *
235
+     * @param string $state
236
+     *
237
+     * @return array
238
+     * @throws \Exception
239
+     */
240 240
     public function getDocuments($state = 'published')
241 241
     {
242
-		if (!in_array($state, Document::$DOCUMENT_STATES)) {
243
-			throw new \Exception('Unsupported document state: ' . $state);
244
-		}
242
+        if (!in_array($state, Document::$DOCUMENT_STATES)) {
243
+            throw new \Exception('Unsupported document state: ' . $state);
244
+        }
245 245
         return $this->getDocumentsByPath('/', $state);
246 246
     }
247 247
 
248
-	public function getDocumentsWithState($folderPath = '/')
249
-	{
250
-		$db = $this->getContentDbHandle();
251
-		$folderPathWithWildcard = $folderPath . '%';
248
+    public function getDocumentsWithState($folderPath = '/')
249
+    {
250
+        $db = $this->getContentDbHandle();
251
+        $folderPathWithWildcard = $folderPath . '%';
252 252
 
253
-		$ifRootIndex = 1;
254
-		if ($folderPath == '/') {
255
-			$ifRootIndex = 0;
256
-		}
253
+        $ifRootIndex = 1;
254
+        if ($folderPath == '/') {
255
+            $ifRootIndex = 0;
256
+        }
257 257
 
258
-		$sql = '
258
+        $sql = '
259 259
             SELECT documents_unpublished.*,
260 260
             	   IFNULL(documents_published.state,"unpublished") as state,
261 261
             	   IFNULL(documents_published.publicationDate,NULL) as publicationDate,
@@ -269,32 +269,32 @@  discard block
 block discarded – undo
269 269
                AND documents_unpublished.path != ' . $db->quote($folderPath) . '
270 270
           ORDER BY documents_unpublished.`type` DESC, documents_unpublished.`path` ASC
271 271
         ';
272
-		$stmt = $this->getDbStatement($sql);
273
-
274
-
275
-
276
-		$documents = $stmt->fetchAll(\PDO::FETCH_CLASS, '\CloudControl\Cms\storage\Document');
277
-		foreach ($documents as $key => $document) {
278
-			$documents = $this->setAssetsToDocumentFolders($document, $db, $documents, $key);
279
-		}
280
-		//dump($documents);
281
-		return $documents;
282
-	}
283
-
284
-	/**
285
-	 * Get all documents and folders in a certain path
286
-	 *
287
-	 * @param        $folderPath
288
-	 * @param string $state
289
-	 *
290
-	 * @return array
291
-	 * @throws \Exception
292
-	 */
272
+        $stmt = $this->getDbStatement($sql);
273
+
274
+
275
+
276
+        $documents = $stmt->fetchAll(\PDO::FETCH_CLASS, '\CloudControl\Cms\storage\Document');
277
+        foreach ($documents as $key => $document) {
278
+            $documents = $this->setAssetsToDocumentFolders($document, $db, $documents, $key);
279
+        }
280
+        //dump($documents);
281
+        return $documents;
282
+    }
283
+
284
+    /**
285
+     * Get all documents and folders in a certain path
286
+     *
287
+     * @param        $folderPath
288
+     * @param string $state
289
+     *
290
+     * @return array
291
+     * @throws \Exception
292
+     */
293 293
     public function getDocumentsByPath($folderPath, $state = 'published')
294 294
     {
295
-    	if (!in_array($state, Document::$DOCUMENT_STATES)) {
296
-    		throw new \Exception('Unsupported document state: ' . $state);
297
-		}
295
+        if (!in_array($state, Document::$DOCUMENT_STATES)) {
296
+            throw new \Exception('Unsupported document state: ' . $state);
297
+        }
298 298
         $db = $this->getContentDbHandle();
299 299
         $folderPathWithWildcard = $folderPath . '%';
300 300
 
@@ -308,7 +308,7 @@  discard block
 block discarded – undo
308 308
 
309 309
         $documents = $stmt->fetchAll(\PDO::FETCH_CLASS, '\CloudControl\Cms\storage\Document');
310 310
         foreach ($documents as $key => $document) {
311
-			$documents = $this->setAssetsToDocumentFolders($document, $db, $documents, $key);
311
+            $documents = $this->setAssetsToDocumentFolders($document, $db, $documents, $key);
312 312
         }
313 313
         return $documents;
314 314
     }
@@ -330,24 +330,24 @@  discard block
 block discarded – undo
330 330
             return $this->getRootFolder();
331 331
         }
332 332
         if (substr($containerPath, -1) === '/'){
333
-			$containerPath = substr($containerPath, 0, -1);
334
-		}
333
+            $containerPath = substr($containerPath, 0, -1);
334
+        }
335 335
         $containerFolder = $this->getDocumentByPath($containerPath, 'unpublished');
336 336
         return $containerFolder;
337 337
     }
338 338
 
339
-	/**
340
-	 * @param        $path
341
-	 * @param string $state
342
-	 *
343
-	 * @return bool|\CloudControl\Cms\storage\Document
344
-	 * @throws \Exception
345
-	 */
339
+    /**
340
+     * @param        $path
341
+     * @param string $state
342
+     *
343
+     * @return bool|\CloudControl\Cms\storage\Document
344
+     * @throws \Exception
345
+     */
346 346
     public function getDocumentByPath($path, $state = 'published')
347 347
     {
348
-		if (!in_array($state, Document::$DOCUMENT_STATES)) {
349
-			throw new \Exception('Unsupported document state: ' . $state);
350
-		}
348
+        if (!in_array($state, Document::$DOCUMENT_STATES)) {
349
+            throw new \Exception('Unsupported document state: ' . $state);
350
+        }
351 351
         $db = $this->getContentDbHandle();
352 352
         $document = $this->fetchDocument('
353 353
             SELECT *
@@ -361,87 +361,87 @@  discard block
 block discarded – undo
361 361
         return $document;
362 362
     }
363 363
 
364
-	/**
365
-	 * Returns the count of all documents stored in the db
366
-	 *
367
-	 * @param string $state
368
-	 *
369
-	 * @return int
370
-	 * @throws \Exception
371
-	 */
372
-	public function getTotalDocumentCount($state = 'published')
373
-	{
374
-		if (!in_array($state, Document::$DOCUMENT_STATES)) {
375
-			throw new \Exception('Unsupported document state: ' . $state);
376
-		}
377
-		$db = $this->getContentDbHandle();
378
-		$stmt = $db->query('
364
+    /**
365
+     * Returns the count of all documents stored in the db
366
+     *
367
+     * @param string $state
368
+     *
369
+     * @return int
370
+     * @throws \Exception
371
+     */
372
+    public function getTotalDocumentCount($state = 'published')
373
+    {
374
+        if (!in_array($state, Document::$DOCUMENT_STATES)) {
375
+            throw new \Exception('Unsupported document state: ' . $state);
376
+        }
377
+        $db = $this->getContentDbHandle();
378
+        $stmt = $db->query('
379 379
 			SELECT count(*)
380 380
 			  FROM documents_' . $state . '
381 381
 			 WHERE `type` != "folder"
382 382
 		');
383
-		$result = $stmt->fetch(\PDO::FETCH_ASSOC);
384
-		if (!is_array($result )) {
385
-			return 0;
386
-		}
387
-		return intval(current($result));
388
-	}
389
-
390
-	public function getPublishedDocumentsNoFolders()
391
-	{
392
-		$db = $this->getContentDbHandle();
393
-		$sql = '
383
+        $result = $stmt->fetch(\PDO::FETCH_ASSOC);
384
+        if (!is_array($result )) {
385
+            return 0;
386
+        }
387
+        return intval(current($result));
388
+    }
389
+
390
+    public function getPublishedDocumentsNoFolders()
391
+    {
392
+        $db = $this->getContentDbHandle();
393
+        $sql = '
394 394
 			SELECT *
395 395
 			  FROM documents_published
396 396
 			 WHERE `type` != "folder"
397 397
 		';
398
-		$stmt = $db->query($sql);
399
-		$result = $stmt->fetchAll(\PDO::FETCH_CLASS, '\CloudControl\Cms\storage\Document');
400
-		if ($stmt === false || !$stmt->execute()) {
401
-			$errorInfo = $db->errorInfo();
402
-			$errorMsg = $errorInfo[2];
403
-			throw new \Exception('SQLite Exception: ' . $errorMsg . ' in SQL: <br /><pre>' . $sql . '</pre>');
404
-		}
405
-		return $result;
406
-	}
407
-
408
-	private function publishOrUnpublishDocumentByPath($path, $publish = true) {
409
-		if ($publish) {
410
-			$sql = '
398
+        $stmt = $db->query($sql);
399
+        $result = $stmt->fetchAll(\PDO::FETCH_CLASS, '\CloudControl\Cms\storage\Document');
400
+        if ($stmt === false || !$stmt->execute()) {
401
+            $errorInfo = $db->errorInfo();
402
+            $errorMsg = $errorInfo[2];
403
+            throw new \Exception('SQLite Exception: ' . $errorMsg . ' in SQL: <br /><pre>' . $sql . '</pre>');
404
+        }
405
+        return $result;
406
+    }
407
+
408
+    private function publishOrUnpublishDocumentByPath($path, $publish = true) {
409
+        if ($publish) {
410
+            $sql = '
411 411
 				INSERT OR REPLACE INTO documents_published 
412 412
 					  (`id`,`path`,`title`,`slug`,`type`,`documentType`,`documentTypeSlug`,`state`,`lastModificationDate`,`creationDate`,`publicationDate`,`lastModifiedBy`,`fields`,`bricks`,`dynamicBricks`)
413 413
 				SELECT `id`,`path`,`title`,`slug`,`type`,`documentType`,`documentTypeSlug`,"published" as state,`lastModificationDate`,`creationDate`,' . time() . ' as publicationDate, `lastModifiedBy`,`fields`,`bricks`,`dynamicBricks`
414 414
 				  FROM documents_unpublished
415 415
 				 WHERE `path` = :path
416 416
 			';
417
-		} else {
418
-			$sql = 'DELETE FROM documents_published
417
+        } else {
418
+            $sql = 'DELETE FROM documents_published
419 419
 					  WHERE `path` = :path';
420
-		}
421
-		$db = $this->getContentDbHandle();
422
-		$stmt = $db->prepare($sql);
423
-		if ($stmt === false) {
424
-			$errorInfo = $db->errorInfo();
425
-			$errorMsg = $errorInfo[2];
426
-			throw new \Exception('SQLite Exception: ' . $errorMsg . ' in SQL: <br /><pre>' . $sql . '</pre>');
427
-		}
428
-		$stmt->bindValue(':path', $path);
429
-		$stmt->execute();
430
-	}
431
-
432
-	public function publishDocumentByPath($path)
433
-	{
434
-		$this->publishOrUnpublishDocumentByPath($path);
435
-	}
436
-
437
-	public function unpublishDocumentByPath($path)
438
-	{
439
-		$this->publishOrUnpublishDocumentByPath($path, false);
440
-	}
441
-
442
-	public function cleanPublishedDeletedDocuments()
443
-	{
444
-		$sql = '   DELETE FROM documents_published
420
+        }
421
+        $db = $this->getContentDbHandle();
422
+        $stmt = $db->prepare($sql);
423
+        if ($stmt === false) {
424
+            $errorInfo = $db->errorInfo();
425
+            $errorMsg = $errorInfo[2];
426
+            throw new \Exception('SQLite Exception: ' . $errorMsg . ' in SQL: <br /><pre>' . $sql . '</pre>');
427
+        }
428
+        $stmt->bindValue(':path', $path);
429
+        $stmt->execute();
430
+    }
431
+
432
+    public function publishDocumentByPath($path)
433
+    {
434
+        $this->publishOrUnpublishDocumentByPath($path);
435
+    }
436
+
437
+    public function unpublishDocumentByPath($path)
438
+    {
439
+        $this->publishOrUnpublishDocumentByPath($path, false);
440
+    }
441
+
442
+    public function cleanPublishedDeletedDocuments()
443
+    {
444
+        $sql = '   DELETE FROM documents_published
445 445
 						 WHERE documents_published.path IN (
446 446
 						SELECT documents_published.path
447 447
 						  FROM documents_published
@@ -449,11 +449,11 @@  discard block
 block discarded – undo
449 449
 							ON documents_unpublished.path = documents_published.path
450 450
 						 WHERE documents_unpublished.path IS NULL
451 451
 		)';
452
-		$stmt = $this->getDbStatement($sql);
453
-		$stmt->execute();
454
-	}
452
+        $stmt = $this->getDbStatement($sql);
453
+        $stmt->execute();
454
+    }
455 455
 
456
-	/**
456
+    /**
457 457
      * Return the results of the query as array of Documents
458 458
      * @param $sql
459 459
      * @return array
@@ -507,21 +507,21 @@  discard block
 block discarded – undo
507 507
         return $rootFolder;
508 508
     }
509 509
 
510
-	/**
511
-	 * Save the document to the database
512
-	 *
513
-	 * @param Document $documentObject
514
-	 * @param string   $state
515
-	 *
516
-	 * @return bool
517
-	 * @throws \Exception
518
-	 * @internal param $path
519
-	 */
510
+    /**
511
+     * Save the document to the database
512
+     *
513
+     * @param Document $documentObject
514
+     * @param string   $state
515
+     *
516
+     * @return bool
517
+     * @throws \Exception
518
+     * @internal param $path
519
+     */
520 520
     public function saveDocument($documentObject, $state = 'published')
521 521
     {
522
-		if (!in_array($state, Document::$DOCUMENT_STATES)) {
523
-			throw new \Exception('Unsupported document state: ' . $state);
524
-		}
522
+        if (!in_array($state, Document::$DOCUMENT_STATES)) {
523
+            throw new \Exception('Unsupported document state: ' . $state);
524
+        }
525 525
         $db = $this->getContentDbHandle();
526 526
         $stmt = $this->getDbStatement('
527 527
             INSERT OR REPLACE INTO documents_' . $state . ' (`path`,`title`,`slug`,`type`,`documentType`,`documentTypeSlug`,`state`,`lastModificationDate`,`creationDate`,`lastModifiedBy`,`fields`,`bricks`,`dynamicBricks`)
@@ -545,15 +545,15 @@  discard block
 block discarded – undo
545 545
         return $result;
546 546
     }
547 547
 
548
-	/**
549
-	 * Delete the document from the database
550
-	 * If it's a folder, also delete it's contents
551
-	 *
552
-	 * @param        $path
553
-	 *
554
-	 * @internal param string $state
555
-	 *
556
-	 */
548
+    /**
549
+     * Delete the document from the database
550
+     * If it's a folder, also delete it's contents
551
+     *
552
+     * @param        $path
553
+     *
554
+     * @internal param string $state
555
+     *
556
+     */
557 557
     public function deleteDocumentByPath($path)
558 558
     {
559 559
         $db = $this->getContentDbHandle();
@@ -578,24 +578,24 @@  discard block
 block discarded – undo
578 578
         }
579 579
     }
580 580
 
581
-	/**
582
-	 * @param $document
583
-	 * @param $db
584
-	 * @param $documents
585
-	 * @param $key
586
-	 *
587
-	 * @return mixed
588
-	 */
589
-	private function setAssetsToDocumentFolders($document, $db, $documents, $key)
590
-	{
591
-		if ($document->type === 'folder') {
592
-			$document->dbHandle = $db;
593
-			$document->documentStorage = new DocumentStorage($this);
594
-			$documents[$key] = $document;
595
-		}
596
-
597
-		return $documents;
598
-	}
581
+    /**
582
+     * @param $document
583
+     * @param $db
584
+     * @param $documents
585
+     * @param $key
586
+     *
587
+     * @return mixed
588
+     */
589
+    private function setAssetsToDocumentFolders($document, $db, $documents, $key)
590
+    {
591
+        if ($document->type === 'folder') {
592
+            $document->dbHandle = $db;
593
+            $document->documentStorage = new DocumentStorage($this);
594
+            $documents[$key] = $document;
595
+        }
596
+
597
+        return $documents;
598
+    }
599 599
 
600 600
     private function initConfigIfNotExists($json, $subsetName)
601 601
     {
Please login to merge, or discard this patch.
src/storage/Storage.php 1 patch
Indentation   +265 added lines, -265 removed lines patch added patch discarded remove patch
@@ -15,52 +15,52 @@  discard block
 block discarded – undo
15 15
     use CloudControl\Cms\storage\storage\ValuelistsStorage;
16 16
 
17 17
     /**
18
-	 * Class JsonStorage
18
+     * Class JsonStorage
19 19
      * @package CloudControl\Cms\storage
20
-	 */
21
-	class Storage
22
-	{
23
-		/**
24
-		 * @var SitemapStorage
25
-		 */
26
-		protected $sitemap;
27
-		/**
28
-		 * @var ImagesStorage
29
-		 */
30
-		protected $images;
31
-		/**
32
-		 * @var ImageSetStorage
33
-		 */
34
-		protected $imageSet;
35
-		/**
36
-		 * @var FilesStorage
37
-		 */
38
-		protected $files;
39
-		/**
40
-		 * @var UsersStorage
41
-		 */
42
-		protected $users;
43
-		/**
44
-		 * @var DocumentTypesStorage
45
-		 */
46
-		protected $documentTypes;
47
-		/**
48
-		 * @var BricksStorage
49
-		 */
50
-		protected $bricks;
51
-		/**
52
-		 * @var ApplicationComponentsStorage
53
-		 */
54
-		protected $applicationComponents;
20
+     */
21
+    class Storage
22
+    {
23
+        /**
24
+         * @var SitemapStorage
25
+         */
26
+        protected $sitemap;
27
+        /**
28
+         * @var ImagesStorage
29
+         */
30
+        protected $images;
31
+        /**
32
+         * @var ImageSetStorage
33
+         */
34
+        protected $imageSet;
35
+        /**
36
+         * @var FilesStorage
37
+         */
38
+        protected $files;
39
+        /**
40
+         * @var UsersStorage
41
+         */
42
+        protected $users;
43
+        /**
44
+         * @var DocumentTypesStorage
45
+         */
46
+        protected $documentTypes;
47
+        /**
48
+         * @var BricksStorage
49
+         */
50
+        protected $bricks;
51
+        /**
52
+         * @var ApplicationComponentsStorage
53
+         */
54
+        protected $applicationComponents;
55 55
 
56
-		/**
57
-		 * @var ValuelistsStorage
58
-		 */
59
-		protected $valuelists;
60
-		/**
61
-		 * @var DocumentStorage
62
-		 */
63
-		protected $documents;
56
+        /**
57
+         * @var ValuelistsStorage
58
+         */
59
+        protected $valuelists;
60
+        /**
61
+         * @var DocumentStorage
62
+         */
63
+        protected $documents;
64 64
         /**
65 65
          * @var RedirectsStorage
66 66
          */
@@ -75,13 +75,13 @@  discard block
 block discarded – undo
75 75
         protected $filesDir;
76 76
 
77 77
         /**
78
-		 * @var String
79
-		 */
80
-		private $storageDir;
81
-		/**
82
-		 * @var Repository
83
-		 */
84
-		private $repository;
78
+         * @var String
79
+         */
80
+        private $storageDir;
81
+        /**
82
+         * @var Repository
83
+         */
84
+        private $repository;
85 85
 
86 86
         /**
87 87
          * JsonStorage constructor.
@@ -91,245 +91,245 @@  discard block
 block discarded – undo
91 91
          * @param $filesDir
92 92
          */
93 93
         public function __construct($storageDir, $imagesDir, $filesDir)
94
-		{
95
-			$this->storageDir = $storageDir;
94
+        {
95
+            $this->storageDir = $storageDir;
96 96
             $this->imagesDir = $imagesDir;
97 97
             $this->filesDir = $filesDir;
98
-			$this->config();
99
-		}
98
+            $this->config();
99
+        }
100 100
 
101
-		/**
102
-		 * Retrieve the data from the storagepath
103
-		 * so it can be interacted with
104
-		 *
105
-		 * @throws \Exception
106
-		 */
107
-		private function config()
108
-		{
109
-			$storagePath = $this->storageDir;
110
-			if (realpath($storagePath) === false) {
111
-				throw new \Exception('Storage doesnt seem to be initialized, consider running composer install to do so.');
112
-			} else {
113
-				$this->repository = new Repository($storagePath);
114
-			}
101
+        /**
102
+         * Retrieve the data from the storagepath
103
+         * so it can be interacted with
104
+         *
105
+         * @throws \Exception
106
+         */
107
+        private function config()
108
+        {
109
+            $storagePath = $this->storageDir;
110
+            if (realpath($storagePath) === false) {
111
+                throw new \Exception('Storage doesnt seem to be initialized, consider running composer install to do so.');
112
+            } else {
113
+                $this->repository = new Repository($storagePath);
114
+            }
115 115
 
116
-		}
116
+        }
117 117
 
118
-		/**
119
-		 * @return \CloudControl\Cms\storage\storage\UsersStorage
120
-		 */
121
-		public function getUsers()
122
-		{
123
-			if (!$this->users instanceof UsersStorage) {
124
-				$this->users = new UsersStorage($this->repository);
125
-			}
126
-			return $this->users;
127
-		}
118
+        /**
119
+         * @return \CloudControl\Cms\storage\storage\UsersStorage
120
+         */
121
+        public function getUsers()
122
+        {
123
+            if (!$this->users instanceof UsersStorage) {
124
+                $this->users = new UsersStorage($this->repository);
125
+            }
126
+            return $this->users;
127
+        }
128 128
 
129
-		/**
130
-		 * Get documents
131
-		 *
132
-		 * @return DocumentStorage
133
-		 */
134
-		public function getDocuments()
135
-		{
136
-			if (!$this->documents instanceof DocumentStorage) {
137
-				$this->documents = new DocumentStorage($this->repository);
138
-			}
139
-			return $this->documents;
140
-		}
129
+        /**
130
+         * Get documents
131
+         *
132
+         * @return DocumentStorage
133
+         */
134
+        public function getDocuments()
135
+        {
136
+            if (!$this->documents instanceof DocumentStorage) {
137
+                $this->documents = new DocumentStorage($this->repository);
138
+            }
139
+            return $this->documents;
140
+        }
141 141
 
142
-		/**
143
-		 * Add new document in given path
144
-		 *
145
-		 * @param array $postValues
146
-		 *
147
-		 * @throws \Exception
148
-		 */
149
-		public function addDocumentFolder($postValues)
150
-		{
151
-			$documentFolderObject = DocumentFolderFactory::createDocumentFolderFromPostValues($postValues);
152
-			if ($postValues['path'] === '/') {
153
-				$documentFolderObject->path = $postValues['path'] . $documentFolderObject->slug;
154
-			} else {
155
-				$documentFolderObject->path = $postValues['path'] . '/' . $documentFolderObject->slug;
156
-			}
157
-			$this->repository->saveDocument($documentFolderObject, 'published');
158
-			$this->repository->saveDocument($documentFolderObject, 'unpublished');
159
-		}
142
+        /**
143
+         * Add new document in given path
144
+         *
145
+         * @param array $postValues
146
+         *
147
+         * @throws \Exception
148
+         */
149
+        public function addDocumentFolder($postValues)
150
+        {
151
+            $documentFolderObject = DocumentFolderFactory::createDocumentFolderFromPostValues($postValues);
152
+            if ($postValues['path'] === '/') {
153
+                $documentFolderObject->path = $postValues['path'] . $documentFolderObject->slug;
154
+            } else {
155
+                $documentFolderObject->path = $postValues['path'] . '/' . $documentFolderObject->slug;
156
+            }
157
+            $this->repository->saveDocument($documentFolderObject, 'published');
158
+            $this->repository->saveDocument($documentFolderObject, 'unpublished');
159
+        }
160 160
 
161
-		/**
162
-		 * Delete a folder by its compound slug
163
-		 *
164
-		 * @param $slug
165
-		 *
166
-		 * @throws \Exception
167
-		 */
168
-		public function deleteDocumentFolderBySlug($slug)
169
-		{
170
-			$path = '/' . $slug;
171
-			$this->repository->deleteDocumentByPath($path, 'published');
172
-			$this->repository->deleteDocumentByPath($path, 'unpublished');
173
-			$this->repository->cleanPublishedDeletedDocuments();
174
-		}
161
+        /**
162
+         * Delete a folder by its compound slug
163
+         *
164
+         * @param $slug
165
+         *
166
+         * @throws \Exception
167
+         */
168
+        public function deleteDocumentFolderBySlug($slug)
169
+        {
170
+            $path = '/' . $slug;
171
+            $this->repository->deleteDocumentByPath($path, 'published');
172
+            $this->repository->deleteDocumentByPath($path, 'unpublished');
173
+            $this->repository->cleanPublishedDeletedDocuments();
174
+        }
175 175
 
176
-		public function publishDocumentBySlug($slug)
177
-		{
178
-			$path = '/' . $slug;
179
-			$this->repository->publishDocumentByPath($path);
180
-		}
176
+        public function publishDocumentBySlug($slug)
177
+        {
178
+            $path = '/' . $slug;
179
+            $this->repository->publishDocumentByPath($path);
180
+        }
181 181
 
182
-		public function unpublishDocumentBySlug($slug)
183
-		{
184
-			$path = '/' . $slug;
185
-			$this->repository->unpublishDocumentByPath($path);
186
-		}
182
+        public function unpublishDocumentBySlug($slug)
183
+        {
184
+            $path = '/' . $slug;
185
+            $this->repository->unpublishDocumentByPath($path);
186
+        }
187 187
 
188
-		/**
189
-		 * Retrieve a folder by its compound slug
190
-		 *
191
-		 * @param $slug
192
-		 *
193
-		 * @return mixed
194
-		 * @throws \Exception
195
-		 */
196
-		public function getDocumentFolderBySlug($slug)
197
-		{
198
-			$path = '/' . $slug;
188
+        /**
189
+         * Retrieve a folder by its compound slug
190
+         *
191
+         * @param $slug
192
+         *
193
+         * @return mixed
194
+         * @throws \Exception
195
+         */
196
+        public function getDocumentFolderBySlug($slug)
197
+        {
198
+            $path = '/' . $slug;
199 199
 
200
-			return $this->repository->getDocumentByPath($path);
201
-		}
200
+            return $this->repository->getDocumentByPath($path);
201
+        }
202 202
 
203
-		/**
204
-		 * Save changes to folder
205
-		 *
206
-		 * @param $postValues
207
-		 *
208
-		 * @throws \Exception
209
-		 */
210
-		public function saveDocumentFolder($postValues)
211
-		{
212
-			$this->addDocumentFolder($postValues);
213
-		}
203
+        /**
204
+         * Save changes to folder
205
+         *
206
+         * @param $postValues
207
+         *
208
+         * @throws \Exception
209
+         */
210
+        public function saveDocumentFolder($postValues)
211
+        {
212
+            $this->addDocumentFolder($postValues);
213
+        }
214 214
 
215
-		/**
216
-		 * @return SitemapStorage
217
-		 */
218
-		public function getSitemap()
219
-		{
220
-			if (!$this->sitemap instanceof SitemapStorage) {
221
-				$this->sitemap = new SitemapStorage($this->repository);
222
-			}
223
-			return $this->sitemap;
224
-		}
215
+        /**
216
+         * @return SitemapStorage
217
+         */
218
+        public function getSitemap()
219
+        {
220
+            if (!$this->sitemap instanceof SitemapStorage) {
221
+                $this->sitemap = new SitemapStorage($this->repository);
222
+            }
223
+            return $this->sitemap;
224
+        }
225 225
 
226
-		/**
227
-		 * Get all images
228
-		 *
229
-		 * @return ImagesStorage
230
-		 */
231
-		public function getImages()
232
-		{
233
-			if (!$this->images instanceof ImagesStorage) {
226
+        /**
227
+         * Get all images
228
+         *
229
+         * @return ImagesStorage
230
+         */
231
+        public function getImages()
232
+        {
233
+            if (!$this->images instanceof ImagesStorage) {
234 234
 
235 235
                 $this->images = new ImagesStorage($this->repository, $this->imagesDir);
236
-			}
237
-			return $this->images;
238
-		}
236
+            }
237
+            return $this->images;
238
+        }
239 239
 
240
-		/**
241
-		 * Get all files
242
-		 *
243
-		 * @return FilesStorage
244
-		 */
245
-		public function getFiles()
246
-		{
247
-			if (!$this->files instanceof FilesStorage) {
248
-				$this->files = new FilesStorage($this->repository, $this->filesDir);
249
-			}
250
-			return $this->files;
251
-		}
240
+        /**
241
+         * Get all files
242
+         *
243
+         * @return FilesStorage
244
+         */
245
+        public function getFiles()
246
+        {
247
+            if (!$this->files instanceof FilesStorage) {
248
+                $this->files = new FilesStorage($this->repository, $this->filesDir);
249
+            }
250
+            return $this->files;
251
+        }
252 252
 
253
-		/**
254
-		 * @return string
255
-		 */
256
-		public function getStorageDir()
257
-		{
258
-			return $this->storageDir;
259
-		}
253
+        /**
254
+         * @return string
255
+         */
256
+        public function getStorageDir()
257
+        {
258
+            return $this->storageDir;
259
+        }
260 260
 
261
-		/**
262
-		 * @return \PDO
263
-		 */
264
-		public function getContentDbHandle()
265
-		{
266
-			return $this->repository->getContentDbHandle();
267
-		}
261
+        /**
262
+         * @return \PDO
263
+         */
264
+        public function getContentDbHandle()
265
+        {
266
+            return $this->repository->getContentDbHandle();
267
+        }
268 268
 
269
-		/**
270
-		 * @return DocumentTypesStorage
271
-		 */
272
-		public function getDocumentTypes()
273
-		{
274
-			if (!$this->documentTypes instanceof DocumentTypesStorage) {
275
-				$this->documentTypes = new DocumentTypesStorage($this->repository);
276
-			}
277
-			return $this->documentTypes;
278
-		}
269
+        /**
270
+         * @return DocumentTypesStorage
271
+         */
272
+        public function getDocumentTypes()
273
+        {
274
+            if (!$this->documentTypes instanceof DocumentTypesStorage) {
275
+                $this->documentTypes = new DocumentTypesStorage($this->repository);
276
+            }
277
+            return $this->documentTypes;
278
+        }
279 279
 
280
-		/**
281
-		 * @return BricksStorage
282
-		 */
283
-		public function getBricks()
284
-		{
285
-			if (!$this->bricks instanceof BricksStorage) {
286
-				$this->bricks = new BricksStorage($this->repository);
287
-			}
288
-			return $this->bricks;
289
-		}
280
+        /**
281
+         * @return BricksStorage
282
+         */
283
+        public function getBricks()
284
+        {
285
+            if (!$this->bricks instanceof BricksStorage) {
286
+                $this->bricks = new BricksStorage($this->repository);
287
+            }
288
+            return $this->bricks;
289
+        }
290 290
 
291
-		/**
292
-		 * Get the image set
293
-		 *
294
-		 * @return ImageSetStorage
295
-		 */
296
-		public function getImageSet()
297
-		{
298
-			if (!$this->imageSet instanceof ImageSetStorage) {
299
-				$this->imageSet = new ImageSetStorage($this->repository);
300
-			}
301
-			return $this->imageSet;
302
-		}
291
+        /**
292
+         * Get the image set
293
+         *
294
+         * @return ImageSetStorage
295
+         */
296
+        public function getImageSet()
297
+        {
298
+            if (!$this->imageSet instanceof ImageSetStorage) {
299
+                $this->imageSet = new ImageSetStorage($this->repository);
300
+            }
301
+            return $this->imageSet;
302
+        }
303 303
 
304
-		/**
305
-		 * @return ApplicationComponentsStorage
306
-		 */
307
-		public function getApplicationComponents()
308
-		{
309
-			if (!$this->applicationComponents instanceof ApplicationComponentsStorage) {
310
-				$this->applicationComponents = new ApplicationComponentsStorage($this->repository);
311
-			}
312
-			return $this->applicationComponents;
313
-		}
304
+        /**
305
+         * @return ApplicationComponentsStorage
306
+         */
307
+        public function getApplicationComponents()
308
+        {
309
+            if (!$this->applicationComponents instanceof ApplicationComponentsStorage) {
310
+                $this->applicationComponents = new ApplicationComponentsStorage($this->repository);
311
+            }
312
+            return $this->applicationComponents;
313
+        }
314 314
 
315
-		/**
316
-		 * @return \CloudControl\Cms\storage\Repository
317
-		 */
318
-		public function getRepository()
319
-		{
320
-			return $this->repository;
321
-		}
315
+        /**
316
+         * @return \CloudControl\Cms\storage\Repository
317
+         */
318
+        public function getRepository()
319
+        {
320
+            return $this->repository;
321
+        }
322 322
 
323
-		/**
324
-		 * @return \CloudControl\Cms\storage\storage\ValuelistsStorage
325
-		 */
326
-		public function getValuelists()
327
-		{
328
-			if (!$this->valuelists instanceof ValuelistsStorage) {
329
-				$this->valuelists = new ValuelistsStorage($this->repository);
330
-			}
331
-			return $this->valuelists;
332
-		}
323
+        /**
324
+         * @return \CloudControl\Cms\storage\storage\ValuelistsStorage
325
+         */
326
+        public function getValuelists()
327
+        {
328
+            if (!$this->valuelists instanceof ValuelistsStorage) {
329
+                $this->valuelists = new ValuelistsStorage($this->repository);
330
+            }
331
+            return $this->valuelists;
332
+        }
333 333
 
334 334
         /**
335 335
          * @return \CloudControl\Cms\storage\storage\RedirectsStorage
@@ -342,5 +342,5 @@  discard block
 block discarded – undo
342 342
             return $this->redirects;
343 343
         }
344 344
 
345
-	}
345
+    }
346 346
 }
347 347
\ No newline at end of file
Please login to merge, or discard this patch.
src/storage/Document.php 1 patch
Indentation   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -75,13 +75,13 @@  discard block
 block discarded – undo
75 75
         $this->$name = $value;
76 76
     }
77 77
 
78
-	/**
79
-	 * @param string $orderBy
80
-	 * @param string $order
81
-	 *
82
-	 * @return array
83
-	 * @throws \Exception
84
-	 */
78
+    /**
79
+     * @param string $orderBy
80
+     * @param string $order
81
+     *
82
+     * @return array
83
+     * @throws \Exception
84
+     */
85 85
     public function getContent($orderBy = 'title', $order = 'ASC')
86 86
     {
87 87
         if (empty($this->content)) {
@@ -89,16 +89,16 @@  discard block
 block discarded – undo
89 89
             $this->content = $docs;
90 90
         }
91 91
 
92
-    	return $this->content;
92
+        return $this->content;
93 93
     }
94 94
 
95
-	/**
96
-	 * @return string
97
-	 */
98
-	public function __toString()
99
-	{
100
-		return 'Document:' . $this->title;
101
-	}
95
+    /**
96
+     * @return string
97
+     */
98
+    public function __toString()
99
+    {
100
+        return 'Document:' . $this->title;
101
+    }
102 102
 
103 103
 
104 104
 }
105 105
\ No newline at end of file
Please login to merge, or discard this patch.
src/storage/storage/DocumentTypesStorage.php 1 patch
Indentation   +100 added lines, -100 removed lines patch added patch discarded remove patch
@@ -10,115 +10,115 @@
 block discarded – undo
10 10
 
11 11
 class DocumentTypesStorage extends AbstractStorage
12 12
 {
13
-	/**
14
-	 * @var BricksStorage
15
-	 */
16
-	protected $bricks;
13
+    /**
14
+     * @var BricksStorage
15
+     */
16
+    protected $bricks;
17 17
 
18
-	/**
19
-	 * @return array
20
-	 */
21
-	public function getDocumentTypes()
22
-	{
23
-		return $this->repository->documentTypes;
24
-	}
18
+    /**
19
+     * @return array
20
+     */
21
+    public function getDocumentTypes()
22
+    {
23
+        return $this->repository->documentTypes;
24
+    }
25 25
 
26
-	/**
27
-	 * Add a document type from post values
28
-	 *
29
-	 * @param $postValues
30
-	 *
31
-	 * @throws \Exception
32
-	 */
33
-	public function addDocumentType($postValues)
34
-	{
35
-		$documentTypeObject = DocumentTypeFactory::createDocumentTypeFromPostValues($postValues);
26
+    /**
27
+     * Add a document type from post values
28
+     *
29
+     * @param $postValues
30
+     *
31
+     * @throws \Exception
32
+     */
33
+    public function addDocumentType($postValues)
34
+    {
35
+        $documentTypeObject = DocumentTypeFactory::createDocumentTypeFromPostValues($postValues);
36 36
 
37
-		$documentTypes = $this->repository->documentTypes;
38
-		$documentTypes[] = $documentTypeObject;
39
-		$this->repository->documentTypes = $documentTypes;
37
+        $documentTypes = $this->repository->documentTypes;
38
+        $documentTypes[] = $documentTypeObject;
39
+        $this->repository->documentTypes = $documentTypes;
40 40
 
41
-		$this->save();
42
-	}
41
+        $this->save();
42
+    }
43 43
 
44
-	/**
45
-	 * Delete document type
46
-	 *
47
-	 * @param $slug
48
-	 *
49
-	 * @throws \Exception
50
-	 */
51
-	public function deleteDocumentTypeBySlug($slug)
52
-	{
53
-		$documentTypes = $this->repository->documentTypes;
54
-		foreach ($documentTypes as $key => $documentTypeObject) {
55
-			if ($documentTypeObject->slug == $slug) {
56
-				unset($documentTypes[$key]);
57
-			}
58
-		}
59
-		$documentTypes = array_values($documentTypes);
60
-		$this->repository->documentTypes = $documentTypes;
61
-		$this->save();
62
-	}
44
+    /**
45
+     * Delete document type
46
+     *
47
+     * @param $slug
48
+     *
49
+     * @throws \Exception
50
+     */
51
+    public function deleteDocumentTypeBySlug($slug)
52
+    {
53
+        $documentTypes = $this->repository->documentTypes;
54
+        foreach ($documentTypes as $key => $documentTypeObject) {
55
+            if ($documentTypeObject->slug == $slug) {
56
+                unset($documentTypes[$key]);
57
+            }
58
+        }
59
+        $documentTypes = array_values($documentTypes);
60
+        $this->repository->documentTypes = $documentTypes;
61
+        $this->save();
62
+    }
63 63
 
64
-	/**
65
-	 * Get document type by its slug
66
-	 *
67
-	 * @param      $slug
68
-	 * @param bool $getBricks
69
-	 *
70
-	 * @return mixed
71
-	 */
72
-	public function getDocumentTypeBySlug($slug, $getBricks = false)
73
-	{
74
-		$documentTypes = $this->repository->documentTypes;
75
-		foreach ($documentTypes as $documentType) {
76
-			if ($documentType->slug == $slug) {
77
-				if ($getBricks === true) {
78
-					foreach ($documentType->bricks as $key => $brick) {
79
-						$brickStructure = $this->getBricks()->getBrickBySlug($brick->brickSlug);
80
-						$documentType->bricks[$key]->structure = $brickStructure;
81
-					}
82
-					foreach ($documentType->dynamicBricks as $key => $brickSlug) {
83
-						$brickStructure = $this->getBricks()->getBrickBySlug($brickSlug);
84
-						$documentType->dynamicBricks[$key] = $brickStructure;
85
-					}
86
-				}
64
+    /**
65
+     * Get document type by its slug
66
+     *
67
+     * @param      $slug
68
+     * @param bool $getBricks
69
+     *
70
+     * @return mixed
71
+     */
72
+    public function getDocumentTypeBySlug($slug, $getBricks = false)
73
+    {
74
+        $documentTypes = $this->repository->documentTypes;
75
+        foreach ($documentTypes as $documentType) {
76
+            if ($documentType->slug == $slug) {
77
+                if ($getBricks === true) {
78
+                    foreach ($documentType->bricks as $key => $brick) {
79
+                        $brickStructure = $this->getBricks()->getBrickBySlug($brick->brickSlug);
80
+                        $documentType->bricks[$key]->structure = $brickStructure;
81
+                    }
82
+                    foreach ($documentType->dynamicBricks as $key => $brickSlug) {
83
+                        $brickStructure = $this->getBricks()->getBrickBySlug($brickSlug);
84
+                        $documentType->dynamicBricks[$key] = $brickStructure;
85
+                    }
86
+                }
87 87
 
88
-				return $documentType;
89
-			}
90
-		}
88
+                return $documentType;
89
+            }
90
+        }
91 91
 
92
-		return null;
93
-	}
92
+        return null;
93
+    }
94 94
 
95
-	/**
96
-	 * Save changes to a document type
97
-	 *
98
-	 * @param $slug
99
-	 * @param $postValues
100
-	 *
101
-	 * @throws \Exception
102
-	 */
103
-	public function saveDocumentType($slug, $postValues)
104
-	{
105
-		$documentTypeObject = DocumentTypeFactory::createDocumentTypeFromPostValues($postValues);
95
+    /**
96
+     * Save changes to a document type
97
+     *
98
+     * @param $slug
99
+     * @param $postValues
100
+     *
101
+     * @throws \Exception
102
+     */
103
+    public function saveDocumentType($slug, $postValues)
104
+    {
105
+        $documentTypeObject = DocumentTypeFactory::createDocumentTypeFromPostValues($postValues);
106 106
 
107
-		$documentTypes = $this->repository->documentTypes;
108
-		foreach ($documentTypes as $key => $documentType) {
109
-			if ($documentType->slug == $slug) {
110
-				$documentTypes[$key] = $documentTypeObject;
111
-			}
112
-		}
113
-		$this->repository->documentTypes = $documentTypes;
114
-		$this->save();
115
-	}
107
+        $documentTypes = $this->repository->documentTypes;
108
+        foreach ($documentTypes as $key => $documentType) {
109
+            if ($documentType->slug == $slug) {
110
+                $documentTypes[$key] = $documentTypeObject;
111
+            }
112
+        }
113
+        $this->repository->documentTypes = $documentTypes;
114
+        $this->save();
115
+    }
116 116
 
117
-	private function getBricks()
118
-	{
119
-		if (!$this->bricks instanceof BricksStorage) {
120
-			$this->bricks = new BricksStorage($this->repository);
121
-		}
122
-		return $this->bricks;
123
-	}
117
+    private function getBricks()
118
+    {
119
+        if (!$this->bricks instanceof BricksStorage) {
120
+            $this->bricks = new BricksStorage($this->repository);
121
+        }
122
+        return $this->bricks;
123
+    }
124 124
 }
125 125
\ No newline at end of file
Please login to merge, or discard this patch.
src/storage/storage/BricksStorage.php 1 patch
Indentation   +78 added lines, -78 removed lines patch added patch discarded remove patch
@@ -10,91 +10,91 @@
 block discarded – undo
10 10
 
11 11
 class BricksStorage extends AbstractStorage
12 12
 {
13
-	/**
14
-	 * @return array
15
-	 */
16
-	public function getBricks()
17
-	{
18
-		return $this->repository->bricks;
19
-	}
13
+    /**
14
+     * @return array
15
+     */
16
+    public function getBricks()
17
+    {
18
+        return $this->repository->bricks;
19
+    }
20 20
 
21
-	/**
22
-	 * Add a brick
23
-	 *
24
-	 * @param $postValues
25
-	 *
26
-	 * @throws \Exception
27
-	 */
28
-	public function addBrick($postValues)
29
-	{
30
-		$brickObject = BrickFactory::createBrickFromPostValues($postValues);
21
+    /**
22
+     * Add a brick
23
+     *
24
+     * @param $postValues
25
+     *
26
+     * @throws \Exception
27
+     */
28
+    public function addBrick($postValues)
29
+    {
30
+        $brickObject = BrickFactory::createBrickFromPostValues($postValues);
31 31
 
32
-		$bricks = $this->repository->bricks;
33
-		$bricks[] = $brickObject;
34
-		$this->repository->bricks = $bricks;
32
+        $bricks = $this->repository->bricks;
33
+        $bricks[] = $brickObject;
34
+        $this->repository->bricks = $bricks;
35 35
 
36
-		$this->save();
37
-	}
36
+        $this->save();
37
+    }
38 38
 
39
-	/**
40
-	 * Get a brick by its slug
41
-	 *
42
-	 * @param $slug
43
-	 *
44
-	 * @return \stdClass
45
-	 */
46
-	public function getBrickBySlug($slug)
47
-	{
48
-		$bricks = $this->repository->bricks;
49
-		foreach ($bricks as $brick) {
50
-			if ($brick->slug == $slug) {
51
-				return $brick;
52
-			}
53
-		}
39
+    /**
40
+     * Get a brick by its slug
41
+     *
42
+     * @param $slug
43
+     *
44
+     * @return \stdClass
45
+     */
46
+    public function getBrickBySlug($slug)
47
+    {
48
+        $bricks = $this->repository->bricks;
49
+        foreach ($bricks as $brick) {
50
+            if ($brick->slug == $slug) {
51
+                return $brick;
52
+            }
53
+        }
54 54
 
55
-		return null;
56
-	}
55
+        return null;
56
+    }
57 57
 
58
-	/**
59
-	 * Save changes to a brick
60
-	 *
61
-	 * @param $slug
62
-	 * @param $postValues
63
-	 *
64
-	 * @throws \Exception
65
-	 */
66
-	public function saveBrick($slug, $postValues)
67
-	{
68
-		$brickObject = BrickFactory::createBrickFromPostValues($postValues);
58
+    /**
59
+     * Save changes to a brick
60
+     *
61
+     * @param $slug
62
+     * @param $postValues
63
+     *
64
+     * @throws \Exception
65
+     */
66
+    public function saveBrick($slug, $postValues)
67
+    {
68
+        $brickObject = BrickFactory::createBrickFromPostValues($postValues);
69 69
 
70
-		$bricks = $this->repository->bricks;
71
-		foreach ($bricks as $key => $brick) {
72
-			if ($brick->slug == $slug) {
73
-				$bricks[$key] = $brickObject;
74
-			}
75
-		}
76
-		$this->repository->bricks = $bricks;
77
-		$this->save();
78
-	}
70
+        $bricks = $this->repository->bricks;
71
+        foreach ($bricks as $key => $brick) {
72
+            if ($brick->slug == $slug) {
73
+                $bricks[$key] = $brickObject;
74
+            }
75
+        }
76
+        $this->repository->bricks = $bricks;
77
+        $this->save();
78
+    }
79 79
 
80
-	/**
81
-	 * Delete a brick by its slug
82
-	 *
83
-	 * @param $slug
84
-	 *
85
-	 * @throws \Exception
86
-	 */
87
-	public function deleteBrickBySlug($slug)
88
-	{
89
-		$bricks = $this->repository->bricks;
90
-		foreach ($bricks as $key => $brickObject) {
91
-			if ($brickObject->slug == $slug) {
92
-				unset($bricks[$key]);
93
-			}
94
-		}
80
+    /**
81
+     * Delete a brick by its slug
82
+     *
83
+     * @param $slug
84
+     *
85
+     * @throws \Exception
86
+     */
87
+    public function deleteBrickBySlug($slug)
88
+    {
89
+        $bricks = $this->repository->bricks;
90
+        foreach ($bricks as $key => $brickObject) {
91
+            if ($brickObject->slug == $slug) {
92
+                unset($bricks[$key]);
93
+            }
94
+        }
95 95
 
96
-		$bricks = array_values($bricks);
97
-		$this->repository->bricks = $bricks;
98
-		$this->save();
99
-	}
96
+        $bricks = array_values($bricks);
97
+        $this->repository->bricks = $bricks;
98
+        $this->save();
99
+    }
100 100
 }
101 101
\ No newline at end of file
Please login to merge, or discard this patch.
src/storage/storage/DocumentStorage.php 1 patch
Indentation   +118 added lines, -118 removed lines patch added patch discarded remove patch
@@ -10,123 +10,123 @@
 block discarded – undo
10 10
 
11 11
 class DocumentStorage extends AbstractStorage
12 12
 {
13
-	/**
14
-	 * Get documents
15
-	 *
16
-	 * @param string $state
17
-	 *
18
-	 * @return array
19
-	 * @throws \Exception
20
-	 */
21
-	public function getDocuments($state = 'published')
22
-	{
23
-		if (!in_array($state, Document::$DOCUMENT_STATES)) {
24
-			throw new \Exception('Unsupported document state: ' . $state);
25
-		}
26
-		return $this->repository->getDocuments($state);
27
-	}
28
-
29
-	public function getDocumentsWithState($folderPath = '/')
30
-	{
31
-		return $this->repository->getDocumentsWithState($folderPath);
32
-	}
33
-
34
-	/**
35
-	 * @return int
36
-	 */
37
-	public function getTotalDocumentCount()
38
-	{
39
-		return $this->repository->getTotalDocumentCount();
40
-	}
41
-
42
-	/**
43
-	 * @param string $slug
44
-	 *
45
-	 * @param string $state
46
-	 *
47
-	 * @return mixed
48
-	 * @throws \Exception
49
-	 */
50
-	public function getDocumentBySlug($slug, $state = 'published')
51
-	{
52
-		if (!in_array($state, Document::$DOCUMENT_STATES)) {
53
-			throw new \Exception('Unsupported document state: ' . $state);
54
-		}
55
-		$path = '/' . $slug;
56
-
57
-		return $this->repository->getDocumentByPath($path, $state);
58
-	}
59
-
60
-	/**
61
-	 * @param $postValues
62
-	 * @param $state
63
-	 *
64
-	 * @throws \Exception
65
-	 */
66
-	public function saveDocument($postValues, $state = 'unpublished')
67
-	{
68
-		if (!in_array($state, Document::$DOCUMENT_STATES)) {
69
-			throw new \Exception('Unsupported document state: ' . $state);
70
-		}
71
-		$oldPath = '/' . $postValues['path'];
72
-
73
-		$container = $this->getDocumentContainerByPath($oldPath);
74
-		$documentObject = DocumentFactory::createDocumentFromPostValues($postValues, new DocumentTypesStorage($this->repository));
75
-		if ($container->path === '/') {
76
-			$newPath = $container->path . $documentObject->slug;
77
-		} else {
78
-			$newPath = $container->path . '/' . $documentObject->slug;
79
-		}
80
-		$documentObject->path = $newPath;
81
-		$this->repository->saveDocument($documentObject, $state);
82
-	}
83
-
84
-	/**
85
-	 * @param        $postValues
86
-	 * @param string $state
87
-	 */
88
-	public function addDocument($postValues, $state = 'unpublished')
89
-	{
90
-		$documentObject = DocumentFactory::createDocumentFromPostValues($postValues, new DocumentTypesStorage($this->repository));
91
-		if ($postValues['path'] === '/') {
92
-			$documentObject->path = $postValues['path'] . $documentObject->slug;
93
-		} else {
94
-			$documentObject->path = $postValues['path'] . '/' . $documentObject->slug;
95
-		}
96
-
97
-		$this->repository->saveDocument($documentObject, $state);
98
-	}
99
-
100
-	/**
101
-	 * @param $slug
102
-	 */
103
-	public function deleteDocumentBySlug($slug)
104
-	{
105
-		$path = '/' . $slug;
106
-		$this->repository->deleteDocumentByPath($path);
107
-	}
108
-
109
-	/**
110
-	 * Returns the folder containing the document
111
-	 *
112
-	 * @param $path
113
-	 *
114
-	 * @return bool|\CloudControl\Cms\storage\Document
115
-	 * @throws \Exception
116
-	 */
117
-	private function getDocumentContainerByPath($path)
118
-	{
119
-		return $this->repository->getDocumentContainerByPath($path);
120
-	}
121
-
122
-	public function getPublishedDocumentsNoFolders()
123
-	{
124
-		return $this->repository->getPublishedDocumentsNoFolders();
125
-	}
126
-
127
-	public function cleanPublishedDeletedDocuments()
128
-	{
129
-		$this->repository->cleanPublishedDeletedDocuments();
130
-	}
13
+    /**
14
+     * Get documents
15
+     *
16
+     * @param string $state
17
+     *
18
+     * @return array
19
+     * @throws \Exception
20
+     */
21
+    public function getDocuments($state = 'published')
22
+    {
23
+        if (!in_array($state, Document::$DOCUMENT_STATES)) {
24
+            throw new \Exception('Unsupported document state: ' . $state);
25
+        }
26
+        return $this->repository->getDocuments($state);
27
+    }
28
+
29
+    public function getDocumentsWithState($folderPath = '/')
30
+    {
31
+        return $this->repository->getDocumentsWithState($folderPath);
32
+    }
33
+
34
+    /**
35
+     * @return int
36
+     */
37
+    public function getTotalDocumentCount()
38
+    {
39
+        return $this->repository->getTotalDocumentCount();
40
+    }
41
+
42
+    /**
43
+     * @param string $slug
44
+     *
45
+     * @param string $state
46
+     *
47
+     * @return mixed
48
+     * @throws \Exception
49
+     */
50
+    public function getDocumentBySlug($slug, $state = 'published')
51
+    {
52
+        if (!in_array($state, Document::$DOCUMENT_STATES)) {
53
+            throw new \Exception('Unsupported document state: ' . $state);
54
+        }
55
+        $path = '/' . $slug;
56
+
57
+        return $this->repository->getDocumentByPath($path, $state);
58
+    }
59
+
60
+    /**
61
+     * @param $postValues
62
+     * @param $state
63
+     *
64
+     * @throws \Exception
65
+     */
66
+    public function saveDocument($postValues, $state = 'unpublished')
67
+    {
68
+        if (!in_array($state, Document::$DOCUMENT_STATES)) {
69
+            throw new \Exception('Unsupported document state: ' . $state);
70
+        }
71
+        $oldPath = '/' . $postValues['path'];
72
+
73
+        $container = $this->getDocumentContainerByPath($oldPath);
74
+        $documentObject = DocumentFactory::createDocumentFromPostValues($postValues, new DocumentTypesStorage($this->repository));
75
+        if ($container->path === '/') {
76
+            $newPath = $container->path . $documentObject->slug;
77
+        } else {
78
+            $newPath = $container->path . '/' . $documentObject->slug;
79
+        }
80
+        $documentObject->path = $newPath;
81
+        $this->repository->saveDocument($documentObject, $state);
82
+    }
83
+
84
+    /**
85
+     * @param        $postValues
86
+     * @param string $state
87
+     */
88
+    public function addDocument($postValues, $state = 'unpublished')
89
+    {
90
+        $documentObject = DocumentFactory::createDocumentFromPostValues($postValues, new DocumentTypesStorage($this->repository));
91
+        if ($postValues['path'] === '/') {
92
+            $documentObject->path = $postValues['path'] . $documentObject->slug;
93
+        } else {
94
+            $documentObject->path = $postValues['path'] . '/' . $documentObject->slug;
95
+        }
96
+
97
+        $this->repository->saveDocument($documentObject, $state);
98
+    }
99
+
100
+    /**
101
+     * @param $slug
102
+     */
103
+    public function deleteDocumentBySlug($slug)
104
+    {
105
+        $path = '/' . $slug;
106
+        $this->repository->deleteDocumentByPath($path);
107
+    }
108
+
109
+    /**
110
+     * Returns the folder containing the document
111
+     *
112
+     * @param $path
113
+     *
114
+     * @return bool|\CloudControl\Cms\storage\Document
115
+     * @throws \Exception
116
+     */
117
+    private function getDocumentContainerByPath($path)
118
+    {
119
+        return $this->repository->getDocumentContainerByPath($path);
120
+    }
121
+
122
+    public function getPublishedDocumentsNoFolders()
123
+    {
124
+        return $this->repository->getPublishedDocumentsNoFolders();
125
+    }
126
+
127
+    public function cleanPublishedDeletedDocuments()
128
+    {
129
+        $this->repository->cleanPublishedDeletedDocuments();
130
+    }
131 131
 
132 132
 }
133 133
\ No newline at end of file
Please login to merge, or discard this patch.
src/storage/storage/AbstractStorage.php 1 patch
Indentation   +53 added lines, -53 removed lines patch added patch discarded remove patch
@@ -11,63 +11,63 @@
 block discarded – undo
11 11
 
12 12
 abstract class AbstractStorage
13 13
 {
14
-	/**
15
-	 * @var Repository
16
-	 */
17
-	protected $repository;
14
+    /**
15
+     * @var Repository
16
+     */
17
+    protected $repository;
18 18
 
19
-	public function __construct($repository)
20
-	{
21
-		$this->repository = $repository;
22
-	}
19
+    public function __construct($repository)
20
+    {
21
+        $this->repository = $repository;
22
+    }
23 23
 
24
-	/**
25
-	 * Converts filename to lowercase, remove non-ascii chars
26
-	 * And adds "-copy" if the file already exists
27
-	 *
28
-	 * @param $filename
29
-	 * @param $path
30
-	 *
31
-	 * @return string
32
-	 */
33
-	protected function validateFilename($filename, $path)
34
-	{
35
-		$fileParts = explode('.', $filename);
36
-		if (count($fileParts) > 1) {
37
-			$extension = end($fileParts);
38
-			array_pop($fileParts);
39
-			$fileNameWithoutExtension = implode('-', $fileParts);
40
-			$fileNameWithoutExtension = StringUtil::slugify($fileNameWithoutExtension);
41
-			$filename = $fileNameWithoutExtension . '.' . $extension;
42
-		} else {
43
-			$filename = StringUtil::slugify($filename);
44
-		}
24
+    /**
25
+     * Converts filename to lowercase, remove non-ascii chars
26
+     * And adds "-copy" if the file already exists
27
+     *
28
+     * @param $filename
29
+     * @param $path
30
+     *
31
+     * @return string
32
+     */
33
+    protected function validateFilename($filename, $path)
34
+    {
35
+        $fileParts = explode('.', $filename);
36
+        if (count($fileParts) > 1) {
37
+            $extension = end($fileParts);
38
+            array_pop($fileParts);
39
+            $fileNameWithoutExtension = implode('-', $fileParts);
40
+            $fileNameWithoutExtension = StringUtil::slugify($fileNameWithoutExtension);
41
+            $filename = $fileNameWithoutExtension . '.' . $extension;
42
+        } else {
43
+            $filename = StringUtil::slugify($filename);
44
+        }
45 45
 
46
-		if (file_exists($path . '/' . $filename)) {
47
-			$fileParts = explode('.', $filename);
48
-			if (count($fileParts) > 1) {
49
-				$extension = end($fileParts);
50
-				array_pop($fileParts);
51
-				$fileNameWithoutExtension = implode('-', $fileParts);
52
-				$fileNameWithoutExtension .= '-copy';
53
-				$filename = $fileNameWithoutExtension . '.' . $extension;
54
-			} else {
55
-				$filename .= '-copy';
56
-			}
46
+        if (file_exists($path . '/' . $filename)) {
47
+            $fileParts = explode('.', $filename);
48
+            if (count($fileParts) > 1) {
49
+                $extension = end($fileParts);
50
+                array_pop($fileParts);
51
+                $fileNameWithoutExtension = implode('-', $fileParts);
52
+                $fileNameWithoutExtension .= '-copy';
53
+                $filename = $fileNameWithoutExtension . '.' . $extension;
54
+            } else {
55
+                $filename .= '-copy';
56
+            }
57 57
 
58
-			return $this->validateFilename($filename, $path);
59
-		}
58
+            return $this->validateFilename($filename, $path);
59
+        }
60 60
 
61
-		return $filename;
62
-	}
61
+        return $filename;
62
+    }
63 63
 
64
-	/**
65
-	 * Save changes made to the repository
66
-	 *
67
-	 * @throws \Exception
68
-	 */
69
-	protected function save()
70
-	{
71
-		$this->repository->save();
72
-	}
64
+    /**
65
+     * Save changes made to the repository
66
+     *
67
+     * @throws \Exception
68
+     */
69
+    protected function save()
70
+    {
71
+        $this->repository->save();
72
+    }
73 73
 }
74 74
\ No newline at end of file
Please login to merge, or discard this patch.
src/storage/storage/ApplicationComponentsStorage.php 1 patch
Indentation   +64 added lines, -64 removed lines patch added patch discarded remove patch
@@ -10,75 +10,75 @@
 block discarded – undo
10 10
 
11 11
 class ApplicationComponentsStorage extends AbstractStorage
12 12
 {
13
-	/**
14
-	 * @return array
15
-	 */
16
-	public function getApplicationComponents()
17
-	{
18
-		return $this->repository->applicationComponents;
19
-	}
13
+    /**
14
+     * @return array
15
+     */
16
+    public function getApplicationComponents()
17
+    {
18
+        return $this->repository->applicationComponents;
19
+    }
20 20
 
21
-	/**
22
-	 * @param $postValues
23
-	 */
24
-	public function addApplicationComponent($postValues)
25
-	{
26
-		$applicationComponent = ApplicationComponentFactory::createApplicationComponentFromPostValues($postValues);
27
-		$applicationComponents = $this->repository->applicationComponents;
28
-		$applicationComponents[] = $applicationComponent;
29
-		$this->repository->applicationComponents = $applicationComponents;
21
+    /**
22
+     * @param $postValues
23
+     */
24
+    public function addApplicationComponent($postValues)
25
+    {
26
+        $applicationComponent = ApplicationComponentFactory::createApplicationComponentFromPostValues($postValues);
27
+        $applicationComponents = $this->repository->applicationComponents;
28
+        $applicationComponents[] = $applicationComponent;
29
+        $this->repository->applicationComponents = $applicationComponents;
30 30
 
31
-		$this->save();
32
-	}
31
+        $this->save();
32
+    }
33 33
 
34
-	/**
35
-	 * @param $slug
36
-	 *
37
-	 * @return mixed|null
38
-	 */
39
-	public function getApplicationComponentBySlug($slug)
40
-	{
41
-		$applicationComponents = $this->getApplicationComponents();
42
-		foreach ($applicationComponents as $applicationComponent) {
43
-			if ($applicationComponent->slug == $slug) {
44
-				return $applicationComponent;
45
-			}
46
-		}
34
+    /**
35
+     * @param $slug
36
+     *
37
+     * @return mixed|null
38
+     */
39
+    public function getApplicationComponentBySlug($slug)
40
+    {
41
+        $applicationComponents = $this->getApplicationComponents();
42
+        foreach ($applicationComponents as $applicationComponent) {
43
+            if ($applicationComponent->slug == $slug) {
44
+                return $applicationComponent;
45
+            }
46
+        }
47 47
 
48
-		return null;
49
-	}
48
+        return null;
49
+    }
50 50
 
51
-	/**
52
-	 * @param $slug
53
-	 * @param $postValues
54
-	 */
55
-	public function saveApplicationComponent($slug, $postValues)
56
-	{
57
-		$newApplicationComponent = ApplicationComponentFactory::createApplicationComponentFromPostValues($postValues);
51
+    /**
52
+     * @param $slug
53
+     * @param $postValues
54
+     */
55
+    public function saveApplicationComponent($slug, $postValues)
56
+    {
57
+        $newApplicationComponent = ApplicationComponentFactory::createApplicationComponentFromPostValues($postValues);
58 58
 
59
-		$applicationComponents = $this->getApplicationComponents();
60
-		foreach ($applicationComponents as $key => $applicationComponent) {
61
-			if ($applicationComponent->slug == $slug) {
62
-				$applicationComponents[$key] = $newApplicationComponent;
63
-			}
64
-		}
65
-		$this->repository->applicationComponents = $applicationComponents;
66
-		$this->save();
67
-	}
59
+        $applicationComponents = $this->getApplicationComponents();
60
+        foreach ($applicationComponents as $key => $applicationComponent) {
61
+            if ($applicationComponent->slug == $slug) {
62
+                $applicationComponents[$key] = $newApplicationComponent;
63
+            }
64
+        }
65
+        $this->repository->applicationComponents = $applicationComponents;
66
+        $this->save();
67
+    }
68 68
 
69
-	/**
70
-	 * @param $slug
71
-	 */
72
-	public function deleteApplicationComponentBySlug($slug)
73
-	{
74
-		$applicationComponents = $this->getApplicationComponents();
75
-		foreach ($applicationComponents as $key => $applicationComponent) {
76
-			if ($applicationComponent->slug == $slug) {
77
-				unset($applicationComponents[$key]);
78
-			}
79
-		}
80
-		$applicationComponents = array_values($applicationComponents);
81
-		$this->repository->applicationComponents = $applicationComponents;
82
-		$this->save();
83
-	}
69
+    /**
70
+     * @param $slug
71
+     */
72
+    public function deleteApplicationComponentBySlug($slug)
73
+    {
74
+        $applicationComponents = $this->getApplicationComponents();
75
+        foreach ($applicationComponents as $key => $applicationComponent) {
76
+            if ($applicationComponent->slug == $slug) {
77
+                unset($applicationComponents[$key]);
78
+            }
79
+        }
80
+        $applicationComponents = array_values($applicationComponents);
81
+        $this->repository->applicationComponents = $applicationComponents;
82
+        $this->save();
83
+    }
84 84
 }
85 85
\ No newline at end of file
Please login to merge, or discard this patch.
src/storage/storage/SitemapStorage.php 1 patch
Indentation   +100 added lines, -100 removed lines patch added patch discarded remove patch
@@ -12,111 +12,111 @@
 block discarded – undo
12 12
 
13 13
 class SitemapStorage extends AbstractStorage
14 14
 {
15
-	/**
16
-	 * @return array
17
-	 */
18
-	public function getSitemap()
19
-	{
20
-		return $this->repository->sitemap;
21
-	}
15
+    /**
16
+     * @return array
17
+     */
18
+    public function getSitemap()
19
+    {
20
+        return $this->repository->sitemap;
21
+    }
22 22
 
23
-	/**
24
-	 * Add a sitemap item
25
-	 *
26
-	 * @param $postValues
27
-	 *
28
-	 * @throws \Exception
29
-	 */
30
-	public function addSitemapItem($postValues)
31
-	{
32
-		$sitemapObject = SitemapItemFactory::createSitemapItemFromPostValues($postValues);
33
-		$sitemap = $this->repository->sitemap;
34
-		$sitemap[] = $sitemapObject;
35
-		$this->repository->sitemap = $sitemap;
36
-		$this->save();
37
-	}
23
+    /**
24
+     * Add a sitemap item
25
+     *
26
+     * @param $postValues
27
+     *
28
+     * @throws \Exception
29
+     */
30
+    public function addSitemapItem($postValues)
31
+    {
32
+        $sitemapObject = SitemapItemFactory::createSitemapItemFromPostValues($postValues);
33
+        $sitemap = $this->repository->sitemap;
34
+        $sitemap[] = $sitemapObject;
35
+        $this->repository->sitemap = $sitemap;
36
+        $this->save();
37
+    }
38 38
 
39
-	/**
40
-	 * Save changes to a sitemap item
41
-	 *
42
-	 * @param $slug
43
-	 * @param $postValues
44
-	 *
45
-	 * @throws \Exception
46
-	 */
47
-	public function saveSitemapItem($slug, $postValues)
48
-	{
49
-		$sitemapObject = SitemapItemFactory::createSitemapItemFromPostValues($postValues);
39
+    /**
40
+     * Save changes to a sitemap item
41
+     *
42
+     * @param $slug
43
+     * @param $postValues
44
+     *
45
+     * @throws \Exception
46
+     */
47
+    public function saveSitemapItem($slug, $postValues)
48
+    {
49
+        $sitemapObject = SitemapItemFactory::createSitemapItemFromPostValues($postValues);
50 50
 
51
-		$sitemap = $this->repository->sitemap;
52
-		foreach ($sitemap as $key => $sitemapItem) {
53
-			if ($sitemapItem->slug == $slug) {
54
-				$sitemap[$key] = $sitemapObject;
55
-			}
56
-		}
57
-		$this->repository->sitemap = $sitemap;
58
-		$this->save();
59
-	}
51
+        $sitemap = $this->repository->sitemap;
52
+        foreach ($sitemap as $key => $sitemapItem) {
53
+            if ($sitemapItem->slug == $slug) {
54
+                $sitemap[$key] = $sitemapObject;
55
+            }
56
+        }
57
+        $this->repository->sitemap = $sitemap;
58
+        $this->save();
59
+    }
60 60
 
61
-	/**
62
-	 * Delete a sitemap item by its slug
63
-	 *
64
-	 * @param $slug
65
-	 *
66
-	 * @throws \Exception
67
-	 */
68
-	public function deleteSitemapItemBySlug($slug)
69
-	{
70
-		$sitemap = $this->repository->sitemap;
71
-		foreach ($sitemap as $key => $sitemapItem) {
72
-			if ($sitemapItem->slug == $slug) {
73
-				unset($sitemap[$key]);
74
-			}
75
-		}
76
-		$sitemap = array_values($sitemap);
77
-		$this->repository->sitemap = $sitemap;
78
-		$this->save();
79
-	}
61
+    /**
62
+     * Delete a sitemap item by its slug
63
+     *
64
+     * @param $slug
65
+     *
66
+     * @throws \Exception
67
+     */
68
+    public function deleteSitemapItemBySlug($slug)
69
+    {
70
+        $sitemap = $this->repository->sitemap;
71
+        foreach ($sitemap as $key => $sitemapItem) {
72
+            if ($sitemapItem->slug == $slug) {
73
+                unset($sitemap[$key]);
74
+            }
75
+        }
76
+        $sitemap = array_values($sitemap);
77
+        $this->repository->sitemap = $sitemap;
78
+        $this->save();
79
+    }
80 80
 
81
-	/**
82
-	 * Save changes to a sitemap item
83
-	 *
84
-	 * @param $postValues
85
-	 *
86
-	 * @throws \Exception
87
-	 */
88
-	public function saveSitemap($postValues)
89
-	{
90
-		if (isset($postValues['sitemapitem']) && is_array($postValues['sitemapitem'])) {
91
-			$sitemap = array();
92
-			foreach ($postValues['sitemapitem'] as $sitemapItem) {
93
-				$sitemapItemObject = json_decode($sitemapItem);
94
-				if (isset($sitemapItemObject->object)) {
95
-					unset($sitemapItemObject->object);
96
-				}
97
-				$sitemap[] = $sitemapItemObject;
98
-			}
99
-			$this->repository->sitemap = $sitemap;
100
-			$this->save();
101
-		}
102
-	}
81
+    /**
82
+     * Save changes to a sitemap item
83
+     *
84
+     * @param $postValues
85
+     *
86
+     * @throws \Exception
87
+     */
88
+    public function saveSitemap($postValues)
89
+    {
90
+        if (isset($postValues['sitemapitem']) && is_array($postValues['sitemapitem'])) {
91
+            $sitemap = array();
92
+            foreach ($postValues['sitemapitem'] as $sitemapItem) {
93
+                $sitemapItemObject = json_decode($sitemapItem);
94
+                if (isset($sitemapItemObject->object)) {
95
+                    unset($sitemapItemObject->object);
96
+                }
97
+                $sitemap[] = $sitemapItemObject;
98
+            }
99
+            $this->repository->sitemap = $sitemap;
100
+            $this->save();
101
+        }
102
+    }
103 103
 
104
-	/**
105
-	 * Get a sitemap item by its slug
106
-	 *
107
-	 * @param $slug
108
-	 *
109
-	 * @return mixed
110
-	 */
111
-	public function getSitemapItemBySlug($slug)
112
-	{
113
-		$sitemap = $this->repository->sitemap;
114
-		foreach ($sitemap as $sitemapItem) {
115
-			if ($sitemapItem->slug == $slug) {
116
-				return $sitemapItem;
117
-			}
118
-		}
104
+    /**
105
+     * Get a sitemap item by its slug
106
+     *
107
+     * @param $slug
108
+     *
109
+     * @return mixed
110
+     */
111
+    public function getSitemapItemBySlug($slug)
112
+    {
113
+        $sitemap = $this->repository->sitemap;
114
+        foreach ($sitemap as $sitemapItem) {
115
+            if ($sitemapItem->slug == $slug) {
116
+                return $sitemapItem;
117
+            }
118
+        }
119 119
 
120
-		return null;
121
-	}
120
+        return null;
121
+    }
122 122
 }
123 123
\ No newline at end of file
Please login to merge, or discard this patch.