@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | public function getDocuments($state = 'published') |
22 | 22 | { |
23 | 23 | if (!in_array($state, Document::$DOCUMENT_STATES)) { |
24 | - throw new \Exception('Unsupported document state: ' . $state); |
|
24 | + throw new \Exception('Unsupported document state: '.$state); |
|
25 | 25 | } |
26 | 26 | return $this->repository->getDocuments($state); |
27 | 27 | } |
@@ -50,9 +50,9 @@ discard block |
||
50 | 50 | public function getDocumentBySlug($slug, $state = 'published') |
51 | 51 | { |
52 | 52 | if (!in_array($state, Document::$DOCUMENT_STATES)) { |
53 | - throw new \Exception('Unsupported document state: ' . $state); |
|
53 | + throw new \Exception('Unsupported document state: '.$state); |
|
54 | 54 | } |
55 | - $path = '/' . $slug; |
|
55 | + $path = '/'.$slug; |
|
56 | 56 | |
57 | 57 | return $this->repository->getDocumentByPath($path, $state); |
58 | 58 | } |
@@ -66,16 +66,16 @@ discard block |
||
66 | 66 | public function saveDocument($postValues, $state = 'unpublished') |
67 | 67 | { |
68 | 68 | if (!in_array($state, Document::$DOCUMENT_STATES)) { |
69 | - throw new \Exception('Unsupported document state: ' . $state); |
|
69 | + throw new \Exception('Unsupported document state: '.$state); |
|
70 | 70 | } |
71 | - $oldPath = '/' . $postValues['path']; |
|
71 | + $oldPath = '/'.$postValues['path']; |
|
72 | 72 | |
73 | 73 | $container = $this->getDocumentContainerByPath($oldPath); |
74 | 74 | $documentObject = DocumentFactory::createDocumentFromPostValues($postValues, new DocumentTypesStorage($this->repository)); |
75 | 75 | if ($container->path === '/') { |
76 | - $newPath = $container->path . $documentObject->slug; |
|
76 | + $newPath = $container->path.$documentObject->slug; |
|
77 | 77 | } else { |
78 | - $newPath = $container->path . '/' . $documentObject->slug; |
|
78 | + $newPath = $container->path.'/'.$documentObject->slug; |
|
79 | 79 | } |
80 | 80 | $documentObject->path = $newPath; |
81 | 81 | $this->repository->saveDocument($documentObject, $state); |
@@ -89,9 +89,9 @@ discard block |
||
89 | 89 | { |
90 | 90 | $documentObject = DocumentFactory::createDocumentFromPostValues($postValues, new DocumentTypesStorage($this->repository)); |
91 | 91 | if ($postValues['path'] === '/') { |
92 | - $documentObject->path = $postValues['path'] . $documentObject->slug; |
|
92 | + $documentObject->path = $postValues['path'].$documentObject->slug; |
|
93 | 93 | } else { |
94 | - $documentObject->path = $postValues['path'] . '/' . $documentObject->slug; |
|
94 | + $documentObject->path = $postValues['path'].'/'.$documentObject->slug; |
|
95 | 95 | } |
96 | 96 | |
97 | 97 | $this->repository->saveDocument($documentObject, $state); |
@@ -102,7 +102,7 @@ discard block |
||
102 | 102 | */ |
103 | 103 | public function deleteDocumentBySlug($slug) |
104 | 104 | { |
105 | - $path = '/' . $slug; |
|
105 | + $path = '/'.$slug; |
|
106 | 106 | $this->repository->deleteDocumentByPath($path); |
107 | 107 | } |
108 | 108 |
@@ -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,13 +82,13 @@ discard block |
||
82 | 82 | * @return array |
83 | 83 | * @throws \Exception |
84 | 84 | */ |
85 | - public function getContent($orderBy = 'title', $order = 'ASC') |
|
86 | - { |
|
87 | - $docs = $this->documentStorage->getDocumentsWithState($this->path); |
|
88 | - return $docs; |
|
89 | - //dump($this->path, $docs); |
|
90 | - $folderPathWithWildcard = $this->path . '%'; |
|
91 | - $sql = ' SELECT * |
|
85 | + public function getContent($orderBy = 'title', $order = 'ASC') |
|
86 | + { |
|
87 | + $docs = $this->documentStorage->getDocumentsWithState($this->path); |
|
88 | + return $docs; |
|
89 | + //dump($this->path, $docs); |
|
90 | + $folderPathWithWildcard = $this->path . '%'; |
|
91 | + $sql = ' SELECT * |
|
92 | 92 | FROM documents_published |
93 | 93 | WHERE `path` LIKE ' . $this->dbHandle->quote($folderPathWithWildcard) . ' |
94 | 94 | AND substr(`path`, ' . (strlen($this->path) + 2) . ') NOT LIKE "%/%" |
@@ -96,24 +96,24 @@ discard block |
||
96 | 96 | AND path != ' . $this->dbHandle->quote($this->path) . ' |
97 | 97 | ORDER BY ' . (in_array($orderBy, $this->orderableFields) ? $orderBy : 'title') . ' ' . ($order === 'ASC' ? 'ASC' : 'DESC') . ' |
98 | 98 | '; |
99 | - $stmt = $this->dbHandle->prepare($sql); |
|
99 | + $stmt = $this->dbHandle->prepare($sql); |
|
100 | 100 | if ($stmt === false) { |
101 | 101 | $errorInfo = $this->dbHandle->errorInfo(); |
102 | 102 | $errorMsg = $errorInfo[2]; |
103 | 103 | throw new \Exception('SQLite Exception: ' . $errorMsg . ' in SQL: <br /><pre>' . $sql . '</pre>'); |
104 | 104 | } |
105 | - $stmt->bindColumn(':orderBy', $orderBy, \PDO::PARAM_STMT); |
|
105 | + $stmt->bindColumn(':orderBy', $orderBy, \PDO::PARAM_STMT); |
|
106 | 106 | $stmt->execute(); |
107 | - $contents = $stmt->fetchAll(\PDO::FETCH_CLASS, '\library\storage\Document'); |
|
108 | - foreach ($contents as $key => $document) { |
|
109 | - if ($document->type === 'folder') { |
|
110 | - $document->dbHandle = $this->dbHandle; |
|
111 | - $contents[$key] = $document; |
|
112 | - } |
|
113 | - } |
|
114 | - $this->content = $contents; |
|
115 | - return $this->content; |
|
116 | - } |
|
107 | + $contents = $stmt->fetchAll(\PDO::FETCH_CLASS, '\library\storage\Document'); |
|
108 | + foreach ($contents as $key => $document) { |
|
109 | + if ($document->type === 'folder') { |
|
110 | + $document->dbHandle = $this->dbHandle; |
|
111 | + $contents[$key] = $document; |
|
112 | + } |
|
113 | + } |
|
114 | + $this->content = $contents; |
|
115 | + return $this->content; |
|
116 | + } |
|
117 | 117 | |
118 | 118 | /** |
119 | 119 | * @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(); |
@@ -87,20 +87,20 @@ discard block |
||
87 | 87 | $docs = $this->documentStorage->getDocumentsWithState($this->path); |
88 | 88 | return $docs; |
89 | 89 | //dump($this->path, $docs); |
90 | - $folderPathWithWildcard = $this->path . '%'; |
|
90 | + $folderPathWithWildcard = $this->path.'%'; |
|
91 | 91 | $sql = ' SELECT * |
92 | 92 | FROM documents_published |
93 | - WHERE `path` LIKE ' . $this->dbHandle->quote($folderPathWithWildcard) . ' |
|
94 | - AND substr(`path`, ' . (strlen($this->path) + 2) . ') NOT LIKE "%/%" |
|
95 | - AND substr(`path`, ' . (strlen($this->path) + 1) . ', 1) = "/" |
|
96 | - AND path != ' . $this->dbHandle->quote($this->path) . ' |
|
97 | - ORDER BY ' . (in_array($orderBy, $this->orderableFields) ? $orderBy : 'title') . ' ' . ($order === 'ASC' ? 'ASC' : 'DESC') . ' |
|
93 | + WHERE `path` LIKE ' . $this->dbHandle->quote($folderPathWithWildcard).' |
|
94 | + AND substr(`path`, ' . (strlen($this->path) + 2).') NOT LIKE "%/%" |
|
95 | + AND substr(`path`, ' . (strlen($this->path) + 1).', 1) = "/" |
|
96 | + AND path != ' . $this->dbHandle->quote($this->path).' |
|
97 | + ORDER BY ' . (in_array($orderBy, $this->orderableFields) ? $orderBy : 'title').' '.($order === 'ASC' ? 'ASC' : 'DESC').' |
|
98 | 98 | '; |
99 | 99 | $stmt = $this->dbHandle->prepare($sql); |
100 | 100 | if ($stmt === false) { |
101 | 101 | $errorInfo = $this->dbHandle->errorInfo(); |
102 | 102 | $errorMsg = $errorInfo[2]; |
103 | - throw new \Exception('SQLite Exception: ' . $errorMsg . ' in SQL: <br /><pre>' . $sql . '</pre>'); |
|
103 | + throw new \Exception('SQLite Exception: '.$errorMsg.' in SQL: <br /><pre>'.$sql.'</pre>'); |
|
104 | 104 | } |
105 | 105 | $stmt->bindColumn(':orderBy', $orderBy, \PDO::PARAM_STMT); |
106 | 106 | $stmt->execute(); |
@@ -120,7 +120,7 @@ discard block |
||
120 | 120 | */ |
121 | 121 | public function __toString() |
122 | 122 | { |
123 | - return 'Document:' . $this->title; |
|
123 | + return 'Document:'.$this->title; |
|
124 | 124 | } |
125 | 125 | |
126 | 126 |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | */ |
83 | 83 | private function config() |
84 | 84 | { |
85 | - $storagePath = __DIR__ . '/../../' . $this->storageDir; |
|
85 | + $storagePath = __DIR__.'/../../'.$this->storageDir; |
|
86 | 86 | if (realpath($storagePath) === false) { |
87 | 87 | initFramework(); |
88 | 88 | if (Repository::create($storagePath)) { |
@@ -90,7 +90,7 @@ discard block |
||
90 | 90 | $repository->init(); |
91 | 91 | $this->repository = $repository; |
92 | 92 | } else { |
93 | - throw new \Exception('Could not create repository directory: ' . $storagePath); |
|
93 | + throw new \Exception('Could not create repository directory: '.$storagePath); |
|
94 | 94 | } |
95 | 95 | } else { |
96 | 96 | $this->repository = new Repository($storagePath); |
@@ -133,9 +133,9 @@ discard block |
||
133 | 133 | { |
134 | 134 | $documentFolderObject = DocumentFolderFactory::createDocumentFolderFromPostValues($postValues); |
135 | 135 | if ($postValues['path'] === '/') { |
136 | - $documentFolderObject->path = $postValues['path'] . $documentFolderObject->slug; |
|
136 | + $documentFolderObject->path = $postValues['path'].$documentFolderObject->slug; |
|
137 | 137 | } else { |
138 | - $documentFolderObject->path = $postValues['path'] . '/' . $documentFolderObject->slug; |
|
138 | + $documentFolderObject->path = $postValues['path'].'/'.$documentFolderObject->slug; |
|
139 | 139 | } |
140 | 140 | $this->repository->saveDocument($documentFolderObject, 'published'); |
141 | 141 | $this->repository->saveDocument($documentFolderObject, 'unpublished'); |
@@ -150,7 +150,7 @@ discard block |
||
150 | 150 | */ |
151 | 151 | public function deleteDocumentFolderBySlug($slug) |
152 | 152 | { |
153 | - $path = '/' . $slug; |
|
153 | + $path = '/'.$slug; |
|
154 | 154 | $this->repository->deleteDocumentByPath($path, 'published'); |
155 | 155 | $this->repository->deleteDocumentByPath($path, 'unpublished'); |
156 | 156 | $this->repository->cleanPublishedDeletedDocuments(); |
@@ -158,13 +158,13 @@ discard block |
||
158 | 158 | |
159 | 159 | public function publishDocumentBySlug($slug) |
160 | 160 | { |
161 | - $path = '/' . $slug; |
|
161 | + $path = '/'.$slug; |
|
162 | 162 | $this->repository->publishDocumentByPath($path); |
163 | 163 | } |
164 | 164 | |
165 | 165 | public function unpublishDocumentBySlug($slug) |
166 | 166 | { |
167 | - $path = '/' . $slug; |
|
167 | + $path = '/'.$slug; |
|
168 | 168 | $this->repository->unpublishDocumentByPath($path); |
169 | 169 | } |
170 | 170 | |
@@ -178,7 +178,7 @@ discard block |
||
178 | 178 | */ |
179 | 179 | public function getDocumentFolderBySlug($slug) |
180 | 180 | { |
181 | - $path = '/' . $slug; |
|
181 | + $path = '/'.$slug; |
|
182 | 182 | |
183 | 183 | return $this->repository->getDocumentByPath($path); |
184 | 184 | } |
@@ -310,7 +310,7 @@ |
||
310 | 310 | } |
311 | 311 | |
312 | 312 | /** |
313 | - * @return \library\storage\storage\UsersStorage |
|
313 | + * @return ValuelistsStorage |
|
314 | 314 | */ |
315 | 315 | public function getValuelists() |
316 | 316 | { |
@@ -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 = __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . $this->storageDir . DIRECTORY_SEPARATOR; |
|
177 | - $this->searchDbHandle = new \PDO('sqlite:' . $path . self::SEARCH_TEMP_DB); |
|
176 | + $path = __DIR__.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.$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 = __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . $this->storageDir . DIRECTORY_SEPARATOR; |
|
189 | - rename($path . self::SEARCH_TEMP_DB, $path . 'search.db'); |
|
188 | + $path = __DIR__.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.$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 |
@@ -72,7 +72,7 @@ discard block |
||
72 | 72 | } |
73 | 73 | |
74 | 74 | private function showJson($obj, $httpHeader = 'HTTP/1.0 200 OK') { |
75 | - header($_SERVER['SERVER_PROTOCOL'] . $httpHeader, true); |
|
75 | + header($_SERVER['SERVER_PROTOCOL'].$httpHeader, true); |
|
76 | 76 | header('Content-type: application/json'); |
77 | 77 | die(json_encode($obj)); |
78 | 78 | } |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | */ |
85 | 85 | private function stepRouting($step, $cmsComponent, $indexer) |
86 | 86 | { |
87 | - switch($step) { |
|
87 | + switch ($step) { |
|
88 | 88 | case 'resetIndex': $indexer->resetIndex(); break; |
89 | 89 | case 'cleanPublishedDeletedDocuments': $cmsComponent->storage->getDocuments()->cleanPublishedDeletedDocuments(); break; |
90 | 90 | case 'createDocumentTermCount': |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | case 'createTermFieldLengthNorm': $indexer->createTermFieldLengthNorm(); break; |
96 | 96 | case 'createInverseDocumentFrequency': $indexer->createInverseDocumentFrequency(); break; |
97 | 97 | case 'replaceOldIndex': $indexer->replaceOldIndex(); break; |
98 | - default : $this->showJson('Invalid step: ' . $step . '.', 'HTTP/1.0 500 Internal Server Error'); break; |
|
98 | + default : $this->showJson('Invalid step: '.$step.'.', 'HTTP/1.0 500 Internal Server Error'); break; |
|
99 | 99 | } |
100 | 100 | $this->showJson('done'); |
101 | 101 | } |
@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <? include('documents/function.renderAction.php'); ?> |
2 | 2 | <? include('documents/function.renderDocument.php'); ?> |
3 | 3 | <? include('documents/function.renderFolder.php'); ?> |
4 | -<script>window.onload=function(){History.init();History.replaceState(null, 'Cloud Control CMS', '/<?=$request::$subfolders . $cmsPrefix?>/documents?path=/');};</script> |
|
4 | +<script>window.onload=function(){History.init();History.replaceState(null, 'Cloud Control CMS', '/<?=$request::$subfolders.$cmsPrefix?>/documents?path=/');};</script> |
|
5 | 5 | <section class="documents"> |
6 | 6 | <h2><i class="fa fa-file-text-o"></i> Documents</h2> |
7 | 7 | <nav class="actions"> |
@@ -27,9 +27,9 @@ discard block |
||
27 | 27 | <? foreach ($documents as $document) : ?> |
28 | 28 | <li class="grid-container"> |
29 | 29 | <? if ($document->type == 'document') : ?> |
30 | - <?renderDocument($document, $cmsPrefix);?> |
|
30 | + <?renderDocument($document, $cmsPrefix); ?> |
|
31 | 31 | <? elseif ($document->type == 'folder') : ?> |
32 | - <?renderFolder($document, $cmsPrefix, '', true);?> |
|
32 | + <?renderFolder($document, $cmsPrefix, '', true); ?> |
|
33 | 33 | <? endif ?> |
34 | 34 | </li> |
35 | 35 | <? endforeach ?> |
@@ -21,9 +21,9 @@ discard block |
||
21 | 21 | <div class="documentActions grid-box-2"> |
22 | 22 | <? if ($document->state == 'unpublished' || $document->unpublishedChanges) : ?> |
23 | 23 | <?renderAction('Publish', |
24 | - 'publish', |
|
25 | - \library\cc\Request::$subfolders . $cmsPrefix . '/documents/publish-document?slug=' . $slugPrefix . $document->slug, |
|
26 | - 'check');?> |
|
24 | + 'publish', |
|
25 | + \library\cc\Request::$subfolders . $cmsPrefix . '/documents/publish-document?slug=' . $slugPrefix . $document->slug, |
|
26 | + 'check');?> |
|
27 | 27 | <? endif ?> |
28 | 28 | <? if ($document->state == 'published') : ?> |
29 | 29 | <?renderAction('Unpublish', |
@@ -40,7 +40,7 @@ discard block |
||
40 | 40 | 'error', |
41 | 41 | \library\cc\Request::$subfolders . $cmsPrefix . '/documents/delete-document?slug=' . $slugPrefix . $document->slug, |
42 | 42 | 'trash', |
43 | - 'return confirm(\'Are you sure you want to delete this document?\');');?> |
|
43 | + 'return confirm(\'Are you sure you want to delete this document?\');');?> |
|
44 | 44 | <? endif ?> |
45 | 45 | </div> |
46 | 46 | <?}?> |
@@ -7,7 +7,7 @@ discard block |
||
7 | 7 | function renderDocument($document, $cmsPrefix, $slugPrefix = '') {?> |
8 | 8 | <div class="grid-box-10"> |
9 | 9 | <h3> |
10 | - <a class="btn documentTitle" href="<?=\library\cc\Request::$subfolders?><?=$cmsPrefix?>/documents/edit-document?slug=<?=$slugPrefix . $document->slug?>" title="Edit"> |
|
10 | + <a class="btn documentTitle" href="<?=\library\cc\Request::$subfolders?><?=$cmsPrefix?>/documents/edit-document?slug=<?=$slugPrefix.$document->slug?>" title="Edit"> |
|
11 | 11 | <i class="fa fa-file-text-o"></i> |
12 | 12 | <small class="state <?=strtolower($document->state)?>"><i class="fa <?=$document->state == 'published' ? 'fa-check-circle-o' : 'fa-times-circle-o' ?>"></i></small> |
13 | 13 | <?=$document->title?> |
@@ -28,25 +28,25 @@ discard block |
||
28 | 28 | <? if ($document->state == 'unpublished' || $document->unpublishedChanges) : ?> |
29 | 29 | <?renderAction('Publish', |
30 | 30 | 'publish', |
31 | - \library\cc\Request::$subfolders . $cmsPrefix . '/documents/publish-document?slug=' . $slugPrefix . $document->slug, |
|
32 | - 'check');?> |
|
31 | + \library\cc\Request::$subfolders.$cmsPrefix.'/documents/publish-document?slug='.$slugPrefix.$document->slug, |
|
32 | + 'check'); ?> |
|
33 | 33 | <? endif ?> |
34 | 34 | <? if ($document->state == 'published') : ?> |
35 | 35 | <?renderAction('Unpublish', |
36 | 36 | 'unpublish', |
37 | - \library\cc\Request::$subfolders . $cmsPrefix . '/documents/unpublish-document?slug=' . $slugPrefix . $document->slug, |
|
38 | - 'times');?> |
|
37 | + \library\cc\Request::$subfolders.$cmsPrefix.'/documents/unpublish-document?slug='.$slugPrefix.$document->slug, |
|
38 | + 'times'); ?> |
|
39 | 39 | <? endif ?> |
40 | 40 | <?renderAction('Edit', |
41 | 41 | '', |
42 | - \library\cc\Request::$subfolders . $cmsPrefix . '/documents/edit-document?slug=' . $slugPrefix . $document->slug, |
|
43 | - 'pencil');?> |
|
42 | + \library\cc\Request::$subfolders.$cmsPrefix.'/documents/edit-document?slug='.$slugPrefix.$document->slug, |
|
43 | + 'pencil'); ?> |
|
44 | 44 | <? if ($document->state == 'unpublished') : ?> |
45 | 45 | <?renderAction('Delete', |
46 | 46 | 'error', |
47 | - \library\cc\Request::$subfolders . $cmsPrefix . '/documents/delete-document?slug=' . $slugPrefix . $document->slug, |
|
47 | + \library\cc\Request::$subfolders.$cmsPrefix.'/documents/delete-document?slug='.$slugPrefix.$document->slug, |
|
48 | 48 | 'trash', |
49 | - 'return confirm(\'Are you sure you want to delete this document?\');');?> |
|
49 | + 'return confirm(\'Are you sure you want to delete this document?\');'); ?> |
|
50 | 50 | <? endif ?> |
51 | 51 | </div> |
52 | 52 | <?}?> |
@@ -106,13 +106,13 @@ discard block |
||
106 | 106 | if (in_array($name, $this->fileBasedSubsets)) { |
107 | 107 | return $this->$name; |
108 | 108 | } else { |
109 | - throw new \Exception('Trying to get undefined property from Repository: ' . $name); |
|
109 | + throw new \Exception('Trying to get undefined property from Repository: '.$name); |
|
110 | 110 | } |
111 | 111 | } else { |
112 | 112 | if (in_array($name, $this->fileBasedSubsets)) { |
113 | 113 | return $this->loadSubset($name); |
114 | 114 | } else { |
115 | - throw new \Exception('Trying to get undefined property from Repository: ' . $name); |
|
115 | + throw new \Exception('Trying to get undefined property from Repository: '.$name); |
|
116 | 116 | } |
117 | 117 | } |
118 | 118 | } |
@@ -127,10 +127,10 @@ discard block |
||
127 | 127 | { |
128 | 128 | if (in_array($name, $this->fileBasedSubsets)) { |
129 | 129 | $this->$name = $value; |
130 | - $changes = $name . 'Changes'; |
|
130 | + $changes = $name.'Changes'; |
|
131 | 131 | $this->$changes = true; |
132 | 132 | } else { |
133 | - throw new \Exception('Trying to persist unknown subset in repository: ' . $name . ' <br /><pre>' . print_r($value, true) . '</pre>'); |
|
133 | + throw new \Exception('Trying to persist unknown subset in repository: '.$name.' <br /><pre>'.print_r($value, true).'</pre>'); |
|
134 | 134 | } |
135 | 135 | } |
136 | 136 | |
@@ -139,7 +139,7 @@ discard block |
||
139 | 139 | */ |
140 | 140 | public function save() |
141 | 141 | { |
142 | - array_map(function ($value) { |
|
142 | + array_map(function($value) { |
|
143 | 143 | $this->saveSubset($value); |
144 | 144 | }, $this->fileBasedSubsets); |
145 | 145 | } |
@@ -150,10 +150,10 @@ discard block |
||
150 | 150 | */ |
151 | 151 | protected function saveSubset($subset) |
152 | 152 | { |
153 | - $changes = $subset . 'Changes'; |
|
153 | + $changes = $subset.'Changes'; |
|
154 | 154 | if ($this->$changes === true) { |
155 | 155 | $json = json_encode($this->$subset, JSON_PRETTY_PRINT); |
156 | - $subsetStoragePath = $this->storagePath . DIRECTORY_SEPARATOR . $subset . '.json'; |
|
156 | + $subsetStoragePath = $this->storagePath.DIRECTORY_SEPARATOR.$subset.'.json'; |
|
157 | 157 | file_put_contents($subsetStoragePath, $json); |
158 | 158 | |
159 | 159 | $this->$changes = false; |
@@ -167,7 +167,7 @@ discard block |
||
167 | 167 | */ |
168 | 168 | protected function loadSubset($subset) |
169 | 169 | { |
170 | - $subsetStoragePath = $this->storagePath . DIRECTORY_SEPARATOR . $subset . '.json'; |
|
170 | + $subsetStoragePath = $this->storagePath.DIRECTORY_SEPARATOR.$subset.'.json'; |
|
171 | 171 | $json = file_get_contents($subsetStoragePath); |
172 | 172 | $json = json_decode($json); |
173 | 173 | $this->$subset = $json; |
@@ -215,7 +215,7 @@ discard block |
||
215 | 215 | public function getContentDbHandle() |
216 | 216 | { |
217 | 217 | if ($this->contentDbHandle === null) { |
218 | - $this->contentDbHandle = new \PDO('sqlite:' . $this->storagePath . DIRECTORY_SEPARATOR . 'content.db'); |
|
218 | + $this->contentDbHandle = new \PDO('sqlite:'.$this->storagePath.DIRECTORY_SEPARATOR.'content.db'); |
|
219 | 219 | } |
220 | 220 | return $this->contentDbHandle; |
221 | 221 | } |
@@ -231,7 +231,7 @@ discard block |
||
231 | 231 | public function getDocuments($state = 'published') |
232 | 232 | { |
233 | 233 | if (!in_array($state, Document::$DOCUMENT_STATES)) { |
234 | - throw new \Exception('Unsupported document state: ' . $state); |
|
234 | + throw new \Exception('Unsupported document state: '.$state); |
|
235 | 235 | } |
236 | 236 | return $this->getDocumentsByPath('/', $state); |
237 | 237 | } |
@@ -239,7 +239,7 @@ discard block |
||
239 | 239 | public function getDocumentsWithState($folderPath = '/') |
240 | 240 | { |
241 | 241 | $db = $this->getContentDbHandle(); |
242 | - $folderPathWithWildcard = $folderPath . '%'; |
|
242 | + $folderPathWithWildcard = $folderPath.'%'; |
|
243 | 243 | |
244 | 244 | $ifRootIndex = 1; |
245 | 245 | if ($folderPath == '/') { |
@@ -254,10 +254,10 @@ discard block |
||
254 | 254 | FROM documents_unpublished |
255 | 255 | LEFT JOIN documents_published |
256 | 256 | ON documents_published.path = documents_unpublished.path |
257 | - WHERE documents_unpublished.`path` LIKE ' . $db->quote($folderPathWithWildcard) . ' |
|
258 | - AND substr(documents_unpublished.`path`, ' . (strlen($folderPath) + $ifRootIndex + 1) . ') NOT LIKE "%/%" |
|
259 | - AND length(documents_unpublished.`path`) > ' . (strlen($folderPath) + $ifRootIndex) . ' |
|
260 | - AND documents_unpublished.path != ' . $db->quote($folderPath) . ' |
|
257 | + WHERE documents_unpublished.`path` LIKE ' . $db->quote($folderPathWithWildcard).' |
|
258 | + AND substr(documents_unpublished.`path`, ' . (strlen($folderPath) + $ifRootIndex + 1).') NOT LIKE "%/%" |
|
259 | + AND length(documents_unpublished.`path`) > ' . (strlen($folderPath) + $ifRootIndex).' |
|
260 | + AND documents_unpublished.path != ' . $db->quote($folderPath).' |
|
261 | 261 | ORDER BY documents_unpublished.`type` DESC, documents_unpublished.`path` ASC |
262 | 262 | '; |
263 | 263 | $stmt = $this->getDbStatement($sql); |
@@ -284,16 +284,16 @@ discard block |
||
284 | 284 | public function getDocumentsByPath($folderPath, $state = 'published') |
285 | 285 | { |
286 | 286 | if (!in_array($state, Document::$DOCUMENT_STATES)) { |
287 | - throw new \Exception('Unsupported document state: ' . $state); |
|
287 | + throw new \Exception('Unsupported document state: '.$state); |
|
288 | 288 | } |
289 | 289 | $db = $this->getContentDbHandle(); |
290 | - $folderPathWithWildcard = $folderPath . '%'; |
|
290 | + $folderPathWithWildcard = $folderPath.'%'; |
|
291 | 291 | |
292 | 292 | $sql = 'SELECT * |
293 | - FROM documents_' . $state . ' |
|
294 | - WHERE `path` LIKE ' . $db->quote($folderPathWithWildcard) . ' |
|
295 | - AND substr(`path`, ' . (strlen($folderPath) + 1) . ') NOT LIKE "%/%" |
|
296 | - AND path != ' . $db->quote($folderPath) . ' |
|
293 | + FROM documents_' . $state.' |
|
294 | + WHERE `path` LIKE ' . $db->quote($folderPathWithWildcard).' |
|
295 | + AND substr(`path`, ' . (strlen($folderPath) + 1).') NOT LIKE "%/%" |
|
296 | + AND path != ' . $db->quote($folderPath).' |
|
297 | 297 | ORDER BY `type` DESC, `path` ASC'; |
298 | 298 | $stmt = $this->getDbStatement($sql); |
299 | 299 | |
@@ -320,7 +320,7 @@ discard block |
||
320 | 320 | if ($containerPath === '/') { |
321 | 321 | return $this->getRootFolder(); |
322 | 322 | } |
323 | - if (substr($containerPath, -1) === '/'){ |
|
323 | + if (substr($containerPath, -1) === '/') { |
|
324 | 324 | $containerPath = substr($containerPath, 0, -1); |
325 | 325 | } |
326 | 326 | $containerFolder = $this->getDocumentByPath($containerPath, 'unpublished'); |
@@ -337,13 +337,13 @@ discard block |
||
337 | 337 | public function getDocumentByPath($path, $state = 'published') |
338 | 338 | { |
339 | 339 | if (!in_array($state, Document::$DOCUMENT_STATES)) { |
340 | - throw new \Exception('Unsupported document state: ' . $state); |
|
340 | + throw new \Exception('Unsupported document state: '.$state); |
|
341 | 341 | } |
342 | 342 | $db = $this->getContentDbHandle(); |
343 | 343 | $document = $this->fetchDocument(' |
344 | 344 | SELECT * |
345 | - FROM documents_' . $state . ' |
|
346 | - WHERE path = ' . $db->quote($path) . ' |
|
345 | + FROM documents_' . $state.' |
|
346 | + WHERE path = ' . $db->quote($path).' |
|
347 | 347 | '); |
348 | 348 | if ($document instanceof Document && $document->type === 'folder') { |
349 | 349 | $document->dbHandle = $db; |
@@ -363,16 +363,16 @@ discard block |
||
363 | 363 | public function getTotalDocumentCount($state = 'published') |
364 | 364 | { |
365 | 365 | if (!in_array($state, Document::$DOCUMENT_STATES)) { |
366 | - throw new \Exception('Unsupported document state: ' . $state); |
|
366 | + throw new \Exception('Unsupported document state: '.$state); |
|
367 | 367 | } |
368 | 368 | $db = $this->getContentDbHandle(); |
369 | 369 | $stmt = $db->query(' |
370 | 370 | SELECT count(*) |
371 | - FROM documents_' . $state . ' |
|
371 | + FROM documents_' . $state.' |
|
372 | 372 | WHERE `type` != "folder" |
373 | 373 | '); |
374 | 374 | $result = $stmt->fetch(\PDO::FETCH_ASSOC); |
375 | - if (!is_array($result )) { |
|
375 | + if (!is_array($result)) { |
|
376 | 376 | return 0; |
377 | 377 | } |
378 | 378 | return intval(current($result)); |
@@ -391,7 +391,7 @@ discard block |
||
391 | 391 | if ($stmt === false || !$stmt->execute()) { |
392 | 392 | $errorInfo = $db->errorInfo(); |
393 | 393 | $errorMsg = $errorInfo[2]; |
394 | - throw new \Exception('SQLite Exception: ' . $errorMsg . ' in SQL: <br /><pre>' . $sql . '</pre>'); |
|
394 | + throw new \Exception('SQLite Exception: '.$errorMsg.' in SQL: <br /><pre>'.$sql.'</pre>'); |
|
395 | 395 | } |
396 | 396 | return $result; |
397 | 397 | } |
@@ -401,7 +401,7 @@ discard block |
||
401 | 401 | $sql = ' |
402 | 402 | INSERT OR REPLACE INTO documents_published |
403 | 403 | (`id`,`path`,`title`,`slug`,`type`,`documentType`,`documentTypeSlug`,`state`,`lastModificationDate`,`creationDate`,`publicationDate`,`lastModifiedBy`,`fields`,`bricks`,`dynamicBricks`) |
404 | - SELECT `id`,`path`,`title`,`slug`,`type`,`documentType`,`documentTypeSlug`,"published" as state,`lastModificationDate`,`creationDate`,' . time() . ' as publicationDate, `lastModifiedBy`,`fields`,`bricks`,`dynamicBricks` |
|
404 | + SELECT `id`,`path`,`title`,`slug`,`type`,`documentType`,`documentTypeSlug`,"published" as state,`lastModificationDate`,`creationDate`,' . time().' as publicationDate, `lastModifiedBy`,`fields`,`bricks`,`dynamicBricks` |
|
405 | 405 | FROM documents_unpublished |
406 | 406 | WHERE `path` = :path |
407 | 407 | '; |
@@ -414,7 +414,7 @@ discard block |
||
414 | 414 | if ($stmt === false) { |
415 | 415 | $errorInfo = $db->errorInfo(); |
416 | 416 | $errorMsg = $errorInfo[2]; |
417 | - throw new \Exception('SQLite Exception: ' . $errorMsg . ' in SQL: <br /><pre>' . $sql . '</pre>'); |
|
417 | + throw new \Exception('SQLite Exception: '.$errorMsg.' in SQL: <br /><pre>'.$sql.'</pre>'); |
|
418 | 418 | } |
419 | 419 | $stmt->bindValue(':path', $path); |
420 | 420 | $stmt->execute(); |
@@ -481,7 +481,7 @@ discard block |
||
481 | 481 | if ($stmt === false) { |
482 | 482 | $errorInfo = $db->errorInfo(); |
483 | 483 | $errorMsg = $errorInfo[2]; |
484 | - throw new \Exception('SQLite Exception: ' . $errorMsg . ' in SQL: <br /><pre>' . $sql . '</pre>'); |
|
484 | + throw new \Exception('SQLite Exception: '.$errorMsg.' in SQL: <br /><pre>'.$sql.'</pre>'); |
|
485 | 485 | } |
486 | 486 | return $stmt; |
487 | 487 | } |
@@ -511,25 +511,25 @@ discard block |
||
511 | 511 | public function saveDocument($documentObject, $state = 'published') |
512 | 512 | { |
513 | 513 | if (!in_array($state, Document::$DOCUMENT_STATES)) { |
514 | - throw new \Exception('Unsupported document state: ' . $state); |
|
514 | + throw new \Exception('Unsupported document state: '.$state); |
|
515 | 515 | } |
516 | 516 | $db = $this->getContentDbHandle(); |
517 | 517 | $stmt = $this->getDbStatement(' |
518 | - INSERT OR REPLACE INTO documents_' . $state . ' (`path`,`title`,`slug`,`type`,`documentType`,`documentTypeSlug`,`state`,`lastModificationDate`,`creationDate`,`lastModifiedBy`,`fields`,`bricks`,`dynamicBricks`) |
|
518 | + INSERT OR REPLACE INTO documents_' . $state.' (`path`,`title`,`slug`,`type`,`documentType`,`documentTypeSlug`,`state`,`lastModificationDate`,`creationDate`,`lastModifiedBy`,`fields`,`bricks`,`dynamicBricks`) |
|
519 | 519 | VALUES( |
520 | - ' . $db->quote($documentObject->path) . ', |
|
521 | - ' . $db->quote($documentObject->title) . ', |
|
522 | - ' . $db->quote($documentObject->slug) . ', |
|
523 | - ' . $db->quote($documentObject->type) . ', |
|
524 | - ' . $db->quote($documentObject->documentType) . ', |
|
525 | - ' . $db->quote($documentObject->documentTypeSlug) . ', |
|
526 | - ' . $db->quote($documentObject->state) . ', |
|
527 | - ' . $db->quote($documentObject->lastModificationDate) . ', |
|
528 | - ' . $db->quote($documentObject->creationDate) . ', |
|
529 | - ' . $db->quote($documentObject->lastModifiedBy) . ', |
|
530 | - ' . $db->quote(json_encode($documentObject->fields)) . ', |
|
531 | - ' . $db->quote(json_encode($documentObject->bricks)) . ', |
|
532 | - ' . $db->quote(json_encode($documentObject->dynamicBricks)) . ' |
|
520 | + ' . $db->quote($documentObject->path).', |
|
521 | + ' . $db->quote($documentObject->title).', |
|
522 | + ' . $db->quote($documentObject->slug).', |
|
523 | + ' . $db->quote($documentObject->type).', |
|
524 | + ' . $db->quote($documentObject->documentType).', |
|
525 | + ' . $db->quote($documentObject->documentTypeSlug).', |
|
526 | + ' . $db->quote($documentObject->state).', |
|
527 | + ' . $db->quote($documentObject->lastModificationDate).', |
|
528 | + ' . $db->quote($documentObject->creationDate).', |
|
529 | + ' . $db->quote($documentObject->lastModifiedBy).', |
|
530 | + ' . $db->quote(json_encode($documentObject->fields)).', |
|
531 | + ' . $db->quote(json_encode($documentObject->bricks)).', |
|
532 | + ' . $db->quote(json_encode($documentObject->dynamicBricks)).' |
|
533 | 533 | ) |
534 | 534 | '); |
535 | 535 | $result = $stmt->execute(); |
@@ -553,16 +553,16 @@ discard block |
||
553 | 553 | if ($documentToDelete->type == 'document') { |
554 | 554 | $stmt = $this->getDbStatement(' |
555 | 555 | DELETE FROM documents_unpublished |
556 | - WHERE path = ' . $db->quote($path) . ' |
|
556 | + WHERE path = ' . $db->quote($path).' |
|
557 | 557 | '); |
558 | 558 | $stmt->execute(); |
559 | 559 | } elseif ($documentToDelete->type == 'folder') { |
560 | - $folderPathWithWildcard = $path . '%'; |
|
560 | + $folderPathWithWildcard = $path.'%'; |
|
561 | 561 | $stmt = $this->getDbStatement(' |
562 | 562 | DELETE FROM documents_unpublished |
563 | - WHERE (path LIKE ' . $db->quote($folderPathWithWildcard) . ' |
|
564 | - AND substr(`path`, ' . (strlen($path) + 1) . ', 1) = "/") |
|
565 | - OR path = ' . $db->quote($path) . ' |
|
563 | + WHERE (path LIKE ' . $db->quote($folderPathWithWildcard).' |
|
564 | + AND substr(`path`, ' . (strlen($path) + 1).', 1) = "/") |
|
565 | + OR path = ' . $db->quote($path).' |
|
566 | 566 | '); |
567 | 567 | $stmt->execute(); |
568 | 568 | } |
@@ -22,138 +22,138 @@ discard block |
||
22 | 22 | */ |
23 | 23 | class Repository |
24 | 24 | { |
25 | - protected $storagePath; |
|
26 | - |
|
27 | - protected $fileBasedSubsets = array('sitemap', 'applicationComponents', 'documentTypes', 'bricks', 'imageSet', 'images', 'files', 'users', 'valuelists'); |
|
28 | - |
|
29 | - protected $sitemap; |
|
30 | - protected $sitemapChanges = false; |
|
31 | - |
|
32 | - protected $applicationComponents; |
|
33 | - protected $applicationComponentsChanges = false; |
|
34 | - |
|
35 | - protected $documentTypes; |
|
36 | - protected $documentTypesChanges = false; |
|
37 | - |
|
38 | - protected $bricks; |
|
39 | - protected $bricksChanges = false; |
|
40 | - |
|
41 | - protected $imageSet; |
|
42 | - protected $imageSetChanges = false; |
|
43 | - |
|
44 | - protected $images; |
|
45 | - protected $imagesChanges = false; |
|
46 | - |
|
47 | - protected $files; |
|
48 | - protected $filesChanges = false; |
|
49 | - |
|
50 | - protected $users; |
|
51 | - protected $usersChanges = false; |
|
52 | - |
|
53 | - protected $valuelists; |
|
54 | - protected $valuelistsChanges = false; |
|
55 | - |
|
56 | - protected $contentDbHandle; |
|
57 | - |
|
58 | - |
|
59 | - /** |
|
60 | - * Repository constructor. |
|
61 | - * @param $storagePath |
|
62 | - * @throws \Exception |
|
63 | - */ |
|
64 | - public function __construct($storagePath) |
|
65 | - { |
|
66 | - $storagePath = realpath($storagePath); |
|
67 | - if (is_dir($storagePath) && $storagePath !== false) { |
|
68 | - $this->storagePath = $storagePath; |
|
69 | - } else { |
|
70 | - throw new \Exception('Repository not yet initialized.'); |
|
71 | - } |
|
72 | - } |
|
73 | - |
|
74 | - /** |
|
75 | - * Creates the folder in which to create all storage related files |
|
76 | - * |
|
77 | - * @param $storagePath |
|
78 | - * @return bool |
|
79 | - */ |
|
80 | - public static function create($storagePath) |
|
81 | - { |
|
82 | - return mkdir($storagePath); |
|
83 | - } |
|
84 | - |
|
85 | - /** |
|
86 | - * Initiates default storage |
|
87 | - * @throws \Exception |
|
88 | - */ |
|
89 | - public function init() |
|
90 | - { |
|
91 | - $storageDefaultPath = realpath('../library/cc/install/_storage.json'); |
|
92 | - $contentSqlPath = realpath('../library/cc/install/content.sql'); |
|
93 | - |
|
94 | - $this->initConfigStorage($storageDefaultPath); |
|
95 | - $this->initContentDb($contentSqlPath); |
|
96 | - |
|
97 | - $this->save(); |
|
98 | - } |
|
99 | - |
|
100 | - /** |
|
101 | - * Load filebased subset and return it's contents |
|
102 | - * |
|
103 | - * @param $name |
|
104 | - * @return mixed|string |
|
105 | - * @throws \Exception |
|
106 | - */ |
|
107 | - public function __get($name) |
|
108 | - { |
|
109 | - if (isset($this->$name)) { |
|
110 | - if (in_array($name, $this->fileBasedSubsets)) { |
|
111 | - return $this->$name; |
|
112 | - } else { |
|
113 | - throw new \Exception('Trying to get undefined property from Repository: ' . $name); |
|
114 | - } |
|
115 | - } else { |
|
116 | - if (in_array($name, $this->fileBasedSubsets)) { |
|
117 | - return $this->loadSubset($name); |
|
118 | - } else { |
|
119 | - throw new \Exception('Trying to get undefined property from Repository: ' . $name); |
|
120 | - } |
|
121 | - } |
|
122 | - } |
|
123 | - |
|
124 | - /** |
|
125 | - * Set filebased subset contents |
|
126 | - * @param $name |
|
127 | - * @param $value |
|
128 | - * @throws \Exception |
|
129 | - */ |
|
130 | - public function __set($name, $value) |
|
131 | - { |
|
132 | - if (in_array($name, $this->fileBasedSubsets)) { |
|
133 | - $this->$name = $value; |
|
134 | - $changes = $name . 'Changes'; |
|
135 | - $this->$changes = true; |
|
136 | - } else { |
|
137 | - throw new \Exception('Trying to persist unknown subset in repository: ' . $name . ' <br /><pre>' . print_r($value, true) . '</pre>'); |
|
138 | - } |
|
139 | - } |
|
140 | - |
|
141 | - /** |
|
142 | - * Persist all subsets |
|
143 | - */ |
|
144 | - public function save() |
|
145 | - { |
|
146 | - array_map(function ($value) { |
|
147 | - $this->saveSubset($value); |
|
25 | + protected $storagePath; |
|
26 | + |
|
27 | + protected $fileBasedSubsets = array('sitemap', 'applicationComponents', 'documentTypes', 'bricks', 'imageSet', 'images', 'files', 'users', 'valuelists'); |
|
28 | + |
|
29 | + protected $sitemap; |
|
30 | + protected $sitemapChanges = false; |
|
31 | + |
|
32 | + protected $applicationComponents; |
|
33 | + protected $applicationComponentsChanges = false; |
|
34 | + |
|
35 | + protected $documentTypes; |
|
36 | + protected $documentTypesChanges = false; |
|
37 | + |
|
38 | + protected $bricks; |
|
39 | + protected $bricksChanges = false; |
|
40 | + |
|
41 | + protected $imageSet; |
|
42 | + protected $imageSetChanges = false; |
|
43 | + |
|
44 | + protected $images; |
|
45 | + protected $imagesChanges = false; |
|
46 | + |
|
47 | + protected $files; |
|
48 | + protected $filesChanges = false; |
|
49 | + |
|
50 | + protected $users; |
|
51 | + protected $usersChanges = false; |
|
52 | + |
|
53 | + protected $valuelists; |
|
54 | + protected $valuelistsChanges = false; |
|
55 | + |
|
56 | + protected $contentDbHandle; |
|
57 | + |
|
58 | + |
|
59 | + /** |
|
60 | + * Repository constructor. |
|
61 | + * @param $storagePath |
|
62 | + * @throws \Exception |
|
63 | + */ |
|
64 | + public function __construct($storagePath) |
|
65 | + { |
|
66 | + $storagePath = realpath($storagePath); |
|
67 | + if (is_dir($storagePath) && $storagePath !== false) { |
|
68 | + $this->storagePath = $storagePath; |
|
69 | + } else { |
|
70 | + throw new \Exception('Repository not yet initialized.'); |
|
71 | + } |
|
72 | + } |
|
73 | + |
|
74 | + /** |
|
75 | + * Creates the folder in which to create all storage related files |
|
76 | + * |
|
77 | + * @param $storagePath |
|
78 | + * @return bool |
|
79 | + */ |
|
80 | + public static function create($storagePath) |
|
81 | + { |
|
82 | + return mkdir($storagePath); |
|
83 | + } |
|
84 | + |
|
85 | + /** |
|
86 | + * Initiates default storage |
|
87 | + * @throws \Exception |
|
88 | + */ |
|
89 | + public function init() |
|
90 | + { |
|
91 | + $storageDefaultPath = realpath('../library/cc/install/_storage.json'); |
|
92 | + $contentSqlPath = realpath('../library/cc/install/content.sql'); |
|
93 | + |
|
94 | + $this->initConfigStorage($storageDefaultPath); |
|
95 | + $this->initContentDb($contentSqlPath); |
|
96 | + |
|
97 | + $this->save(); |
|
98 | + } |
|
99 | + |
|
100 | + /** |
|
101 | + * Load filebased subset and return it's contents |
|
102 | + * |
|
103 | + * @param $name |
|
104 | + * @return mixed|string |
|
105 | + * @throws \Exception |
|
106 | + */ |
|
107 | + public function __get($name) |
|
108 | + { |
|
109 | + if (isset($this->$name)) { |
|
110 | + if (in_array($name, $this->fileBasedSubsets)) { |
|
111 | + return $this->$name; |
|
112 | + } else { |
|
113 | + throw new \Exception('Trying to get undefined property from Repository: ' . $name); |
|
114 | + } |
|
115 | + } else { |
|
116 | + if (in_array($name, $this->fileBasedSubsets)) { |
|
117 | + return $this->loadSubset($name); |
|
118 | + } else { |
|
119 | + throw new \Exception('Trying to get undefined property from Repository: ' . $name); |
|
120 | + } |
|
121 | + } |
|
122 | + } |
|
123 | + |
|
124 | + /** |
|
125 | + * Set filebased subset contents |
|
126 | + * @param $name |
|
127 | + * @param $value |
|
128 | + * @throws \Exception |
|
129 | + */ |
|
130 | + public function __set($name, $value) |
|
131 | + { |
|
132 | + if (in_array($name, $this->fileBasedSubsets)) { |
|
133 | + $this->$name = $value; |
|
134 | + $changes = $name . 'Changes'; |
|
135 | + $this->$changes = true; |
|
136 | + } else { |
|
137 | + throw new \Exception('Trying to persist unknown subset in repository: ' . $name . ' <br /><pre>' . print_r($value, true) . '</pre>'); |
|
138 | + } |
|
139 | + } |
|
140 | + |
|
141 | + /** |
|
142 | + * Persist all subsets |
|
143 | + */ |
|
144 | + public function save() |
|
145 | + { |
|
146 | + array_map(function ($value) { |
|
147 | + $this->saveSubset($value); |
|
148 | 148 | }, $this->fileBasedSubsets); |
149 | - } |
|
150 | - |
|
151 | - /** |
|
152 | - * Persist subset to disk |
|
153 | - * @param $subset |
|
154 | - */ |
|
155 | - protected function saveSubset($subset) |
|
156 | - { |
|
149 | + } |
|
150 | + |
|
151 | + /** |
|
152 | + * Persist subset to disk |
|
153 | + * @param $subset |
|
154 | + */ |
|
155 | + protected function saveSubset($subset) |
|
156 | + { |
|
157 | 157 | $changes = $subset . 'Changes'; |
158 | 158 | if ($this->$changes === true) { |
159 | 159 | $json = json_encode($this->$subset, JSON_PRETTY_PRINT); |
@@ -162,69 +162,69 @@ discard block |
||
162 | 162 | |
163 | 163 | $this->$changes = false; |
164 | 164 | } |
165 | - } |
|
166 | - |
|
167 | - /** |
|
168 | - * Load subset from disk |
|
169 | - * @param $subset |
|
170 | - * @return mixed|string |
|
171 | - */ |
|
172 | - protected function loadSubset($subset) |
|
173 | - { |
|
174 | - $subsetStoragePath = $this->storagePath . DIRECTORY_SEPARATOR . $subset . '.json'; |
|
175 | - $json = file_get_contents($subsetStoragePath); |
|
176 | - $json = json_decode($json); |
|
177 | - $this->$subset = $json; |
|
178 | - return $json; |
|
179 | - } |
|
180 | - |
|
181 | - /** |
|
182 | - * @param $contentSqlPath |
|
183 | - */ |
|
184 | - protected function initContentDb($contentSqlPath) |
|
185 | - { |
|
186 | - $db = $this->getContentDbHandle(); |
|
187 | - $sql = file_get_contents($contentSqlPath); |
|
188 | - $db->exec($sql); |
|
189 | - } |
|
190 | - |
|
191 | - /** |
|
192 | - * @param $storageDefaultPath |
|
193 | - */ |
|
194 | - protected function initConfigStorage($storageDefaultPath) |
|
195 | - { |
|
196 | - $json = file_get_contents($storageDefaultPath); |
|
197 | - $json = json_decode($json); |
|
198 | - $this->sitemap = $json->sitemap; |
|
199 | - $this->sitemapChanges = true; |
|
200 | - $this->applicationComponents = $json->applicationComponents; |
|
201 | - $this->applicationComponentsChanges = true; |
|
202 | - $this->documentTypes = $json->documentTypes; |
|
203 | - $this->documentTypesChanges = true; |
|
204 | - $this->bricks = $json->bricks; |
|
205 | - $this->bricksChanges = true; |
|
206 | - $this->imageSet = $json->imageSet; |
|
207 | - $this->imageSetChanges = true; |
|
208 | - $this->images = $json->images; |
|
209 | - $this->imagesChanges = true; |
|
210 | - $this->files = $json->files; |
|
211 | - $this->filesChanges = true; |
|
212 | - $this->users = $json->users; |
|
213 | - $this->usersChanges = true; |
|
214 | - $this->valuelists = $json->valuelists; |
|
215 | - $this->valuelistsChanges = true; |
|
216 | - } |
|
217 | - |
|
218 | - /** |
|
219 | - * @return \PDO |
|
220 | - */ |
|
221 | - public function getContentDbHandle() |
|
222 | - { |
|
223 | - if ($this->contentDbHandle === null) { |
|
224 | - $this->contentDbHandle = new \PDO('sqlite:' . $this->storagePath . DIRECTORY_SEPARATOR . 'content.db'); |
|
225 | - } |
|
226 | - return $this->contentDbHandle; |
|
227 | - } |
|
165 | + } |
|
166 | + |
|
167 | + /** |
|
168 | + * Load subset from disk |
|
169 | + * @param $subset |
|
170 | + * @return mixed|string |
|
171 | + */ |
|
172 | + protected function loadSubset($subset) |
|
173 | + { |
|
174 | + $subsetStoragePath = $this->storagePath . DIRECTORY_SEPARATOR . $subset . '.json'; |
|
175 | + $json = file_get_contents($subsetStoragePath); |
|
176 | + $json = json_decode($json); |
|
177 | + $this->$subset = $json; |
|
178 | + return $json; |
|
179 | + } |
|
180 | + |
|
181 | + /** |
|
182 | + * @param $contentSqlPath |
|
183 | + */ |
|
184 | + protected function initContentDb($contentSqlPath) |
|
185 | + { |
|
186 | + $db = $this->getContentDbHandle(); |
|
187 | + $sql = file_get_contents($contentSqlPath); |
|
188 | + $db->exec($sql); |
|
189 | + } |
|
190 | + |
|
191 | + /** |
|
192 | + * @param $storageDefaultPath |
|
193 | + */ |
|
194 | + protected function initConfigStorage($storageDefaultPath) |
|
195 | + { |
|
196 | + $json = file_get_contents($storageDefaultPath); |
|
197 | + $json = json_decode($json); |
|
198 | + $this->sitemap = $json->sitemap; |
|
199 | + $this->sitemapChanges = true; |
|
200 | + $this->applicationComponents = $json->applicationComponents; |
|
201 | + $this->applicationComponentsChanges = true; |
|
202 | + $this->documentTypes = $json->documentTypes; |
|
203 | + $this->documentTypesChanges = true; |
|
204 | + $this->bricks = $json->bricks; |
|
205 | + $this->bricksChanges = true; |
|
206 | + $this->imageSet = $json->imageSet; |
|
207 | + $this->imageSetChanges = true; |
|
208 | + $this->images = $json->images; |
|
209 | + $this->imagesChanges = true; |
|
210 | + $this->files = $json->files; |
|
211 | + $this->filesChanges = true; |
|
212 | + $this->users = $json->users; |
|
213 | + $this->usersChanges = true; |
|
214 | + $this->valuelists = $json->valuelists; |
|
215 | + $this->valuelistsChanges = true; |
|
216 | + } |
|
217 | + |
|
218 | + /** |
|
219 | + * @return \PDO |
|
220 | + */ |
|
221 | + public function getContentDbHandle() |
|
222 | + { |
|
223 | + if ($this->contentDbHandle === null) { |
|
224 | + $this->contentDbHandle = new \PDO('sqlite:' . $this->storagePath . DIRECTORY_SEPARATOR . 'content.db'); |
|
225 | + } |
|
226 | + return $this->contentDbHandle; |
|
227 | + } |
|
228 | 228 | |
229 | 229 | /** |
230 | 230 | * Get all documents |
@@ -234,13 +234,13 @@ discard block |
||
234 | 234 | * @return array |
235 | 235 | * @throws \Exception |
236 | 236 | */ |
237 | - public function getDocuments($state = 'published') |
|
238 | - { |
|
237 | + public function getDocuments($state = 'published') |
|
238 | + { |
|
239 | 239 | if (!in_array($state, Document::$DOCUMENT_STATES)) { |
240 | 240 | throw new \Exception('Unsupported document state: ' . $state); |
241 | 241 | } |
242 | - return $this->getDocumentsByPath('/', $state); |
|
243 | - } |
|
242 | + return $this->getDocumentsByPath('/', $state); |
|
243 | + } |
|
244 | 244 | |
245 | 245 | public function getDocumentsWithState($folderPath = '/') |
246 | 246 | { |
@@ -287,51 +287,51 @@ discard block |
||
287 | 287 | * @return array |
288 | 288 | * @throws \Exception |
289 | 289 | */ |
290 | - public function getDocumentsByPath($folderPath, $state = 'published') |
|
291 | - { |
|
292 | - if (!in_array($state, Document::$DOCUMENT_STATES)) { |
|
293 | - throw new \Exception('Unsupported document state: ' . $state); |
|
290 | + public function getDocumentsByPath($folderPath, $state = 'published') |
|
291 | + { |
|
292 | + if (!in_array($state, Document::$DOCUMENT_STATES)) { |
|
293 | + throw new \Exception('Unsupported document state: ' . $state); |
|
294 | 294 | } |
295 | - $db = $this->getContentDbHandle(); |
|
296 | - $folderPathWithWildcard = $folderPath . '%'; |
|
295 | + $db = $this->getContentDbHandle(); |
|
296 | + $folderPathWithWildcard = $folderPath . '%'; |
|
297 | 297 | |
298 | - $sql = 'SELECT * |
|
298 | + $sql = 'SELECT * |
|
299 | 299 | FROM documents_' . $state . ' |
300 | 300 | WHERE `path` LIKE ' . $db->quote($folderPathWithWildcard) . ' |
301 | 301 | AND substr(`path`, ' . (strlen($folderPath) + 1) . ') NOT LIKE "%/%" |
302 | 302 | AND path != ' . $db->quote($folderPath) . ' |
303 | 303 | ORDER BY `type` DESC, `path` ASC'; |
304 | - $stmt = $this->getDbStatement($sql); |
|
304 | + $stmt = $this->getDbStatement($sql); |
|
305 | 305 | |
306 | - $documents = $stmt->fetchAll(\PDO::FETCH_CLASS, '\library\storage\Document'); |
|
307 | - foreach ($documents as $key => $document) { |
|
306 | + $documents = $stmt->fetchAll(\PDO::FETCH_CLASS, '\library\storage\Document'); |
|
307 | + foreach ($documents as $key => $document) { |
|
308 | 308 | $documents = $this->setAssetsToDocumentFolders($document, $db, $documents, $key); |
309 | - } |
|
310 | - return $documents; |
|
311 | - } |
|
312 | - |
|
313 | - |
|
314 | - /** |
|
315 | - * @param $path |
|
316 | - * @return bool|Document |
|
317 | - */ |
|
318 | - public function getDocumentContainerByPath($path) |
|
319 | - { |
|
320 | - $document = $this->getDocumentByPath($path, 'unpublished'); |
|
321 | - if ($document === false) { |
|
322 | - return false; |
|
323 | - } |
|
324 | - $slugLength = strlen($document->slug); |
|
325 | - $containerPath = substr($path, 0, -$slugLength); |
|
326 | - if ($containerPath === '/') { |
|
327 | - return $this->getRootFolder(); |
|
328 | - } |
|
329 | - if (substr($containerPath, -1) === '/'){ |
|
309 | + } |
|
310 | + return $documents; |
|
311 | + } |
|
312 | + |
|
313 | + |
|
314 | + /** |
|
315 | + * @param $path |
|
316 | + * @return bool|Document |
|
317 | + */ |
|
318 | + public function getDocumentContainerByPath($path) |
|
319 | + { |
|
320 | + $document = $this->getDocumentByPath($path, 'unpublished'); |
|
321 | + if ($document === false) { |
|
322 | + return false; |
|
323 | + } |
|
324 | + $slugLength = strlen($document->slug); |
|
325 | + $containerPath = substr($path, 0, -$slugLength); |
|
326 | + if ($containerPath === '/') { |
|
327 | + return $this->getRootFolder(); |
|
328 | + } |
|
329 | + if (substr($containerPath, -1) === '/'){ |
|
330 | 330 | $containerPath = substr($containerPath, 0, -1); |
331 | 331 | } |
332 | - $containerFolder = $this->getDocumentByPath($containerPath, 'unpublished'); |
|
333 | - return $containerFolder; |
|
334 | - } |
|
332 | + $containerFolder = $this->getDocumentByPath($containerPath, 'unpublished'); |
|
333 | + return $containerFolder; |
|
334 | + } |
|
335 | 335 | |
336 | 336 | /** |
337 | 337 | * @param $path |
@@ -340,23 +340,23 @@ discard block |
||
340 | 340 | * @return bool|\library\storage\Document |
341 | 341 | * @throws \Exception |
342 | 342 | */ |
343 | - public function getDocumentByPath($path, $state = 'published') |
|
344 | - { |
|
343 | + public function getDocumentByPath($path, $state = 'published') |
|
344 | + { |
|
345 | 345 | if (!in_array($state, Document::$DOCUMENT_STATES)) { |
346 | 346 | throw new \Exception('Unsupported document state: ' . $state); |
347 | 347 | } |
348 | - $db = $this->getContentDbHandle(); |
|
349 | - $document = $this->fetchDocument(' |
|
348 | + $db = $this->getContentDbHandle(); |
|
349 | + $document = $this->fetchDocument(' |
|
350 | 350 | SELECT * |
351 | 351 | FROM documents_' . $state . ' |
352 | 352 | WHERE path = ' . $db->quote($path) . ' |
353 | 353 | '); |
354 | - if ($document instanceof Document && $document->type === 'folder') { |
|
355 | - $document->dbHandle = $db; |
|
356 | - $document->documentStorage = new DocumentStorage($this); |
|
357 | - } |
|
358 | - return $document; |
|
359 | - } |
|
354 | + if ($document instanceof Document && $document->type === 'folder') { |
|
355 | + $document->dbHandle = $db; |
|
356 | + $document->documentStorage = new DocumentStorage($this); |
|
357 | + } |
|
358 | + return $document; |
|
359 | + } |
|
360 | 360 | |
361 | 361 | /** |
362 | 362 | * Returns the count of all documents stored in the db |
@@ -451,58 +451,58 @@ discard block |
||
451 | 451 | } |
452 | 452 | |
453 | 453 | /** |
454 | - * Return the results of the query as array of Documents |
|
455 | - * @param $sql |
|
456 | - * @return array |
|
457 | - * @throws \Exception |
|
458 | - */ |
|
459 | - protected function fetchAllDocuments($sql) |
|
460 | - { |
|
461 | - $stmt = $this->getDbStatement($sql); |
|
462 | - return $stmt->fetchAll(\PDO::FETCH_CLASS, '\library\storage\Document'); |
|
463 | - } |
|
464 | - |
|
465 | - /** |
|
466 | - * Return the result of the query as Document |
|
467 | - * @param $sql |
|
468 | - * @return mixed |
|
469 | - * @throws \Exception |
|
470 | - */ |
|
471 | - protected function fetchDocument($sql) |
|
472 | - { |
|
473 | - $stmt = $this->getDbStatement($sql); |
|
474 | - return $stmt->fetchObject('\library\storage\Document'); |
|
475 | - } |
|
476 | - |
|
477 | - /** |
|
478 | - * Prepare the sql statement |
|
479 | - * @param $sql |
|
480 | - * @return \PDOStatement |
|
481 | - * @throws \Exception |
|
482 | - */ |
|
483 | - protected function getDbStatement($sql) |
|
484 | - { |
|
485 | - $db = $this->getContentDbHandle(); |
|
486 | - $stmt = $db->query($sql); |
|
487 | - if ($stmt === false) { |
|
488 | - $errorInfo = $db->errorInfo(); |
|
489 | - $errorMsg = $errorInfo[2]; |
|
490 | - throw new \Exception('SQLite Exception: ' . $errorMsg . ' in SQL: <br /><pre>' . $sql . '</pre>'); |
|
491 | - } |
|
492 | - return $stmt; |
|
493 | - } |
|
494 | - |
|
495 | - /** |
|
496 | - * Create a (non-existent) root folder Document and return it |
|
497 | - * @return Document |
|
498 | - */ |
|
499 | - protected function getRootFolder() |
|
500 | - { |
|
501 | - $rootFolder = new Document(); |
|
502 | - $rootFolder->path = '/'; |
|
503 | - $rootFolder->type = 'folder'; |
|
504 | - return $rootFolder; |
|
505 | - } |
|
454 | + * Return the results of the query as array of Documents |
|
455 | + * @param $sql |
|
456 | + * @return array |
|
457 | + * @throws \Exception |
|
458 | + */ |
|
459 | + protected function fetchAllDocuments($sql) |
|
460 | + { |
|
461 | + $stmt = $this->getDbStatement($sql); |
|
462 | + return $stmt->fetchAll(\PDO::FETCH_CLASS, '\library\storage\Document'); |
|
463 | + } |
|
464 | + |
|
465 | + /** |
|
466 | + * Return the result of the query as Document |
|
467 | + * @param $sql |
|
468 | + * @return mixed |
|
469 | + * @throws \Exception |
|
470 | + */ |
|
471 | + protected function fetchDocument($sql) |
|
472 | + { |
|
473 | + $stmt = $this->getDbStatement($sql); |
|
474 | + return $stmt->fetchObject('\library\storage\Document'); |
|
475 | + } |
|
476 | + |
|
477 | + /** |
|
478 | + * Prepare the sql statement |
|
479 | + * @param $sql |
|
480 | + * @return \PDOStatement |
|
481 | + * @throws \Exception |
|
482 | + */ |
|
483 | + protected function getDbStatement($sql) |
|
484 | + { |
|
485 | + $db = $this->getContentDbHandle(); |
|
486 | + $stmt = $db->query($sql); |
|
487 | + if ($stmt === false) { |
|
488 | + $errorInfo = $db->errorInfo(); |
|
489 | + $errorMsg = $errorInfo[2]; |
|
490 | + throw new \Exception('SQLite Exception: ' . $errorMsg . ' in SQL: <br /><pre>' . $sql . '</pre>'); |
|
491 | + } |
|
492 | + return $stmt; |
|
493 | + } |
|
494 | + |
|
495 | + /** |
|
496 | + * Create a (non-existent) root folder Document and return it |
|
497 | + * @return Document |
|
498 | + */ |
|
499 | + protected function getRootFolder() |
|
500 | + { |
|
501 | + $rootFolder = new Document(); |
|
502 | + $rootFolder->path = '/'; |
|
503 | + $rootFolder->type = 'folder'; |
|
504 | + return $rootFolder; |
|
505 | + } |
|
506 | 506 | |
507 | 507 | /** |
508 | 508 | * Save the document to the database |
@@ -514,13 +514,13 @@ discard block |
||
514 | 514 | * @throws \Exception |
515 | 515 | * @internal param $path |
516 | 516 | */ |
517 | - public function saveDocument($documentObject, $state = 'published') |
|
518 | - { |
|
517 | + public function saveDocument($documentObject, $state = 'published') |
|
518 | + { |
|
519 | 519 | if (!in_array($state, Document::$DOCUMENT_STATES)) { |
520 | 520 | throw new \Exception('Unsupported document state: ' . $state); |
521 | 521 | } |
522 | - $db = $this->getContentDbHandle(); |
|
523 | - $stmt = $this->getDbStatement(' |
|
522 | + $db = $this->getContentDbHandle(); |
|
523 | + $stmt = $this->getDbStatement(' |
|
524 | 524 | INSERT OR REPLACE INTO documents_' . $state . ' (`path`,`title`,`slug`,`type`,`documentType`,`documentTypeSlug`,`state`,`lastModificationDate`,`creationDate`,`lastModifiedBy`,`fields`,`bricks`,`dynamicBricks`) |
525 | 525 | VALUES( |
526 | 526 | ' . $db->quote($documentObject->path) . ', |
@@ -538,9 +538,9 @@ discard block |
||
538 | 538 | ' . $db->quote(json_encode($documentObject->dynamicBricks)) . ' |
539 | 539 | ) |
540 | 540 | '); |
541 | - $result = $stmt->execute(); |
|
542 | - return $result; |
|
543 | - } |
|
541 | + $result = $stmt->execute(); |
|
542 | + return $result; |
|
543 | + } |
|
544 | 544 | |
545 | 545 | /** |
546 | 546 | * Delete the document from the database |
@@ -551,29 +551,29 @@ discard block |
||
551 | 551 | * @internal param string $state |
552 | 552 | * |
553 | 553 | */ |
554 | - public function deleteDocumentByPath($path) |
|
555 | - { |
|
556 | - $db = $this->getContentDbHandle(); |
|
557 | - $documentToDelete = $this->getDocumentByPath($path, 'unpublished'); |
|
558 | - if ($documentToDelete instanceof Document) { |
|
559 | - if ($documentToDelete->type == 'document') { |
|
560 | - $stmt = $this->getDbStatement(' |
|
554 | + public function deleteDocumentByPath($path) |
|
555 | + { |
|
556 | + $db = $this->getContentDbHandle(); |
|
557 | + $documentToDelete = $this->getDocumentByPath($path, 'unpublished'); |
|
558 | + if ($documentToDelete instanceof Document) { |
|
559 | + if ($documentToDelete->type == 'document') { |
|
560 | + $stmt = $this->getDbStatement(' |
|
561 | 561 | DELETE FROM documents_unpublished |
562 | 562 | WHERE path = ' . $db->quote($path) . ' |
563 | 563 | '); |
564 | - $stmt->execute(); |
|
565 | - } elseif ($documentToDelete->type == 'folder') { |
|
566 | - $folderPathWithWildcard = $path . '%'; |
|
567 | - $stmt = $this->getDbStatement(' |
|
564 | + $stmt->execute(); |
|
565 | + } elseif ($documentToDelete->type == 'folder') { |
|
566 | + $folderPathWithWildcard = $path . '%'; |
|
567 | + $stmt = $this->getDbStatement(' |
|
568 | 568 | DELETE FROM documents_unpublished |
569 | 569 | WHERE (path LIKE ' . $db->quote($folderPathWithWildcard) . ' |
570 | 570 | AND substr(`path`, ' . (strlen($path) + 1) . ', 1) = "/") |
571 | 571 | OR path = ' . $db->quote($path) . ' |
572 | 572 | '); |
573 | - $stmt->execute(); |
|
574 | - } |
|
575 | - } |
|
576 | - } |
|
573 | + $stmt->execute(); |
|
574 | + } |
|
575 | + } |
|
576 | + } |
|
577 | 577 | |
578 | 578 | /** |
579 | 579 | * @param $document |
@@ -5,10 +5,10 @@ discard block |
||
5 | 5 | * @param string $slugPrefix |
6 | 6 | * @param bool $root |
7 | 7 | */ |
8 | -function renderFolder($document, $cmsPrefix, $slugPrefix ='', $root = false) {?> |
|
8 | +function renderFolder($document, $cmsPrefix, $slugPrefix = '', $root = false) {?> |
|
9 | 9 | <div class="grid-box-8"> |
10 | 10 | <h3> |
11 | - <a class="btn documentTitle openFolder" data-slug="<?=$slugPrefix . $document->slug?>" title="Open"> |
|
11 | + <a class="btn documentTitle openFolder" data-slug="<?=$slugPrefix.$document->slug?>" title="Open"> |
|
12 | 12 | <i class="fa fa-folder-o "></i> <?=$document->title?> |
13 | 13 | </a> |
14 | 14 | </h3> |
@@ -16,21 +16,21 @@ discard block |
||
16 | 16 | <div class="documentActions grid-box-4"> |
17 | 17 | <?renderAction('Edit', |
18 | 18 | '', |
19 | - \library\cc\Request::$subfolders . $cmsPrefix . '/documents/edit-folder?slug=' . $slugPrefix . $document->slug, |
|
20 | - 'pencil');?> |
|
19 | + \library\cc\Request::$subfolders.$cmsPrefix.'/documents/edit-folder?slug='.$slugPrefix.$document->slug, |
|
20 | + 'pencil'); ?> |
|
21 | 21 | <?renderAction('Delete', |
22 | 22 | 'error', |
23 | - \library\cc\Request::$subfolders . $cmsPrefix . '/documents/delete-folder?slug=' . $slugPrefix . $document->slug, |
|
23 | + \library\cc\Request::$subfolders.$cmsPrefix.'/documents/delete-folder?slug='.$slugPrefix.$document->slug, |
|
24 | 24 | 'trash', |
25 | - 'return confirm(\'Are you sure you want to delete this document?\');');?> |
|
25 | + 'return confirm(\'Are you sure you want to delete this document?\');'); ?> |
|
26 | 26 | </div> |
27 | 27 | <ul class="documents grid-wrapper nested<?=$root ? ' root' : '' ?>"> |
28 | 28 | <? foreach ($document->content as $subDocument) : ?> |
29 | 29 | <li class="grid-container"> |
30 | 30 | <? if ($subDocument->type == 'document') : ?> |
31 | - <?renderDocument($subDocument, $cmsPrefix, $slugPrefix . $document->slug . '/');?> |
|
31 | + <?renderDocument($subDocument, $cmsPrefix, $slugPrefix.$document->slug.'/'); ?> |
|
32 | 32 | <? elseif ($subDocument->type == 'folder') : ?> |
33 | - <?renderFolder($subDocument, $cmsPrefix, $slugPrefix . $document->slug . '/');?> |
|
33 | + <?renderFolder($subDocument, $cmsPrefix, $slugPrefix.$document->slug.'/'); ?> |
|
34 | 34 | <? endif ?> |
35 | 35 | </li> |
36 | 36 | <? endforeach ?> |