@@ -181,7 +181,7 @@ discard block |
||
181 | 181 | } |
182 | 182 | |
183 | 183 | /** |
184 | - * @param $request |
|
184 | + * @param \library\cc\Request $request |
|
185 | 185 | * |
186 | 186 | * @return mixed|string |
187 | 187 | */ |
@@ -214,6 +214,9 @@ discard block |
||
214 | 214 | } |
215 | 215 | } |
216 | 216 | |
217 | + /** |
|
218 | + * @param \library\cc\Request $request |
|
219 | + */ |
|
217 | 220 | private function logOffRouting($request, $relativeCmsUri) |
218 | 221 | { |
219 | 222 | if ($relativeCmsUri == '/log-off') { |
@@ -307,7 +310,7 @@ discard block |
||
307 | 310 | } |
308 | 311 | |
309 | 312 | /** |
310 | - * @param $crypt |
|
313 | + * @param Crypt $crypt |
|
311 | 314 | * @param $request |
312 | 315 | */ |
313 | 316 | protected function invalidCredentials($crypt, $request) |
@@ -319,7 +322,7 @@ discard block |
||
319 | 322 | |
320 | 323 | /** |
321 | 324 | * @param $user |
322 | - * @param $crypt |
|
325 | + * @param Crypt $crypt |
|
323 | 326 | * @param $request |
324 | 327 | */ |
325 | 328 | protected function checkPassword($user, $crypt, $request) |
@@ -338,7 +341,7 @@ discard block |
||
338 | 341 | } |
339 | 342 | |
340 | 343 | /** |
341 | - * @param $request |
|
344 | + * @param \library\cc\Request $request |
|
342 | 345 | */ |
343 | 346 | protected function checkLoginAttempt($request) |
344 | 347 | { |
@@ -147,7 +147,7 @@ discard block |
||
147 | 147 | * submitting the form |
148 | 148 | * |
149 | 149 | * @param $postValues |
150 | - * @param $storage |
|
150 | + * @param Storage $storage |
|
151 | 151 | */ |
152 | 152 | protected function postSubmit($postValues, $storage) |
153 | 153 | { |
@@ -318,7 +318,7 @@ discard block |
||
318 | 318 | } |
319 | 319 | |
320 | 320 | /** |
321 | - * @param $form |
|
321 | + * @param string|null $form |
|
322 | 322 | */ |
323 | 323 | private function setFormParameter($form) |
324 | 324 | { |
@@ -358,7 +358,7 @@ discard block |
||
358 | 358 | /** |
359 | 359 | * Convert path to indeces |
360 | 360 | * |
361 | - * @param $path |
|
361 | + * @param string $path |
|
362 | 362 | * |
363 | 363 | * @return array |
364 | 364 | * @throws \Exception |
@@ -373,7 +373,7 @@ discard block |
||
373 | 373 | * |
374 | 374 | * @param $postValues |
375 | 375 | * |
376 | - * @return \stdClass |
|
376 | + * @return Document |
|
377 | 377 | * @throws \Exception |
378 | 378 | */ |
379 | 379 | private function createDocumentFolderFromPostValues($postValues) |
@@ -666,6 +666,9 @@ discard block |
||
666 | 666 | } |
667 | 667 | } |
668 | 668 | |
669 | + /** |
|
670 | + * @param string $path |
|
671 | + */ |
|
669 | 672 | private function validateFilename($filename, $path) |
670 | 673 | { |
671 | 674 | $fileParts = explode('.', $filename); |
@@ -2,19 +2,19 @@ discard block |
||
2 | 2 | namespace library\storage |
3 | 3 | { |
4 | 4 | |
5 | - use library\crypt\Crypt; |
|
6 | - use library\images\ImageResizer; |
|
5 | + use library\crypt\Crypt; |
|
6 | + use library\images\ImageResizer; |
|
7 | 7 | |
8 | - /** |
|
8 | + /** |
|
9 | 9 | * Class JsonStorage |
10 | 10 | * @package library\storage |
11 | 11 | */ |
12 | 12 | class JsonStorage implements Storage |
13 | 13 | { |
14 | 14 | private $storageDir; |
15 | - /** |
|
16 | - * @var Repository |
|
17 | - */ |
|
15 | + /** |
|
16 | + * @var Repository |
|
17 | + */ |
|
18 | 18 | private $repository; |
19 | 19 | |
20 | 20 | /** |
@@ -124,9 +124,9 @@ discard block |
||
124 | 124 | if (!empty($doesItExist)) { |
125 | 125 | throw new \Exception('Trying to add username that already exists.'); |
126 | 126 | } |
127 | - $users = $this->repository->users; |
|
128 | - $users[] = $userObj; |
|
129 | - $this->repository->users = $users; |
|
127 | + $users = $this->repository->users; |
|
128 | + $users[] = $userObj; |
|
129 | + $this->repository->users = $users; |
|
130 | 130 | $this->save(); |
131 | 131 | } |
132 | 132 | |
@@ -194,40 +194,40 @@ discard block |
||
194 | 194 | */ |
195 | 195 | public function getDocumentBySlug($slug) |
196 | 196 | { |
197 | - $path = '/' . $slug; |
|
197 | + $path = '/' . $slug; |
|
198 | 198 | return $this->repository->getDocumentByPath($path); |
199 | 199 | } |
200 | 200 | |
201 | 201 | public function saveDocument($postValues) |
202 | 202 | { |
203 | - $oldPath = '/' . $postValues['path']; |
|
203 | + $oldPath = '/' . $postValues['path']; |
|
204 | 204 | |
205 | - $container = $this->getDocumentContainerByPath($oldPath); |
|
206 | - $documentObject = $this->createDocumentFromPostValues($postValues); |
|
207 | - if ($container->path === '/') { |
|
208 | - $newPath = $container->path . $documentObject->slug; |
|
209 | - } else { |
|
210 | - $newPath = $container->path . '/' . $documentObject->slug; |
|
211 | - } |
|
212 | - $documentObject->path = $newPath; |
|
213 | - $this->repository->saveDocument($documentObject); |
|
214 | - } |
|
205 | + $container = $this->getDocumentContainerByPath($oldPath); |
|
206 | + $documentObject = $this->createDocumentFromPostValues($postValues); |
|
207 | + if ($container->path === '/') { |
|
208 | + $newPath = $container->path . $documentObject->slug; |
|
209 | + } else { |
|
210 | + $newPath = $container->path . '/' . $documentObject->slug; |
|
211 | + } |
|
212 | + $documentObject->path = $newPath; |
|
213 | + $this->repository->saveDocument($documentObject); |
|
214 | + } |
|
215 | 215 | |
216 | 216 | public function addDocument($postValues) |
217 | 217 | { |
218 | 218 | $documentObject = $this->createDocumentFromPostValues($postValues); |
219 | - if ($postValues['path'] === '/') { |
|
220 | - $documentObject->path = $postValues['path'] . $documentObject->slug; |
|
221 | - } else { |
|
222 | - $documentObject->path = $postValues['path'] . '/' . $documentObject->slug; |
|
223 | - } |
|
219 | + if ($postValues['path'] === '/') { |
|
220 | + $documentObject->path = $postValues['path'] . $documentObject->slug; |
|
221 | + } else { |
|
222 | + $documentObject->path = $postValues['path'] . '/' . $documentObject->slug; |
|
223 | + } |
|
224 | 224 | |
225 | - $this->repository->saveDocument($documentObject); |
|
225 | + $this->repository->saveDocument($documentObject); |
|
226 | 226 | } |
227 | 227 | |
228 | 228 | public function deleteDocumentBySlug($slug) |
229 | 229 | { |
230 | - $path = '/' . $slug; |
|
230 | + $path = '/' . $slug; |
|
231 | 231 | $this->repository->deleteDocumentByPath($path); |
232 | 232 | } |
233 | 233 | |
@@ -307,13 +307,13 @@ discard block |
||
307 | 307 | */ |
308 | 308 | public function addDocumentFolder($postValues) |
309 | 309 | { |
310 | - $documentFolderObject = $this->createDocumentFolderFromPostValues($postValues); |
|
311 | - if ($postValues['path'] === '/') { |
|
312 | - $documentFolderObject->path = $postValues['path'] . $documentFolderObject->slug; |
|
313 | - } else { |
|
314 | - $documentFolderObject->path = $postValues['path'] . '/' . $documentFolderObject->slug; |
|
315 | - } |
|
316 | - $this->repository->saveDocument($documentFolderObject); |
|
310 | + $documentFolderObject = $this->createDocumentFolderFromPostValues($postValues); |
|
311 | + if ($postValues['path'] === '/') { |
|
312 | + $documentFolderObject->path = $postValues['path'] . $documentFolderObject->slug; |
|
313 | + } else { |
|
314 | + $documentFolderObject->path = $postValues['path'] . '/' . $documentFolderObject->slug; |
|
315 | + } |
|
316 | + $this->repository->saveDocument($documentFolderObject); |
|
317 | 317 | } |
318 | 318 | |
319 | 319 | /** |
@@ -325,7 +325,7 @@ discard block |
||
325 | 325 | */ |
326 | 326 | public function deleteDocumentFolderBySlug($slug) |
327 | 327 | { |
328 | - $path = '/' . $slug; |
|
328 | + $path = '/' . $slug; |
|
329 | 329 | $this->repository->deleteDocumentByPath($path); |
330 | 330 | } |
331 | 331 | |
@@ -339,7 +339,7 @@ discard block |
||
339 | 339 | */ |
340 | 340 | public function getDocumentFolderBySlug($slug) |
341 | 341 | { |
342 | - $path = '/' . $slug; |
|
342 | + $path = '/' . $slug; |
|
343 | 343 | return $this->repository->getDocumentByPath($path); |
344 | 344 | } |
345 | 345 | |
@@ -352,7 +352,7 @@ discard block |
||
352 | 352 | */ |
353 | 353 | public function saveDocumentFolder($postValues) |
354 | 354 | { |
355 | - $this->addDocumentFolder($postValues); |
|
355 | + $this->addDocumentFolder($postValues); |
|
356 | 356 | } |
357 | 357 | |
358 | 358 | /** |
@@ -365,7 +365,7 @@ discard block |
||
365 | 365 | */ |
366 | 366 | private function getDocumentContainerByPath($path) |
367 | 367 | { |
368 | - return $this->repository->getDocumentContainerByPath($path); |
|
368 | + return $this->repository->getDocumentContainerByPath($path); |
|
369 | 369 | } |
370 | 370 | |
371 | 371 | /** |
@@ -569,9 +569,9 @@ discard block |
||
569 | 569 | $imageObject->size = $postValues['size']; |
570 | 570 | $imageObject->set = $fileNames; |
571 | 571 | |
572 | - $images = $this->repository->images; |
|
572 | + $images = $this->repository->images; |
|
573 | 573 | $images[] = $imageObject; |
574 | - $this->repository->images = $images; |
|
574 | + $this->repository->images = $images; |
|
575 | 575 | |
576 | 576 | $this->save(); |
577 | 577 | } else { |
@@ -606,7 +606,7 @@ discard block |
||
606 | 606 | /** |
607 | 607 | * @param $filename |
608 | 608 | * @return null |
609 | - */ |
|
609 | + */ |
|
610 | 610 | public function getImageByName($filename) |
611 | 611 | { |
612 | 612 | $images = $this->getImages(); |
@@ -657,9 +657,9 @@ discard block |
||
657 | 657 | $file->type = $postValues['type']; |
658 | 658 | $file->size = $postValues['size']; |
659 | 659 | |
660 | - $files = $this->repository->files; |
|
660 | + $files = $this->repository->files; |
|
661 | 661 | $files[] = $file; |
662 | - $this->repository->files = $files; |
|
662 | + $this->repository->files = $files; |
|
663 | 663 | $this->save(); |
664 | 664 | } else { |
665 | 665 | throw new \Exception('Error moving uploaded file'); |
@@ -698,7 +698,7 @@ discard block |
||
698 | 698 | /** |
699 | 699 | * @param $filename |
700 | 700 | * @return null |
701 | - */ |
|
701 | + */ |
|
702 | 702 | public function getFileByName($filename) |
703 | 703 | { |
704 | 704 | $files = $this->getFiles(); |
@@ -713,7 +713,7 @@ discard block |
||
713 | 713 | /** |
714 | 714 | * @param $filename |
715 | 715 | * @throws \Exception |
716 | - */ |
|
716 | + */ |
|
717 | 717 | public function deleteFileByName($filename) |
718 | 718 | { |
719 | 719 | $destinationPath = realpath(__DIR__ . '/../../www/files/'); |
@@ -758,9 +758,9 @@ discard block |
||
758 | 758 | { |
759 | 759 | $documentTypeObject = $this->createDocumentTypeFromPostValues($postValues); |
760 | 760 | |
761 | - $documentTypes = $this->repository->documentTypes; |
|
762 | - $documentTypes[] = $documentTypeObject; |
|
763 | - $this->repository->documentTypes = $documentTypes; |
|
761 | + $documentTypes = $this->repository->documentTypes; |
|
762 | + $documentTypes[] = $documentTypeObject; |
|
763 | + $this->repository->documentTypes = $documentTypes; |
|
764 | 764 | |
765 | 765 | $this->save(); |
766 | 766 | } |
@@ -906,9 +906,9 @@ discard block |
||
906 | 906 | { |
907 | 907 | $brickObject = $this->createBrickFromPostValues($postValues); |
908 | 908 | |
909 | - $bricks = $this->repository->bricks; |
|
910 | - $bricks[] = $brickObject; |
|
911 | - $this->repository->bricks = $bricks; |
|
909 | + $bricks = $this->repository->bricks; |
|
910 | + $bricks[] = $brickObject; |
|
911 | + $this->repository->bricks = $bricks; |
|
912 | 912 | |
913 | 913 | $this->save(); |
914 | 914 | } |
@@ -1113,9 +1113,9 @@ discard block |
||
1113 | 1113 | { |
1114 | 1114 | $imageSetObject = $this->createImageSetFromPostValues($postValues); |
1115 | 1115 | |
1116 | - $imageSet = $this->repository->imageSet; |
|
1117 | - $imageSet[] = $imageSetObject; |
|
1118 | - $this->repository->imageSet = $imageSet; |
|
1116 | + $imageSet = $this->repository->imageSet; |
|
1117 | + $imageSet[] = $imageSetObject; |
|
1118 | + $this->repository->imageSet = $imageSet; |
|
1119 | 1119 | |
1120 | 1120 | $this->save(); |
1121 | 1121 | } |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | */ |
37 | 37 | private function config() |
38 | 38 | { |
39 | - $storagePath = __DIR__ . '/../../' . $this->storageDir; |
|
39 | + $storagePath = __DIR__.'/../../'.$this->storageDir; |
|
40 | 40 | if (realpath($storagePath) === false) { |
41 | 41 | initFramework($storagePath); |
42 | 42 | if (Repository::create($storagePath)) { |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | $repository->init(); |
45 | 45 | $this->repository = $repository; |
46 | 46 | } else { |
47 | - throw new \Exception('Could not create repository directory: ' . $storagePath); |
|
47 | + throw new \Exception('Could not create repository directory: '.$storagePath); |
|
48 | 48 | } |
49 | 49 | } else { |
50 | 50 | $this->repository = new Repository($storagePath); |
@@ -194,20 +194,20 @@ discard block |
||
194 | 194 | */ |
195 | 195 | public function getDocumentBySlug($slug) |
196 | 196 | { |
197 | - $path = '/' . $slug; |
|
197 | + $path = '/'.$slug; |
|
198 | 198 | return $this->repository->getDocumentByPath($path); |
199 | 199 | } |
200 | 200 | |
201 | 201 | public function saveDocument($postValues) |
202 | 202 | { |
203 | - $oldPath = '/' . $postValues['path']; |
|
203 | + $oldPath = '/'.$postValues['path']; |
|
204 | 204 | |
205 | 205 | $container = $this->getDocumentContainerByPath($oldPath); |
206 | 206 | $documentObject = $this->createDocumentFromPostValues($postValues); |
207 | 207 | if ($container->path === '/') { |
208 | - $newPath = $container->path . $documentObject->slug; |
|
208 | + $newPath = $container->path.$documentObject->slug; |
|
209 | 209 | } else { |
210 | - $newPath = $container->path . '/' . $documentObject->slug; |
|
210 | + $newPath = $container->path.'/'.$documentObject->slug; |
|
211 | 211 | } |
212 | 212 | $documentObject->path = $newPath; |
213 | 213 | $this->repository->saveDocument($documentObject); |
@@ -217,9 +217,9 @@ discard block |
||
217 | 217 | { |
218 | 218 | $documentObject = $this->createDocumentFromPostValues($postValues); |
219 | 219 | if ($postValues['path'] === '/') { |
220 | - $documentObject->path = $postValues['path'] . $documentObject->slug; |
|
220 | + $documentObject->path = $postValues['path'].$documentObject->slug; |
|
221 | 221 | } else { |
222 | - $documentObject->path = $postValues['path'] . '/' . $documentObject->slug; |
|
222 | + $documentObject->path = $postValues['path'].'/'.$documentObject->slug; |
|
223 | 223 | } |
224 | 224 | |
225 | 225 | $this->repository->saveDocument($documentObject); |
@@ -227,7 +227,7 @@ discard block |
||
227 | 227 | |
228 | 228 | public function deleteDocumentBySlug($slug) |
229 | 229 | { |
230 | - $path = '/' . $slug; |
|
230 | + $path = '/'.$slug; |
|
231 | 231 | $this->repository->deleteDocumentByPath($path); |
232 | 232 | } |
233 | 233 | |
@@ -309,9 +309,9 @@ discard block |
||
309 | 309 | { |
310 | 310 | $documentFolderObject = $this->createDocumentFolderFromPostValues($postValues); |
311 | 311 | if ($postValues['path'] === '/') { |
312 | - $documentFolderObject->path = $postValues['path'] . $documentFolderObject->slug; |
|
312 | + $documentFolderObject->path = $postValues['path'].$documentFolderObject->slug; |
|
313 | 313 | } else { |
314 | - $documentFolderObject->path = $postValues['path'] . '/' . $documentFolderObject->slug; |
|
314 | + $documentFolderObject->path = $postValues['path'].'/'.$documentFolderObject->slug; |
|
315 | 315 | } |
316 | 316 | $this->repository->saveDocument($documentFolderObject); |
317 | 317 | } |
@@ -325,7 +325,7 @@ discard block |
||
325 | 325 | */ |
326 | 326 | public function deleteDocumentFolderBySlug($slug) |
327 | 327 | { |
328 | - $path = '/' . $slug; |
|
328 | + $path = '/'.$slug; |
|
329 | 329 | $this->repository->deleteDocumentByPath($path); |
330 | 330 | } |
331 | 331 | |
@@ -339,7 +339,7 @@ discard block |
||
339 | 339 | */ |
340 | 340 | public function getDocumentFolderBySlug($slug) |
341 | 341 | { |
342 | - $path = '/' . $slug; |
|
342 | + $path = '/'.$slug; |
|
343 | 343 | return $this->repository->getDocumentByPath($path); |
344 | 344 | } |
345 | 345 | |
@@ -550,13 +550,13 @@ discard block |
||
550 | 550 | |
551 | 551 | public function addImage($postValues) |
552 | 552 | { |
553 | - $destinationPath = realpath(__DIR__ . '/../../www/images/'); |
|
553 | + $destinationPath = realpath(__DIR__.'/../../www/images/'); |
|
554 | 554 | |
555 | 555 | $filename = $this->validateFilename($postValues['name'], $destinationPath); |
556 | - $destination = $destinationPath . '/' . $filename; |
|
556 | + $destination = $destinationPath.'/'.$filename; |
|
557 | 557 | |
558 | 558 | if ($postValues['error'] != '0') { |
559 | - throw new \Exception('Error uploading file. Error code: ' . $postValues['error']); |
|
559 | + throw new \Exception('Error uploading file. Error code: '.$postValues['error']); |
|
560 | 560 | } |
561 | 561 | |
562 | 562 | if (move_uploaded_file($postValues['tmp_name'], $destination)) { |
@@ -581,14 +581,14 @@ discard block |
||
581 | 581 | |
582 | 582 | public function deleteImageByName($filename) |
583 | 583 | { |
584 | - $destinationPath = realpath(__DIR__ . '/../../www/images/'); |
|
584 | + $destinationPath = realpath(__DIR__.'/../../www/images/'); |
|
585 | 585 | |
586 | 586 | $images = $this->getImages(); |
587 | 587 | |
588 | 588 | foreach ($images as $key => $image) { |
589 | 589 | if ($image->file == $filename) { |
590 | 590 | foreach ($image->set as $imageSetFilename) { |
591 | - $destination = $destinationPath . '/' . $imageSetFilename; |
|
591 | + $destination = $destinationPath.'/'.$imageSetFilename; |
|
592 | 592 | if (file_exists($destination)) { |
593 | 593 | unlink($destination); |
594 | 594 | } else { |
@@ -630,7 +630,7 @@ discard block |
||
630 | 630 | */ |
631 | 631 | public function getFiles() |
632 | 632 | { |
633 | - $files = $this->repository->files; |
|
633 | + $files = $this->repository->files; |
|
634 | 634 | usort($files, array($this, 'compareFiles')); |
635 | 635 | return $files; |
636 | 636 | } |
@@ -642,13 +642,13 @@ discard block |
||
642 | 642 | |
643 | 643 | public function addFile($postValues) |
644 | 644 | { |
645 | - $destinationPath = realpath(__DIR__ . '/../../www/files/'); |
|
645 | + $destinationPath = realpath(__DIR__.'/../../www/files/'); |
|
646 | 646 | |
647 | 647 | $filename = $this->validateFilename($postValues['name'], $destinationPath); |
648 | - $destination = $destinationPath . '/' . $filename; |
|
648 | + $destination = $destinationPath.'/'.$filename; |
|
649 | 649 | |
650 | 650 | if ($postValues['error'] != '0') { |
651 | - throw new \Exception('Error uploading file. Error code: ' . $postValues['error']); |
|
651 | + throw new \Exception('Error uploading file. Error code: '.$postValues['error']); |
|
652 | 652 | } |
653 | 653 | |
654 | 654 | if (move_uploaded_file($postValues['tmp_name'], $destination)) { |
@@ -674,23 +674,23 @@ discard block |
||
674 | 674 | array_pop($fileParts); |
675 | 675 | $fileNameWithoutExtension = implode('-', $fileParts); |
676 | 676 | $fileNameWithoutExtension = slugify($fileNameWithoutExtension); |
677 | - $filename = $fileNameWithoutExtension . '.' . $extension; |
|
677 | + $filename = $fileNameWithoutExtension.'.'.$extension; |
|
678 | 678 | } else { |
679 | 679 | $filename = slugify($filename); |
680 | 680 | } |
681 | 681 | |
682 | - if (file_exists($path . '/' . $filename)) { |
|
682 | + if (file_exists($path.'/'.$filename)) { |
|
683 | 683 | $fileParts = explode('.', $filename); |
684 | 684 | if (count($fileParts) > 1) { |
685 | 685 | $extension = end($fileParts); |
686 | 686 | array_pop($fileParts); |
687 | 687 | $fileNameWithoutExtension = implode('-', $fileParts); |
688 | 688 | $fileNameWithoutExtension .= '-copy'; |
689 | - $filename = $fileNameWithoutExtension . '.' . $extension; |
|
689 | + $filename = $fileNameWithoutExtension.'.'.$extension; |
|
690 | 690 | } else { |
691 | 691 | $filename .= '-copy'; |
692 | 692 | } |
693 | - return $this->validateFilename($filename,$path); |
|
693 | + return $this->validateFilename($filename, $path); |
|
694 | 694 | } |
695 | 695 | return $filename; |
696 | 696 | } |
@@ -716,8 +716,8 @@ discard block |
||
716 | 716 | */ |
717 | 717 | public function deleteFileByName($filename) |
718 | 718 | { |
719 | - $destinationPath = realpath(__DIR__ . '/../../www/files/'); |
|
720 | - $destination = $destinationPath . '/' . $filename; |
|
719 | + $destinationPath = realpath(__DIR__.'/../../www/files/'); |
|
720 | + $destination = $destinationPath.'/'.$filename; |
|
721 | 721 | |
722 | 722 | if (file_exists($destination)) { |
723 | 723 | $files = $this->getFiles(); |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | |
52 | 52 | /** |
53 | 53 | * Repository constructor. |
54 | - * @param $storagePath |
|
54 | + * @param string $storagePath |
|
55 | 55 | * @throws \Exception |
56 | 56 | */ |
57 | 57 | public function __construct($storagePath) |
@@ -67,7 +67,7 @@ discard block |
||
67 | 67 | /** |
68 | 68 | * Creates the folder in which to create all storage related files |
69 | 69 | * |
70 | - * @param $storagePath |
|
70 | + * @param string $storagePath |
|
71 | 71 | * @return bool |
72 | 72 | */ |
73 | 73 | public static function create($storagePath) |
@@ -130,6 +130,9 @@ discard block |
||
130 | 130 | $this->usersChanges ? $this->saveSubset('users') : null; |
131 | 131 | } |
132 | 132 | |
133 | + /** |
|
134 | + * @param string $subset |
|
135 | + */ |
|
133 | 136 | protected function saveSubset($subset) |
134 | 137 | { |
135 | 138 | $json = json_encode($this->$subset); |
@@ -149,7 +152,7 @@ discard block |
||
149 | 152 | } |
150 | 153 | |
151 | 154 | /** |
152 | - * @param $contentSqlPath |
|
155 | + * @param string $contentSqlPath |
|
153 | 156 | */ |
154 | 157 | protected function initContentDb($contentSqlPath) |
155 | 158 | { |
@@ -159,7 +162,7 @@ discard block |
||
159 | 162 | } |
160 | 163 | |
161 | 164 | /** |
162 | - * @param $storageDefaultPath |
|
165 | + * @param string $storageDefaultPath |
|
163 | 166 | */ |
164 | 167 | protected function initConfigStorage($storageDefaultPath) |
165 | 168 | { |
@@ -199,6 +202,9 @@ discard block |
||
199 | 202 | return $this->getDocumentsByPath('/'); |
200 | 203 | } |
201 | 204 | |
205 | + /** |
|
206 | + * @param string $folderPath |
|
207 | + */ |
|
202 | 208 | public function getDocumentsByPath($folderPath) |
203 | 209 | { |
204 | 210 | $db = $this->getContentDbHandle(); |
@@ -267,6 +273,9 @@ discard block |
||
267 | 273 | return $stmt->fetchAll(\PDO::FETCH_CLASS, '\library\storage\Document'); |
268 | 274 | } |
269 | 275 | |
276 | + /** |
|
277 | + * @param string $sql |
|
278 | + */ |
|
270 | 279 | protected function fetchDocument($sql) |
271 | 280 | { |
272 | 281 | $stmt = $this->getDbStatement($sql); |
@@ -328,6 +337,9 @@ discard block |
||
328 | 337 | return $result; |
329 | 338 | } |
330 | 339 | |
340 | + /** |
|
341 | + * @param string $path |
|
342 | + */ |
|
331 | 343 | public function deleteDocumentByPath($path) |
332 | 344 | { |
333 | 345 | $db = $this->getContentDbHandle(); |
@@ -19,192 +19,192 @@ discard block |
||
19 | 19 | |
20 | 20 | class Repository |
21 | 21 | { |
22 | - protected $storagePath; |
|
23 | - |
|
24 | - protected $fileBasedSubsets = array('sitemap', 'applicationComponents', 'documentTypes', 'bricks', 'imageSet', 'images', 'files', 'users'); |
|
25 | - |
|
26 | - protected $sitemap; |
|
27 | - protected $sitemapChanges = false; |
|
28 | - |
|
29 | - protected $applicationComponents; |
|
30 | - protected $applicationComponentsChanges = false; |
|
31 | - |
|
32 | - protected $documentTypes; |
|
33 | - protected $documentTypesChanges = false; |
|
34 | - |
|
35 | - protected $bricks; |
|
36 | - protected $bricksChanges = false; |
|
37 | - |
|
38 | - protected $imageSet; |
|
39 | - protected $imageSetChanges = false; |
|
40 | - |
|
41 | - protected $images; |
|
42 | - protected $imagesChanges = false; |
|
43 | - |
|
44 | - protected $files; |
|
45 | - protected $filesChanges = false; |
|
46 | - |
|
47 | - protected $users; |
|
48 | - protected $usersChanges = false; |
|
49 | - |
|
50 | - protected $contentDbHandle; |
|
51 | - |
|
52 | - /** |
|
53 | - * Repository constructor. |
|
54 | - * @param $storagePath |
|
55 | - * @throws \Exception |
|
56 | - */ |
|
57 | - public function __construct($storagePath) |
|
58 | - { |
|
59 | - $storagePath = realpath($storagePath); |
|
60 | - if (is_dir($storagePath) && $storagePath !== false) { |
|
61 | - $this->storagePath = $storagePath; |
|
62 | - } else { |
|
63 | - throw new \Exception('Repository not yet initialized.'); |
|
64 | - } |
|
65 | - } |
|
66 | - |
|
67 | - /** |
|
68 | - * Creates the folder in which to create all storage related files |
|
69 | - * |
|
70 | - * @param $storagePath |
|
71 | - * @return bool |
|
72 | - */ |
|
73 | - public static function create($storagePath) |
|
74 | - { |
|
75 | - return mkdir($storagePath); |
|
76 | - } |
|
77 | - |
|
78 | - /** |
|
79 | - * Initiates default storage |
|
80 | - * @throws \Exception |
|
81 | - */ |
|
82 | - public function init() |
|
83 | - { |
|
84 | - $storageDefaultPath = realpath('../library/cc/install/_storage.json'); |
|
85 | - $contentSqlPath = realpath('../library/cc/install/content.sql'); |
|
86 | - |
|
87 | - $this->initConfigStorage($storageDefaultPath); |
|
88 | - $this->initContentDb($contentSqlPath); |
|
89 | - |
|
90 | - $this->save(); |
|
91 | - } |
|
92 | - |
|
93 | - public function __get($name) |
|
94 | - { |
|
95 | - if (isset($this->$name)) { |
|
96 | - if (in_array($name, $this->fileBasedSubsets)) { |
|
97 | - return $this->$name; |
|
98 | - } else { |
|
99 | - dump(); |
|
100 | - } |
|
101 | - } else { |
|
102 | - if (in_array($name, $this->fileBasedSubsets)) { |
|
103 | - return $this->loadSubset($name); |
|
104 | - } else { |
|
105 | - throw new \Exception('Trying to get undefined property from Repository: ' . $name); |
|
106 | - } |
|
107 | - } |
|
108 | - } |
|
109 | - |
|
110 | - public function __set($name, $value) |
|
111 | - { |
|
112 | - if (in_array($name, $this->fileBasedSubsets)) { |
|
113 | - $this->$name = $value; |
|
114 | - $changes = $name . 'Changes'; |
|
115 | - $this->$changes = true; |
|
116 | - } else { |
|
117 | - throw new \Exception('Trying to persist unknown subset in repository: ' . $name . ' <br /><pre>' . print_r($value, true) . '</pre>'); |
|
118 | - } |
|
119 | - } |
|
120 | - |
|
121 | - public function save() |
|
122 | - { |
|
123 | - $this->sitemapChanges ? $this->saveSubset('sitemap') : null; |
|
124 | - $this->applicationComponentsChanges ? $this->saveSubset('applicationComponents') : null; |
|
125 | - $this->documentTypesChanges ? $this->saveSubset('documentTypes') : null; |
|
126 | - $this->bricksChanges ? $this->saveSubset('bricks') : null; |
|
127 | - $this->imageSetChanges ? $this->saveSubset('imageSet') : null; |
|
128 | - $this->imagesChanges ? $this->saveSubset('images') : null; |
|
129 | - $this->filesChanges ? $this->saveSubset('files') : null; |
|
130 | - $this->usersChanges ? $this->saveSubset('users') : null; |
|
131 | - } |
|
132 | - |
|
133 | - protected function saveSubset($subset) |
|
134 | - { |
|
135 | - $json = json_encode($this->$subset); |
|
136 | - $subsetStoragePath = $this->storagePath . DIRECTORY_SEPARATOR . $subset . '.json'; |
|
137 | - file_put_contents($subsetStoragePath, $json); |
|
138 | - $changes = $subset . 'Changes'; |
|
139 | - $this->$changes = false; |
|
140 | - } |
|
141 | - |
|
142 | - protected function loadSubset($subset) |
|
143 | - { |
|
144 | - $subsetStoragePath = $this->storagePath . DIRECTORY_SEPARATOR . $subset . '.json'; |
|
145 | - $json = file_get_contents($subsetStoragePath); |
|
146 | - $json = json_decode($json); |
|
147 | - $this->$subset = $json; |
|
148 | - return $json; |
|
149 | - } |
|
150 | - |
|
151 | - /** |
|
152 | - * @param $contentSqlPath |
|
153 | - */ |
|
154 | - protected function initContentDb($contentSqlPath) |
|
155 | - { |
|
156 | - $db = $this->getContentDbHandle(); |
|
157 | - $sql = file_get_contents($contentSqlPath); |
|
158 | - $db->exec($sql); |
|
159 | - } |
|
160 | - |
|
161 | - /** |
|
162 | - * @param $storageDefaultPath |
|
163 | - */ |
|
164 | - protected function initConfigStorage($storageDefaultPath) |
|
165 | - { |
|
166 | - $json = file_get_contents($storageDefaultPath); |
|
167 | - $json = json_decode($json); |
|
168 | - $this->sitemap = $json->sitemap; |
|
169 | - $this->sitemapChanges = true; |
|
170 | - $this->applicationComponents = $json->applicationComponents; |
|
171 | - $this->applicationComponentsChanges = true; |
|
172 | - $this->documentTypes = $json->documentTypes; |
|
173 | - $this->documentTypesChanges = true; |
|
174 | - $this->bricks = $json->bricks; |
|
175 | - $this->bricksChanges = true; |
|
176 | - $this->imageSet = $json->imageSet; |
|
177 | - $this->imageSetChanges = true; |
|
178 | - $this->images = $json->images; |
|
179 | - $this->imagesChanges = true; |
|
180 | - $this->files = $json->files; |
|
181 | - $this->filesChanges = true; |
|
182 | - $this->users = $json->users; |
|
183 | - $this->usersChanges = true; |
|
184 | - } |
|
185 | - |
|
186 | - /** |
|
187 | - * @return \PDO |
|
188 | - */ |
|
189 | - protected function getContentDbHandle() |
|
190 | - { |
|
191 | - if ($this->contentDbHandle === null) { |
|
192 | - $this->contentDbHandle = new \PDO('sqlite:' . $this->storagePath . DIRECTORY_SEPARATOR . 'content.db'); |
|
193 | - } |
|
194 | - return $this->contentDbHandle; |
|
195 | - } |
|
196 | - |
|
197 | - public function getDocuments() |
|
198 | - { |
|
199 | - return $this->getDocumentsByPath('/'); |
|
200 | - } |
|
201 | - |
|
202 | - public function getDocumentsByPath($folderPath) |
|
203 | - { |
|
204 | - $db = $this->getContentDbHandle(); |
|
205 | - $folderPathWithWildcard = $folderPath . '%'; |
|
206 | - |
|
207 | - $stmt = $this->getDbStatement(' |
|
22 | + protected $storagePath; |
|
23 | + |
|
24 | + protected $fileBasedSubsets = array('sitemap', 'applicationComponents', 'documentTypes', 'bricks', 'imageSet', 'images', 'files', 'users'); |
|
25 | + |
|
26 | + protected $sitemap; |
|
27 | + protected $sitemapChanges = false; |
|
28 | + |
|
29 | + protected $applicationComponents; |
|
30 | + protected $applicationComponentsChanges = false; |
|
31 | + |
|
32 | + protected $documentTypes; |
|
33 | + protected $documentTypesChanges = false; |
|
34 | + |
|
35 | + protected $bricks; |
|
36 | + protected $bricksChanges = false; |
|
37 | + |
|
38 | + protected $imageSet; |
|
39 | + protected $imageSetChanges = false; |
|
40 | + |
|
41 | + protected $images; |
|
42 | + protected $imagesChanges = false; |
|
43 | + |
|
44 | + protected $files; |
|
45 | + protected $filesChanges = false; |
|
46 | + |
|
47 | + protected $users; |
|
48 | + protected $usersChanges = false; |
|
49 | + |
|
50 | + protected $contentDbHandle; |
|
51 | + |
|
52 | + /** |
|
53 | + * Repository constructor. |
|
54 | + * @param $storagePath |
|
55 | + * @throws \Exception |
|
56 | + */ |
|
57 | + public function __construct($storagePath) |
|
58 | + { |
|
59 | + $storagePath = realpath($storagePath); |
|
60 | + if (is_dir($storagePath) && $storagePath !== false) { |
|
61 | + $this->storagePath = $storagePath; |
|
62 | + } else { |
|
63 | + throw new \Exception('Repository not yet initialized.'); |
|
64 | + } |
|
65 | + } |
|
66 | + |
|
67 | + /** |
|
68 | + * Creates the folder in which to create all storage related files |
|
69 | + * |
|
70 | + * @param $storagePath |
|
71 | + * @return bool |
|
72 | + */ |
|
73 | + public static function create($storagePath) |
|
74 | + { |
|
75 | + return mkdir($storagePath); |
|
76 | + } |
|
77 | + |
|
78 | + /** |
|
79 | + * Initiates default storage |
|
80 | + * @throws \Exception |
|
81 | + */ |
|
82 | + public function init() |
|
83 | + { |
|
84 | + $storageDefaultPath = realpath('../library/cc/install/_storage.json'); |
|
85 | + $contentSqlPath = realpath('../library/cc/install/content.sql'); |
|
86 | + |
|
87 | + $this->initConfigStorage($storageDefaultPath); |
|
88 | + $this->initContentDb($contentSqlPath); |
|
89 | + |
|
90 | + $this->save(); |
|
91 | + } |
|
92 | + |
|
93 | + public function __get($name) |
|
94 | + { |
|
95 | + if (isset($this->$name)) { |
|
96 | + if (in_array($name, $this->fileBasedSubsets)) { |
|
97 | + return $this->$name; |
|
98 | + } else { |
|
99 | + dump(); |
|
100 | + } |
|
101 | + } else { |
|
102 | + if (in_array($name, $this->fileBasedSubsets)) { |
|
103 | + return $this->loadSubset($name); |
|
104 | + } else { |
|
105 | + throw new \Exception('Trying to get undefined property from Repository: ' . $name); |
|
106 | + } |
|
107 | + } |
|
108 | + } |
|
109 | + |
|
110 | + public function __set($name, $value) |
|
111 | + { |
|
112 | + if (in_array($name, $this->fileBasedSubsets)) { |
|
113 | + $this->$name = $value; |
|
114 | + $changes = $name . 'Changes'; |
|
115 | + $this->$changes = true; |
|
116 | + } else { |
|
117 | + throw new \Exception('Trying to persist unknown subset in repository: ' . $name . ' <br /><pre>' . print_r($value, true) . '</pre>'); |
|
118 | + } |
|
119 | + } |
|
120 | + |
|
121 | + public function save() |
|
122 | + { |
|
123 | + $this->sitemapChanges ? $this->saveSubset('sitemap') : null; |
|
124 | + $this->applicationComponentsChanges ? $this->saveSubset('applicationComponents') : null; |
|
125 | + $this->documentTypesChanges ? $this->saveSubset('documentTypes') : null; |
|
126 | + $this->bricksChanges ? $this->saveSubset('bricks') : null; |
|
127 | + $this->imageSetChanges ? $this->saveSubset('imageSet') : null; |
|
128 | + $this->imagesChanges ? $this->saveSubset('images') : null; |
|
129 | + $this->filesChanges ? $this->saveSubset('files') : null; |
|
130 | + $this->usersChanges ? $this->saveSubset('users') : null; |
|
131 | + } |
|
132 | + |
|
133 | + protected function saveSubset($subset) |
|
134 | + { |
|
135 | + $json = json_encode($this->$subset); |
|
136 | + $subsetStoragePath = $this->storagePath . DIRECTORY_SEPARATOR . $subset . '.json'; |
|
137 | + file_put_contents($subsetStoragePath, $json); |
|
138 | + $changes = $subset . 'Changes'; |
|
139 | + $this->$changes = false; |
|
140 | + } |
|
141 | + |
|
142 | + protected function loadSubset($subset) |
|
143 | + { |
|
144 | + $subsetStoragePath = $this->storagePath . DIRECTORY_SEPARATOR . $subset . '.json'; |
|
145 | + $json = file_get_contents($subsetStoragePath); |
|
146 | + $json = json_decode($json); |
|
147 | + $this->$subset = $json; |
|
148 | + return $json; |
|
149 | + } |
|
150 | + |
|
151 | + /** |
|
152 | + * @param $contentSqlPath |
|
153 | + */ |
|
154 | + protected function initContentDb($contentSqlPath) |
|
155 | + { |
|
156 | + $db = $this->getContentDbHandle(); |
|
157 | + $sql = file_get_contents($contentSqlPath); |
|
158 | + $db->exec($sql); |
|
159 | + } |
|
160 | + |
|
161 | + /** |
|
162 | + * @param $storageDefaultPath |
|
163 | + */ |
|
164 | + protected function initConfigStorage($storageDefaultPath) |
|
165 | + { |
|
166 | + $json = file_get_contents($storageDefaultPath); |
|
167 | + $json = json_decode($json); |
|
168 | + $this->sitemap = $json->sitemap; |
|
169 | + $this->sitemapChanges = true; |
|
170 | + $this->applicationComponents = $json->applicationComponents; |
|
171 | + $this->applicationComponentsChanges = true; |
|
172 | + $this->documentTypes = $json->documentTypes; |
|
173 | + $this->documentTypesChanges = true; |
|
174 | + $this->bricks = $json->bricks; |
|
175 | + $this->bricksChanges = true; |
|
176 | + $this->imageSet = $json->imageSet; |
|
177 | + $this->imageSetChanges = true; |
|
178 | + $this->images = $json->images; |
|
179 | + $this->imagesChanges = true; |
|
180 | + $this->files = $json->files; |
|
181 | + $this->filesChanges = true; |
|
182 | + $this->users = $json->users; |
|
183 | + $this->usersChanges = true; |
|
184 | + } |
|
185 | + |
|
186 | + /** |
|
187 | + * @return \PDO |
|
188 | + */ |
|
189 | + protected function getContentDbHandle() |
|
190 | + { |
|
191 | + if ($this->contentDbHandle === null) { |
|
192 | + $this->contentDbHandle = new \PDO('sqlite:' . $this->storagePath . DIRECTORY_SEPARATOR . 'content.db'); |
|
193 | + } |
|
194 | + return $this->contentDbHandle; |
|
195 | + } |
|
196 | + |
|
197 | + public function getDocuments() |
|
198 | + { |
|
199 | + return $this->getDocumentsByPath('/'); |
|
200 | + } |
|
201 | + |
|
202 | + public function getDocumentsByPath($folderPath) |
|
203 | + { |
|
204 | + $db = $this->getContentDbHandle(); |
|
205 | + $folderPathWithWildcard = $folderPath . '%'; |
|
206 | + |
|
207 | + $stmt = $this->getDbStatement(' |
|
208 | 208 | SELECT * |
209 | 209 | FROM documents |
210 | 210 | WHERE `path` LIKE ' . $db->quote($folderPathWithWildcard) . ' |
@@ -213,100 +213,100 @@ discard block |
||
213 | 213 | ORDER BY `type` DESC, `path` ASC |
214 | 214 | '); |
215 | 215 | |
216 | - $documents = $stmt->fetchAll(\PDO::FETCH_CLASS, '\library\storage\Document'); |
|
217 | - foreach ($documents as $key => $document) { |
|
218 | - if ($document->type === 'folder') { |
|
219 | - $document->dbHandle = $db; |
|
220 | - $documents[$key] = $document; |
|
221 | - } |
|
222 | - } |
|
223 | - return $documents; |
|
224 | - } |
|
225 | - |
|
226 | - |
|
227 | - /** |
|
228 | - * @param $path |
|
229 | - * @return bool|Document |
|
230 | - */ |
|
231 | - public function getDocumentContainerByPath($path) |
|
232 | - { |
|
233 | - $document = $this->getDocumentByPath($path); |
|
234 | - if ($document === false) { |
|
235 | - return false; |
|
236 | - } |
|
237 | - $slugLength = strlen($document->slug); |
|
238 | - $containerPath = substr($path, 0, -$slugLength); |
|
239 | - if ($containerPath === '/') { |
|
240 | - return $this->getRootFolder(); |
|
241 | - } |
|
242 | - $containerFolder = $this->getDocumentByPath($containerPath); |
|
243 | - return $containerFolder; |
|
244 | - } |
|
245 | - |
|
246 | - /** |
|
247 | - * @param $path |
|
248 | - * @return bool|Document |
|
249 | - */ |
|
250 | - public function getDocumentByPath($path) |
|
251 | - { |
|
252 | - $db = $this->getContentDbHandle(); |
|
253 | - $document = $this->fetchDocument(' |
|
216 | + $documents = $stmt->fetchAll(\PDO::FETCH_CLASS, '\library\storage\Document'); |
|
217 | + foreach ($documents as $key => $document) { |
|
218 | + if ($document->type === 'folder') { |
|
219 | + $document->dbHandle = $db; |
|
220 | + $documents[$key] = $document; |
|
221 | + } |
|
222 | + } |
|
223 | + return $documents; |
|
224 | + } |
|
225 | + |
|
226 | + |
|
227 | + /** |
|
228 | + * @param $path |
|
229 | + * @return bool|Document |
|
230 | + */ |
|
231 | + public function getDocumentContainerByPath($path) |
|
232 | + { |
|
233 | + $document = $this->getDocumentByPath($path); |
|
234 | + if ($document === false) { |
|
235 | + return false; |
|
236 | + } |
|
237 | + $slugLength = strlen($document->slug); |
|
238 | + $containerPath = substr($path, 0, -$slugLength); |
|
239 | + if ($containerPath === '/') { |
|
240 | + return $this->getRootFolder(); |
|
241 | + } |
|
242 | + $containerFolder = $this->getDocumentByPath($containerPath); |
|
243 | + return $containerFolder; |
|
244 | + } |
|
245 | + |
|
246 | + /** |
|
247 | + * @param $path |
|
248 | + * @return bool|Document |
|
249 | + */ |
|
250 | + public function getDocumentByPath($path) |
|
251 | + { |
|
252 | + $db = $this->getContentDbHandle(); |
|
253 | + $document = $this->fetchDocument(' |
|
254 | 254 | SELECT * |
255 | 255 | FROM documents |
256 | 256 | WHERE path = ' . $db->quote($path) . ' |
257 | 257 | '); |
258 | - if ($document instanceof Document && $document->type === 'folder') { |
|
259 | - $document->dbHandle = $db; |
|
260 | - } |
|
261 | - return $document; |
|
262 | - } |
|
263 | - |
|
264 | - protected function fetchAllDocuments($sql) |
|
265 | - { |
|
266 | - $stmt = $this->getDbStatement($sql); |
|
267 | - return $stmt->fetchAll(\PDO::FETCH_CLASS, '\library\storage\Document'); |
|
268 | - } |
|
269 | - |
|
270 | - protected function fetchDocument($sql) |
|
271 | - { |
|
272 | - $stmt = $this->getDbStatement($sql); |
|
273 | - return $stmt->fetchObject('\library\storage\Document'); |
|
274 | - } |
|
275 | - |
|
276 | - /** |
|
277 | - * @param $sql |
|
278 | - * @return \PDOStatement |
|
279 | - * @throws \Exception |
|
280 | - */ |
|
281 | - protected function getDbStatement($sql) |
|
282 | - { |
|
283 | - $db = $this->getContentDbHandle(); |
|
284 | - $stmt = $db->query($sql); |
|
285 | - if ($stmt === false) { |
|
286 | - $errorInfo = $db->errorInfo(); |
|
287 | - $errorMsg = $errorInfo[2]; |
|
288 | - throw new \Exception('SQLite Exception: ' . $errorMsg . ' in SQL: <br /><pre>' . $sql . '</pre>'); |
|
289 | - } |
|
290 | - return $stmt; |
|
291 | - } |
|
292 | - |
|
293 | - protected function getRootFolder() |
|
294 | - { |
|
295 | - $rootFolder = new Document(); |
|
296 | - $rootFolder->path = '/'; |
|
297 | - $rootFolder->type = 'folder'; |
|
298 | - return $rootFolder; |
|
299 | - } |
|
300 | - |
|
301 | - /** |
|
302 | - * @param $path |
|
303 | - * @param Document $documentObject |
|
304 | - * @return bool |
|
305 | - */ |
|
306 | - public function saveDocument($documentObject) |
|
307 | - { |
|
308 | - $db = $this->getContentDbHandle(); |
|
309 | - $stmt = $this->getDbStatement(' |
|
258 | + if ($document instanceof Document && $document->type === 'folder') { |
|
259 | + $document->dbHandle = $db; |
|
260 | + } |
|
261 | + return $document; |
|
262 | + } |
|
263 | + |
|
264 | + protected function fetchAllDocuments($sql) |
|
265 | + { |
|
266 | + $stmt = $this->getDbStatement($sql); |
|
267 | + return $stmt->fetchAll(\PDO::FETCH_CLASS, '\library\storage\Document'); |
|
268 | + } |
|
269 | + |
|
270 | + protected function fetchDocument($sql) |
|
271 | + { |
|
272 | + $stmt = $this->getDbStatement($sql); |
|
273 | + return $stmt->fetchObject('\library\storage\Document'); |
|
274 | + } |
|
275 | + |
|
276 | + /** |
|
277 | + * @param $sql |
|
278 | + * @return \PDOStatement |
|
279 | + * @throws \Exception |
|
280 | + */ |
|
281 | + protected function getDbStatement($sql) |
|
282 | + { |
|
283 | + $db = $this->getContentDbHandle(); |
|
284 | + $stmt = $db->query($sql); |
|
285 | + if ($stmt === false) { |
|
286 | + $errorInfo = $db->errorInfo(); |
|
287 | + $errorMsg = $errorInfo[2]; |
|
288 | + throw new \Exception('SQLite Exception: ' . $errorMsg . ' in SQL: <br /><pre>' . $sql . '</pre>'); |
|
289 | + } |
|
290 | + return $stmt; |
|
291 | + } |
|
292 | + |
|
293 | + protected function getRootFolder() |
|
294 | + { |
|
295 | + $rootFolder = new Document(); |
|
296 | + $rootFolder->path = '/'; |
|
297 | + $rootFolder->type = 'folder'; |
|
298 | + return $rootFolder; |
|
299 | + } |
|
300 | + |
|
301 | + /** |
|
302 | + * @param $path |
|
303 | + * @param Document $documentObject |
|
304 | + * @return bool |
|
305 | + */ |
|
306 | + public function saveDocument($documentObject) |
|
307 | + { |
|
308 | + $db = $this->getContentDbHandle(); |
|
309 | + $stmt = $this->getDbStatement(' |
|
310 | 310 | INSERT OR REPLACE INTO documents (`path`,`title`,`slug`,`type`,`documentType`,`documentTypeSlug`,`state`,`lastModificationDate`,`creationDate`,`lastModifiedBy`,`fields`,`bricks`,`dynamicBricks`) |
311 | 311 | VALUES( |
312 | 312 | ' . $db->quote($documentObject->path) . ', |
@@ -324,31 +324,31 @@ discard block |
||
324 | 324 | ' . $db->quote(json_encode($documentObject->dynamicBricks)) . ' |
325 | 325 | ) |
326 | 326 | '); |
327 | - $result = $stmt->execute(); |
|
328 | - return $result; |
|
329 | - } |
|
330 | - |
|
331 | - public function deleteDocumentByPath($path) |
|
332 | - { |
|
333 | - $db = $this->getContentDbHandle(); |
|
334 | - $documentToDelete = $this->getDocumentByPath($path); |
|
335 | - if ($documentToDelete instanceof Document) { |
|
336 | - if ($documentToDelete->type == 'document') { |
|
337 | - $stmt = $this->getDbStatement(' |
|
327 | + $result = $stmt->execute(); |
|
328 | + return $result; |
|
329 | + } |
|
330 | + |
|
331 | + public function deleteDocumentByPath($path) |
|
332 | + { |
|
333 | + $db = $this->getContentDbHandle(); |
|
334 | + $documentToDelete = $this->getDocumentByPath($path); |
|
335 | + if ($documentToDelete instanceof Document) { |
|
336 | + if ($documentToDelete->type == 'document') { |
|
337 | + $stmt = $this->getDbStatement(' |
|
338 | 338 | DELETE FROM documents |
339 | 339 | WHERE path = ' . $db->quote($path) . ' |
340 | 340 | '); |
341 | - } elseif ($documentToDelete->type == 'folder') { |
|
342 | - $folderPathWithWildcard = $path . '%'; |
|
343 | - $stmt = $this->getDbStatement(' |
|
341 | + } elseif ($documentToDelete->type == 'folder') { |
|
342 | + $folderPathWithWildcard = $path . '%'; |
|
343 | + $stmt = $this->getDbStatement(' |
|
344 | 344 | DELETE FROM documents |
345 | 345 | WHERE (path LIKE ' . $db->quote($folderPathWithWildcard) . ' |
346 | 346 | AND substr(`path`, ' . (strlen($path) + 1) . ', 1) = "/") |
347 | 347 | OR path = ' . $db->quote($path) . ' |
348 | 348 | '); |
349 | - } |
|
350 | - } |
|
349 | + } |
|
350 | + } |
|
351 | 351 | |
352 | - $stmt->execute(); |
|
353 | - } |
|
352 | + $stmt->execute(); |
|
353 | + } |
|
354 | 354 | } |
355 | 355 | \ No newline at end of file |
@@ -102,7 +102,7 @@ discard block |
||
102 | 102 | if (in_array($name, $this->fileBasedSubsets)) { |
103 | 103 | return $this->loadSubset($name); |
104 | 104 | } else { |
105 | - throw new \Exception('Trying to get undefined property from Repository: ' . $name); |
|
105 | + throw new \Exception('Trying to get undefined property from Repository: '.$name); |
|
106 | 106 | } |
107 | 107 | } |
108 | 108 | } |
@@ -111,10 +111,10 @@ discard block |
||
111 | 111 | { |
112 | 112 | if (in_array($name, $this->fileBasedSubsets)) { |
113 | 113 | $this->$name = $value; |
114 | - $changes = $name . 'Changes'; |
|
114 | + $changes = $name.'Changes'; |
|
115 | 115 | $this->$changes = true; |
116 | 116 | } else { |
117 | - throw new \Exception('Trying to persist unknown subset in repository: ' . $name . ' <br /><pre>' . print_r($value, true) . '</pre>'); |
|
117 | + throw new \Exception('Trying to persist unknown subset in repository: '.$name.' <br /><pre>'.print_r($value, true).'</pre>'); |
|
118 | 118 | } |
119 | 119 | } |
120 | 120 | |
@@ -133,15 +133,15 @@ discard block |
||
133 | 133 | protected function saveSubset($subset) |
134 | 134 | { |
135 | 135 | $json = json_encode($this->$subset); |
136 | - $subsetStoragePath = $this->storagePath . DIRECTORY_SEPARATOR . $subset . '.json'; |
|
136 | + $subsetStoragePath = $this->storagePath.DIRECTORY_SEPARATOR.$subset.'.json'; |
|
137 | 137 | file_put_contents($subsetStoragePath, $json); |
138 | - $changes = $subset . 'Changes'; |
|
138 | + $changes = $subset.'Changes'; |
|
139 | 139 | $this->$changes = false; |
140 | 140 | } |
141 | 141 | |
142 | 142 | protected function loadSubset($subset) |
143 | 143 | { |
144 | - $subsetStoragePath = $this->storagePath . DIRECTORY_SEPARATOR . $subset . '.json'; |
|
144 | + $subsetStoragePath = $this->storagePath.DIRECTORY_SEPARATOR.$subset.'.json'; |
|
145 | 145 | $json = file_get_contents($subsetStoragePath); |
146 | 146 | $json = json_decode($json); |
147 | 147 | $this->$subset = $json; |
@@ -189,7 +189,7 @@ discard block |
||
189 | 189 | protected function getContentDbHandle() |
190 | 190 | { |
191 | 191 | if ($this->contentDbHandle === null) { |
192 | - $this->contentDbHandle = new \PDO('sqlite:' . $this->storagePath . DIRECTORY_SEPARATOR . 'content.db'); |
|
192 | + $this->contentDbHandle = new \PDO('sqlite:'.$this->storagePath.DIRECTORY_SEPARATOR.'content.db'); |
|
193 | 193 | } |
194 | 194 | return $this->contentDbHandle; |
195 | 195 | } |
@@ -202,14 +202,14 @@ discard block |
||
202 | 202 | public function getDocumentsByPath($folderPath) |
203 | 203 | { |
204 | 204 | $db = $this->getContentDbHandle(); |
205 | - $folderPathWithWildcard = $folderPath . '%'; |
|
205 | + $folderPathWithWildcard = $folderPath.'%'; |
|
206 | 206 | |
207 | 207 | $stmt = $this->getDbStatement(' |
208 | 208 | SELECT * |
209 | 209 | FROM documents |
210 | - WHERE `path` LIKE ' . $db->quote($folderPathWithWildcard) . ' |
|
211 | - AND substr(`path`, ' . (strlen($folderPath) + 1) . ') NOT LIKE "%/%" |
|
212 | - AND path != ' . $db->quote($folderPath) . ' |
|
210 | + WHERE `path` LIKE ' . $db->quote($folderPathWithWildcard).' |
|
211 | + AND substr(`path`, ' . (strlen($folderPath) + 1).') NOT LIKE "%/%" |
|
212 | + AND path != ' . $db->quote($folderPath).' |
|
213 | 213 | ORDER BY `type` DESC, `path` ASC |
214 | 214 | '); |
215 | 215 | |
@@ -253,7 +253,7 @@ discard block |
||
253 | 253 | $document = $this->fetchDocument(' |
254 | 254 | SELECT * |
255 | 255 | FROM documents |
256 | - WHERE path = ' . $db->quote($path) . ' |
|
256 | + WHERE path = ' . $db->quote($path).' |
|
257 | 257 | '); |
258 | 258 | if ($document instanceof Document && $document->type === 'folder') { |
259 | 259 | $document->dbHandle = $db; |
@@ -285,7 +285,7 @@ discard block |
||
285 | 285 | if ($stmt === false) { |
286 | 286 | $errorInfo = $db->errorInfo(); |
287 | 287 | $errorMsg = $errorInfo[2]; |
288 | - throw new \Exception('SQLite Exception: ' . $errorMsg . ' in SQL: <br /><pre>' . $sql . '</pre>'); |
|
288 | + throw new \Exception('SQLite Exception: '.$errorMsg.' in SQL: <br /><pre>'.$sql.'</pre>'); |
|
289 | 289 | } |
290 | 290 | return $stmt; |
291 | 291 | } |
@@ -309,19 +309,19 @@ discard block |
||
309 | 309 | $stmt = $this->getDbStatement(' |
310 | 310 | INSERT OR REPLACE INTO documents (`path`,`title`,`slug`,`type`,`documentType`,`documentTypeSlug`,`state`,`lastModificationDate`,`creationDate`,`lastModifiedBy`,`fields`,`bricks`,`dynamicBricks`) |
311 | 311 | VALUES( |
312 | - ' . $db->quote($documentObject->path) . ', |
|
313 | - ' . $db->quote($documentObject->title) . ', |
|
314 | - ' . $db->quote($documentObject->slug) . ', |
|
315 | - ' . $db->quote($documentObject->type) . ', |
|
316 | - ' . $db->quote($documentObject->documentType) . ', |
|
317 | - ' . $db->quote($documentObject->documentTypeSlug) . ', |
|
318 | - ' . $db->quote($documentObject->state) . ', |
|
319 | - ' . $db->quote($documentObject->lastModificationDate) . ', |
|
320 | - ' . $db->quote($documentObject->creationDate) . ', |
|
321 | - ' . $db->quote($documentObject->lastModifiedBy) . ', |
|
322 | - ' . $db->quote(json_encode($documentObject->fields)) . ', |
|
323 | - ' . $db->quote(json_encode($documentObject->bricks)) . ', |
|
324 | - ' . $db->quote(json_encode($documentObject->dynamicBricks)) . ' |
|
312 | + ' . $db->quote($documentObject->path).', |
|
313 | + ' . $db->quote($documentObject->title).', |
|
314 | + ' . $db->quote($documentObject->slug).', |
|
315 | + ' . $db->quote($documentObject->type).', |
|
316 | + ' . $db->quote($documentObject->documentType).', |
|
317 | + ' . $db->quote($documentObject->documentTypeSlug).', |
|
318 | + ' . $db->quote($documentObject->state).', |
|
319 | + ' . $db->quote($documentObject->lastModificationDate).', |
|
320 | + ' . $db->quote($documentObject->creationDate).', |
|
321 | + ' . $db->quote($documentObject->lastModifiedBy).', |
|
322 | + ' . $db->quote(json_encode($documentObject->fields)).', |
|
323 | + ' . $db->quote(json_encode($documentObject->bricks)).', |
|
324 | + ' . $db->quote(json_encode($documentObject->dynamicBricks)).' |
|
325 | 325 | ) |
326 | 326 | '); |
327 | 327 | $result = $stmt->execute(); |
@@ -336,15 +336,15 @@ discard block |
||
336 | 336 | if ($documentToDelete->type == 'document') { |
337 | 337 | $stmt = $this->getDbStatement(' |
338 | 338 | DELETE FROM documents |
339 | - WHERE path = ' . $db->quote($path) . ' |
|
339 | + WHERE path = ' . $db->quote($path).' |
|
340 | 340 | '); |
341 | 341 | } elseif ($documentToDelete->type == 'folder') { |
342 | - $folderPathWithWildcard = $path . '%'; |
|
342 | + $folderPathWithWildcard = $path.'%'; |
|
343 | 343 | $stmt = $this->getDbStatement(' |
344 | 344 | DELETE FROM documents |
345 | - WHERE (path LIKE ' . $db->quote($folderPathWithWildcard) . ' |
|
346 | - AND substr(`path`, ' . (strlen($path) + 1) . ', 1) = "/") |
|
347 | - OR path = ' . $db->quote($path) . ' |
|
345 | + WHERE (path LIKE ' . $db->quote($folderPathWithWildcard).' |
|
346 | + AND substr(`path`, ' . (strlen($path) + 1).', 1) = "/") |
|
347 | + OR path = ' . $db->quote($path).' |
|
348 | 348 | '); |
349 | 349 | } |
350 | 350 | } |
@@ -10,85 +10,85 @@ |
||
10 | 10 | |
11 | 11 | class Document |
12 | 12 | { |
13 | - public $id; |
|
14 | - public $path; |
|
15 | - public $title; |
|
16 | - public $slug; |
|
17 | - public $type; |
|
18 | - public $documentType; |
|
19 | - public $documentTypeSlug; |
|
20 | - public $state; |
|
21 | - public $lastModificationDate; |
|
22 | - public $creationDate; |
|
23 | - public $lastModifiedBy; |
|
24 | - protected $fields; |
|
25 | - protected $bricks; |
|
26 | - protected $dynamicBricks; |
|
27 | - protected $content; |
|
13 | + public $id; |
|
14 | + public $path; |
|
15 | + public $title; |
|
16 | + public $slug; |
|
17 | + public $type; |
|
18 | + public $documentType; |
|
19 | + public $documentTypeSlug; |
|
20 | + public $state; |
|
21 | + public $lastModificationDate; |
|
22 | + public $creationDate; |
|
23 | + public $lastModifiedBy; |
|
24 | + protected $fields; |
|
25 | + protected $bricks; |
|
26 | + protected $dynamicBricks; |
|
27 | + protected $content; |
|
28 | 28 | |
29 | - protected $dbHandle; |
|
29 | + protected $dbHandle; |
|
30 | 30 | |
31 | - protected $jsonEncodedFields = array('fields', 'bricks', 'dynamicBricks'); |
|
31 | + protected $jsonEncodedFields = array('fields', 'bricks', 'dynamicBricks'); |
|
32 | 32 | |
33 | - public function __get($name) { |
|
34 | - if (in_array($name, $this->jsonEncodedFields)) { |
|
35 | - if (is_string($this->$name)) { |
|
36 | - return json_decode($this->$name); |
|
37 | - } else { |
|
38 | - return $this->$name; |
|
39 | - } |
|
40 | - } elseif ($name === 'content') { |
|
41 | - if ($this->dbHandle === null) { |
|
42 | - throw new \Exception('Document doesnt have a dbHandle handle. (path: ' . $this->path . ')'); |
|
43 | - } else { |
|
44 | - if ($this->content === null) { |
|
45 | - $this->getContent(); |
|
46 | - } |
|
47 | - return $this->content; |
|
48 | - } |
|
49 | - } elseif ($name === 'repository') { |
|
50 | - throw new \Exception('Trying to get protected property repository.'); |
|
51 | - } |
|
52 | - return $this->$name; |
|
53 | - } |
|
33 | + public function __get($name) { |
|
34 | + if (in_array($name, $this->jsonEncodedFields)) { |
|
35 | + if (is_string($this->$name)) { |
|
36 | + return json_decode($this->$name); |
|
37 | + } else { |
|
38 | + return $this->$name; |
|
39 | + } |
|
40 | + } elseif ($name === 'content') { |
|
41 | + if ($this->dbHandle === null) { |
|
42 | + throw new \Exception('Document doesnt have a dbHandle handle. (path: ' . $this->path . ')'); |
|
43 | + } else { |
|
44 | + if ($this->content === null) { |
|
45 | + $this->getContent(); |
|
46 | + } |
|
47 | + return $this->content; |
|
48 | + } |
|
49 | + } elseif ($name === 'repository') { |
|
50 | + throw new \Exception('Trying to get protected property repository.'); |
|
51 | + } |
|
52 | + return $this->$name; |
|
53 | + } |
|
54 | 54 | |
55 | - public function __set($name, $value) { |
|
56 | - if (in_array($name, $this->jsonEncodedFields)) { |
|
57 | - $this->$name = json_encode($value); |
|
58 | - } elseif ($name === 'content') { |
|
59 | - // Dont do anything for now.. |
|
60 | - return; |
|
61 | - } |
|
55 | + public function __set($name, $value) { |
|
56 | + if (in_array($name, $this->jsonEncodedFields)) { |
|
57 | + $this->$name = json_encode($value); |
|
58 | + } elseif ($name === 'content') { |
|
59 | + // Dont do anything for now.. |
|
60 | + return; |
|
61 | + } |
|
62 | 62 | |
63 | - $this->$name = $value; |
|
64 | - } |
|
63 | + $this->$name = $value; |
|
64 | + } |
|
65 | 65 | |
66 | - /** |
|
67 | - * @throws \Exception |
|
68 | - */ |
|
69 | - protected function getContent() |
|
70 | - { |
|
71 | - $folderPathWithWildcard = $this->path . '%'; |
|
72 | - $sql = ' SELECT * |
|
66 | + /** |
|
67 | + * @throws \Exception |
|
68 | + */ |
|
69 | + protected function getContent() |
|
70 | + { |
|
71 | + $folderPathWithWildcard = $this->path . '%'; |
|
72 | + $sql = ' SELECT * |
|
73 | 73 | FROM documents |
74 | 74 | WHERE `path` LIKE ' . $this->dbHandle->quote($folderPathWithWildcard) . ' |
75 | 75 | AND substr(`path`, ' . (strlen($this->path) + 2) . ') NOT LIKE "%/%" |
76 | 76 | AND substr(`path`, ' . (strlen($this->path) + 1) . ', 1) = "/" |
77 | 77 | AND path != ' . $this->dbHandle->quote($this->path) . ' |
78 | 78 | '; |
79 | - $stmt = $this->dbHandle->query($sql); |
|
80 | - if ($stmt === false) { |
|
81 | - $errorInfo = $this->dbHandle->errorInfo(); |
|
82 | - $errorMsg = $errorInfo[2]; |
|
83 | - throw new \Exception('SQLite Exception: ' . $errorMsg . ' in SQL: <br /><pre>' . $sql . '</pre>'); |
|
84 | - } |
|
85 | - $contents = $stmt->fetchAll(\PDO::FETCH_CLASS, '\library\storage\Document'); |
|
86 | - foreach ($contents as $key => $document) { |
|
87 | - if ($document->type === 'folder') { |
|
88 | - $document->dbHandle = $this->dbHandle; |
|
89 | - $contents[$key] = $document; |
|
90 | - } |
|
91 | - } |
|
92 | - $this->content = $contents; |
|
93 | - } |
|
79 | + $stmt = $this->dbHandle->query($sql); |
|
80 | + if ($stmt === false) { |
|
81 | + $errorInfo = $this->dbHandle->errorInfo(); |
|
82 | + $errorMsg = $errorInfo[2]; |
|
83 | + throw new \Exception('SQLite Exception: ' . $errorMsg . ' in SQL: <br /><pre>' . $sql . '</pre>'); |
|
84 | + } |
|
85 | + $contents = $stmt->fetchAll(\PDO::FETCH_CLASS, '\library\storage\Document'); |
|
86 | + foreach ($contents as $key => $document) { |
|
87 | + if ($document->type === 'folder') { |
|
88 | + $document->dbHandle = $this->dbHandle; |
|
89 | + $contents[$key] = $document; |
|
90 | + } |
|
91 | + } |
|
92 | + $this->content = $contents; |
|
93 | + } |
|
94 | 94 | } |
95 | 95 | \ No newline at end of file |
@@ -39,7 +39,7 @@ discard block |
||
39 | 39 | } |
40 | 40 | } elseif ($name === 'content') { |
41 | 41 | if ($this->dbHandle === null) { |
42 | - throw new \Exception('Document doesnt have a dbHandle handle. (path: ' . $this->path . ')'); |
|
42 | + throw new \Exception('Document doesnt have a dbHandle handle. (path: '.$this->path.')'); |
|
43 | 43 | } else { |
44 | 44 | if ($this->content === null) { |
45 | 45 | $this->getContent(); |
@@ -68,19 +68,19 @@ discard block |
||
68 | 68 | */ |
69 | 69 | protected function getContent() |
70 | 70 | { |
71 | - $folderPathWithWildcard = $this->path . '%'; |
|
71 | + $folderPathWithWildcard = $this->path.'%'; |
|
72 | 72 | $sql = ' SELECT * |
73 | 73 | FROM documents |
74 | - WHERE `path` LIKE ' . $this->dbHandle->quote($folderPathWithWildcard) . ' |
|
75 | - AND substr(`path`, ' . (strlen($this->path) + 2) . ') NOT LIKE "%/%" |
|
76 | - AND substr(`path`, ' . (strlen($this->path) + 1) . ', 1) = "/" |
|
77 | - AND path != ' . $this->dbHandle->quote($this->path) . ' |
|
74 | + WHERE `path` LIKE ' . $this->dbHandle->quote($folderPathWithWildcard).' |
|
75 | + AND substr(`path`, ' . (strlen($this->path) + 2).') NOT LIKE "%/%" |
|
76 | + AND substr(`path`, ' . (strlen($this->path) + 1).', 1) = "/" |
|
77 | + AND path != ' . $this->dbHandle->quote($this->path).' |
|
78 | 78 | '; |
79 | 79 | $stmt = $this->dbHandle->query($sql); |
80 | 80 | if ($stmt === false) { |
81 | 81 | $errorInfo = $this->dbHandle->errorInfo(); |
82 | 82 | $errorMsg = $errorInfo[2]; |
83 | - throw new \Exception('SQLite Exception: ' . $errorMsg . ' in SQL: <br /><pre>' . $sql . '</pre>'); |
|
83 | + throw new \Exception('SQLite Exception: '.$errorMsg.' in SQL: <br /><pre>'.$sql.'</pre>'); |
|
84 | 84 | } |
85 | 85 | $contents = $stmt->fetchAll(\PDO::FETCH_CLASS, '\library\storage\Document'); |
86 | 86 | foreach ($contents as $key => $document) { |