@@ -19,192 +19,192 @@ discard block |
||
19 | 19 | |
20 | 20 | class Repository |
21 | 21 | { |
22 | - protected $storagePath; |
|
23 | - |
|
24 | - protected $fileBasedSubsets = array('sitemap', 'applicationComponents', 'documentTypes', 'bricks', 'imageSet', 'images', 'files', 'users'); |
|
25 | - |
|
26 | - protected $sitemap; |
|
27 | - protected $sitemapChanges = false; |
|
28 | - |
|
29 | - protected $applicationComponents; |
|
30 | - protected $applicationComponentsChanges = false; |
|
31 | - |
|
32 | - protected $documentTypes; |
|
33 | - protected $documentTypesChanges = false; |
|
34 | - |
|
35 | - protected $bricks; |
|
36 | - protected $bricksChanges = false; |
|
37 | - |
|
38 | - protected $imageSet; |
|
39 | - protected $imageSetChanges = false; |
|
40 | - |
|
41 | - protected $images; |
|
42 | - protected $imagesChanges = false; |
|
43 | - |
|
44 | - protected $files; |
|
45 | - protected $filesChanges = false; |
|
46 | - |
|
47 | - protected $users; |
|
48 | - protected $usersChanges = false; |
|
49 | - |
|
50 | - protected $contentDbHandle; |
|
51 | - |
|
52 | - /** |
|
53 | - * Repository constructor. |
|
54 | - * @param $storagePath |
|
55 | - * @throws \Exception |
|
56 | - */ |
|
57 | - public function __construct($storagePath) |
|
58 | - { |
|
59 | - $storagePath = realpath($storagePath); |
|
60 | - if (is_dir($storagePath) && $storagePath !== false) { |
|
61 | - $this->storagePath = $storagePath; |
|
62 | - } else { |
|
63 | - throw new \Exception('Repository not yet initialized.'); |
|
64 | - } |
|
65 | - } |
|
66 | - |
|
67 | - /** |
|
68 | - * Creates the folder in which to create all storage related files |
|
69 | - * |
|
70 | - * @param $storagePath |
|
71 | - * @return bool |
|
72 | - */ |
|
73 | - public static function create($storagePath) |
|
74 | - { |
|
75 | - return mkdir($storagePath); |
|
76 | - } |
|
77 | - |
|
78 | - /** |
|
79 | - * Initiates default storage |
|
80 | - * @throws \Exception |
|
81 | - */ |
|
82 | - public function init() |
|
83 | - { |
|
84 | - $storageDefaultPath = realpath('../library/cc/install/_storage.json'); |
|
85 | - $contentSqlPath = realpath('../library/cc/install/content.sql'); |
|
86 | - |
|
87 | - $this->initConfigStorage($storageDefaultPath); |
|
88 | - $this->initContentDb($contentSqlPath); |
|
89 | - |
|
90 | - $this->save(); |
|
91 | - } |
|
92 | - |
|
93 | - public function __get($name) |
|
94 | - { |
|
95 | - if (isset($this->$name)) { |
|
96 | - if (in_array($name, $this->fileBasedSubsets)) { |
|
97 | - return $this->$name; |
|
98 | - } else { |
|
99 | - dump(); |
|
100 | - } |
|
101 | - } else { |
|
102 | - if (in_array($name, $this->fileBasedSubsets)) { |
|
103 | - return $this->loadSubset($name); |
|
104 | - } else { |
|
105 | - throw new \Exception('Trying to get undefined property from Repository: ' . $name); |
|
106 | - } |
|
107 | - } |
|
108 | - } |
|
109 | - |
|
110 | - public function __set($name, $value) |
|
111 | - { |
|
112 | - if (in_array($name, $this->fileBasedSubsets)) { |
|
113 | - $this->$name = $value; |
|
114 | - $changes = $name . 'Changes'; |
|
115 | - $this->$changes = true; |
|
116 | - } else { |
|
117 | - throw new \Exception('Trying to persist unknown subset in repository: ' . $name . ' <br /><pre>' . print_r($value, true) . '</pre>'); |
|
118 | - } |
|
119 | - } |
|
120 | - |
|
121 | - public function save() |
|
122 | - { |
|
123 | - $this->sitemapChanges ? $this->saveSubset('sitemap') : null; |
|
124 | - $this->applicationComponentsChanges ? $this->saveSubset('applicationComponents') : null; |
|
125 | - $this->documentTypesChanges ? $this->saveSubset('documentTypes') : null; |
|
126 | - $this->bricksChanges ? $this->saveSubset('bricks') : null; |
|
127 | - $this->imageSetChanges ? $this->saveSubset('imageSet') : null; |
|
128 | - $this->imagesChanges ? $this->saveSubset('images') : null; |
|
129 | - $this->filesChanges ? $this->saveSubset('files') : null; |
|
130 | - $this->usersChanges ? $this->saveSubset('users') : null; |
|
131 | - } |
|
132 | - |
|
133 | - protected function saveSubset($subset) |
|
134 | - { |
|
135 | - $json = json_encode($this->$subset); |
|
136 | - $subsetStoragePath = $this->storagePath . DIRECTORY_SEPARATOR . $subset . '.json'; |
|
137 | - file_put_contents($subsetStoragePath, $json); |
|
138 | - $changes = $subset . 'Changes'; |
|
139 | - $this->$changes = false; |
|
140 | - } |
|
141 | - |
|
142 | - protected function loadSubset($subset) |
|
143 | - { |
|
144 | - $subsetStoragePath = $this->storagePath . DIRECTORY_SEPARATOR . $subset . '.json'; |
|
145 | - $json = file_get_contents($subsetStoragePath); |
|
146 | - $json = json_decode($json); |
|
147 | - $this->$subset = $json; |
|
148 | - return $json; |
|
149 | - } |
|
150 | - |
|
151 | - /** |
|
152 | - * @param $contentSqlPath |
|
153 | - */ |
|
154 | - protected function initContentDb($contentSqlPath) |
|
155 | - { |
|
156 | - $db = $this->getContentDbHandle(); |
|
157 | - $sql = file_get_contents($contentSqlPath); |
|
158 | - $db->exec($sql); |
|
159 | - } |
|
160 | - |
|
161 | - /** |
|
162 | - * @param $storageDefaultPath |
|
163 | - */ |
|
164 | - protected function initConfigStorage($storageDefaultPath) |
|
165 | - { |
|
166 | - $json = file_get_contents($storageDefaultPath); |
|
167 | - $json = json_decode($json); |
|
168 | - $this->sitemap = $json->sitemap; |
|
169 | - $this->sitemapChanges = true; |
|
170 | - $this->applicationComponents = $json->applicationComponents; |
|
171 | - $this->applicationComponentsChanges = true; |
|
172 | - $this->documentTypes = $json->documentTypes; |
|
173 | - $this->documentTypesChanges = true; |
|
174 | - $this->bricks = $json->bricks; |
|
175 | - $this->bricksChanges = true; |
|
176 | - $this->imageSet = $json->imageSet; |
|
177 | - $this->imageSetChanges = true; |
|
178 | - $this->images = $json->images; |
|
179 | - $this->imagesChanges = true; |
|
180 | - $this->files = $json->files; |
|
181 | - $this->filesChanges = true; |
|
182 | - $this->users = $json->users; |
|
183 | - $this->usersChanges = true; |
|
184 | - } |
|
185 | - |
|
186 | - /** |
|
187 | - * @return \PDO |
|
188 | - */ |
|
189 | - protected function getContentDbHandle() |
|
190 | - { |
|
191 | - if ($this->contentDbHandle === null) { |
|
192 | - $this->contentDbHandle = new \PDO('sqlite:' . $this->storagePath . DIRECTORY_SEPARATOR . 'content.db'); |
|
193 | - } |
|
194 | - return $this->contentDbHandle; |
|
195 | - } |
|
196 | - |
|
197 | - public function getDocuments() |
|
198 | - { |
|
199 | - return $this->getDocumentsByPath('/'); |
|
200 | - } |
|
201 | - |
|
202 | - public function getDocumentsByPath($folderPath) |
|
203 | - { |
|
204 | - $db = $this->getContentDbHandle(); |
|
205 | - $folderPathWithWildcard = $folderPath . '%'; |
|
206 | - |
|
207 | - $stmt = $this->getDbStatement(' |
|
22 | + protected $storagePath; |
|
23 | + |
|
24 | + protected $fileBasedSubsets = array('sitemap', 'applicationComponents', 'documentTypes', 'bricks', 'imageSet', 'images', 'files', 'users'); |
|
25 | + |
|
26 | + protected $sitemap; |
|
27 | + protected $sitemapChanges = false; |
|
28 | + |
|
29 | + protected $applicationComponents; |
|
30 | + protected $applicationComponentsChanges = false; |
|
31 | + |
|
32 | + protected $documentTypes; |
|
33 | + protected $documentTypesChanges = false; |
|
34 | + |
|
35 | + protected $bricks; |
|
36 | + protected $bricksChanges = false; |
|
37 | + |
|
38 | + protected $imageSet; |
|
39 | + protected $imageSetChanges = false; |
|
40 | + |
|
41 | + protected $images; |
|
42 | + protected $imagesChanges = false; |
|
43 | + |
|
44 | + protected $files; |
|
45 | + protected $filesChanges = false; |
|
46 | + |
|
47 | + protected $users; |
|
48 | + protected $usersChanges = false; |
|
49 | + |
|
50 | + protected $contentDbHandle; |
|
51 | + |
|
52 | + /** |
|
53 | + * Repository constructor. |
|
54 | + * @param $storagePath |
|
55 | + * @throws \Exception |
|
56 | + */ |
|
57 | + public function __construct($storagePath) |
|
58 | + { |
|
59 | + $storagePath = realpath($storagePath); |
|
60 | + if (is_dir($storagePath) && $storagePath !== false) { |
|
61 | + $this->storagePath = $storagePath; |
|
62 | + } else { |
|
63 | + throw new \Exception('Repository not yet initialized.'); |
|
64 | + } |
|
65 | + } |
|
66 | + |
|
67 | + /** |
|
68 | + * Creates the folder in which to create all storage related files |
|
69 | + * |
|
70 | + * @param $storagePath |
|
71 | + * @return bool |
|
72 | + */ |
|
73 | + public static function create($storagePath) |
|
74 | + { |
|
75 | + return mkdir($storagePath); |
|
76 | + } |
|
77 | + |
|
78 | + /** |
|
79 | + * Initiates default storage |
|
80 | + * @throws \Exception |
|
81 | + */ |
|
82 | + public function init() |
|
83 | + { |
|
84 | + $storageDefaultPath = realpath('../library/cc/install/_storage.json'); |
|
85 | + $contentSqlPath = realpath('../library/cc/install/content.sql'); |
|
86 | + |
|
87 | + $this->initConfigStorage($storageDefaultPath); |
|
88 | + $this->initContentDb($contentSqlPath); |
|
89 | + |
|
90 | + $this->save(); |
|
91 | + } |
|
92 | + |
|
93 | + public function __get($name) |
|
94 | + { |
|
95 | + if (isset($this->$name)) { |
|
96 | + if (in_array($name, $this->fileBasedSubsets)) { |
|
97 | + return $this->$name; |
|
98 | + } else { |
|
99 | + dump(); |
|
100 | + } |
|
101 | + } else { |
|
102 | + if (in_array($name, $this->fileBasedSubsets)) { |
|
103 | + return $this->loadSubset($name); |
|
104 | + } else { |
|
105 | + throw new \Exception('Trying to get undefined property from Repository: ' . $name); |
|
106 | + } |
|
107 | + } |
|
108 | + } |
|
109 | + |
|
110 | + public function __set($name, $value) |
|
111 | + { |
|
112 | + if (in_array($name, $this->fileBasedSubsets)) { |
|
113 | + $this->$name = $value; |
|
114 | + $changes = $name . 'Changes'; |
|
115 | + $this->$changes = true; |
|
116 | + } else { |
|
117 | + throw new \Exception('Trying to persist unknown subset in repository: ' . $name . ' <br /><pre>' . print_r($value, true) . '</pre>'); |
|
118 | + } |
|
119 | + } |
|
120 | + |
|
121 | + public function save() |
|
122 | + { |
|
123 | + $this->sitemapChanges ? $this->saveSubset('sitemap') : null; |
|
124 | + $this->applicationComponentsChanges ? $this->saveSubset('applicationComponents') : null; |
|
125 | + $this->documentTypesChanges ? $this->saveSubset('documentTypes') : null; |
|
126 | + $this->bricksChanges ? $this->saveSubset('bricks') : null; |
|
127 | + $this->imageSetChanges ? $this->saveSubset('imageSet') : null; |
|
128 | + $this->imagesChanges ? $this->saveSubset('images') : null; |
|
129 | + $this->filesChanges ? $this->saveSubset('files') : null; |
|
130 | + $this->usersChanges ? $this->saveSubset('users') : null; |
|
131 | + } |
|
132 | + |
|
133 | + protected function saveSubset($subset) |
|
134 | + { |
|
135 | + $json = json_encode($this->$subset); |
|
136 | + $subsetStoragePath = $this->storagePath . DIRECTORY_SEPARATOR . $subset . '.json'; |
|
137 | + file_put_contents($subsetStoragePath, $json); |
|
138 | + $changes = $subset . 'Changes'; |
|
139 | + $this->$changes = false; |
|
140 | + } |
|
141 | + |
|
142 | + protected function loadSubset($subset) |
|
143 | + { |
|
144 | + $subsetStoragePath = $this->storagePath . DIRECTORY_SEPARATOR . $subset . '.json'; |
|
145 | + $json = file_get_contents($subsetStoragePath); |
|
146 | + $json = json_decode($json); |
|
147 | + $this->$subset = $json; |
|
148 | + return $json; |
|
149 | + } |
|
150 | + |
|
151 | + /** |
|
152 | + * @param $contentSqlPath |
|
153 | + */ |
|
154 | + protected function initContentDb($contentSqlPath) |
|
155 | + { |
|
156 | + $db = $this->getContentDbHandle(); |
|
157 | + $sql = file_get_contents($contentSqlPath); |
|
158 | + $db->exec($sql); |
|
159 | + } |
|
160 | + |
|
161 | + /** |
|
162 | + * @param $storageDefaultPath |
|
163 | + */ |
|
164 | + protected function initConfigStorage($storageDefaultPath) |
|
165 | + { |
|
166 | + $json = file_get_contents($storageDefaultPath); |
|
167 | + $json = json_decode($json); |
|
168 | + $this->sitemap = $json->sitemap; |
|
169 | + $this->sitemapChanges = true; |
|
170 | + $this->applicationComponents = $json->applicationComponents; |
|
171 | + $this->applicationComponentsChanges = true; |
|
172 | + $this->documentTypes = $json->documentTypes; |
|
173 | + $this->documentTypesChanges = true; |
|
174 | + $this->bricks = $json->bricks; |
|
175 | + $this->bricksChanges = true; |
|
176 | + $this->imageSet = $json->imageSet; |
|
177 | + $this->imageSetChanges = true; |
|
178 | + $this->images = $json->images; |
|
179 | + $this->imagesChanges = true; |
|
180 | + $this->files = $json->files; |
|
181 | + $this->filesChanges = true; |
|
182 | + $this->users = $json->users; |
|
183 | + $this->usersChanges = true; |
|
184 | + } |
|
185 | + |
|
186 | + /** |
|
187 | + * @return \PDO |
|
188 | + */ |
|
189 | + protected function getContentDbHandle() |
|
190 | + { |
|
191 | + if ($this->contentDbHandle === null) { |
|
192 | + $this->contentDbHandle = new \PDO('sqlite:' . $this->storagePath . DIRECTORY_SEPARATOR . 'content.db'); |
|
193 | + } |
|
194 | + return $this->contentDbHandle; |
|
195 | + } |
|
196 | + |
|
197 | + public function getDocuments() |
|
198 | + { |
|
199 | + return $this->getDocumentsByPath('/'); |
|
200 | + } |
|
201 | + |
|
202 | + public function getDocumentsByPath($folderPath) |
|
203 | + { |
|
204 | + $db = $this->getContentDbHandle(); |
|
205 | + $folderPathWithWildcard = $folderPath . '%'; |
|
206 | + |
|
207 | + $stmt = $this->getDbStatement(' |
|
208 | 208 | SELECT * |
209 | 209 | FROM documents |
210 | 210 | WHERE `path` LIKE ' . $db->quote($folderPathWithWildcard) . ' |
@@ -213,100 +213,100 @@ discard block |
||
213 | 213 | ORDER BY `type` DESC, `path` ASC |
214 | 214 | '); |
215 | 215 | |
216 | - $documents = $stmt->fetchAll(\PDO::FETCH_CLASS, '\library\storage\Document'); |
|
217 | - foreach ($documents as $key => $document) { |
|
218 | - if ($document->type === 'folder') { |
|
219 | - $document->dbHandle = $db; |
|
220 | - $documents[$key] = $document; |
|
221 | - } |
|
222 | - } |
|
223 | - return $documents; |
|
224 | - } |
|
225 | - |
|
226 | - |
|
227 | - /** |
|
228 | - * @param $path |
|
229 | - * @return bool|Document |
|
230 | - */ |
|
231 | - public function getDocumentContainerByPath($path) |
|
232 | - { |
|
233 | - $document = $this->getDocumentByPath($path); |
|
234 | - if ($document === false) { |
|
235 | - return false; |
|
236 | - } |
|
237 | - $slugLength = strlen($document->slug); |
|
238 | - $containerPath = substr($path, 0, -$slugLength); |
|
239 | - if ($containerPath === '/') { |
|
240 | - return $this->getRootFolder(); |
|
241 | - } |
|
242 | - $containerFolder = $this->getDocumentByPath($containerPath); |
|
243 | - return $containerFolder; |
|
244 | - } |
|
245 | - |
|
246 | - /** |
|
247 | - * @param $path |
|
248 | - * @return bool|Document |
|
249 | - */ |
|
250 | - public function getDocumentByPath($path) |
|
251 | - { |
|
252 | - $db = $this->getContentDbHandle(); |
|
253 | - $document = $this->fetchDocument(' |
|
216 | + $documents = $stmt->fetchAll(\PDO::FETCH_CLASS, '\library\storage\Document'); |
|
217 | + foreach ($documents as $key => $document) { |
|
218 | + if ($document->type === 'folder') { |
|
219 | + $document->dbHandle = $db; |
|
220 | + $documents[$key] = $document; |
|
221 | + } |
|
222 | + } |
|
223 | + return $documents; |
|
224 | + } |
|
225 | + |
|
226 | + |
|
227 | + /** |
|
228 | + * @param $path |
|
229 | + * @return bool|Document |
|
230 | + */ |
|
231 | + public function getDocumentContainerByPath($path) |
|
232 | + { |
|
233 | + $document = $this->getDocumentByPath($path); |
|
234 | + if ($document === false) { |
|
235 | + return false; |
|
236 | + } |
|
237 | + $slugLength = strlen($document->slug); |
|
238 | + $containerPath = substr($path, 0, -$slugLength); |
|
239 | + if ($containerPath === '/') { |
|
240 | + return $this->getRootFolder(); |
|
241 | + } |
|
242 | + $containerFolder = $this->getDocumentByPath($containerPath); |
|
243 | + return $containerFolder; |
|
244 | + } |
|
245 | + |
|
246 | + /** |
|
247 | + * @param $path |
|
248 | + * @return bool|Document |
|
249 | + */ |
|
250 | + public function getDocumentByPath($path) |
|
251 | + { |
|
252 | + $db = $this->getContentDbHandle(); |
|
253 | + $document = $this->fetchDocument(' |
|
254 | 254 | SELECT * |
255 | 255 | FROM documents |
256 | 256 | WHERE path = ' . $db->quote($path) . ' |
257 | 257 | '); |
258 | - if ($document instanceof Document && $document->type === 'folder') { |
|
259 | - $document->dbHandle = $db; |
|
260 | - } |
|
261 | - return $document; |
|
262 | - } |
|
263 | - |
|
264 | - protected function fetchAllDocuments($sql) |
|
265 | - { |
|
266 | - $stmt = $this->getDbStatement($sql); |
|
267 | - return $stmt->fetchAll(\PDO::FETCH_CLASS, '\library\storage\Document'); |
|
268 | - } |
|
269 | - |
|
270 | - protected function fetchDocument($sql) |
|
271 | - { |
|
272 | - $stmt = $this->getDbStatement($sql); |
|
273 | - return $stmt->fetchObject('\library\storage\Document'); |
|
274 | - } |
|
275 | - |
|
276 | - /** |
|
277 | - * @param $sql |
|
278 | - * @return \PDOStatement |
|
279 | - * @throws \Exception |
|
280 | - */ |
|
281 | - protected function getDbStatement($sql) |
|
282 | - { |
|
283 | - $db = $this->getContentDbHandle(); |
|
284 | - $stmt = $db->query($sql); |
|
285 | - if ($stmt === false) { |
|
286 | - $errorInfo = $db->errorInfo(); |
|
287 | - $errorMsg = $errorInfo[2]; |
|
288 | - throw new \Exception('SQLite Exception: ' . $errorMsg . ' in SQL: <br /><pre>' . $sql . '</pre>'); |
|
289 | - } |
|
290 | - return $stmt; |
|
291 | - } |
|
292 | - |
|
293 | - protected function getRootFolder() |
|
294 | - { |
|
295 | - $rootFolder = new Document(); |
|
296 | - $rootFolder->path = '/'; |
|
297 | - $rootFolder->type = 'folder'; |
|
298 | - return $rootFolder; |
|
299 | - } |
|
300 | - |
|
301 | - /** |
|
302 | - * @param $path |
|
303 | - * @param Document $documentObject |
|
304 | - * @return bool |
|
305 | - */ |
|
306 | - public function saveDocument($documentObject) |
|
307 | - { |
|
308 | - $db = $this->getContentDbHandle(); |
|
309 | - $stmt = $this->getDbStatement(' |
|
258 | + if ($document instanceof Document && $document->type === 'folder') { |
|
259 | + $document->dbHandle = $db; |
|
260 | + } |
|
261 | + return $document; |
|
262 | + } |
|
263 | + |
|
264 | + protected function fetchAllDocuments($sql) |
|
265 | + { |
|
266 | + $stmt = $this->getDbStatement($sql); |
|
267 | + return $stmt->fetchAll(\PDO::FETCH_CLASS, '\library\storage\Document'); |
|
268 | + } |
|
269 | + |
|
270 | + protected function fetchDocument($sql) |
|
271 | + { |
|
272 | + $stmt = $this->getDbStatement($sql); |
|
273 | + return $stmt->fetchObject('\library\storage\Document'); |
|
274 | + } |
|
275 | + |
|
276 | + /** |
|
277 | + * @param $sql |
|
278 | + * @return \PDOStatement |
|
279 | + * @throws \Exception |
|
280 | + */ |
|
281 | + protected function getDbStatement($sql) |
|
282 | + { |
|
283 | + $db = $this->getContentDbHandle(); |
|
284 | + $stmt = $db->query($sql); |
|
285 | + if ($stmt === false) { |
|
286 | + $errorInfo = $db->errorInfo(); |
|
287 | + $errorMsg = $errorInfo[2]; |
|
288 | + throw new \Exception('SQLite Exception: ' . $errorMsg . ' in SQL: <br /><pre>' . $sql . '</pre>'); |
|
289 | + } |
|
290 | + return $stmt; |
|
291 | + } |
|
292 | + |
|
293 | + protected function getRootFolder() |
|
294 | + { |
|
295 | + $rootFolder = new Document(); |
|
296 | + $rootFolder->path = '/'; |
|
297 | + $rootFolder->type = 'folder'; |
|
298 | + return $rootFolder; |
|
299 | + } |
|
300 | + |
|
301 | + /** |
|
302 | + * @param $path |
|
303 | + * @param Document $documentObject |
|
304 | + * @return bool |
|
305 | + */ |
|
306 | + public function saveDocument($documentObject) |
|
307 | + { |
|
308 | + $db = $this->getContentDbHandle(); |
|
309 | + $stmt = $this->getDbStatement(' |
|
310 | 310 | INSERT OR REPLACE INTO documents (`path`,`title`,`slug`,`type`,`documentType`,`documentTypeSlug`,`state`,`lastModificationDate`,`creationDate`,`lastModifiedBy`,`fields`,`bricks`,`dynamicBricks`) |
311 | 311 | VALUES( |
312 | 312 | ' . $db->quote($documentObject->path) . ', |
@@ -324,31 +324,31 @@ discard block |
||
324 | 324 | ' . $db->quote(json_encode($documentObject->dynamicBricks)) . ' |
325 | 325 | ) |
326 | 326 | '); |
327 | - $result = $stmt->execute(); |
|
328 | - return $result; |
|
329 | - } |
|
330 | - |
|
331 | - public function deleteDocumentByPath($path) |
|
332 | - { |
|
333 | - $db = $this->getContentDbHandle(); |
|
334 | - $documentToDelete = $this->getDocumentByPath($path); |
|
335 | - if ($documentToDelete instanceof Document) { |
|
336 | - if ($documentToDelete->type == 'document') { |
|
337 | - $stmt = $this->getDbStatement(' |
|
327 | + $result = $stmt->execute(); |
|
328 | + return $result; |
|
329 | + } |
|
330 | + |
|
331 | + public function deleteDocumentByPath($path) |
|
332 | + { |
|
333 | + $db = $this->getContentDbHandle(); |
|
334 | + $documentToDelete = $this->getDocumentByPath($path); |
|
335 | + if ($documentToDelete instanceof Document) { |
|
336 | + if ($documentToDelete->type == 'document') { |
|
337 | + $stmt = $this->getDbStatement(' |
|
338 | 338 | DELETE FROM documents |
339 | 339 | WHERE path = ' . $db->quote($path) . ' |
340 | 340 | '); |
341 | - $stmt->execute(); |
|
342 | - } elseif ($documentToDelete->type == 'folder') { |
|
343 | - $folderPathWithWildcard = $path . '%'; |
|
344 | - $stmt = $this->getDbStatement(' |
|
341 | + $stmt->execute(); |
|
342 | + } elseif ($documentToDelete->type == 'folder') { |
|
343 | + $folderPathWithWildcard = $path . '%'; |
|
344 | + $stmt = $this->getDbStatement(' |
|
345 | 345 | DELETE FROM documents |
346 | 346 | WHERE (path LIKE ' . $db->quote($folderPathWithWildcard) . ' |
347 | 347 | AND substr(`path`, ' . (strlen($path) + 1) . ', 1) = "/") |
348 | 348 | OR path = ' . $db->quote($path) . ' |
349 | 349 | '); |
350 | - $stmt->execute(); |
|
351 | - } |
|
352 | - } |
|
353 | - } |
|
350 | + $stmt->execute(); |
|
351 | + } |
|
352 | + } |
|
353 | + } |
|
354 | 354 | } |
355 | 355 | \ No newline at end of file |
@@ -102,7 +102,7 @@ discard block |
||
102 | 102 | if (in_array($name, $this->fileBasedSubsets)) { |
103 | 103 | return $this->loadSubset($name); |
104 | 104 | } else { |
105 | - throw new \Exception('Trying to get undefined property from Repository: ' . $name); |
|
105 | + throw new \Exception('Trying to get undefined property from Repository: '.$name); |
|
106 | 106 | } |
107 | 107 | } |
108 | 108 | } |
@@ -111,10 +111,10 @@ discard block |
||
111 | 111 | { |
112 | 112 | if (in_array($name, $this->fileBasedSubsets)) { |
113 | 113 | $this->$name = $value; |
114 | - $changes = $name . 'Changes'; |
|
114 | + $changes = $name.'Changes'; |
|
115 | 115 | $this->$changes = true; |
116 | 116 | } else { |
117 | - throw new \Exception('Trying to persist unknown subset in repository: ' . $name . ' <br /><pre>' . print_r($value, true) . '</pre>'); |
|
117 | + throw new \Exception('Trying to persist unknown subset in repository: '.$name.' <br /><pre>'.print_r($value, true).'</pre>'); |
|
118 | 118 | } |
119 | 119 | } |
120 | 120 | |
@@ -133,15 +133,15 @@ discard block |
||
133 | 133 | protected function saveSubset($subset) |
134 | 134 | { |
135 | 135 | $json = json_encode($this->$subset); |
136 | - $subsetStoragePath = $this->storagePath . DIRECTORY_SEPARATOR . $subset . '.json'; |
|
136 | + $subsetStoragePath = $this->storagePath.DIRECTORY_SEPARATOR.$subset.'.json'; |
|
137 | 137 | file_put_contents($subsetStoragePath, $json); |
138 | - $changes = $subset . 'Changes'; |
|
138 | + $changes = $subset.'Changes'; |
|
139 | 139 | $this->$changes = false; |
140 | 140 | } |
141 | 141 | |
142 | 142 | protected function loadSubset($subset) |
143 | 143 | { |
144 | - $subsetStoragePath = $this->storagePath . DIRECTORY_SEPARATOR . $subset . '.json'; |
|
144 | + $subsetStoragePath = $this->storagePath.DIRECTORY_SEPARATOR.$subset.'.json'; |
|
145 | 145 | $json = file_get_contents($subsetStoragePath); |
146 | 146 | $json = json_decode($json); |
147 | 147 | $this->$subset = $json; |
@@ -189,7 +189,7 @@ discard block |
||
189 | 189 | protected function getContentDbHandle() |
190 | 190 | { |
191 | 191 | if ($this->contentDbHandle === null) { |
192 | - $this->contentDbHandle = new \PDO('sqlite:' . $this->storagePath . DIRECTORY_SEPARATOR . 'content.db'); |
|
192 | + $this->contentDbHandle = new \PDO('sqlite:'.$this->storagePath.DIRECTORY_SEPARATOR.'content.db'); |
|
193 | 193 | } |
194 | 194 | return $this->contentDbHandle; |
195 | 195 | } |
@@ -202,14 +202,14 @@ discard block |
||
202 | 202 | public function getDocumentsByPath($folderPath) |
203 | 203 | { |
204 | 204 | $db = $this->getContentDbHandle(); |
205 | - $folderPathWithWildcard = $folderPath . '%'; |
|
205 | + $folderPathWithWildcard = $folderPath.'%'; |
|
206 | 206 | |
207 | 207 | $stmt = $this->getDbStatement(' |
208 | 208 | SELECT * |
209 | 209 | FROM documents |
210 | - WHERE `path` LIKE ' . $db->quote($folderPathWithWildcard) . ' |
|
211 | - AND substr(`path`, ' . (strlen($folderPath) + 1) . ') NOT LIKE "%/%" |
|
212 | - AND path != ' . $db->quote($folderPath) . ' |
|
210 | + WHERE `path` LIKE ' . $db->quote($folderPathWithWildcard).' |
|
211 | + AND substr(`path`, ' . (strlen($folderPath) + 1).') NOT LIKE "%/%" |
|
212 | + AND path != ' . $db->quote($folderPath).' |
|
213 | 213 | ORDER BY `type` DESC, `path` ASC |
214 | 214 | '); |
215 | 215 | |
@@ -253,7 +253,7 @@ discard block |
||
253 | 253 | $document = $this->fetchDocument(' |
254 | 254 | SELECT * |
255 | 255 | FROM documents |
256 | - WHERE path = ' . $db->quote($path) . ' |
|
256 | + WHERE path = ' . $db->quote($path).' |
|
257 | 257 | '); |
258 | 258 | if ($document instanceof Document && $document->type === 'folder') { |
259 | 259 | $document->dbHandle = $db; |
@@ -285,7 +285,7 @@ discard block |
||
285 | 285 | if ($stmt === false) { |
286 | 286 | $errorInfo = $db->errorInfo(); |
287 | 287 | $errorMsg = $errorInfo[2]; |
288 | - throw new \Exception('SQLite Exception: ' . $errorMsg . ' in SQL: <br /><pre>' . $sql . '</pre>'); |
|
288 | + throw new \Exception('SQLite Exception: '.$errorMsg.' in SQL: <br /><pre>'.$sql.'</pre>'); |
|
289 | 289 | } |
290 | 290 | return $stmt; |
291 | 291 | } |
@@ -309,19 +309,19 @@ discard block |
||
309 | 309 | $stmt = $this->getDbStatement(' |
310 | 310 | INSERT OR REPLACE INTO documents (`path`,`title`,`slug`,`type`,`documentType`,`documentTypeSlug`,`state`,`lastModificationDate`,`creationDate`,`lastModifiedBy`,`fields`,`bricks`,`dynamicBricks`) |
311 | 311 | VALUES( |
312 | - ' . $db->quote($documentObject->path) . ', |
|
313 | - ' . $db->quote($documentObject->title) . ', |
|
314 | - ' . $db->quote($documentObject->slug) . ', |
|
315 | - ' . $db->quote($documentObject->type) . ', |
|
316 | - ' . $db->quote($documentObject->documentType) . ', |
|
317 | - ' . $db->quote($documentObject->documentTypeSlug) . ', |
|
318 | - ' . $db->quote($documentObject->state) . ', |
|
319 | - ' . $db->quote($documentObject->lastModificationDate) . ', |
|
320 | - ' . $db->quote($documentObject->creationDate) . ', |
|
321 | - ' . $db->quote($documentObject->lastModifiedBy) . ', |
|
322 | - ' . $db->quote(json_encode($documentObject->fields)) . ', |
|
323 | - ' . $db->quote(json_encode($documentObject->bricks)) . ', |
|
324 | - ' . $db->quote(json_encode($documentObject->dynamicBricks)) . ' |
|
312 | + ' . $db->quote($documentObject->path).', |
|
313 | + ' . $db->quote($documentObject->title).', |
|
314 | + ' . $db->quote($documentObject->slug).', |
|
315 | + ' . $db->quote($documentObject->type).', |
|
316 | + ' . $db->quote($documentObject->documentType).', |
|
317 | + ' . $db->quote($documentObject->documentTypeSlug).', |
|
318 | + ' . $db->quote($documentObject->state).', |
|
319 | + ' . $db->quote($documentObject->lastModificationDate).', |
|
320 | + ' . $db->quote($documentObject->creationDate).', |
|
321 | + ' . $db->quote($documentObject->lastModifiedBy).', |
|
322 | + ' . $db->quote(json_encode($documentObject->fields)).', |
|
323 | + ' . $db->quote(json_encode($documentObject->bricks)).', |
|
324 | + ' . $db->quote(json_encode($documentObject->dynamicBricks)).' |
|
325 | 325 | ) |
326 | 326 | '); |
327 | 327 | $result = $stmt->execute(); |
@@ -336,16 +336,16 @@ discard block |
||
336 | 336 | if ($documentToDelete->type == 'document') { |
337 | 337 | $stmt = $this->getDbStatement(' |
338 | 338 | DELETE FROM documents |
339 | - WHERE path = ' . $db->quote($path) . ' |
|
339 | + WHERE path = ' . $db->quote($path).' |
|
340 | 340 | '); |
341 | 341 | $stmt->execute(); |
342 | 342 | } elseif ($documentToDelete->type == 'folder') { |
343 | - $folderPathWithWildcard = $path . '%'; |
|
343 | + $folderPathWithWildcard = $path.'%'; |
|
344 | 344 | $stmt = $this->getDbStatement(' |
345 | 345 | DELETE FROM documents |
346 | - WHERE (path LIKE ' . $db->quote($folderPathWithWildcard) . ' |
|
347 | - AND substr(`path`, ' . (strlen($path) + 1) . ', 1) = "/") |
|
348 | - OR path = ' . $db->quote($path) . ' |
|
346 | + WHERE (path LIKE ' . $db->quote($folderPathWithWildcard).' |
|
347 | + AND substr(`path`, ' . (strlen($path) + 1).', 1) = "/") |
|
348 | + OR path = ' . $db->quote($path).' |
|
349 | 349 | '); |
350 | 350 | $stmt->execute(); |
351 | 351 | } |