@@ -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 | /** |
@@ -76,12 +76,12 @@ discard block |
||
| 76 | 76 | return $return; |
| 77 | 77 | } |
| 78 | 78 | |
| 79 | - /** |
|
| 80 | - * Get user by slug |
|
| 81 | - * |
|
| 82 | - * @param $slug |
|
| 83 | - * @return array |
|
| 84 | - */ |
|
| 79 | + /** |
|
| 80 | + * Get user by slug |
|
| 81 | + * |
|
| 82 | + * @param $slug |
|
| 83 | + * @return array |
|
| 84 | + */ |
|
| 85 | 85 | public function getUserBySlug($slug) |
| 86 | 86 | { |
| 87 | 87 | $return = array(); |
@@ -97,23 +97,23 @@ discard block |
||
| 97 | 97 | return $return; |
| 98 | 98 | } |
| 99 | 99 | |
| 100 | - /** |
|
| 101 | - * Get all users |
|
| 102 | - * |
|
| 103 | - * @return mixed |
|
| 104 | - */ |
|
| 100 | + /** |
|
| 101 | + * Get all users |
|
| 102 | + * |
|
| 103 | + * @return mixed |
|
| 104 | + */ |
|
| 105 | 105 | public function getUsers() |
| 106 | 106 | { |
| 107 | 107 | return $this->repository->users; |
| 108 | 108 | } |
| 109 | 109 | |
| 110 | - /** |
|
| 111 | - * Save user |
|
| 112 | - * |
|
| 113 | - * @param $slug |
|
| 114 | - * @param $postValues |
|
| 115 | - * @throws \Exception |
|
| 116 | - */ |
|
| 110 | + /** |
|
| 111 | + * Save user |
|
| 112 | + * |
|
| 113 | + * @param $slug |
|
| 114 | + * @param $postValues |
|
| 115 | + * @throws \Exception |
|
| 116 | + */ |
|
| 117 | 117 | public function saveUser($slug, $postValues) |
| 118 | 118 | { |
| 119 | 119 | $userObj = $this->createUserFromPostValues($postValues); |
@@ -134,12 +134,12 @@ discard block |
||
| 134 | 134 | $this->save(); |
| 135 | 135 | } |
| 136 | 136 | |
| 137 | - /** |
|
| 138 | - * Add user |
|
| 139 | - * |
|
| 140 | - * @param $postValues |
|
| 141 | - * @throws \Exception |
|
| 142 | - */ |
|
| 137 | + /** |
|
| 138 | + * Add user |
|
| 139 | + * |
|
| 140 | + * @param $postValues |
|
| 141 | + * @throws \Exception |
|
| 142 | + */ |
|
| 143 | 143 | public function addUser($postValues) |
| 144 | 144 | { |
| 145 | 145 | $userObj = $this->createUserFromPostValues($postValues); |
@@ -148,17 +148,17 @@ discard block |
||
| 148 | 148 | if (!empty($doesItExist)) { |
| 149 | 149 | throw new \Exception('Trying to add username that already exists.'); |
| 150 | 150 | } |
| 151 | - $users = $this->repository->users; |
|
| 152 | - $users[] = $userObj; |
|
| 153 | - $this->repository->users = $users; |
|
| 151 | + $users = $this->repository->users; |
|
| 152 | + $users[] = $userObj; |
|
| 153 | + $this->repository->users = $users; |
|
| 154 | 154 | $this->save(); |
| 155 | 155 | } |
| 156 | 156 | |
| 157 | - /** |
|
| 158 | - * Delete user by slug |
|
| 159 | - * @param $slug |
|
| 160 | - * @throws \Exception |
|
| 161 | - */ |
|
| 157 | + /** |
|
| 158 | + * Delete user by slug |
|
| 159 | + * @param $slug |
|
| 160 | + * @throws \Exception |
|
| 161 | + */ |
|
| 162 | 162 | public function deleteUserBySlug($slug) |
| 163 | 163 | { |
| 164 | 164 | $userToDelete = $this->getUserBySlug($slug); |
@@ -175,12 +175,12 @@ discard block |
||
| 175 | 175 | $this->save(); |
| 176 | 176 | } |
| 177 | 177 | |
| 178 | - /** |
|
| 179 | - * Create user from POST values |
|
| 180 | - * @param $postValues |
|
| 181 | - * @return \stdClass |
|
| 182 | - * @throws \Exception |
|
| 183 | - */ |
|
| 178 | + /** |
|
| 179 | + * Create user from POST values |
|
| 180 | + * @param $postValues |
|
| 181 | + * @return \stdClass |
|
| 182 | + * @throws \Exception |
|
| 183 | + */ |
|
| 184 | 184 | private function createUserFromPostValues($postValues) |
| 185 | 185 | { |
| 186 | 186 | if (isset($postValues['username'])) { |
@@ -229,40 +229,40 @@ discard block |
||
| 229 | 229 | */ |
| 230 | 230 | public function getDocumentBySlug($slug) |
| 231 | 231 | { |
| 232 | - $path = '/' . $slug; |
|
| 232 | + $path = '/' . $slug; |
|
| 233 | 233 | return $this->repository->getDocumentByPath($path); |
| 234 | 234 | } |
| 235 | 235 | |
| 236 | 236 | public function saveDocument($postValues) |
| 237 | 237 | { |
| 238 | - $oldPath = '/' . $postValues['path']; |
|
| 238 | + $oldPath = '/' . $postValues['path']; |
|
| 239 | 239 | |
| 240 | - $container = $this->getDocumentContainerByPath($oldPath); |
|
| 241 | - $documentObject = $this->createDocumentFromPostValues($postValues); |
|
| 242 | - if ($container->path === '/') { |
|
| 243 | - $newPath = $container->path . $documentObject->slug; |
|
| 244 | - } else { |
|
| 245 | - $newPath = $container->path . '/' . $documentObject->slug; |
|
| 246 | - } |
|
| 247 | - $documentObject->path = $newPath; |
|
| 248 | - $this->repository->saveDocument($documentObject); |
|
| 249 | - } |
|
| 240 | + $container = $this->getDocumentContainerByPath($oldPath); |
|
| 241 | + $documentObject = $this->createDocumentFromPostValues($postValues); |
|
| 242 | + if ($container->path === '/') { |
|
| 243 | + $newPath = $container->path . $documentObject->slug; |
|
| 244 | + } else { |
|
| 245 | + $newPath = $container->path . '/' . $documentObject->slug; |
|
| 246 | + } |
|
| 247 | + $documentObject->path = $newPath; |
|
| 248 | + $this->repository->saveDocument($documentObject); |
|
| 249 | + } |
|
| 250 | 250 | |
| 251 | 251 | public function addDocument($postValues) |
| 252 | 252 | { |
| 253 | 253 | $documentObject = $this->createDocumentFromPostValues($postValues); |
| 254 | - if ($postValues['path'] === '/') { |
|
| 255 | - $documentObject->path = $postValues['path'] . $documentObject->slug; |
|
| 256 | - } else { |
|
| 257 | - $documentObject->path = $postValues['path'] . '/' . $documentObject->slug; |
|
| 258 | - } |
|
| 254 | + if ($postValues['path'] === '/') { |
|
| 255 | + $documentObject->path = $postValues['path'] . $documentObject->slug; |
|
| 256 | + } else { |
|
| 257 | + $documentObject->path = $postValues['path'] . '/' . $documentObject->slug; |
|
| 258 | + } |
|
| 259 | 259 | |
| 260 | - $this->repository->saveDocument($documentObject); |
|
| 260 | + $this->repository->saveDocument($documentObject); |
|
| 261 | 261 | } |
| 262 | 262 | |
| 263 | 263 | public function deleteDocumentBySlug($slug) |
| 264 | 264 | { |
| 265 | - $path = '/' . $slug; |
|
| 265 | + $path = '/' . $slug; |
|
| 266 | 266 | $this->repository->deleteDocumentByPath($path); |
| 267 | 267 | } |
| 268 | 268 | |
@@ -313,13 +313,13 @@ discard block |
||
| 313 | 313 | $brickArray[] = $brickObj; |
| 314 | 314 | } |
| 315 | 315 | |
| 316 | - $bricks = $documentObj->bricks; |
|
| 316 | + $bricks = $documentObj->bricks; |
|
| 317 | 317 | $bricks[$brickSlug] = $brickArray; |
| 318 | - $documentObj->bricks = $bricks; |
|
| 318 | + $documentObj->bricks = $bricks; |
|
| 319 | 319 | } else { |
| 320 | - $bricks = $documentObj->bricks; |
|
| 320 | + $bricks = $documentObj->bricks; |
|
| 321 | 321 | $bricks[$brickSlug] = $brick; |
| 322 | - $documentObj->bricks = $bricks; |
|
| 322 | + $documentObj->bricks = $bricks; |
|
| 323 | 323 | } |
| 324 | 324 | } |
| 325 | 325 | } |
@@ -330,9 +330,9 @@ discard block |
||
| 330 | 330 | $brickObj = new \stdClass(); |
| 331 | 331 | $brickObj->type = $brickTypeSlug; |
| 332 | 332 | $brickObj->fields = $brickContent; |
| 333 | - $dynamicBricks = $documentObj->dynamicBricks; |
|
| 333 | + $dynamicBricks = $documentObj->dynamicBricks; |
|
| 334 | 334 | $dynamicBricks[] = $brickObj; |
| 335 | - $documentObj->dynamicBricks = $dynamicBricks; |
|
| 335 | + $documentObj->dynamicBricks = $dynamicBricks; |
|
| 336 | 336 | } |
| 337 | 337 | } |
| 338 | 338 | } |
@@ -348,13 +348,13 @@ discard block |
||
| 348 | 348 | */ |
| 349 | 349 | public function addDocumentFolder($postValues) |
| 350 | 350 | { |
| 351 | - $documentFolderObject = $this->createDocumentFolderFromPostValues($postValues); |
|
| 352 | - if ($postValues['path'] === '/') { |
|
| 353 | - $documentFolderObject->path = $postValues['path'] . $documentFolderObject->slug; |
|
| 354 | - } else { |
|
| 355 | - $documentFolderObject->path = $postValues['path'] . '/' . $documentFolderObject->slug; |
|
| 356 | - } |
|
| 357 | - $this->repository->saveDocument($documentFolderObject); |
|
| 351 | + $documentFolderObject = $this->createDocumentFolderFromPostValues($postValues); |
|
| 352 | + if ($postValues['path'] === '/') { |
|
| 353 | + $documentFolderObject->path = $postValues['path'] . $documentFolderObject->slug; |
|
| 354 | + } else { |
|
| 355 | + $documentFolderObject->path = $postValues['path'] . '/' . $documentFolderObject->slug; |
|
| 356 | + } |
|
| 357 | + $this->repository->saveDocument($documentFolderObject); |
|
| 358 | 358 | } |
| 359 | 359 | |
| 360 | 360 | /** |
@@ -366,7 +366,7 @@ discard block |
||
| 366 | 366 | */ |
| 367 | 367 | public function deleteDocumentFolderBySlug($slug) |
| 368 | 368 | { |
| 369 | - $path = '/' . $slug; |
|
| 369 | + $path = '/' . $slug; |
|
| 370 | 370 | $this->repository->deleteDocumentByPath($path); |
| 371 | 371 | } |
| 372 | 372 | |
@@ -380,7 +380,7 @@ discard block |
||
| 380 | 380 | */ |
| 381 | 381 | public function getDocumentFolderBySlug($slug) |
| 382 | 382 | { |
| 383 | - $path = '/' . $slug; |
|
| 383 | + $path = '/' . $slug; |
|
| 384 | 384 | return $this->repository->getDocumentByPath($path); |
| 385 | 385 | } |
| 386 | 386 | |
@@ -393,7 +393,7 @@ discard block |
||
| 393 | 393 | */ |
| 394 | 394 | public function saveDocumentFolder($postValues) |
| 395 | 395 | { |
| 396 | - $this->addDocumentFolder($postValues); |
|
| 396 | + $this->addDocumentFolder($postValues); |
|
| 397 | 397 | } |
| 398 | 398 | |
| 399 | 399 | /** |
@@ -406,7 +406,7 @@ discard block |
||
| 406 | 406 | */ |
| 407 | 407 | private function getDocumentContainerByPath($path) |
| 408 | 408 | { |
| 409 | - return $this->repository->getDocumentContainerByPath($path); |
|
| 409 | + return $this->repository->getDocumentContainerByPath($path); |
|
| 410 | 410 | } |
| 411 | 411 | |
| 412 | 412 | /** |
@@ -610,9 +610,9 @@ discard block |
||
| 610 | 610 | $imageObject->size = $postValues['size']; |
| 611 | 611 | $imageObject->set = $fileNames; |
| 612 | 612 | |
| 613 | - $images = $this->repository->images; |
|
| 613 | + $images = $this->repository->images; |
|
| 614 | 614 | $images[] = $imageObject; |
| 615 | - $this->repository->images = $images; |
|
| 615 | + $this->repository->images = $images; |
|
| 616 | 616 | |
| 617 | 617 | $this->save(); |
| 618 | 618 | } else { |
@@ -647,7 +647,7 @@ discard block |
||
| 647 | 647 | /** |
| 648 | 648 | * @param $filename |
| 649 | 649 | * @return null |
| 650 | - */ |
|
| 650 | + */ |
|
| 651 | 651 | public function getImageByName($filename) |
| 652 | 652 | { |
| 653 | 653 | $images = $this->getImages(); |
@@ -698,9 +698,9 @@ discard block |
||
| 698 | 698 | $file->type = $postValues['type']; |
| 699 | 699 | $file->size = $postValues['size']; |
| 700 | 700 | |
| 701 | - $files = $this->repository->files; |
|
| 701 | + $files = $this->repository->files; |
|
| 702 | 702 | $files[] = $file; |
| 703 | - $this->repository->files = $files; |
|
| 703 | + $this->repository->files = $files; |
|
| 704 | 704 | $this->save(); |
| 705 | 705 | } else { |
| 706 | 706 | throw new \Exception('Error moving uploaded file'); |
@@ -739,7 +739,7 @@ discard block |
||
| 739 | 739 | /** |
| 740 | 740 | * @param $filename |
| 741 | 741 | * @return null |
| 742 | - */ |
|
| 742 | + */ |
|
| 743 | 743 | public function getFileByName($filename) |
| 744 | 744 | { |
| 745 | 745 | $files = $this->getFiles(); |
@@ -754,7 +754,7 @@ discard block |
||
| 754 | 754 | /** |
| 755 | 755 | * @param $filename |
| 756 | 756 | * @throws \Exception |
| 757 | - */ |
|
| 757 | + */ |
|
| 758 | 758 | public function deleteFileByName($filename) |
| 759 | 759 | { |
| 760 | 760 | $destinationPath = realpath(__DIR__ . '/../../www/files/'); |
@@ -799,9 +799,9 @@ discard block |
||
| 799 | 799 | { |
| 800 | 800 | $documentTypeObject = $this->createDocumentTypeFromPostValues($postValues); |
| 801 | 801 | |
| 802 | - $documentTypes = $this->repository->documentTypes; |
|
| 803 | - $documentTypes[] = $documentTypeObject; |
|
| 804 | - $this->repository->documentTypes = $documentTypes; |
|
| 802 | + $documentTypes = $this->repository->documentTypes; |
|
| 803 | + $documentTypes[] = $documentTypeObject; |
|
| 804 | + $this->repository->documentTypes = $documentTypes; |
|
| 805 | 805 | |
| 806 | 806 | $this->save(); |
| 807 | 807 | } |
@@ -947,9 +947,9 @@ discard block |
||
| 947 | 947 | { |
| 948 | 948 | $brickObject = $this->createBrickFromPostValues($postValues); |
| 949 | 949 | |
| 950 | - $bricks = $this->repository->bricks; |
|
| 951 | - $bricks[] = $brickObject; |
|
| 952 | - $this->repository->bricks = $bricks; |
|
| 950 | + $bricks = $this->repository->bricks; |
|
| 951 | + $bricks[] = $brickObject; |
|
| 952 | + $this->repository->bricks = $bricks; |
|
| 953 | 953 | |
| 954 | 954 | $this->save(); |
| 955 | 955 | } |
@@ -1154,9 +1154,9 @@ discard block |
||
| 1154 | 1154 | { |
| 1155 | 1155 | $imageSetObject = $this->createImageSetFromPostValues($postValues); |
| 1156 | 1156 | |
| 1157 | - $imageSet = $this->repository->imageSet; |
|
| 1158 | - $imageSet[] = $imageSetObject; |
|
| 1159 | - $this->repository->imageSet = $imageSet; |
|
| 1157 | + $imageSet = $this->repository->imageSet; |
|
| 1158 | + $imageSet[] = $imageSetObject; |
|
| 1159 | + $this->repository->imageSet = $imageSet; |
|
| 1160 | 1160 | |
| 1161 | 1161 | $this->save(); |
| 1162 | 1162 | } |
@@ -19,227 +19,227 @@ 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 | - /** |
|
| 94 | - * Load filebased subset and return it's contents |
|
| 95 | - * |
|
| 96 | - * @param $name |
|
| 97 | - * @return mixed|string |
|
| 98 | - * @throws \Exception |
|
| 99 | - */ |
|
| 100 | - public function __get($name) |
|
| 101 | - { |
|
| 102 | - if (isset($this->$name)) { |
|
| 103 | - if (in_array($name, $this->fileBasedSubsets)) { |
|
| 104 | - return $this->$name; |
|
| 105 | - } else { |
|
| 106 | - throw new \Exception('Trying to get undefined property from Repository: ' . $name); |
|
| 107 | - } |
|
| 108 | - } else { |
|
| 109 | - if (in_array($name, $this->fileBasedSubsets)) { |
|
| 110 | - return $this->loadSubset($name); |
|
| 111 | - } else { |
|
| 112 | - throw new \Exception('Trying to get undefined property from Repository: ' . $name); |
|
| 113 | - } |
|
| 114 | - } |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - /** |
|
| 118 | - * Set filebased subset contents |
|
| 119 | - * @param $name |
|
| 120 | - * @param $value |
|
| 121 | - * @throws \Exception |
|
| 122 | - */ |
|
| 123 | - public function __set($name, $value) |
|
| 124 | - { |
|
| 125 | - if (in_array($name, $this->fileBasedSubsets)) { |
|
| 126 | - $this->$name = $value; |
|
| 127 | - $changes = $name . 'Changes'; |
|
| 128 | - $this->$changes = true; |
|
| 129 | - } else { |
|
| 130 | - throw new \Exception('Trying to persist unknown subset in repository: ' . $name . ' <br /><pre>' . print_r($value, true) . '</pre>'); |
|
| 131 | - } |
|
| 132 | - } |
|
| 133 | - |
|
| 134 | - /** |
|
| 135 | - * Persist all subsets |
|
| 136 | - */ |
|
| 137 | - public function save() |
|
| 138 | - { |
|
| 139 | - $this->sitemapChanges ? $this->saveSubset('sitemap') : null; |
|
| 140 | - $this->applicationComponentsChanges ? $this->saveSubset('applicationComponents') : null; |
|
| 141 | - $this->documentTypesChanges ? $this->saveSubset('documentTypes') : null; |
|
| 142 | - $this->bricksChanges ? $this->saveSubset('bricks') : null; |
|
| 143 | - $this->imageSetChanges ? $this->saveSubset('imageSet') : null; |
|
| 144 | - $this->imagesChanges ? $this->saveSubset('images') : null; |
|
| 145 | - $this->filesChanges ? $this->saveSubset('files') : null; |
|
| 146 | - $this->usersChanges ? $this->saveSubset('users') : null; |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - /** |
|
| 150 | - * Persist subset to disk |
|
| 151 | - * @param $subset |
|
| 152 | - */ |
|
| 153 | - protected function saveSubset($subset) |
|
| 154 | - { |
|
| 155 | - $json = json_encode($this->$subset); |
|
| 156 | - $subsetStoragePath = $this->storagePath . DIRECTORY_SEPARATOR . $subset . '.json'; |
|
| 157 | - file_put_contents($subsetStoragePath, $json); |
|
| 158 | - $changes = $subset . 'Changes'; |
|
| 159 | - $this->$changes = false; |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - /** |
|
| 163 | - * Load subset from disk |
|
| 164 | - * @param $subset |
|
| 165 | - * @return mixed|string |
|
| 166 | - */ |
|
| 167 | - protected function loadSubset($subset) |
|
| 168 | - { |
|
| 169 | - $subsetStoragePath = $this->storagePath . DIRECTORY_SEPARATOR . $subset . '.json'; |
|
| 170 | - $json = file_get_contents($subsetStoragePath); |
|
| 171 | - $json = json_decode($json); |
|
| 172 | - $this->$subset = $json; |
|
| 173 | - return $json; |
|
| 174 | - } |
|
| 175 | - |
|
| 176 | - /** |
|
| 177 | - * @param $contentSqlPath |
|
| 178 | - */ |
|
| 179 | - protected function initContentDb($contentSqlPath) |
|
| 180 | - { |
|
| 181 | - $db = $this->getContentDbHandle(); |
|
| 182 | - $sql = file_get_contents($contentSqlPath); |
|
| 183 | - $db->exec($sql); |
|
| 184 | - } |
|
| 185 | - |
|
| 186 | - /** |
|
| 187 | - * @param $storageDefaultPath |
|
| 188 | - */ |
|
| 189 | - protected function initConfigStorage($storageDefaultPath) |
|
| 190 | - { |
|
| 191 | - $json = file_get_contents($storageDefaultPath); |
|
| 192 | - $json = json_decode($json); |
|
| 193 | - $this->sitemap = $json->sitemap; |
|
| 194 | - $this->sitemapChanges = true; |
|
| 195 | - $this->applicationComponents = $json->applicationComponents; |
|
| 196 | - $this->applicationComponentsChanges = true; |
|
| 197 | - $this->documentTypes = $json->documentTypes; |
|
| 198 | - $this->documentTypesChanges = true; |
|
| 199 | - $this->bricks = $json->bricks; |
|
| 200 | - $this->bricksChanges = true; |
|
| 201 | - $this->imageSet = $json->imageSet; |
|
| 202 | - $this->imageSetChanges = true; |
|
| 203 | - $this->images = $json->images; |
|
| 204 | - $this->imagesChanges = true; |
|
| 205 | - $this->files = $json->files; |
|
| 206 | - $this->filesChanges = true; |
|
| 207 | - $this->users = $json->users; |
|
| 208 | - $this->usersChanges = true; |
|
| 209 | - } |
|
| 210 | - |
|
| 211 | - /** |
|
| 212 | - * @return \PDO |
|
| 213 | - */ |
|
| 214 | - protected function getContentDbHandle() |
|
| 215 | - { |
|
| 216 | - if ($this->contentDbHandle === null) { |
|
| 217 | - $this->contentDbHandle = new \PDO('sqlite:' . $this->storagePath . DIRECTORY_SEPARATOR . 'content.db'); |
|
| 218 | - } |
|
| 219 | - return $this->contentDbHandle; |
|
| 220 | - } |
|
| 221 | - |
|
| 222 | - /** |
|
| 223 | - * Get all documents |
|
| 224 | - * @return array |
|
| 225 | - */ |
|
| 226 | - public function getDocuments() |
|
| 227 | - { |
|
| 228 | - return $this->getDocumentsByPath('/'); |
|
| 229 | - } |
|
| 230 | - |
|
| 231 | - /** |
|
| 232 | - * Get all documents and folders in a certain path |
|
| 233 | - * @param $folderPath |
|
| 234 | - * @return array |
|
| 235 | - * @throws \Exception |
|
| 236 | - */ |
|
| 237 | - public function getDocumentsByPath($folderPath) |
|
| 238 | - { |
|
| 239 | - $db = $this->getContentDbHandle(); |
|
| 240 | - $folderPathWithWildcard = $folderPath . '%'; |
|
| 241 | - |
|
| 242 | - $stmt = $this->getDbStatement(' |
|
| 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 | + /** |
|
| 94 | + * Load filebased subset and return it's contents |
|
| 95 | + * |
|
| 96 | + * @param $name |
|
| 97 | + * @return mixed|string |
|
| 98 | + * @throws \Exception |
|
| 99 | + */ |
|
| 100 | + public function __get($name) |
|
| 101 | + { |
|
| 102 | + if (isset($this->$name)) { |
|
| 103 | + if (in_array($name, $this->fileBasedSubsets)) { |
|
| 104 | + return $this->$name; |
|
| 105 | + } else { |
|
| 106 | + throw new \Exception('Trying to get undefined property from Repository: ' . $name); |
|
| 107 | + } |
|
| 108 | + } else { |
|
| 109 | + if (in_array($name, $this->fileBasedSubsets)) { |
|
| 110 | + return $this->loadSubset($name); |
|
| 111 | + } else { |
|
| 112 | + throw new \Exception('Trying to get undefined property from Repository: ' . $name); |
|
| 113 | + } |
|
| 114 | + } |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + /** |
|
| 118 | + * Set filebased subset contents |
|
| 119 | + * @param $name |
|
| 120 | + * @param $value |
|
| 121 | + * @throws \Exception |
|
| 122 | + */ |
|
| 123 | + public function __set($name, $value) |
|
| 124 | + { |
|
| 125 | + if (in_array($name, $this->fileBasedSubsets)) { |
|
| 126 | + $this->$name = $value; |
|
| 127 | + $changes = $name . 'Changes'; |
|
| 128 | + $this->$changes = true; |
|
| 129 | + } else { |
|
| 130 | + throw new \Exception('Trying to persist unknown subset in repository: ' . $name . ' <br /><pre>' . print_r($value, true) . '</pre>'); |
|
| 131 | + } |
|
| 132 | + } |
|
| 133 | + |
|
| 134 | + /** |
|
| 135 | + * Persist all subsets |
|
| 136 | + */ |
|
| 137 | + public function save() |
|
| 138 | + { |
|
| 139 | + $this->sitemapChanges ? $this->saveSubset('sitemap') : null; |
|
| 140 | + $this->applicationComponentsChanges ? $this->saveSubset('applicationComponents') : null; |
|
| 141 | + $this->documentTypesChanges ? $this->saveSubset('documentTypes') : null; |
|
| 142 | + $this->bricksChanges ? $this->saveSubset('bricks') : null; |
|
| 143 | + $this->imageSetChanges ? $this->saveSubset('imageSet') : null; |
|
| 144 | + $this->imagesChanges ? $this->saveSubset('images') : null; |
|
| 145 | + $this->filesChanges ? $this->saveSubset('files') : null; |
|
| 146 | + $this->usersChanges ? $this->saveSubset('users') : null; |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + /** |
|
| 150 | + * Persist subset to disk |
|
| 151 | + * @param $subset |
|
| 152 | + */ |
|
| 153 | + protected function saveSubset($subset) |
|
| 154 | + { |
|
| 155 | + $json = json_encode($this->$subset); |
|
| 156 | + $subsetStoragePath = $this->storagePath . DIRECTORY_SEPARATOR . $subset . '.json'; |
|
| 157 | + file_put_contents($subsetStoragePath, $json); |
|
| 158 | + $changes = $subset . 'Changes'; |
|
| 159 | + $this->$changes = false; |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + /** |
|
| 163 | + * Load subset from disk |
|
| 164 | + * @param $subset |
|
| 165 | + * @return mixed|string |
|
| 166 | + */ |
|
| 167 | + protected function loadSubset($subset) |
|
| 168 | + { |
|
| 169 | + $subsetStoragePath = $this->storagePath . DIRECTORY_SEPARATOR . $subset . '.json'; |
|
| 170 | + $json = file_get_contents($subsetStoragePath); |
|
| 171 | + $json = json_decode($json); |
|
| 172 | + $this->$subset = $json; |
|
| 173 | + return $json; |
|
| 174 | + } |
|
| 175 | + |
|
| 176 | + /** |
|
| 177 | + * @param $contentSqlPath |
|
| 178 | + */ |
|
| 179 | + protected function initContentDb($contentSqlPath) |
|
| 180 | + { |
|
| 181 | + $db = $this->getContentDbHandle(); |
|
| 182 | + $sql = file_get_contents($contentSqlPath); |
|
| 183 | + $db->exec($sql); |
|
| 184 | + } |
|
| 185 | + |
|
| 186 | + /** |
|
| 187 | + * @param $storageDefaultPath |
|
| 188 | + */ |
|
| 189 | + protected function initConfigStorage($storageDefaultPath) |
|
| 190 | + { |
|
| 191 | + $json = file_get_contents($storageDefaultPath); |
|
| 192 | + $json = json_decode($json); |
|
| 193 | + $this->sitemap = $json->sitemap; |
|
| 194 | + $this->sitemapChanges = true; |
|
| 195 | + $this->applicationComponents = $json->applicationComponents; |
|
| 196 | + $this->applicationComponentsChanges = true; |
|
| 197 | + $this->documentTypes = $json->documentTypes; |
|
| 198 | + $this->documentTypesChanges = true; |
|
| 199 | + $this->bricks = $json->bricks; |
|
| 200 | + $this->bricksChanges = true; |
|
| 201 | + $this->imageSet = $json->imageSet; |
|
| 202 | + $this->imageSetChanges = true; |
|
| 203 | + $this->images = $json->images; |
|
| 204 | + $this->imagesChanges = true; |
|
| 205 | + $this->files = $json->files; |
|
| 206 | + $this->filesChanges = true; |
|
| 207 | + $this->users = $json->users; |
|
| 208 | + $this->usersChanges = true; |
|
| 209 | + } |
|
| 210 | + |
|
| 211 | + /** |
|
| 212 | + * @return \PDO |
|
| 213 | + */ |
|
| 214 | + protected function getContentDbHandle() |
|
| 215 | + { |
|
| 216 | + if ($this->contentDbHandle === null) { |
|
| 217 | + $this->contentDbHandle = new \PDO('sqlite:' . $this->storagePath . DIRECTORY_SEPARATOR . 'content.db'); |
|
| 218 | + } |
|
| 219 | + return $this->contentDbHandle; |
|
| 220 | + } |
|
| 221 | + |
|
| 222 | + /** |
|
| 223 | + * Get all documents |
|
| 224 | + * @return array |
|
| 225 | + */ |
|
| 226 | + public function getDocuments() |
|
| 227 | + { |
|
| 228 | + return $this->getDocumentsByPath('/'); |
|
| 229 | + } |
|
| 230 | + |
|
| 231 | + /** |
|
| 232 | + * Get all documents and folders in a certain path |
|
| 233 | + * @param $folderPath |
|
| 234 | + * @return array |
|
| 235 | + * @throws \Exception |
|
| 236 | + */ |
|
| 237 | + public function getDocumentsByPath($folderPath) |
|
| 238 | + { |
|
| 239 | + $db = $this->getContentDbHandle(); |
|
| 240 | + $folderPathWithWildcard = $folderPath . '%'; |
|
| 241 | + |
|
| 242 | + $stmt = $this->getDbStatement(' |
|
| 243 | 243 | SELECT * |
| 244 | 244 | FROM documents |
| 245 | 245 | WHERE `path` LIKE ' . $db->quote($folderPathWithWildcard) . ' |
@@ -248,119 +248,119 @@ discard block |
||
| 248 | 248 | ORDER BY `type` DESC, `path` ASC |
| 249 | 249 | '); |
| 250 | 250 | |
| 251 | - $documents = $stmt->fetchAll(\PDO::FETCH_CLASS, '\library\storage\Document'); |
|
| 252 | - foreach ($documents as $key => $document) { |
|
| 253 | - if ($document->type === 'folder') { |
|
| 254 | - $document->dbHandle = $db; |
|
| 255 | - $documents[$key] = $document; |
|
| 256 | - } |
|
| 257 | - } |
|
| 258 | - return $documents; |
|
| 259 | - } |
|
| 260 | - |
|
| 261 | - |
|
| 262 | - /** |
|
| 263 | - * @param $path |
|
| 264 | - * @return bool|Document |
|
| 265 | - */ |
|
| 266 | - public function getDocumentContainerByPath($path) |
|
| 267 | - { |
|
| 268 | - $document = $this->getDocumentByPath($path); |
|
| 269 | - if ($document === false) { |
|
| 270 | - return false; |
|
| 271 | - } |
|
| 272 | - $slugLength = strlen($document->slug); |
|
| 273 | - $containerPath = substr($path, 0, -$slugLength); |
|
| 274 | - if ($containerPath === '/') { |
|
| 275 | - return $this->getRootFolder(); |
|
| 276 | - } |
|
| 277 | - $containerFolder = $this->getDocumentByPath($containerPath); |
|
| 278 | - return $containerFolder; |
|
| 279 | - } |
|
| 280 | - |
|
| 281 | - /** |
|
| 282 | - * @param $path |
|
| 283 | - * @return bool|Document |
|
| 284 | - */ |
|
| 285 | - public function getDocumentByPath($path) |
|
| 286 | - { |
|
| 287 | - $db = $this->getContentDbHandle(); |
|
| 288 | - $document = $this->fetchDocument(' |
|
| 251 | + $documents = $stmt->fetchAll(\PDO::FETCH_CLASS, '\library\storage\Document'); |
|
| 252 | + foreach ($documents as $key => $document) { |
|
| 253 | + if ($document->type === 'folder') { |
|
| 254 | + $document->dbHandle = $db; |
|
| 255 | + $documents[$key] = $document; |
|
| 256 | + } |
|
| 257 | + } |
|
| 258 | + return $documents; |
|
| 259 | + } |
|
| 260 | + |
|
| 261 | + |
|
| 262 | + /** |
|
| 263 | + * @param $path |
|
| 264 | + * @return bool|Document |
|
| 265 | + */ |
|
| 266 | + public function getDocumentContainerByPath($path) |
|
| 267 | + { |
|
| 268 | + $document = $this->getDocumentByPath($path); |
|
| 269 | + if ($document === false) { |
|
| 270 | + return false; |
|
| 271 | + } |
|
| 272 | + $slugLength = strlen($document->slug); |
|
| 273 | + $containerPath = substr($path, 0, -$slugLength); |
|
| 274 | + if ($containerPath === '/') { |
|
| 275 | + return $this->getRootFolder(); |
|
| 276 | + } |
|
| 277 | + $containerFolder = $this->getDocumentByPath($containerPath); |
|
| 278 | + return $containerFolder; |
|
| 279 | + } |
|
| 280 | + |
|
| 281 | + /** |
|
| 282 | + * @param $path |
|
| 283 | + * @return bool|Document |
|
| 284 | + */ |
|
| 285 | + public function getDocumentByPath($path) |
|
| 286 | + { |
|
| 287 | + $db = $this->getContentDbHandle(); |
|
| 288 | + $document = $this->fetchDocument(' |
|
| 289 | 289 | SELECT * |
| 290 | 290 | FROM documents |
| 291 | 291 | WHERE path = ' . $db->quote($path) . ' |
| 292 | 292 | '); |
| 293 | - if ($document instanceof Document && $document->type === 'folder') { |
|
| 294 | - $document->dbHandle = $db; |
|
| 295 | - } |
|
| 296 | - return $document; |
|
| 297 | - } |
|
| 298 | - |
|
| 299 | - /** |
|
| 300 | - * Return the results of the query as array of Documents |
|
| 301 | - * @param $sql |
|
| 302 | - * @return array |
|
| 303 | - * @throws \Exception |
|
| 304 | - */ |
|
| 305 | - protected function fetchAllDocuments($sql) |
|
| 306 | - { |
|
| 307 | - $stmt = $this->getDbStatement($sql); |
|
| 308 | - return $stmt->fetchAll(\PDO::FETCH_CLASS, '\library\storage\Document'); |
|
| 309 | - } |
|
| 310 | - |
|
| 311 | - /** |
|
| 312 | - * Return the result of the query as Document |
|
| 313 | - * @param $sql |
|
| 314 | - * @return mixed |
|
| 315 | - * @throws \Exception |
|
| 316 | - */ |
|
| 317 | - protected function fetchDocument($sql) |
|
| 318 | - { |
|
| 319 | - $stmt = $this->getDbStatement($sql); |
|
| 320 | - return $stmt->fetchObject('\library\storage\Document'); |
|
| 321 | - } |
|
| 322 | - |
|
| 323 | - /** |
|
| 324 | - * Prepare the sql statement |
|
| 325 | - * @param $sql |
|
| 326 | - * @return \PDOStatement |
|
| 327 | - * @throws \Exception |
|
| 328 | - */ |
|
| 329 | - protected function getDbStatement($sql) |
|
| 330 | - { |
|
| 331 | - $db = $this->getContentDbHandle(); |
|
| 332 | - $stmt = $db->query($sql); |
|
| 333 | - if ($stmt === false) { |
|
| 334 | - $errorInfo = $db->errorInfo(); |
|
| 335 | - $errorMsg = $errorInfo[2]; |
|
| 336 | - throw new \Exception('SQLite Exception: ' . $errorMsg . ' in SQL: <br /><pre>' . $sql . '</pre>'); |
|
| 337 | - } |
|
| 338 | - return $stmt; |
|
| 339 | - } |
|
| 340 | - |
|
| 341 | - /** |
|
| 342 | - * Create a (non-existent) root folder Document and return it |
|
| 343 | - * @return Document |
|
| 344 | - */ |
|
| 345 | - protected function getRootFolder() |
|
| 346 | - { |
|
| 347 | - $rootFolder = new Document(); |
|
| 348 | - $rootFolder->path = '/'; |
|
| 349 | - $rootFolder->type = 'folder'; |
|
| 350 | - return $rootFolder; |
|
| 351 | - } |
|
| 352 | - |
|
| 353 | - /** |
|
| 354 | - * Save the document to the database |
|
| 355 | - * @param Document $documentObject |
|
| 356 | - * @return bool |
|
| 357 | - * @throws \Exception |
|
| 358 | - * @internal param $path |
|
| 359 | - */ |
|
| 360 | - public function saveDocument($documentObject) |
|
| 361 | - { |
|
| 362 | - $db = $this->getContentDbHandle(); |
|
| 363 | - $stmt = $this->getDbStatement(' |
|
| 293 | + if ($document instanceof Document && $document->type === 'folder') { |
|
| 294 | + $document->dbHandle = $db; |
|
| 295 | + } |
|
| 296 | + return $document; |
|
| 297 | + } |
|
| 298 | + |
|
| 299 | + /** |
|
| 300 | + * Return the results of the query as array of Documents |
|
| 301 | + * @param $sql |
|
| 302 | + * @return array |
|
| 303 | + * @throws \Exception |
|
| 304 | + */ |
|
| 305 | + protected function fetchAllDocuments($sql) |
|
| 306 | + { |
|
| 307 | + $stmt = $this->getDbStatement($sql); |
|
| 308 | + return $stmt->fetchAll(\PDO::FETCH_CLASS, '\library\storage\Document'); |
|
| 309 | + } |
|
| 310 | + |
|
| 311 | + /** |
|
| 312 | + * Return the result of the query as Document |
|
| 313 | + * @param $sql |
|
| 314 | + * @return mixed |
|
| 315 | + * @throws \Exception |
|
| 316 | + */ |
|
| 317 | + protected function fetchDocument($sql) |
|
| 318 | + { |
|
| 319 | + $stmt = $this->getDbStatement($sql); |
|
| 320 | + return $stmt->fetchObject('\library\storage\Document'); |
|
| 321 | + } |
|
| 322 | + |
|
| 323 | + /** |
|
| 324 | + * Prepare the sql statement |
|
| 325 | + * @param $sql |
|
| 326 | + * @return \PDOStatement |
|
| 327 | + * @throws \Exception |
|
| 328 | + */ |
|
| 329 | + protected function getDbStatement($sql) |
|
| 330 | + { |
|
| 331 | + $db = $this->getContentDbHandle(); |
|
| 332 | + $stmt = $db->query($sql); |
|
| 333 | + if ($stmt === false) { |
|
| 334 | + $errorInfo = $db->errorInfo(); |
|
| 335 | + $errorMsg = $errorInfo[2]; |
|
| 336 | + throw new \Exception('SQLite Exception: ' . $errorMsg . ' in SQL: <br /><pre>' . $sql . '</pre>'); |
|
| 337 | + } |
|
| 338 | + return $stmt; |
|
| 339 | + } |
|
| 340 | + |
|
| 341 | + /** |
|
| 342 | + * Create a (non-existent) root folder Document and return it |
|
| 343 | + * @return Document |
|
| 344 | + */ |
|
| 345 | + protected function getRootFolder() |
|
| 346 | + { |
|
| 347 | + $rootFolder = new Document(); |
|
| 348 | + $rootFolder->path = '/'; |
|
| 349 | + $rootFolder->type = 'folder'; |
|
| 350 | + return $rootFolder; |
|
| 351 | + } |
|
| 352 | + |
|
| 353 | + /** |
|
| 354 | + * Save the document to the database |
|
| 355 | + * @param Document $documentObject |
|
| 356 | + * @return bool |
|
| 357 | + * @throws \Exception |
|
| 358 | + * @internal param $path |
|
| 359 | + */ |
|
| 360 | + public function saveDocument($documentObject) |
|
| 361 | + { |
|
| 362 | + $db = $this->getContentDbHandle(); |
|
| 363 | + $stmt = $this->getDbStatement(' |
|
| 364 | 364 | INSERT OR REPLACE INTO documents (`path`,`title`,`slug`,`type`,`documentType`,`documentTypeSlug`,`state`,`lastModificationDate`,`creationDate`,`lastModifiedBy`,`fields`,`bricks`,`dynamicBricks`) |
| 365 | 365 | VALUES( |
| 366 | 366 | ' . $db->quote($documentObject->path) . ', |
@@ -378,37 +378,37 @@ discard block |
||
| 378 | 378 | ' . $db->quote(json_encode($documentObject->dynamicBricks)) . ' |
| 379 | 379 | ) |
| 380 | 380 | '); |
| 381 | - $result = $stmt->execute(); |
|
| 382 | - return $result; |
|
| 383 | - } |
|
| 384 | - |
|
| 385 | - /** |
|
| 386 | - * Delete the document from the database |
|
| 387 | - * If it's a folder, also delete it's contents |
|
| 388 | - * @param $path |
|
| 389 | - * @throws \Exception |
|
| 390 | - */ |
|
| 391 | - public function deleteDocumentByPath($path) |
|
| 392 | - { |
|
| 393 | - $db = $this->getContentDbHandle(); |
|
| 394 | - $documentToDelete = $this->getDocumentByPath($path); |
|
| 395 | - if ($documentToDelete instanceof Document) { |
|
| 396 | - if ($documentToDelete->type == 'document') { |
|
| 397 | - $stmt = $this->getDbStatement(' |
|
| 381 | + $result = $stmt->execute(); |
|
| 382 | + return $result; |
|
| 383 | + } |
|
| 384 | + |
|
| 385 | + /** |
|
| 386 | + * Delete the document from the database |
|
| 387 | + * If it's a folder, also delete it's contents |
|
| 388 | + * @param $path |
|
| 389 | + * @throws \Exception |
|
| 390 | + */ |
|
| 391 | + public function deleteDocumentByPath($path) |
|
| 392 | + { |
|
| 393 | + $db = $this->getContentDbHandle(); |
|
| 394 | + $documentToDelete = $this->getDocumentByPath($path); |
|
| 395 | + if ($documentToDelete instanceof Document) { |
|
| 396 | + if ($documentToDelete->type == 'document') { |
|
| 397 | + $stmt = $this->getDbStatement(' |
|
| 398 | 398 | DELETE FROM documents |
| 399 | 399 | WHERE path = ' . $db->quote($path) . ' |
| 400 | 400 | '); |
| 401 | - $stmt->execute(); |
|
| 402 | - } elseif ($documentToDelete->type == 'folder') { |
|
| 403 | - $folderPathWithWildcard = $path . '%'; |
|
| 404 | - $stmt = $this->getDbStatement(' |
|
| 401 | + $stmt->execute(); |
|
| 402 | + } elseif ($documentToDelete->type == 'folder') { |
|
| 403 | + $folderPathWithWildcard = $path . '%'; |
|
| 404 | + $stmt = $this->getDbStatement(' |
|
| 405 | 405 | DELETE FROM documents |
| 406 | 406 | WHERE (path LIKE ' . $db->quote($folderPathWithWildcard) . ' |
| 407 | 407 | AND substr(`path`, ' . (strlen($path) + 1) . ', 1) = "/") |
| 408 | 408 | OR path = ' . $db->quote($path) . ' |
| 409 | 409 | '); |
| 410 | - $stmt->execute(); |
|
| 411 | - } |
|
| 412 | - } |
|
| 413 | - } |
|
| 410 | + $stmt->execute(); |
|
| 411 | + } |
|
| 412 | + } |
|
| 413 | + } |
|
| 414 | 414 | } |
| 415 | 415 | \ No newline at end of file |