@@ -121,9 +121,9 @@ discard block |
||
| 121 | 121 | if (!empty($doesItExist)) { |
| 122 | 122 | throw new \Exception('Trying to add username that already exists.'); |
| 123 | 123 | } |
| 124 | - $users = $this->repository->users; |
|
| 125 | - $users[] = $userObj; |
|
| 126 | - $this->repository->users = $users; |
|
| 124 | + $users = $this->repository->users; |
|
| 125 | + $users[] = $userObj; |
|
| 126 | + $this->repository->users = $users; |
|
| 127 | 127 | $this->save(); |
| 128 | 128 | } |
| 129 | 129 | |
@@ -795,9 +795,9 @@ discard block |
||
| 795 | 795 | $imageObject->size = $postValues['size']; |
| 796 | 796 | $imageObject->set = $fileNames; |
| 797 | 797 | |
| 798 | - $images = $this->repository->images; |
|
| 798 | + $images = $this->repository->images; |
|
| 799 | 799 | $images[] = $imageObject; |
| 800 | - $this->repository->images = $images; |
|
| 800 | + $this->repository->images = $images; |
|
| 801 | 801 | |
| 802 | 802 | $this->save(); |
| 803 | 803 | } else { |
@@ -832,7 +832,7 @@ discard block |
||
| 832 | 832 | /** |
| 833 | 833 | * @param $filename |
| 834 | 834 | * @return null |
| 835 | - */ |
|
| 835 | + */ |
|
| 836 | 836 | public function getImageByName($filename) |
| 837 | 837 | { |
| 838 | 838 | $images = $this->getImages(); |
@@ -883,9 +883,9 @@ discard block |
||
| 883 | 883 | $file->type = $postValues['type']; |
| 884 | 884 | $file->size = $postValues['size']; |
| 885 | 885 | |
| 886 | - $files = $this->repository->files; |
|
| 886 | + $files = $this->repository->files; |
|
| 887 | 887 | $files[] = $file; |
| 888 | - $this->repository->files = $files; |
|
| 888 | + $this->repository->files = $files; |
|
| 889 | 889 | $this->save(); |
| 890 | 890 | } else { |
| 891 | 891 | throw new \Exception('Error moving uploaded file'); |
@@ -924,7 +924,7 @@ discard block |
||
| 924 | 924 | /** |
| 925 | 925 | * @param $filename |
| 926 | 926 | * @return null |
| 927 | - */ |
|
| 927 | + */ |
|
| 928 | 928 | public function getFileByName($filename) |
| 929 | 929 | { |
| 930 | 930 | $files = $this->getFiles(); |
@@ -939,7 +939,7 @@ discard block |
||
| 939 | 939 | /** |
| 940 | 940 | * @param $filename |
| 941 | 941 | * @throws \Exception |
| 942 | - */ |
|
| 942 | + */ |
|
| 943 | 943 | public function deleteFileByName($filename) |
| 944 | 944 | { |
| 945 | 945 | $destinationPath = realpath(__DIR__ . '/../../www/files/'); |
@@ -984,9 +984,9 @@ discard block |
||
| 984 | 984 | { |
| 985 | 985 | $documentTypeObject = $this->createDocumentTypeFromPostValues($postValues); |
| 986 | 986 | |
| 987 | - $documentTypes = $this->repository->documentTypes; |
|
| 988 | - $documentTypes[] = $documentTypeObject; |
|
| 989 | - $this->repository->documentTypes = $documentTypes; |
|
| 987 | + $documentTypes = $this->repository->documentTypes; |
|
| 988 | + $documentTypes[] = $documentTypeObject; |
|
| 989 | + $this->repository->documentTypes = $documentTypes; |
|
| 990 | 990 | |
| 991 | 991 | $this->save(); |
| 992 | 992 | } |
@@ -1132,9 +1132,9 @@ discard block |
||
| 1132 | 1132 | { |
| 1133 | 1133 | $brickObject = $this->createBrickFromPostValues($postValues); |
| 1134 | 1134 | |
| 1135 | - $bricks = $this->repository->bricks; |
|
| 1136 | - $bricks[] = $brickObject; |
|
| 1137 | - $this->repository->bricks = $bricks; |
|
| 1135 | + $bricks = $this->repository->bricks; |
|
| 1136 | + $bricks[] = $brickObject; |
|
| 1137 | + $this->repository->bricks = $bricks; |
|
| 1138 | 1138 | |
| 1139 | 1139 | $this->save(); |
| 1140 | 1140 | } |
@@ -1339,9 +1339,9 @@ discard block |
||
| 1339 | 1339 | { |
| 1340 | 1340 | $imageSetObject = $this->createImageSetFromPostValues($postValues); |
| 1341 | 1341 | |
| 1342 | - $imageSet = $this->repository->imageSet; |
|
| 1343 | - $imageSet[] = $imageSetObject; |
|
| 1344 | - $this->repository->imageSet = $imageSet; |
|
| 1342 | + $imageSet = $this->repository->imageSet; |
|
| 1343 | + $imageSet[] = $imageSetObject; |
|
| 1344 | + $this->repository->imageSet = $imageSet; |
|
| 1345 | 1345 | |
| 1346 | 1346 | $this->save(); |
| 1347 | 1347 | } |
@@ -10,131 +10,131 @@ |
||
| 10 | 10 | |
| 11 | 11 | class Repository |
| 12 | 12 | { |
| 13 | - protected $storagePath; |
|
| 14 | - |
|
| 15 | - protected $fileBasedSubsets = array('sitemap', 'applicationComponents', 'documentTypes', 'bricks', 'imageSet', 'images', 'files', 'users'); |
|
| 16 | - |
|
| 17 | - protected $sitemap; |
|
| 18 | - protected $sitemapChanges = false; |
|
| 19 | - |
|
| 20 | - protected $applicationComponents; |
|
| 21 | - protected $applicationComponentsChanges = false; |
|
| 22 | - |
|
| 23 | - protected $documentTypes; |
|
| 24 | - protected $documentTypesChanges = false; |
|
| 25 | - |
|
| 26 | - protected $bricks; |
|
| 27 | - protected $bricksChanges = false; |
|
| 28 | - |
|
| 29 | - protected $imageSet; |
|
| 30 | - protected $imageSetChanges = false; |
|
| 31 | - |
|
| 32 | - protected $images; |
|
| 33 | - protected $imagesChanges = false; |
|
| 34 | - |
|
| 35 | - protected $files; |
|
| 36 | - protected $filesChanges = false; |
|
| 37 | - |
|
| 38 | - protected $users; |
|
| 39 | - protected $usersChanges = false; |
|
| 40 | - |
|
| 41 | - /** |
|
| 42 | - * Repository constructor. |
|
| 43 | - */ |
|
| 44 | - public function __construct($storagePath) |
|
| 45 | - { |
|
| 46 | - $storagePath = realpath($storagePath); |
|
| 47 | - if (is_dir($storagePath) && $storagePath !== false) { |
|
| 48 | - $this->storagePath = $storagePath; |
|
| 49 | - } else { |
|
| 50 | - throw new \Exception('Repository not yet initialized.'); |
|
| 51 | - } |
|
| 52 | - } |
|
| 53 | - |
|
| 54 | - public static function create($storagePath) |
|
| 55 | - { |
|
| 56 | - return mkdir($storagePath); |
|
| 57 | - } |
|
| 58 | - |
|
| 59 | - public function init() |
|
| 60 | - { |
|
| 61 | - $storageDefaultPath = realpath('../library/cc/install/_storage.json'); |
|
| 62 | - $json = file_get_contents($storageDefaultPath); |
|
| 63 | - $json = json_decode($json); |
|
| 64 | - $this->sitemap = $json->sitemap; |
|
| 65 | - $this->sitemapChanges = true; |
|
| 66 | - $this->applicationComponents = $json->applicationComponents; |
|
| 67 | - $this->applicationComponentsChanges = true; |
|
| 68 | - $this->documentTypes = $json->documentTypes; |
|
| 69 | - $this->documentTypesChanges = true; |
|
| 70 | - $this->bricks = $json->bricks; |
|
| 71 | - $this->bricksChanges = true; |
|
| 72 | - $this->imageSet = $json->imageSet; |
|
| 73 | - $this->imageSetChanges = true; |
|
| 74 | - $this->images = $json->images; |
|
| 75 | - $this->imagesChanges = true; |
|
| 76 | - $this->files = $json->files; |
|
| 77 | - $this->filesChanges = true; |
|
| 78 | - $this->users = $json->users; |
|
| 79 | - $this->usersChanges = true; |
|
| 80 | - $this->save(); |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - public function __get($name) |
|
| 84 | - { |
|
| 85 | - if (isset($this->$name)) { |
|
| 86 | - if (in_array($name, $this->fileBasedSubsets)) { |
|
| 87 | - return $this->$name; |
|
| 88 | - } else { |
|
| 89 | - dump(); |
|
| 90 | - } |
|
| 91 | - } else { |
|
| 92 | - if (in_array($name, $this->fileBasedSubsets)) { |
|
| 93 | - return $this->loadSubset($name); |
|
| 94 | - } else { |
|
| 95 | - throw new \Exception('Trying to get undefined property from Repository: ' . $name); |
|
| 96 | - } |
|
| 97 | - } |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - public function __set($name, $value) |
|
| 101 | - { |
|
| 102 | - if (in_array($name, $this->fileBasedSubsets)) { |
|
| 103 | - $this->$name = $value; |
|
| 104 | - $changes = $name . 'Changes'; |
|
| 105 | - $this->$changes = true; |
|
| 106 | - } else { |
|
| 107 | - throw new \Exception('Trying to persist unknown subset in repository: ' . $name . ' <br /><pre>' . print_r($value, true) . '</pre>'); |
|
| 108 | - } |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - public function save() |
|
| 112 | - { |
|
| 113 | - $this->sitemapChanges ? $this->saveSubset('sitemap') : null; |
|
| 114 | - $this->applicationComponentsChanges ? $this->saveSubset('applicationComponents') : null; |
|
| 115 | - $this->documentTypesChanges ? $this->saveSubset('documentTypes') : null; |
|
| 116 | - $this->bricksChanges ? $this->saveSubset('bricks') : null; |
|
| 117 | - $this->imageSetChanges ? $this->saveSubset('imageSet') : null; |
|
| 118 | - $this->imagesChanges ? $this->saveSubset('images') : null; |
|
| 119 | - $this->filesChanges ? $this->saveSubset('files') : null; |
|
| 120 | - $this->usersChanges ? $this->saveSubset('users') : null; |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - protected function saveSubset($subset) |
|
| 124 | - { |
|
| 125 | - $json = json_encode($this->$subset); |
|
| 126 | - $subsetStoragePath = $this->storagePath . DIRECTORY_SEPARATOR . $subset . '.json'; |
|
| 127 | - file_put_contents($subsetStoragePath, $json); |
|
| 128 | - $changes = $subset . 'Changes'; |
|
| 129 | - $this->$changes = false; |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - protected function loadSubset($subset) |
|
| 133 | - { |
|
| 134 | - $subsetStoragePath = $this->storagePath . DIRECTORY_SEPARATOR . $subset . '.json'; |
|
| 135 | - $json = file_get_contents($subsetStoragePath); |
|
| 136 | - $json = json_decode($json); |
|
| 137 | - $this->$subset = $json; |
|
| 138 | - return $json; |
|
| 139 | - } |
|
| 13 | + protected $storagePath; |
|
| 14 | + |
|
| 15 | + protected $fileBasedSubsets = array('sitemap', 'applicationComponents', 'documentTypes', 'bricks', 'imageSet', 'images', 'files', 'users'); |
|
| 16 | + |
|
| 17 | + protected $sitemap; |
|
| 18 | + protected $sitemapChanges = false; |
|
| 19 | + |
|
| 20 | + protected $applicationComponents; |
|
| 21 | + protected $applicationComponentsChanges = false; |
|
| 22 | + |
|
| 23 | + protected $documentTypes; |
|
| 24 | + protected $documentTypesChanges = false; |
|
| 25 | + |
|
| 26 | + protected $bricks; |
|
| 27 | + protected $bricksChanges = false; |
|
| 28 | + |
|
| 29 | + protected $imageSet; |
|
| 30 | + protected $imageSetChanges = false; |
|
| 31 | + |
|
| 32 | + protected $images; |
|
| 33 | + protected $imagesChanges = false; |
|
| 34 | + |
|
| 35 | + protected $files; |
|
| 36 | + protected $filesChanges = false; |
|
| 37 | + |
|
| 38 | + protected $users; |
|
| 39 | + protected $usersChanges = false; |
|
| 40 | + |
|
| 41 | + /** |
|
| 42 | + * Repository constructor. |
|
| 43 | + */ |
|
| 44 | + public function __construct($storagePath) |
|
| 45 | + { |
|
| 46 | + $storagePath = realpath($storagePath); |
|
| 47 | + if (is_dir($storagePath) && $storagePath !== false) { |
|
| 48 | + $this->storagePath = $storagePath; |
|
| 49 | + } else { |
|
| 50 | + throw new \Exception('Repository not yet initialized.'); |
|
| 51 | + } |
|
| 52 | + } |
|
| 53 | + |
|
| 54 | + public static function create($storagePath) |
|
| 55 | + { |
|
| 56 | + return mkdir($storagePath); |
|
| 57 | + } |
|
| 58 | + |
|
| 59 | + public function init() |
|
| 60 | + { |
|
| 61 | + $storageDefaultPath = realpath('../library/cc/install/_storage.json'); |
|
| 62 | + $json = file_get_contents($storageDefaultPath); |
|
| 63 | + $json = json_decode($json); |
|
| 64 | + $this->sitemap = $json->sitemap; |
|
| 65 | + $this->sitemapChanges = true; |
|
| 66 | + $this->applicationComponents = $json->applicationComponents; |
|
| 67 | + $this->applicationComponentsChanges = true; |
|
| 68 | + $this->documentTypes = $json->documentTypes; |
|
| 69 | + $this->documentTypesChanges = true; |
|
| 70 | + $this->bricks = $json->bricks; |
|
| 71 | + $this->bricksChanges = true; |
|
| 72 | + $this->imageSet = $json->imageSet; |
|
| 73 | + $this->imageSetChanges = true; |
|
| 74 | + $this->images = $json->images; |
|
| 75 | + $this->imagesChanges = true; |
|
| 76 | + $this->files = $json->files; |
|
| 77 | + $this->filesChanges = true; |
|
| 78 | + $this->users = $json->users; |
|
| 79 | + $this->usersChanges = true; |
|
| 80 | + $this->save(); |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + public function __get($name) |
|
| 84 | + { |
|
| 85 | + if (isset($this->$name)) { |
|
| 86 | + if (in_array($name, $this->fileBasedSubsets)) { |
|
| 87 | + return $this->$name; |
|
| 88 | + } else { |
|
| 89 | + dump(); |
|
| 90 | + } |
|
| 91 | + } else { |
|
| 92 | + if (in_array($name, $this->fileBasedSubsets)) { |
|
| 93 | + return $this->loadSubset($name); |
|
| 94 | + } else { |
|
| 95 | + throw new \Exception('Trying to get undefined property from Repository: ' . $name); |
|
| 96 | + } |
|
| 97 | + } |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + public function __set($name, $value) |
|
| 101 | + { |
|
| 102 | + if (in_array($name, $this->fileBasedSubsets)) { |
|
| 103 | + $this->$name = $value; |
|
| 104 | + $changes = $name . 'Changes'; |
|
| 105 | + $this->$changes = true; |
|
| 106 | + } else { |
|
| 107 | + throw new \Exception('Trying to persist unknown subset in repository: ' . $name . ' <br /><pre>' . print_r($value, true) . '</pre>'); |
|
| 108 | + } |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + public function save() |
|
| 112 | + { |
|
| 113 | + $this->sitemapChanges ? $this->saveSubset('sitemap') : null; |
|
| 114 | + $this->applicationComponentsChanges ? $this->saveSubset('applicationComponents') : null; |
|
| 115 | + $this->documentTypesChanges ? $this->saveSubset('documentTypes') : null; |
|
| 116 | + $this->bricksChanges ? $this->saveSubset('bricks') : null; |
|
| 117 | + $this->imageSetChanges ? $this->saveSubset('imageSet') : null; |
|
| 118 | + $this->imagesChanges ? $this->saveSubset('images') : null; |
|
| 119 | + $this->filesChanges ? $this->saveSubset('files') : null; |
|
| 120 | + $this->usersChanges ? $this->saveSubset('users') : null; |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + protected function saveSubset($subset) |
|
| 124 | + { |
|
| 125 | + $json = json_encode($this->$subset); |
|
| 126 | + $subsetStoragePath = $this->storagePath . DIRECTORY_SEPARATOR . $subset . '.json'; |
|
| 127 | + file_put_contents($subsetStoragePath, $json); |
|
| 128 | + $changes = $subset . 'Changes'; |
|
| 129 | + $this->$changes = false; |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + protected function loadSubset($subset) |
|
| 133 | + { |
|
| 134 | + $subsetStoragePath = $this->storagePath . DIRECTORY_SEPARATOR . $subset . '.json'; |
|
| 135 | + $json = file_get_contents($subsetStoragePath); |
|
| 136 | + $json = json_decode($json); |
|
| 137 | + $this->$subset = $json; |
|
| 138 | + return $json; |
|
| 139 | + } |
|
| 140 | 140 | } |
| 141 | 141 | \ No newline at end of file |