@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | protected function configureDatabase() |
54 | 54 | { |
55 | 55 | $db = $this->getSearchDbHandle(); |
56 | - $sqlPath = __DIR__ . DIRECTORY_SEPARATOR . '../cc/install/search.sql'; |
|
56 | + $sqlPath = __DIR__.DIRECTORY_SEPARATOR.'../cc/install/search.sql'; |
|
57 | 57 | $searchSql = file_get_contents($sqlPath); |
58 | 58 | $db->exec($searchSql); |
59 | 59 | } |
@@ -69,8 +69,8 @@ discard block |
||
69 | 69 | protected function getSearchDbHandle() |
70 | 70 | { |
71 | 71 | if ($this->searchDbHandle === null) { |
72 | - $path = $this->storageDir . DIRECTORY_SEPARATOR; |
|
73 | - $this->searchDbHandle = new \PDO('sqlite:' . $path . 'search.db'); |
|
72 | + $path = $this->storageDir.DIRECTORY_SEPARATOR; |
|
73 | + $this->searchDbHandle = new \PDO('sqlite:'.$path.'search.db'); |
|
74 | 74 | } |
75 | 75 | return $this->searchDbHandle; |
76 | 76 | } |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | $string = strip_tags($string); |
49 | 49 | $string = trim($string); |
50 | 50 | $string = iconv('UTF-8', 'ASCII//TRANSLIT//IGNORE', $string); // Remove special alphanumeric characters |
51 | - $string = str_replace(array('+', '=', '!', ',', '.',';', ':', '?'), ' ', $string); // Replace sentence breaking charaters with spaces |
|
51 | + $string = str_replace(array('+', '=', '!', ',', '.', ';', ':', '?'), ' ', $string); // Replace sentence breaking charaters with spaces |
|
52 | 52 | $string = preg_replace("/[\r\n]+/", " ", $string); // Replace multiple newlines with a single space. |
53 | 53 | $string = preg_replace("/[\t]+/", " ", $string); // Replace multiple tabs with a single space. |
54 | 54 | $string = preg_replace("/[^a-zA-Z0-9 ]/", '', $string); // Filter out everything that is not alphanumeric or a space |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | { |
67 | 67 | $encoding = mb_detect_encoding($string, mb_detect_order(), false); |
68 | 68 | |
69 | - if($encoding == "UTF-8") { |
|
69 | + if ($encoding == "UTF-8") { |
|
70 | 70 | $string = mb_convert_encoding($string, 'UTF-8', 'UTF-8'); |
71 | 71 | } |
72 | 72 |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | $this->storage->getDocuments()->cleanPublishedDeletedDocuments(); |
61 | 61 | $this->addLog('Retrieving documents to be indexed.'); |
62 | 62 | $documents = $this->storage->getDocuments()->getPublishedDocumentsNoFolders(); |
63 | - $this->addLog('Start Document Term Count for ' . count($documents) . ' documents'); |
|
63 | + $this->addLog('Start Document Term Count for '.count($documents).' documents'); |
|
64 | 64 | $this->createDocumentTermCount($documents); |
65 | 65 | $this->addLog('Start Document Term Frequency.'); |
66 | 66 | $this->createDocumentTermFrequency(); |
@@ -161,7 +161,7 @@ discard block |
||
161 | 161 | private function addLog($string) |
162 | 162 | { |
163 | 163 | $currentTime = round(microtime(true) * 1000); |
164 | - $this->log .= date('d-m-Y H:i:s - ') . str_pad($string, 50, " ", STR_PAD_RIGHT) . "\t" . ($currentTime - $this->lastLog) . 'ms since last log. ' . "\t" . ($currentTime - $this->loggingStart) . 'ms since start.' . PHP_EOL; |
|
164 | + $this->log .= date('d-m-Y H:i:s - ').str_pad($string, 50, " ", STR_PAD_RIGHT)."\t".($currentTime - $this->lastLog).'ms since last log. '."\t".($currentTime - $this->loggingStart).'ms since start.'.PHP_EOL; |
|
165 | 165 | $this->lastLog = round(microtime(true) * 1000); |
166 | 166 | } |
167 | 167 | |
@@ -173,8 +173,8 @@ discard block |
||
173 | 173 | protected function getSearchDbHandle() |
174 | 174 | { |
175 | 175 | if ($this->searchDbHandle === null) { |
176 | - $path = $this->storageDir . DIRECTORY_SEPARATOR; |
|
177 | - $this->searchDbHandle = new \PDO('sqlite:' . $path . self::SEARCH_TEMP_DB); |
|
176 | + $path = $this->storageDir.DIRECTORY_SEPARATOR; |
|
177 | + $this->searchDbHandle = new \PDO('sqlite:'.$path.self::SEARCH_TEMP_DB); |
|
178 | 178 | } |
179 | 179 | return $this->searchDbHandle; |
180 | 180 | } |
@@ -185,7 +185,7 @@ discard block |
||
185 | 185 | public function replaceOldIndex() |
186 | 186 | { |
187 | 187 | $this->searchDbHandle = null; |
188 | - $path = $this->storageDir . DIRECTORY_SEPARATOR; |
|
189 | - rename($path . self::SEARCH_TEMP_DB, $path . 'search.db'); |
|
188 | + $path = $this->storageDir.DIRECTORY_SEPARATOR; |
|
189 | + rename($path.self::SEARCH_TEMP_DB, $path.'search.db'); |
|
190 | 190 | } |
191 | 191 | } |
192 | 192 | \ No newline at end of file |
@@ -49,7 +49,7 @@ |
||
49 | 49 | $output = ''; |
50 | 50 | for ($i = 0; $i < $count; $i += 16) { |
51 | 51 | $random_state = |
52 | - md5(microtime() . $random_state); |
|
52 | + md5(microtime().$random_state); |
|
53 | 53 | $output .= |
54 | 54 | pack('H*', md5($random_state)); |
55 | 55 | } |
@@ -1,22 +1,22 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | namespace CloudControl\Cms\storage { |
3 | 3 | |
4 | - use CloudControl\Cms\storage\factories\DocumentFolderFactory; |
|
5 | - use CloudControl\Cms\storage\storage\ApplicationComponentsStorage; |
|
6 | - use CloudControl\Cms\storage\storage\BricksStorage; |
|
7 | - use CloudControl\Cms\storage\storage\DocumentStorage; |
|
8 | - use CloudControl\Cms\storage\storage\DocumentTypesStorage; |
|
9 | - use CloudControl\Cms\storage\storage\FilesStorage; |
|
10 | - use CloudControl\Cms\storage\storage\ImageSetStorage; |
|
11 | - use CloudControl\Cms\storage\storage\ImagesStorage; |
|
12 | - use CloudControl\Cms\storage\storage\RedirectsStorage; |
|
13 | - use CloudControl\Cms\storage\storage\SitemapStorage; |
|
14 | - use CloudControl\Cms\storage\storage\UsersStorage; |
|
15 | - use CloudControl\Cms\storage\storage\ValuelistsStorage; |
|
4 | + use CloudControl\Cms\storage\factories\DocumentFolderFactory; |
|
5 | + use CloudControl\Cms\storage\storage\ApplicationComponentsStorage; |
|
6 | + use CloudControl\Cms\storage\storage\BricksStorage; |
|
7 | + use CloudControl\Cms\storage\storage\DocumentStorage; |
|
8 | + use CloudControl\Cms\storage\storage\DocumentTypesStorage; |
|
9 | + use CloudControl\Cms\storage\storage\FilesStorage; |
|
10 | + use CloudControl\Cms\storage\storage\ImageSetStorage; |
|
11 | + use CloudControl\Cms\storage\storage\ImagesStorage; |
|
12 | + use CloudControl\Cms\storage\storage\RedirectsStorage; |
|
13 | + use CloudControl\Cms\storage\storage\SitemapStorage; |
|
14 | + use CloudControl\Cms\storage\storage\UsersStorage; |
|
15 | + use CloudControl\Cms\storage\storage\ValuelistsStorage; |
|
16 | 16 | |
17 | - /** |
|
17 | + /** |
|
18 | 18 | * Class JsonStorage |
19 | - * @package CloudControl\Cms\storage |
|
19 | + * @package CloudControl\Cms\storage |
|
20 | 20 | */ |
21 | 21 | class Storage |
22 | 22 | { |
@@ -61,20 +61,20 @@ discard block |
||
61 | 61 | * @var DocumentStorage |
62 | 62 | */ |
63 | 63 | protected $documents; |
64 | - /** |
|
65 | - * @var RedirectsStorage |
|
66 | - */ |
|
67 | - protected $redirects; |
|
68 | - /** |
|
69 | - * @var String |
|
70 | - */ |
|
71 | - protected $imagesDir; |
|
72 | - /** |
|
73 | - * @var String |
|
74 | - */ |
|
75 | - protected $filesDir; |
|
64 | + /** |
|
65 | + * @var RedirectsStorage |
|
66 | + */ |
|
67 | + protected $redirects; |
|
68 | + /** |
|
69 | + * @var String |
|
70 | + */ |
|
71 | + protected $imagesDir; |
|
72 | + /** |
|
73 | + * @var String |
|
74 | + */ |
|
75 | + protected $filesDir; |
|
76 | 76 | |
77 | - /** |
|
77 | + /** |
|
78 | 78 | * @var String |
79 | 79 | */ |
80 | 80 | private $storageDir; |
@@ -83,18 +83,18 @@ discard block |
||
83 | 83 | */ |
84 | 84 | private $repository; |
85 | 85 | |
86 | - /** |
|
87 | - * JsonStorage constructor. |
|
88 | - * |
|
89 | - * @param string $storageDir |
|
90 | - * @param $imagesDir |
|
91 | - * @param $filesDir |
|
92 | - */ |
|
93 | - public function __construct($storageDir, $imagesDir, $filesDir) |
|
86 | + /** |
|
87 | + * JsonStorage constructor. |
|
88 | + * |
|
89 | + * @param string $storageDir |
|
90 | + * @param $imagesDir |
|
91 | + * @param $filesDir |
|
92 | + */ |
|
93 | + public function __construct($storageDir, $imagesDir, $filesDir) |
|
94 | 94 | { |
95 | 95 | $this->storageDir = $storageDir; |
96 | - $this->imagesDir = $imagesDir; |
|
97 | - $this->filesDir = $filesDir; |
|
96 | + $this->imagesDir = $imagesDir; |
|
97 | + $this->filesDir = $filesDir; |
|
98 | 98 | $this->config(); |
99 | 99 | } |
100 | 100 | |
@@ -238,7 +238,7 @@ discard block |
||
238 | 238 | { |
239 | 239 | if (!$this->images instanceof ImagesStorage) { |
240 | 240 | |
241 | - $this->images = new ImagesStorage($this->repository, $this->imagesDir); |
|
241 | + $this->images = new ImagesStorage($this->repository, $this->imagesDir); |
|
242 | 242 | } |
243 | 243 | return $this->images; |
244 | 244 | } |
@@ -337,16 +337,16 @@ discard block |
||
337 | 337 | return $this->valuelists; |
338 | 338 | } |
339 | 339 | |
340 | - /** |
|
341 | - * @return \CloudControl\Cms\storage\storage\RedirectsStorage |
|
342 | - */ |
|
343 | - public function getRedirects() |
|
344 | - { |
|
345 | - if (!$this->redirects instanceof RedirectsStorage) { |
|
346 | - $this->redirects = new RedirectsStorage($this->repository); |
|
347 | - } |
|
348 | - return $this->redirects; |
|
349 | - } |
|
340 | + /** |
|
341 | + * @return \CloudControl\Cms\storage\storage\RedirectsStorage |
|
342 | + */ |
|
343 | + public function getRedirects() |
|
344 | + { |
|
345 | + if (!$this->redirects instanceof RedirectsStorage) { |
|
346 | + $this->redirects = new RedirectsStorage($this->repository); |
|
347 | + } |
|
348 | + return $this->redirects; |
|
349 | + } |
|
350 | 350 | |
351 | 351 | } |
352 | 352 | } |
353 | 353 | \ No newline at end of file |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | $repository->init(); |
114 | 114 | $this->repository = $repository; |
115 | 115 | } else { |
116 | - throw new \Exception('Could not create repository directory: ' . $storagePath); |
|
116 | + throw new \Exception('Could not create repository directory: '.$storagePath); |
|
117 | 117 | } |
118 | 118 | } else { |
119 | 119 | $this->repository = new Repository($storagePath); |
@@ -156,9 +156,9 @@ discard block |
||
156 | 156 | { |
157 | 157 | $documentFolderObject = DocumentFolderFactory::createDocumentFolderFromPostValues($postValues); |
158 | 158 | if ($postValues['path'] === '/') { |
159 | - $documentFolderObject->path = $postValues['path'] . $documentFolderObject->slug; |
|
159 | + $documentFolderObject->path = $postValues['path'].$documentFolderObject->slug; |
|
160 | 160 | } else { |
161 | - $documentFolderObject->path = $postValues['path'] . '/' . $documentFolderObject->slug; |
|
161 | + $documentFolderObject->path = $postValues['path'].'/'.$documentFolderObject->slug; |
|
162 | 162 | } |
163 | 163 | $this->repository->saveDocument($documentFolderObject, 'published'); |
164 | 164 | $this->repository->saveDocument($documentFolderObject, 'unpublished'); |
@@ -173,7 +173,7 @@ discard block |
||
173 | 173 | */ |
174 | 174 | public function deleteDocumentFolderBySlug($slug) |
175 | 175 | { |
176 | - $path = '/' . $slug; |
|
176 | + $path = '/'.$slug; |
|
177 | 177 | $this->repository->deleteDocumentByPath($path, 'published'); |
178 | 178 | $this->repository->deleteDocumentByPath($path, 'unpublished'); |
179 | 179 | $this->repository->cleanPublishedDeletedDocuments(); |
@@ -181,13 +181,13 @@ discard block |
||
181 | 181 | |
182 | 182 | public function publishDocumentBySlug($slug) |
183 | 183 | { |
184 | - $path = '/' . $slug; |
|
184 | + $path = '/'.$slug; |
|
185 | 185 | $this->repository->publishDocumentByPath($path); |
186 | 186 | } |
187 | 187 | |
188 | 188 | public function unpublishDocumentBySlug($slug) |
189 | 189 | { |
190 | - $path = '/' . $slug; |
|
190 | + $path = '/'.$slug; |
|
191 | 191 | $this->repository->unpublishDocumentByPath($path); |
192 | 192 | } |
193 | 193 | |
@@ -201,7 +201,7 @@ discard block |
||
201 | 201 | */ |
202 | 202 | public function getDocumentFolderBySlug($slug) |
203 | 203 | { |
204 | - $path = '/' . $slug; |
|
204 | + $path = '/'.$slug; |
|
205 | 205 | |
206 | 206 | return $this->repository->getDocumentByPath($path); |
207 | 207 | } |
@@ -20,60 +20,60 @@ discard block |
||
20 | 20 | */ |
21 | 21 | class Document |
22 | 22 | { |
23 | - public $id; |
|
24 | - public $path; |
|
25 | - public $title; |
|
26 | - public $slug; |
|
27 | - public $type; |
|
28 | - public $documentType; |
|
29 | - public $documentTypeSlug; |
|
30 | - public $state; |
|
31 | - public $lastModificationDate; |
|
32 | - public $creationDate; |
|
33 | - public $lastModifiedBy; |
|
34 | - protected $fields; |
|
35 | - protected $bricks; |
|
36 | - protected $dynamicBricks; |
|
37 | - protected $content; |
|
23 | + public $id; |
|
24 | + public $path; |
|
25 | + public $title; |
|
26 | + public $slug; |
|
27 | + public $type; |
|
28 | + public $documentType; |
|
29 | + public $documentTypeSlug; |
|
30 | + public $state; |
|
31 | + public $lastModificationDate; |
|
32 | + public $creationDate; |
|
33 | + public $lastModifiedBy; |
|
34 | + protected $fields; |
|
35 | + protected $bricks; |
|
36 | + protected $dynamicBricks; |
|
37 | + protected $content; |
|
38 | 38 | |
39 | - protected $dbHandle; |
|
39 | + protected $dbHandle; |
|
40 | 40 | |
41 | - protected $jsonEncodedFields = array('fields', 'bricks', 'dynamicBricks'); |
|
42 | - protected $orderableFields = array('title', 'slug', 'type', 'documentType', 'documentTypeSlug', 'state', 'lastModificationDate', 'creationDate', 'lastModifiedBy'); |
|
41 | + protected $jsonEncodedFields = array('fields', 'bricks', 'dynamicBricks'); |
|
42 | + protected $orderableFields = array('title', 'slug', 'type', 'documentType', 'documentTypeSlug', 'state', 'lastModificationDate', 'creationDate', 'lastModifiedBy'); |
|
43 | 43 | |
44 | - public static $DOCUMENT_STATES = array('published', 'unpublished'); |
|
44 | + public static $DOCUMENT_STATES = array('published', 'unpublished'); |
|
45 | 45 | |
46 | - public function __get($name) { |
|
47 | - if (in_array($name, $this->jsonEncodedFields)) { |
|
48 | - if (is_string($this->$name)) { |
|
49 | - return json_decode($this->$name); |
|
50 | - } else { |
|
51 | - return $this->$name; |
|
52 | - } |
|
53 | - } elseif ($name === 'content') { |
|
54 | - if ($this->dbHandle === null) { |
|
55 | - throw new \Exception('Document doesnt have a dbHandle handle. (path: ' . $this->path . ')'); |
|
56 | - } else { |
|
57 | - if ($this->content === null) { |
|
58 | - return $this->getContent(); |
|
59 | - } |
|
60 | - } |
|
61 | - } elseif ($name === 'dbHandle') { |
|
62 | - throw new \Exception('Trying to get protected property repository.'); |
|
63 | - } |
|
64 | - return $this->$name; |
|
65 | - } |
|
46 | + public function __get($name) { |
|
47 | + if (in_array($name, $this->jsonEncodedFields)) { |
|
48 | + if (is_string($this->$name)) { |
|
49 | + return json_decode($this->$name); |
|
50 | + } else { |
|
51 | + return $this->$name; |
|
52 | + } |
|
53 | + } elseif ($name === 'content') { |
|
54 | + if ($this->dbHandle === null) { |
|
55 | + throw new \Exception('Document doesnt have a dbHandle handle. (path: ' . $this->path . ')'); |
|
56 | + } else { |
|
57 | + if ($this->content === null) { |
|
58 | + return $this->getContent(); |
|
59 | + } |
|
60 | + } |
|
61 | + } elseif ($name === 'dbHandle') { |
|
62 | + throw new \Exception('Trying to get protected property repository.'); |
|
63 | + } |
|
64 | + return $this->$name; |
|
65 | + } |
|
66 | 66 | |
67 | - public function __set($name, $value) { |
|
68 | - if (in_array($name, $this->jsonEncodedFields)) { |
|
69 | - $this->$name = json_encode($value); |
|
70 | - } elseif ($name === 'content') { |
|
71 | - // Dont do anything for now.. |
|
72 | - return; |
|
73 | - } |
|
67 | + public function __set($name, $value) { |
|
68 | + if (in_array($name, $this->jsonEncodedFields)) { |
|
69 | + $this->$name = json_encode($value); |
|
70 | + } elseif ($name === 'content') { |
|
71 | + // Dont do anything for now.. |
|
72 | + return; |
|
73 | + } |
|
74 | 74 | |
75 | - $this->$name = $value; |
|
76 | - } |
|
75 | + $this->$name = $value; |
|
76 | + } |
|
77 | 77 | |
78 | 78 | /** |
79 | 79 | * @param string $orderBy |
@@ -82,15 +82,15 @@ discard block |
||
82 | 82 | * @return array |
83 | 83 | * @throws \Exception |
84 | 84 | */ |
85 | - public function getContent($orderBy = 'title', $order = 'ASC') |
|
86 | - { |
|
87 | - if (empty($this->content)) { |
|
88 | - $docs = $this->documentStorage->getDocumentsWithState($this->path); |
|
89 | - $this->content = $docs; |
|
90 | - } |
|
85 | + public function getContent($orderBy = 'title', $order = 'ASC') |
|
86 | + { |
|
87 | + if (empty($this->content)) { |
|
88 | + $docs = $this->documentStorage->getDocumentsWithState($this->path); |
|
89 | + $this->content = $docs; |
|
90 | + } |
|
91 | 91 | |
92 | - return $this->content; |
|
93 | - } |
|
92 | + return $this->content; |
|
93 | + } |
|
94 | 94 | |
95 | 95 | /** |
96 | 96 | * @return string |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | } |
53 | 53 | } elseif ($name === 'content') { |
54 | 54 | if ($this->dbHandle === null) { |
55 | - throw new \Exception('Document doesnt have a dbHandle handle. (path: ' . $this->path . ')'); |
|
55 | + throw new \Exception('Document doesnt have a dbHandle handle. (path: '.$this->path.')'); |
|
56 | 56 | } else { |
57 | 57 | if ($this->content === null) { |
58 | 58 | return $this->getContent(); |
@@ -97,7 +97,7 @@ discard block |
||
97 | 97 | */ |
98 | 98 | public function __toString() |
99 | 99 | { |
100 | - return 'Document:' . $this->title; |
|
100 | + return 'Document:'.$this->title; |
|
101 | 101 | } |
102 | 102 | |
103 | 103 |
@@ -24,221 +24,221 @@ discard block |
||
24 | 24 | */ |
25 | 25 | class Repository |
26 | 26 | { |
27 | - protected $storagePath; |
|
28 | - |
|
29 | - protected $fileBasedSubsets = array('sitemap', 'applicationComponents', 'documentTypes', 'bricks', 'imageSet', 'images', 'files', 'users', 'valuelists', 'redirects'); |
|
30 | - |
|
31 | - protected $sitemap; |
|
32 | - protected $sitemapChanges = false; |
|
33 | - |
|
34 | - protected $applicationComponents; |
|
35 | - protected $applicationComponentsChanges = false; |
|
36 | - |
|
37 | - protected $documentTypes; |
|
38 | - protected $documentTypesChanges = false; |
|
39 | - |
|
40 | - protected $bricks; |
|
41 | - protected $bricksChanges = false; |
|
42 | - |
|
43 | - protected $imageSet; |
|
44 | - protected $imageSetChanges = false; |
|
45 | - |
|
46 | - protected $images; |
|
47 | - protected $imagesChanges = false; |
|
48 | - |
|
49 | - protected $files; |
|
50 | - protected $filesChanges = false; |
|
51 | - |
|
52 | - protected $users; |
|
53 | - protected $usersChanges = false; |
|
54 | - |
|
55 | - protected $valuelists; |
|
56 | - protected $valuelistsChanges = false; |
|
57 | - |
|
58 | - protected $redirects; |
|
59 | - protected $redirectsChanges = false; |
|
60 | - |
|
61 | - protected $contentDbHandle; |
|
62 | - |
|
63 | - |
|
64 | - /** |
|
65 | - * Repository constructor. |
|
66 | - * @param $storagePath |
|
67 | - * @throws \Exception |
|
68 | - */ |
|
69 | - public function __construct($storagePath) |
|
70 | - { |
|
71 | - $storagePath = realpath($storagePath); |
|
72 | - if (is_dir($storagePath) && $storagePath !== false) { |
|
73 | - $this->storagePath = $storagePath; |
|
74 | - } else { |
|
75 | - throw new \Exception('Repository not yet initialized.'); |
|
76 | - } |
|
77 | - } |
|
78 | - |
|
79 | - /** |
|
80 | - * Creates the folder in which to create all storage related files |
|
81 | - * |
|
82 | - * @param $storagePath |
|
83 | - * @return bool |
|
84 | - */ |
|
85 | - public static function create($storagePath) |
|
86 | - { |
|
87 | - return mkdir($storagePath); |
|
88 | - } |
|
89 | - |
|
90 | - /** |
|
91 | - * Initiates default storage |
|
92 | - * @param $baseStorageDefaultPath |
|
93 | - * @param $baseStorageSqlPath |
|
94 | - */ |
|
95 | - public function init($baseStorageDefaultPath, $baseStorageSqlPath) |
|
96 | - { |
|
97 | - // TODO Make sure storage isnt overwritten when its already initialized |
|
98 | - $storageDefaultPath = realpath($baseStorageDefaultPath); |
|
99 | - $contentSqlPath = realpath($baseStorageSqlPath); |
|
100 | - |
|
101 | - $this->initConfigStorage($storageDefaultPath); |
|
102 | - $this->initContentDb($contentSqlPath); |
|
103 | - |
|
104 | - $this->save(); |
|
105 | - } |
|
106 | - |
|
107 | - /** |
|
108 | - * Load filebased subset and return it's contents |
|
109 | - * |
|
110 | - * @param $name |
|
111 | - * @return mixed|string |
|
112 | - * @throws \Exception |
|
113 | - */ |
|
114 | - public function __get($name) |
|
115 | - { |
|
116 | - if (isset($this->$name)) { |
|
117 | - if (in_array($name, $this->fileBasedSubsets)) { |
|
118 | - return $this->$name; |
|
119 | - } else { |
|
120 | - throw new \Exception('Trying to get undefined property from Repository: ' . $name); |
|
121 | - } |
|
122 | - } else { |
|
123 | - if (in_array($name, $this->fileBasedSubsets)) { |
|
124 | - return $this->loadSubset($name); |
|
125 | - } else { |
|
126 | - throw new \Exception('Trying to get undefined property from Repository: ' . $name); |
|
127 | - } |
|
128 | - } |
|
129 | - } |
|
130 | - |
|
131 | - /** |
|
132 | - * Set filebased subset contents |
|
133 | - * @param $name |
|
134 | - * @param $value |
|
135 | - * @throws \Exception |
|
136 | - */ |
|
137 | - public function __set($name, $value) |
|
138 | - { |
|
139 | - if (in_array($name, $this->fileBasedSubsets)) { |
|
140 | - $this->$name = $value; |
|
141 | - $changes = $name . 'Changes'; |
|
142 | - $this->$changes = true; |
|
143 | - } else { |
|
144 | - throw new \Exception('Trying to persist unknown subset in repository: ' . $name . ' <br /><pre>' . print_r($value, true) . '</pre>'); |
|
145 | - } |
|
146 | - } |
|
147 | - |
|
148 | - /** |
|
149 | - * Persist all subsets |
|
150 | - */ |
|
151 | - public function save() |
|
152 | - { |
|
153 | - $host = $this; |
|
154 | - array_map(function ($value) use ($host) { |
|
155 | - $host->saveSubset($value); |
|
27 | + protected $storagePath; |
|
28 | + |
|
29 | + protected $fileBasedSubsets = array('sitemap', 'applicationComponents', 'documentTypes', 'bricks', 'imageSet', 'images', 'files', 'users', 'valuelists', 'redirects'); |
|
30 | + |
|
31 | + protected $sitemap; |
|
32 | + protected $sitemapChanges = false; |
|
33 | + |
|
34 | + protected $applicationComponents; |
|
35 | + protected $applicationComponentsChanges = false; |
|
36 | + |
|
37 | + protected $documentTypes; |
|
38 | + protected $documentTypesChanges = false; |
|
39 | + |
|
40 | + protected $bricks; |
|
41 | + protected $bricksChanges = false; |
|
42 | + |
|
43 | + protected $imageSet; |
|
44 | + protected $imageSetChanges = false; |
|
45 | + |
|
46 | + protected $images; |
|
47 | + protected $imagesChanges = false; |
|
48 | + |
|
49 | + protected $files; |
|
50 | + protected $filesChanges = false; |
|
51 | + |
|
52 | + protected $users; |
|
53 | + protected $usersChanges = false; |
|
54 | + |
|
55 | + protected $valuelists; |
|
56 | + protected $valuelistsChanges = false; |
|
57 | + |
|
58 | + protected $redirects; |
|
59 | + protected $redirectsChanges = false; |
|
60 | + |
|
61 | + protected $contentDbHandle; |
|
62 | + |
|
63 | + |
|
64 | + /** |
|
65 | + * Repository constructor. |
|
66 | + * @param $storagePath |
|
67 | + * @throws \Exception |
|
68 | + */ |
|
69 | + public function __construct($storagePath) |
|
70 | + { |
|
71 | + $storagePath = realpath($storagePath); |
|
72 | + if (is_dir($storagePath) && $storagePath !== false) { |
|
73 | + $this->storagePath = $storagePath; |
|
74 | + } else { |
|
75 | + throw new \Exception('Repository not yet initialized.'); |
|
76 | + } |
|
77 | + } |
|
78 | + |
|
79 | + /** |
|
80 | + * Creates the folder in which to create all storage related files |
|
81 | + * |
|
82 | + * @param $storagePath |
|
83 | + * @return bool |
|
84 | + */ |
|
85 | + public static function create($storagePath) |
|
86 | + { |
|
87 | + return mkdir($storagePath); |
|
88 | + } |
|
89 | + |
|
90 | + /** |
|
91 | + * Initiates default storage |
|
92 | + * @param $baseStorageDefaultPath |
|
93 | + * @param $baseStorageSqlPath |
|
94 | + */ |
|
95 | + public function init($baseStorageDefaultPath, $baseStorageSqlPath) |
|
96 | + { |
|
97 | + // TODO Make sure storage isnt overwritten when its already initialized |
|
98 | + $storageDefaultPath = realpath($baseStorageDefaultPath); |
|
99 | + $contentSqlPath = realpath($baseStorageSqlPath); |
|
100 | + |
|
101 | + $this->initConfigStorage($storageDefaultPath); |
|
102 | + $this->initContentDb($contentSqlPath); |
|
103 | + |
|
104 | + $this->save(); |
|
105 | + } |
|
106 | + |
|
107 | + /** |
|
108 | + * Load filebased subset and return it's contents |
|
109 | + * |
|
110 | + * @param $name |
|
111 | + * @return mixed|string |
|
112 | + * @throws \Exception |
|
113 | + */ |
|
114 | + public function __get($name) |
|
115 | + { |
|
116 | + if (isset($this->$name)) { |
|
117 | + if (in_array($name, $this->fileBasedSubsets)) { |
|
118 | + return $this->$name; |
|
119 | + } else { |
|
120 | + throw new \Exception('Trying to get undefined property from Repository: ' . $name); |
|
121 | + } |
|
122 | + } else { |
|
123 | + if (in_array($name, $this->fileBasedSubsets)) { |
|
124 | + return $this->loadSubset($name); |
|
125 | + } else { |
|
126 | + throw new \Exception('Trying to get undefined property from Repository: ' . $name); |
|
127 | + } |
|
128 | + } |
|
129 | + } |
|
130 | + |
|
131 | + /** |
|
132 | + * Set filebased subset contents |
|
133 | + * @param $name |
|
134 | + * @param $value |
|
135 | + * @throws \Exception |
|
136 | + */ |
|
137 | + public function __set($name, $value) |
|
138 | + { |
|
139 | + if (in_array($name, $this->fileBasedSubsets)) { |
|
140 | + $this->$name = $value; |
|
141 | + $changes = $name . 'Changes'; |
|
142 | + $this->$changes = true; |
|
143 | + } else { |
|
144 | + throw new \Exception('Trying to persist unknown subset in repository: ' . $name . ' <br /><pre>' . print_r($value, true) . '</pre>'); |
|
145 | + } |
|
146 | + } |
|
147 | + |
|
148 | + /** |
|
149 | + * Persist all subsets |
|
150 | + */ |
|
151 | + public function save() |
|
152 | + { |
|
153 | + $host = $this; |
|
154 | + array_map(function ($value) use ($host) { |
|
155 | + $host->saveSubset($value); |
|
156 | 156 | }, $this->fileBasedSubsets); |
157 | - } |
|
158 | - |
|
159 | - /** |
|
160 | - * Persist subset to disk |
|
161 | - * @param $subset |
|
162 | - */ |
|
163 | - public function saveSubset($subset) |
|
164 | - { |
|
157 | + } |
|
158 | + |
|
159 | + /** |
|
160 | + * Persist subset to disk |
|
161 | + * @param $subset |
|
162 | + */ |
|
163 | + public function saveSubset($subset) |
|
164 | + { |
|
165 | 165 | $changes = $subset . 'Changes'; |
166 | 166 | if ($this->$changes === true) { |
167 | - if (!defined('JSON_PRETTY_PRINT')) { |
|
168 | - $json = json_encode($this->$subset); |
|
169 | - } else { |
|
170 | - $json = json_encode($this->$subset, JSON_PRETTY_PRINT); |
|
171 | - } |
|
167 | + if (!defined('JSON_PRETTY_PRINT')) { |
|
168 | + $json = json_encode($this->$subset); |
|
169 | + } else { |
|
170 | + $json = json_encode($this->$subset, JSON_PRETTY_PRINT); |
|
171 | + } |
|
172 | 172 | $subsetStoragePath = $this->storagePath . DIRECTORY_SEPARATOR . $subset . '.json'; |
173 | 173 | file_put_contents($subsetStoragePath, $json); |
174 | 174 | |
175 | 175 | $this->$changes = false; |
176 | 176 | } |
177 | - } |
|
178 | - |
|
179 | - /** |
|
180 | - * Load subset from disk |
|
181 | - * @param $subset |
|
182 | - * @return mixed|string |
|
183 | - */ |
|
184 | - protected function loadSubset($subset) |
|
185 | - { |
|
186 | - $subsetStoragePath = $this->storagePath . DIRECTORY_SEPARATOR . $subset . '.json'; |
|
187 | - $json = file_get_contents($subsetStoragePath); |
|
188 | - $json = json_decode($json); |
|
189 | - $this->$subset = $json; |
|
190 | - return $json; |
|
191 | - } |
|
192 | - |
|
193 | - /** |
|
194 | - * @param $contentSqlPath |
|
195 | - */ |
|
196 | - protected function initContentDb($contentSqlPath) |
|
197 | - { |
|
198 | - $db = $this->getContentDbHandle(); |
|
199 | - $sql = file_get_contents($contentSqlPath); |
|
200 | - $db->exec($sql); |
|
201 | - } |
|
202 | - |
|
203 | - /** |
|
204 | - * @param $storageDefaultPath |
|
205 | - */ |
|
206 | - protected function initConfigStorage($storageDefaultPath) |
|
207 | - { |
|
208 | - $json = file_get_contents($storageDefaultPath); |
|
209 | - $json = json_decode($json); |
|
210 | - $this->sitemap = $json->sitemap; |
|
211 | - $this->sitemapChanges = true; |
|
212 | - $this->applicationComponents = $json->applicationComponents; |
|
213 | - $this->applicationComponentsChanges = true; |
|
214 | - $this->documentTypes = $json->documentTypes; |
|
215 | - $this->documentTypesChanges = true; |
|
216 | - $this->bricks = $json->bricks; |
|
217 | - $this->bricksChanges = true; |
|
218 | - $this->imageSet = $json->imageSet; |
|
219 | - $this->imageSetChanges = true; |
|
220 | - $this->images = $json->images; |
|
221 | - $this->imagesChanges = true; |
|
222 | - $this->files = $json->files; |
|
223 | - $this->filesChanges = true; |
|
224 | - $this->users = $json->users; |
|
225 | - $this->usersChanges = true; |
|
226 | - $this->valuelists = $json->valuelists; |
|
227 | - $this->valuelistsChanges = true; |
|
228 | - $this->redirects = $json->redirects; |
|
229 | - $this->redirectsChanges = true; |
|
230 | - } |
|
231 | - |
|
232 | - /** |
|
233 | - * @return \PDO |
|
234 | - */ |
|
235 | - public function getContentDbHandle() |
|
236 | - { |
|
237 | - if ($this->contentDbHandle === null) { |
|
238 | - $this->contentDbHandle = new \PDO('sqlite:' . $this->storagePath . DIRECTORY_SEPARATOR . 'content.db'); |
|
239 | - } |
|
240 | - return $this->contentDbHandle; |
|
241 | - } |
|
177 | + } |
|
178 | + |
|
179 | + /** |
|
180 | + * Load subset from disk |
|
181 | + * @param $subset |
|
182 | + * @return mixed|string |
|
183 | + */ |
|
184 | + protected function loadSubset($subset) |
|
185 | + { |
|
186 | + $subsetStoragePath = $this->storagePath . DIRECTORY_SEPARATOR . $subset . '.json'; |
|
187 | + $json = file_get_contents($subsetStoragePath); |
|
188 | + $json = json_decode($json); |
|
189 | + $this->$subset = $json; |
|
190 | + return $json; |
|
191 | + } |
|
192 | + |
|
193 | + /** |
|
194 | + * @param $contentSqlPath |
|
195 | + */ |
|
196 | + protected function initContentDb($contentSqlPath) |
|
197 | + { |
|
198 | + $db = $this->getContentDbHandle(); |
|
199 | + $sql = file_get_contents($contentSqlPath); |
|
200 | + $db->exec($sql); |
|
201 | + } |
|
202 | + |
|
203 | + /** |
|
204 | + * @param $storageDefaultPath |
|
205 | + */ |
|
206 | + protected function initConfigStorage($storageDefaultPath) |
|
207 | + { |
|
208 | + $json = file_get_contents($storageDefaultPath); |
|
209 | + $json = json_decode($json); |
|
210 | + $this->sitemap = $json->sitemap; |
|
211 | + $this->sitemapChanges = true; |
|
212 | + $this->applicationComponents = $json->applicationComponents; |
|
213 | + $this->applicationComponentsChanges = true; |
|
214 | + $this->documentTypes = $json->documentTypes; |
|
215 | + $this->documentTypesChanges = true; |
|
216 | + $this->bricks = $json->bricks; |
|
217 | + $this->bricksChanges = true; |
|
218 | + $this->imageSet = $json->imageSet; |
|
219 | + $this->imageSetChanges = true; |
|
220 | + $this->images = $json->images; |
|
221 | + $this->imagesChanges = true; |
|
222 | + $this->files = $json->files; |
|
223 | + $this->filesChanges = true; |
|
224 | + $this->users = $json->users; |
|
225 | + $this->usersChanges = true; |
|
226 | + $this->valuelists = $json->valuelists; |
|
227 | + $this->valuelistsChanges = true; |
|
228 | + $this->redirects = $json->redirects; |
|
229 | + $this->redirectsChanges = true; |
|
230 | + } |
|
231 | + |
|
232 | + /** |
|
233 | + * @return \PDO |
|
234 | + */ |
|
235 | + public function getContentDbHandle() |
|
236 | + { |
|
237 | + if ($this->contentDbHandle === null) { |
|
238 | + $this->contentDbHandle = new \PDO('sqlite:' . $this->storagePath . DIRECTORY_SEPARATOR . 'content.db'); |
|
239 | + } |
|
240 | + return $this->contentDbHandle; |
|
241 | + } |
|
242 | 242 | |
243 | 243 | /** |
244 | 244 | * Get all documents |
@@ -248,13 +248,13 @@ discard block |
||
248 | 248 | * @return array |
249 | 249 | * @throws \Exception |
250 | 250 | */ |
251 | - public function getDocuments($state = 'published') |
|
252 | - { |
|
251 | + public function getDocuments($state = 'published') |
|
252 | + { |
|
253 | 253 | if (!in_array($state, Document::$DOCUMENT_STATES)) { |
254 | 254 | throw new \Exception('Unsupported document state: ' . $state); |
255 | 255 | } |
256 | - return $this->getDocumentsByPath('/', $state); |
|
257 | - } |
|
256 | + return $this->getDocumentsByPath('/', $state); |
|
257 | + } |
|
258 | 258 | |
259 | 259 | public function getDocumentsWithState($folderPath = '/') |
260 | 260 | { |
@@ -301,51 +301,51 @@ discard block |
||
301 | 301 | * @return array |
302 | 302 | * @throws \Exception |
303 | 303 | */ |
304 | - public function getDocumentsByPath($folderPath, $state = 'published') |
|
305 | - { |
|
306 | - if (!in_array($state, Document::$DOCUMENT_STATES)) { |
|
307 | - throw new \Exception('Unsupported document state: ' . $state); |
|
304 | + public function getDocumentsByPath($folderPath, $state = 'published') |
|
305 | + { |
|
306 | + if (!in_array($state, Document::$DOCUMENT_STATES)) { |
|
307 | + throw new \Exception('Unsupported document state: ' . $state); |
|
308 | 308 | } |
309 | - $db = $this->getContentDbHandle(); |
|
310 | - $folderPathWithWildcard = $folderPath . '%'; |
|
309 | + $db = $this->getContentDbHandle(); |
|
310 | + $folderPathWithWildcard = $folderPath . '%'; |
|
311 | 311 | |
312 | - $sql = 'SELECT * |
|
312 | + $sql = 'SELECT * |
|
313 | 313 | FROM documents_' . $state . ' |
314 | 314 | WHERE `path` LIKE ' . $db->quote($folderPathWithWildcard) . ' |
315 | 315 | AND substr(`path`, ' . (strlen($folderPath) + 1) . ') NOT LIKE "%/%" |
316 | 316 | AND path != ' . $db->quote($folderPath) . ' |
317 | 317 | ORDER BY `type` DESC, `path` ASC'; |
318 | - $stmt = $this->getDbStatement($sql); |
|
318 | + $stmt = $this->getDbStatement($sql); |
|
319 | 319 | |
320 | - $documents = $stmt->fetchAll(\PDO::FETCH_CLASS, '\CloudControl\Cms\storage\Document'); |
|
321 | - foreach ($documents as $key => $document) { |
|
320 | + $documents = $stmt->fetchAll(\PDO::FETCH_CLASS, '\CloudControl\Cms\storage\Document'); |
|
321 | + foreach ($documents as $key => $document) { |
|
322 | 322 | $documents = $this->setAssetsToDocumentFolders($document, $db, $documents, $key); |
323 | - } |
|
324 | - return $documents; |
|
325 | - } |
|
326 | - |
|
327 | - |
|
328 | - /** |
|
329 | - * @param $path |
|
330 | - * @return bool|Document |
|
331 | - */ |
|
332 | - public function getDocumentContainerByPath($path) |
|
333 | - { |
|
334 | - $document = $this->getDocumentByPath($path, 'unpublished'); |
|
335 | - if ($document === false) { |
|
336 | - return false; |
|
337 | - } |
|
338 | - $slugLength = strlen($document->slug); |
|
339 | - $containerPath = substr($path, 0, -$slugLength); |
|
340 | - if ($containerPath === '/') { |
|
341 | - return $this->getRootFolder(); |
|
342 | - } |
|
343 | - if (substr($containerPath, -1) === '/'){ |
|
323 | + } |
|
324 | + return $documents; |
|
325 | + } |
|
326 | + |
|
327 | + |
|
328 | + /** |
|
329 | + * @param $path |
|
330 | + * @return bool|Document |
|
331 | + */ |
|
332 | + public function getDocumentContainerByPath($path) |
|
333 | + { |
|
334 | + $document = $this->getDocumentByPath($path, 'unpublished'); |
|
335 | + if ($document === false) { |
|
336 | + return false; |
|
337 | + } |
|
338 | + $slugLength = strlen($document->slug); |
|
339 | + $containerPath = substr($path, 0, -$slugLength); |
|
340 | + if ($containerPath === '/') { |
|
341 | + return $this->getRootFolder(); |
|
342 | + } |
|
343 | + if (substr($containerPath, -1) === '/'){ |
|
344 | 344 | $containerPath = substr($containerPath, 0, -1); |
345 | 345 | } |
346 | - $containerFolder = $this->getDocumentByPath($containerPath, 'unpublished'); |
|
347 | - return $containerFolder; |
|
348 | - } |
|
346 | + $containerFolder = $this->getDocumentByPath($containerPath, 'unpublished'); |
|
347 | + return $containerFolder; |
|
348 | + } |
|
349 | 349 | |
350 | 350 | /** |
351 | 351 | * @param $path |
@@ -354,23 +354,23 @@ discard block |
||
354 | 354 | * @return bool|\CloudControl\Cms\storage\Document |
355 | 355 | * @throws \Exception |
356 | 356 | */ |
357 | - public function getDocumentByPath($path, $state = 'published') |
|
358 | - { |
|
357 | + public function getDocumentByPath($path, $state = 'published') |
|
358 | + { |
|
359 | 359 | if (!in_array($state, Document::$DOCUMENT_STATES)) { |
360 | 360 | throw new \Exception('Unsupported document state: ' . $state); |
361 | 361 | } |
362 | - $db = $this->getContentDbHandle(); |
|
363 | - $document = $this->fetchDocument(' |
|
362 | + $db = $this->getContentDbHandle(); |
|
363 | + $document = $this->fetchDocument(' |
|
364 | 364 | SELECT * |
365 | 365 | FROM documents_' . $state . ' |
366 | 366 | WHERE path = ' . $db->quote($path) . ' |
367 | 367 | '); |
368 | - if ($document instanceof Document && $document->type === 'folder') { |
|
369 | - $document->dbHandle = $db; |
|
370 | - $document->documentStorage = new DocumentStorage($this); |
|
371 | - } |
|
372 | - return $document; |
|
373 | - } |
|
368 | + if ($document instanceof Document && $document->type === 'folder') { |
|
369 | + $document->dbHandle = $db; |
|
370 | + $document->documentStorage = new DocumentStorage($this); |
|
371 | + } |
|
372 | + return $document; |
|
373 | + } |
|
374 | 374 | |
375 | 375 | /** |
376 | 376 | * Returns the count of all documents stored in the db |
@@ -465,58 +465,58 @@ discard block |
||
465 | 465 | } |
466 | 466 | |
467 | 467 | /** |
468 | - * Return the results of the query as array of Documents |
|
469 | - * @param $sql |
|
470 | - * @return array |
|
471 | - * @throws \Exception |
|
472 | - */ |
|
473 | - protected function fetchAllDocuments($sql) |
|
474 | - { |
|
475 | - $stmt = $this->getDbStatement($sql); |
|
476 | - return $stmt->fetchAll(\PDO::FETCH_CLASS, '\CloudControl\Cms\storage\Document'); |
|
477 | - } |
|
478 | - |
|
479 | - /** |
|
480 | - * Return the result of the query as Document |
|
481 | - * @param $sql |
|
482 | - * @return mixed |
|
483 | - * @throws \Exception |
|
484 | - */ |
|
485 | - protected function fetchDocument($sql) |
|
486 | - { |
|
487 | - $stmt = $this->getDbStatement($sql); |
|
488 | - return $stmt->fetchObject('\CloudControl\Cms\storage\Document'); |
|
489 | - } |
|
490 | - |
|
491 | - /** |
|
492 | - * Prepare the sql statement |
|
493 | - * @param $sql |
|
494 | - * @return \PDOStatement |
|
495 | - * @throws \Exception |
|
496 | - */ |
|
497 | - protected function getDbStatement($sql) |
|
498 | - { |
|
499 | - $db = $this->getContentDbHandle(); |
|
500 | - $stmt = $db->query($sql); |
|
501 | - if ($stmt === false) { |
|
502 | - $errorInfo = $db->errorInfo(); |
|
503 | - $errorMsg = $errorInfo[2]; |
|
504 | - throw new \Exception('SQLite Exception: ' . $errorMsg . ' in SQL: <br /><pre>' . $sql . '</pre>'); |
|
505 | - } |
|
506 | - return $stmt; |
|
507 | - } |
|
508 | - |
|
509 | - /** |
|
510 | - * Create a (non-existent) root folder Document and return it |
|
511 | - * @return Document |
|
512 | - */ |
|
513 | - protected function getRootFolder() |
|
514 | - { |
|
515 | - $rootFolder = new Document(); |
|
516 | - $rootFolder->path = '/'; |
|
517 | - $rootFolder->type = 'folder'; |
|
518 | - return $rootFolder; |
|
519 | - } |
|
468 | + * Return the results of the query as array of Documents |
|
469 | + * @param $sql |
|
470 | + * @return array |
|
471 | + * @throws \Exception |
|
472 | + */ |
|
473 | + protected function fetchAllDocuments($sql) |
|
474 | + { |
|
475 | + $stmt = $this->getDbStatement($sql); |
|
476 | + return $stmt->fetchAll(\PDO::FETCH_CLASS, '\CloudControl\Cms\storage\Document'); |
|
477 | + } |
|
478 | + |
|
479 | + /** |
|
480 | + * Return the result of the query as Document |
|
481 | + * @param $sql |
|
482 | + * @return mixed |
|
483 | + * @throws \Exception |
|
484 | + */ |
|
485 | + protected function fetchDocument($sql) |
|
486 | + { |
|
487 | + $stmt = $this->getDbStatement($sql); |
|
488 | + return $stmt->fetchObject('\CloudControl\Cms\storage\Document'); |
|
489 | + } |
|
490 | + |
|
491 | + /** |
|
492 | + * Prepare the sql statement |
|
493 | + * @param $sql |
|
494 | + * @return \PDOStatement |
|
495 | + * @throws \Exception |
|
496 | + */ |
|
497 | + protected function getDbStatement($sql) |
|
498 | + { |
|
499 | + $db = $this->getContentDbHandle(); |
|
500 | + $stmt = $db->query($sql); |
|
501 | + if ($stmt === false) { |
|
502 | + $errorInfo = $db->errorInfo(); |
|
503 | + $errorMsg = $errorInfo[2]; |
|
504 | + throw new \Exception('SQLite Exception: ' . $errorMsg . ' in SQL: <br /><pre>' . $sql . '</pre>'); |
|
505 | + } |
|
506 | + return $stmt; |
|
507 | + } |
|
508 | + |
|
509 | + /** |
|
510 | + * Create a (non-existent) root folder Document and return it |
|
511 | + * @return Document |
|
512 | + */ |
|
513 | + protected function getRootFolder() |
|
514 | + { |
|
515 | + $rootFolder = new Document(); |
|
516 | + $rootFolder->path = '/'; |
|
517 | + $rootFolder->type = 'folder'; |
|
518 | + return $rootFolder; |
|
519 | + } |
|
520 | 520 | |
521 | 521 | /** |
522 | 522 | * Save the document to the database |
@@ -528,13 +528,13 @@ discard block |
||
528 | 528 | * @throws \Exception |
529 | 529 | * @internal param $path |
530 | 530 | */ |
531 | - public function saveDocument($documentObject, $state = 'published') |
|
532 | - { |
|
531 | + public function saveDocument($documentObject, $state = 'published') |
|
532 | + { |
|
533 | 533 | if (!in_array($state, Document::$DOCUMENT_STATES)) { |
534 | 534 | throw new \Exception('Unsupported document state: ' . $state); |
535 | 535 | } |
536 | - $db = $this->getContentDbHandle(); |
|
537 | - $stmt = $this->getDbStatement(' |
|
536 | + $db = $this->getContentDbHandle(); |
|
537 | + $stmt = $this->getDbStatement(' |
|
538 | 538 | INSERT OR REPLACE INTO documents_' . $state . ' (`path`,`title`,`slug`,`type`,`documentType`,`documentTypeSlug`,`state`,`lastModificationDate`,`creationDate`,`lastModifiedBy`,`fields`,`bricks`,`dynamicBricks`) |
539 | 539 | VALUES( |
540 | 540 | ' . $db->quote($documentObject->path) . ', |
@@ -552,9 +552,9 @@ discard block |
||
552 | 552 | ' . $db->quote(json_encode($documentObject->dynamicBricks)) . ' |
553 | 553 | ) |
554 | 554 | '); |
555 | - $result = $stmt->execute(); |
|
556 | - return $result; |
|
557 | - } |
|
555 | + $result = $stmt->execute(); |
|
556 | + return $result; |
|
557 | + } |
|
558 | 558 | |
559 | 559 | /** |
560 | 560 | * Delete the document from the database |
@@ -565,29 +565,29 @@ discard block |
||
565 | 565 | * @internal param string $state |
566 | 566 | * |
567 | 567 | */ |
568 | - public function deleteDocumentByPath($path) |
|
569 | - { |
|
570 | - $db = $this->getContentDbHandle(); |
|
571 | - $documentToDelete = $this->getDocumentByPath($path, 'unpublished'); |
|
572 | - if ($documentToDelete instanceof Document) { |
|
573 | - if ($documentToDelete->type == 'document') { |
|
574 | - $stmt = $this->getDbStatement(' |
|
568 | + public function deleteDocumentByPath($path) |
|
569 | + { |
|
570 | + $db = $this->getContentDbHandle(); |
|
571 | + $documentToDelete = $this->getDocumentByPath($path, 'unpublished'); |
|
572 | + if ($documentToDelete instanceof Document) { |
|
573 | + if ($documentToDelete->type == 'document') { |
|
574 | + $stmt = $this->getDbStatement(' |
|
575 | 575 | DELETE FROM documents_unpublished |
576 | 576 | WHERE path = ' . $db->quote($path) . ' |
577 | 577 | '); |
578 | - $stmt->execute(); |
|
579 | - } elseif ($documentToDelete->type == 'folder') { |
|
580 | - $folderPathWithWildcard = $path . '%'; |
|
581 | - $stmt = $this->getDbStatement(' |
|
578 | + $stmt->execute(); |
|
579 | + } elseif ($documentToDelete->type == 'folder') { |
|
580 | + $folderPathWithWildcard = $path . '%'; |
|
581 | + $stmt = $this->getDbStatement(' |
|
582 | 582 | DELETE FROM documents_unpublished |
583 | 583 | WHERE (path LIKE ' . $db->quote($folderPathWithWildcard) . ' |
584 | 584 | AND substr(`path`, ' . (strlen($path) + 1) . ', 1) = "/") |
585 | 585 | OR path = ' . $db->quote($path) . ' |
586 | 586 | '); |
587 | - $stmt->execute(); |
|
588 | - } |
|
589 | - } |
|
590 | - } |
|
587 | + $stmt->execute(); |
|
588 | + } |
|
589 | + } |
|
590 | + } |
|
591 | 591 | |
592 | 592 | /** |
593 | 593 | * @param $document |
@@ -115,13 +115,13 @@ discard block |
||
115 | 115 | if (in_array($name, $this->fileBasedSubsets)) { |
116 | 116 | return $this->$name; |
117 | 117 | } else { |
118 | - throw new \Exception('Trying to get undefined property from Repository: ' . $name); |
|
118 | + throw new \Exception('Trying to get undefined property from Repository: '.$name); |
|
119 | 119 | } |
120 | 120 | } else { |
121 | 121 | if (in_array($name, $this->fileBasedSubsets)) { |
122 | 122 | return $this->loadSubset($name); |
123 | 123 | } else { |
124 | - throw new \Exception('Trying to get undefined property from Repository: ' . $name); |
|
124 | + throw new \Exception('Trying to get undefined property from Repository: '.$name); |
|
125 | 125 | } |
126 | 126 | } |
127 | 127 | } |
@@ -136,10 +136,10 @@ discard block |
||
136 | 136 | { |
137 | 137 | if (in_array($name, $this->fileBasedSubsets)) { |
138 | 138 | $this->$name = $value; |
139 | - $changes = $name . 'Changes'; |
|
139 | + $changes = $name.'Changes'; |
|
140 | 140 | $this->$changes = true; |
141 | 141 | } else { |
142 | - throw new \Exception('Trying to persist unknown subset in repository: ' . $name . ' <br /><pre>' . print_r($value, true) . '</pre>'); |
|
142 | + throw new \Exception('Trying to persist unknown subset in repository: '.$name.' <br /><pre>'.print_r($value, true).'</pre>'); |
|
143 | 143 | } |
144 | 144 | } |
145 | 145 | |
@@ -149,7 +149,7 @@ discard block |
||
149 | 149 | public function save() |
150 | 150 | { |
151 | 151 | $host = $this; |
152 | - array_map(function ($value) use ($host) { |
|
152 | + array_map(function($value) use ($host) { |
|
153 | 153 | $host->saveSubset($value); |
154 | 154 | }, $this->fileBasedSubsets); |
155 | 155 | } |
@@ -160,14 +160,14 @@ discard block |
||
160 | 160 | */ |
161 | 161 | public function saveSubset($subset) |
162 | 162 | { |
163 | - $changes = $subset . 'Changes'; |
|
163 | + $changes = $subset.'Changes'; |
|
164 | 164 | if ($this->$changes === true) { |
165 | 165 | if (!defined('JSON_PRETTY_PRINT')) { |
166 | 166 | $json = json_encode($this->$subset); |
167 | 167 | } else { |
168 | 168 | $json = json_encode($this->$subset, JSON_PRETTY_PRINT); |
169 | 169 | } |
170 | - $subsetStoragePath = $this->storagePath . DIRECTORY_SEPARATOR . $subset . '.json'; |
|
170 | + $subsetStoragePath = $this->storagePath.DIRECTORY_SEPARATOR.$subset.'.json'; |
|
171 | 171 | file_put_contents($subsetStoragePath, $json); |
172 | 172 | |
173 | 173 | $this->$changes = false; |
@@ -181,7 +181,7 @@ discard block |
||
181 | 181 | */ |
182 | 182 | protected function loadSubset($subset) |
183 | 183 | { |
184 | - $subsetStoragePath = $this->storagePath . DIRECTORY_SEPARATOR . $subset . '.json'; |
|
184 | + $subsetStoragePath = $this->storagePath.DIRECTORY_SEPARATOR.$subset.'.json'; |
|
185 | 185 | $json = file_get_contents($subsetStoragePath); |
186 | 186 | $json = json_decode($json); |
187 | 187 | $this->$subset = $json; |
@@ -231,7 +231,7 @@ discard block |
||
231 | 231 | public function getContentDbHandle() |
232 | 232 | { |
233 | 233 | if ($this->contentDbHandle === null) { |
234 | - $this->contentDbHandle = new \PDO('sqlite:' . $this->storagePath . DIRECTORY_SEPARATOR . 'content.db'); |
|
234 | + $this->contentDbHandle = new \PDO('sqlite:'.$this->storagePath.DIRECTORY_SEPARATOR.'content.db'); |
|
235 | 235 | } |
236 | 236 | return $this->contentDbHandle; |
237 | 237 | } |
@@ -247,7 +247,7 @@ discard block |
||
247 | 247 | public function getDocuments($state = 'published') |
248 | 248 | { |
249 | 249 | if (!in_array($state, Document::$DOCUMENT_STATES)) { |
250 | - throw new \Exception('Unsupported document state: ' . $state); |
|
250 | + throw new \Exception('Unsupported document state: '.$state); |
|
251 | 251 | } |
252 | 252 | return $this->getDocumentsByPath('/', $state); |
253 | 253 | } |
@@ -255,7 +255,7 @@ discard block |
||
255 | 255 | public function getDocumentsWithState($folderPath = '/') |
256 | 256 | { |
257 | 257 | $db = $this->getContentDbHandle(); |
258 | - $folderPathWithWildcard = $folderPath . '%'; |
|
258 | + $folderPathWithWildcard = $folderPath.'%'; |
|
259 | 259 | |
260 | 260 | $ifRootIndex = 1; |
261 | 261 | if ($folderPath == '/') { |
@@ -270,10 +270,10 @@ discard block |
||
270 | 270 | FROM documents_unpublished |
271 | 271 | LEFT JOIN documents_published |
272 | 272 | ON documents_published.path = documents_unpublished.path |
273 | - WHERE documents_unpublished.`path` LIKE ' . $db->quote($folderPathWithWildcard) . ' |
|
274 | - AND substr(documents_unpublished.`path`, ' . (strlen($folderPath) + $ifRootIndex + 1) . ') NOT LIKE "%/%" |
|
275 | - AND length(documents_unpublished.`path`) > ' . (strlen($folderPath) + $ifRootIndex) . ' |
|
276 | - AND documents_unpublished.path != ' . $db->quote($folderPath) . ' |
|
273 | + WHERE documents_unpublished.`path` LIKE ' . $db->quote($folderPathWithWildcard).' |
|
274 | + AND substr(documents_unpublished.`path`, ' . (strlen($folderPath) + $ifRootIndex + 1).') NOT LIKE "%/%" |
|
275 | + AND length(documents_unpublished.`path`) > ' . (strlen($folderPath) + $ifRootIndex).' |
|
276 | + AND documents_unpublished.path != ' . $db->quote($folderPath).' |
|
277 | 277 | ORDER BY documents_unpublished.`type` DESC, documents_unpublished.`path` ASC |
278 | 278 | '; |
279 | 279 | $stmt = $this->getDbStatement($sql); |
@@ -300,16 +300,16 @@ discard block |
||
300 | 300 | public function getDocumentsByPath($folderPath, $state = 'published') |
301 | 301 | { |
302 | 302 | if (!in_array($state, Document::$DOCUMENT_STATES)) { |
303 | - throw new \Exception('Unsupported document state: ' . $state); |
|
303 | + throw new \Exception('Unsupported document state: '.$state); |
|
304 | 304 | } |
305 | 305 | $db = $this->getContentDbHandle(); |
306 | - $folderPathWithWildcard = $folderPath . '%'; |
|
306 | + $folderPathWithWildcard = $folderPath.'%'; |
|
307 | 307 | |
308 | 308 | $sql = 'SELECT * |
309 | - FROM documents_' . $state . ' |
|
310 | - WHERE `path` LIKE ' . $db->quote($folderPathWithWildcard) . ' |
|
311 | - AND substr(`path`, ' . (strlen($folderPath) + 1) . ') NOT LIKE "%/%" |
|
312 | - AND path != ' . $db->quote($folderPath) . ' |
|
309 | + FROM documents_' . $state.' |
|
310 | + WHERE `path` LIKE ' . $db->quote($folderPathWithWildcard).' |
|
311 | + AND substr(`path`, ' . (strlen($folderPath) + 1).') NOT LIKE "%/%" |
|
312 | + AND path != ' . $db->quote($folderPath).' |
|
313 | 313 | ORDER BY `type` DESC, `path` ASC'; |
314 | 314 | $stmt = $this->getDbStatement($sql); |
315 | 315 | |
@@ -336,7 +336,7 @@ discard block |
||
336 | 336 | if ($containerPath === '/') { |
337 | 337 | return $this->getRootFolder(); |
338 | 338 | } |
339 | - if (substr($containerPath, -1) === '/'){ |
|
339 | + if (substr($containerPath, -1) === '/') { |
|
340 | 340 | $containerPath = substr($containerPath, 0, -1); |
341 | 341 | } |
342 | 342 | $containerFolder = $this->getDocumentByPath($containerPath, 'unpublished'); |
@@ -353,13 +353,13 @@ discard block |
||
353 | 353 | public function getDocumentByPath($path, $state = 'published') |
354 | 354 | { |
355 | 355 | if (!in_array($state, Document::$DOCUMENT_STATES)) { |
356 | - throw new \Exception('Unsupported document state: ' . $state); |
|
356 | + throw new \Exception('Unsupported document state: '.$state); |
|
357 | 357 | } |
358 | 358 | $db = $this->getContentDbHandle(); |
359 | 359 | $document = $this->fetchDocument(' |
360 | 360 | SELECT * |
361 | - FROM documents_' . $state . ' |
|
362 | - WHERE path = ' . $db->quote($path) . ' |
|
361 | + FROM documents_' . $state.' |
|
362 | + WHERE path = ' . $db->quote($path).' |
|
363 | 363 | '); |
364 | 364 | if ($document instanceof Document && $document->type === 'folder') { |
365 | 365 | $document->dbHandle = $db; |
@@ -379,16 +379,16 @@ discard block |
||
379 | 379 | public function getTotalDocumentCount($state = 'published') |
380 | 380 | { |
381 | 381 | if (!in_array($state, Document::$DOCUMENT_STATES)) { |
382 | - throw new \Exception('Unsupported document state: ' . $state); |
|
382 | + throw new \Exception('Unsupported document state: '.$state); |
|
383 | 383 | } |
384 | 384 | $db = $this->getContentDbHandle(); |
385 | 385 | $stmt = $db->query(' |
386 | 386 | SELECT count(*) |
387 | - FROM documents_' . $state . ' |
|
387 | + FROM documents_' . $state.' |
|
388 | 388 | WHERE `type` != "folder" |
389 | 389 | '); |
390 | 390 | $result = $stmt->fetch(\PDO::FETCH_ASSOC); |
391 | - if (!is_array($result )) { |
|
391 | + if (!is_array($result)) { |
|
392 | 392 | return 0; |
393 | 393 | } |
394 | 394 | return intval(current($result)); |
@@ -407,7 +407,7 @@ discard block |
||
407 | 407 | if ($stmt === false || !$stmt->execute()) { |
408 | 408 | $errorInfo = $db->errorInfo(); |
409 | 409 | $errorMsg = $errorInfo[2]; |
410 | - throw new \Exception('SQLite Exception: ' . $errorMsg . ' in SQL: <br /><pre>' . $sql . '</pre>'); |
|
410 | + throw new \Exception('SQLite Exception: '.$errorMsg.' in SQL: <br /><pre>'.$sql.'</pre>'); |
|
411 | 411 | } |
412 | 412 | return $result; |
413 | 413 | } |
@@ -417,7 +417,7 @@ discard block |
||
417 | 417 | $sql = ' |
418 | 418 | INSERT OR REPLACE INTO documents_published |
419 | 419 | (`id`,`path`,`title`,`slug`,`type`,`documentType`,`documentTypeSlug`,`state`,`lastModificationDate`,`creationDate`,`publicationDate`,`lastModifiedBy`,`fields`,`bricks`,`dynamicBricks`) |
420 | - SELECT `id`,`path`,`title`,`slug`,`type`,`documentType`,`documentTypeSlug`,"published" as state,`lastModificationDate`,`creationDate`,' . time() . ' as publicationDate, `lastModifiedBy`,`fields`,`bricks`,`dynamicBricks` |
|
420 | + SELECT `id`,`path`,`title`,`slug`,`type`,`documentType`,`documentTypeSlug`,"published" as state,`lastModificationDate`,`creationDate`,' . time().' as publicationDate, `lastModifiedBy`,`fields`,`bricks`,`dynamicBricks` |
|
421 | 421 | FROM documents_unpublished |
422 | 422 | WHERE `path` = :path |
423 | 423 | '; |
@@ -430,7 +430,7 @@ discard block |
||
430 | 430 | if ($stmt === false) { |
431 | 431 | $errorInfo = $db->errorInfo(); |
432 | 432 | $errorMsg = $errorInfo[2]; |
433 | - throw new \Exception('SQLite Exception: ' . $errorMsg . ' in SQL: <br /><pre>' . $sql . '</pre>'); |
|
433 | + throw new \Exception('SQLite Exception: '.$errorMsg.' in SQL: <br /><pre>'.$sql.'</pre>'); |
|
434 | 434 | } |
435 | 435 | $stmt->bindValue(':path', $path); |
436 | 436 | $stmt->execute(); |
@@ -497,7 +497,7 @@ discard block |
||
497 | 497 | if ($stmt === false) { |
498 | 498 | $errorInfo = $db->errorInfo(); |
499 | 499 | $errorMsg = $errorInfo[2]; |
500 | - throw new \Exception('SQLite Exception: ' . $errorMsg . ' in SQL: <br /><pre>' . $sql . '</pre>'); |
|
500 | + throw new \Exception('SQLite Exception: '.$errorMsg.' in SQL: <br /><pre>'.$sql.'</pre>'); |
|
501 | 501 | } |
502 | 502 | return $stmt; |
503 | 503 | } |
@@ -527,25 +527,25 @@ discard block |
||
527 | 527 | public function saveDocument($documentObject, $state = 'published') |
528 | 528 | { |
529 | 529 | if (!in_array($state, Document::$DOCUMENT_STATES)) { |
530 | - throw new \Exception('Unsupported document state: ' . $state); |
|
530 | + throw new \Exception('Unsupported document state: '.$state); |
|
531 | 531 | } |
532 | 532 | $db = $this->getContentDbHandle(); |
533 | 533 | $stmt = $this->getDbStatement(' |
534 | - INSERT OR REPLACE INTO documents_' . $state . ' (`path`,`title`,`slug`,`type`,`documentType`,`documentTypeSlug`,`state`,`lastModificationDate`,`creationDate`,`lastModifiedBy`,`fields`,`bricks`,`dynamicBricks`) |
|
534 | + INSERT OR REPLACE INTO documents_' . $state.' (`path`,`title`,`slug`,`type`,`documentType`,`documentTypeSlug`,`state`,`lastModificationDate`,`creationDate`,`lastModifiedBy`,`fields`,`bricks`,`dynamicBricks`) |
|
535 | 535 | VALUES( |
536 | - ' . $db->quote($documentObject->path) . ', |
|
537 | - ' . $db->quote($documentObject->title) . ', |
|
538 | - ' . $db->quote($documentObject->slug) . ', |
|
539 | - ' . $db->quote($documentObject->type) . ', |
|
540 | - ' . $db->quote($documentObject->documentType) . ', |
|
541 | - ' . $db->quote($documentObject->documentTypeSlug) . ', |
|
542 | - ' . $db->quote($documentObject->state) . ', |
|
543 | - ' . $db->quote($documentObject->lastModificationDate) . ', |
|
544 | - ' . $db->quote($documentObject->creationDate) . ', |
|
545 | - ' . $db->quote($documentObject->lastModifiedBy) . ', |
|
546 | - ' . $db->quote(json_encode($documentObject->fields)) . ', |
|
547 | - ' . $db->quote(json_encode($documentObject->bricks)) . ', |
|
548 | - ' . $db->quote(json_encode($documentObject->dynamicBricks)) . ' |
|
536 | + ' . $db->quote($documentObject->path).', |
|
537 | + ' . $db->quote($documentObject->title).', |
|
538 | + ' . $db->quote($documentObject->slug).', |
|
539 | + ' . $db->quote($documentObject->type).', |
|
540 | + ' . $db->quote($documentObject->documentType).', |
|
541 | + ' . $db->quote($documentObject->documentTypeSlug).', |
|
542 | + ' . $db->quote($documentObject->state).', |
|
543 | + ' . $db->quote($documentObject->lastModificationDate).', |
|
544 | + ' . $db->quote($documentObject->creationDate).', |
|
545 | + ' . $db->quote($documentObject->lastModifiedBy).', |
|
546 | + ' . $db->quote(json_encode($documentObject->fields)).', |
|
547 | + ' . $db->quote(json_encode($documentObject->bricks)).', |
|
548 | + ' . $db->quote(json_encode($documentObject->dynamicBricks)).' |
|
549 | 549 | ) |
550 | 550 | '); |
551 | 551 | $result = $stmt->execute(); |
@@ -569,16 +569,16 @@ discard block |
||
569 | 569 | if ($documentToDelete->type == 'document') { |
570 | 570 | $stmt = $this->getDbStatement(' |
571 | 571 | DELETE FROM documents_unpublished |
572 | - WHERE path = ' . $db->quote($path) . ' |
|
572 | + WHERE path = ' . $db->quote($path).' |
|
573 | 573 | '); |
574 | 574 | $stmt->execute(); |
575 | 575 | } elseif ($documentToDelete->type == 'folder') { |
576 | - $folderPathWithWildcard = $path . '%'; |
|
576 | + $folderPathWithWildcard = $path.'%'; |
|
577 | 577 | $stmt = $this->getDbStatement(' |
578 | 578 | DELETE FROM documents_unpublished |
579 | - WHERE (path LIKE ' . $db->quote($folderPathWithWildcard) . ' |
|
580 | - AND substr(`path`, ' . (strlen($path) + 1) . ', 1) = "/") |
|
581 | - OR path = ' . $db->quote($path) . ' |
|
579 | + WHERE (path LIKE ' . $db->quote($folderPathWithWildcard).' |
|
580 | + AND substr(`path`, ' . (strlen($path) + 1).', 1) = "/") |
|
581 | + OR path = ' . $db->quote($path).' |
|
582 | 582 | '); |
583 | 583 | $stmt->execute(); |
584 | 584 | } |
@@ -10,26 +10,26 @@ |
||
10 | 10 | |
11 | 11 | class RedirectsFactory |
12 | 12 | { |
13 | - /** |
|
14 | - * Create a new redirect object from postvalues |
|
15 | - * |
|
16 | - * @param $postValues |
|
17 | - * @return \stdClass |
|
18 | - * @throws \Exception |
|
19 | - */ |
|
20 | - public static function createRedirectFromPostValues($postValues) |
|
21 | - { |
|
22 | - if (isset($postValues['title'], $postValues['fromUrl'], $postValues['toUrl'])) { |
|
23 | - $redirectObject = new \stdClass(); |
|
24 | - $redirectObject->title = $postValues['title']; |
|
25 | - $redirectObject->slug = StringUtil::slugify($postValues['title']); |
|
26 | - $redirectObject->fromUrl = $postValues['fromUrl']; |
|
27 | - $redirectObject->toUrl = $postValues['toUrl']; |
|
28 | - $redirectObject->type = $postValues['type']; |
|
13 | + /** |
|
14 | + * Create a new redirect object from postvalues |
|
15 | + * |
|
16 | + * @param $postValues |
|
17 | + * @return \stdClass |
|
18 | + * @throws \Exception |
|
19 | + */ |
|
20 | + public static function createRedirectFromPostValues($postValues) |
|
21 | + { |
|
22 | + if (isset($postValues['title'], $postValues['fromUrl'], $postValues['toUrl'])) { |
|
23 | + $redirectObject = new \stdClass(); |
|
24 | + $redirectObject->title = $postValues['title']; |
|
25 | + $redirectObject->slug = StringUtil::slugify($postValues['title']); |
|
26 | + $redirectObject->fromUrl = $postValues['fromUrl']; |
|
27 | + $redirectObject->toUrl = $postValues['toUrl']; |
|
28 | + $redirectObject->type = $postValues['type']; |
|
29 | 29 | |
30 | - return $redirectObject; |
|
31 | - } else { |
|
32 | - throw new \Exception('Trying to create valuelist with invalid data.'); |
|
33 | - } |
|
34 | - } |
|
30 | + return $redirectObject; |
|
31 | + } else { |
|
32 | + throw new \Exception('Trying to create valuelist with invalid data.'); |
|
33 | + } |
|
34 | + } |
|
35 | 35 | } |
36 | 36 | \ No newline at end of file |
@@ -12,34 +12,34 @@ |
||
12 | 12 | |
13 | 13 | class ValuelistFactory |
14 | 14 | { |
15 | - /** |
|
16 | - * Create a sitemap item from post values |
|
17 | - * |
|
18 | - * @param $postValues |
|
19 | - * |
|
20 | - * @return \stdClass |
|
21 | - * @throws \Exception |
|
22 | - */ |
|
23 | - public static function createValuelistFromPostValues($postValues) |
|
24 | - { |
|
25 | - if (isset($postValues['title'])) { |
|
26 | - $valuelistObject = new \stdClass(); |
|
27 | - $valuelistObject->title = $postValues['title']; |
|
28 | - $valuelistObject->slug = StringUtil::slugify($postValues['title']); |
|
29 | - $valuelistObject->pairs = new \stdClass(); |
|
30 | - if (isset($postValues['keys'], $postValues['values'])) { |
|
31 | - foreach ($postValues['keys'] as $key => $value) { |
|
32 | - $valuelistObject->pairs->$value = $postValues['values'][$key]; |
|
33 | - } |
|
34 | - } |
|
35 | - $object_vars = get_object_vars($valuelistObject->pairs); |
|
36 | - ksort($object_vars); |
|
37 | - $valuelistObject->pairs = (object) $object_vars; |
|
15 | + /** |
|
16 | + * Create a sitemap item from post values |
|
17 | + * |
|
18 | + * @param $postValues |
|
19 | + * |
|
20 | + * @return \stdClass |
|
21 | + * @throws \Exception |
|
22 | + */ |
|
23 | + public static function createValuelistFromPostValues($postValues) |
|
24 | + { |
|
25 | + if (isset($postValues['title'])) { |
|
26 | + $valuelistObject = new \stdClass(); |
|
27 | + $valuelistObject->title = $postValues['title']; |
|
28 | + $valuelistObject->slug = StringUtil::slugify($postValues['title']); |
|
29 | + $valuelistObject->pairs = new \stdClass(); |
|
30 | + if (isset($postValues['keys'], $postValues['values'])) { |
|
31 | + foreach ($postValues['keys'] as $key => $value) { |
|
32 | + $valuelistObject->pairs->$value = $postValues['values'][$key]; |
|
33 | + } |
|
34 | + } |
|
35 | + $object_vars = get_object_vars($valuelistObject->pairs); |
|
36 | + ksort($object_vars); |
|
37 | + $valuelistObject->pairs = (object) $object_vars; |
|
38 | 38 | |
39 | - return $valuelistObject; |
|
40 | - } else { |
|
41 | - throw new \Exception('Trying to create valuelist with invalid data.'); |
|
42 | - } |
|
43 | - } |
|
39 | + return $valuelistObject; |
|
40 | + } else { |
|
41 | + throw new \Exception('Trying to create valuelist with invalid data.'); |
|
42 | + } |
|
43 | + } |
|
44 | 44 | |
45 | 45 | } |
46 | 46 | \ No newline at end of file |