@@ -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 |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <? include('documents/function.renderDocument.php'); ?> |
2 | 2 | <? include('documents/function.renderFolder.php'); ?> |
3 | -<script>window.onload=function(){History.init();History.replaceState(null, 'Cloud Control CMS', '/<?=$request::$subfolders . $cmsPrefix?>/documents?path=/');};</script> |
|
3 | +<script>window.onload=function(){History.init();History.replaceState(null, 'Cloud Control CMS', '/<?=$request::$subfolders.$cmsPrefix?>/documents?path=/');};</script> |
|
4 | 4 | <section class="documents"> |
5 | 5 | <h2><i class="fa fa-file-text-o"></i> Documents</h2> |
6 | 6 | <nav class="actions"> |
@@ -26,9 +26,9 @@ discard block |
||
26 | 26 | <? foreach ($documents as $document) : ?> |
27 | 27 | <li class="grid-container"> |
28 | 28 | <? if ($document->type == 'document') : ?> |
29 | - <?renderDocument($document, $cmsPrefix);?> |
|
29 | + <?renderDocument($document, $cmsPrefix); ?> |
|
30 | 30 | <? elseif ($document->type == 'folder') : ?> |
31 | - <?renderFolder($document, $cmsPrefix, '', true);?> |
|
31 | + <?renderFolder($document, $cmsPrefix, '', true); ?> |
|
32 | 32 | <? endif ?> |
33 | 33 | </li> |
34 | 34 | <? endforeach ?> |
@@ -1,22 +1,22 @@ |
||
1 | -<? function renderFolder($document, $cmsPrefix, $slugPrefix ='', $root = false) {?> |
|
1 | +<? function renderFolder($document, $cmsPrefix, $slugPrefix = '', $root = false) {?> |
|
2 | 2 | <div class="grid-box-8"> |
3 | 3 | <h3> |
4 | - <a class="btn documentTitle openFolder" data-slug="<?=$slugPrefix . $document->slug?>" title="Open"> |
|
4 | + <a class="btn documentTitle openFolder" data-slug="<?=$slugPrefix.$document->slug?>" title="Open"> |
|
5 | 5 | <i class="fa fa-folder-o "></i> <?=$document->title?> |
6 | 6 | </a> |
7 | 7 | </h3> |
8 | 8 | </div> |
9 | 9 | <div class="documentActions grid-box-4"> |
10 | - <a class="btn" href="<?=\library\cc\Request::$subfolders?><?=$cmsPrefix?>/documents/edit-folder?slug=<?=$slugPrefix . $document->slug?>" title="Edit"><i class="fa fa-pencil"></i></a> |
|
11 | - <a onclick="return confirm('Are you sure you want to delete this item?');" class="btn error" href="<?=\library\cc\Request::$subfolders?><?=$cmsPrefix?>/documents/delete-folder?slug=<?=$slugPrefix . $document->slug?>" title="Delete"><i class="fa fa-trash"></i></a> |
|
10 | + <a class="btn" href="<?=\library\cc\Request::$subfolders?><?=$cmsPrefix?>/documents/edit-folder?slug=<?=$slugPrefix.$document->slug?>" title="Edit"><i class="fa fa-pencil"></i></a> |
|
11 | + <a onclick="return confirm('Are you sure you want to delete this item?');" class="btn error" href="<?=\library\cc\Request::$subfolders?><?=$cmsPrefix?>/documents/delete-folder?slug=<?=$slugPrefix.$document->slug?>" title="Delete"><i class="fa fa-trash"></i></a> |
|
12 | 12 | </div> |
13 | 13 | <ul class="documents grid-wrapper nested<?=$root ? ' root' : '' ?>"> |
14 | 14 | <? foreach ($document->content as $subDocument) : ?> |
15 | 15 | <li class="grid-container"> |
16 | 16 | <? if ($subDocument->type == 'document') : ?> |
17 | - <?renderDocument($subDocument, $cmsPrefix, $slugPrefix . $document->slug . '/');?> |
|
17 | + <?renderDocument($subDocument, $cmsPrefix, $slugPrefix.$document->slug.'/'); ?> |
|
18 | 18 | <? elseif ($subDocument->type == 'folder') : ?> |
19 | - <?renderFolder($subDocument, $cmsPrefix, $slugPrefix . $document->slug . '/');?> |
|
19 | + <?renderFolder($subDocument, $cmsPrefix, $slugPrefix.$document->slug.'/'); ?> |
|
20 | 20 | <? endif ?> |
21 | 21 | </li> |
22 | 22 | <? endforeach ?> |
@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <? function renderDocument($document, $cmsPrefix, $slugPrefix = '') {?> |
2 | 2 | <div class="grid-box-10"> |
3 | 3 | <h3> |
4 | - <a class="btn documentTitle" href="<?=\library\cc\Request::$subfolders?><?=$cmsPrefix?>/documents/edit-document?slug=<?=$slugPrefix . $document->slug?>" title="Edit"> |
|
4 | + <a class="btn documentTitle" href="<?=\library\cc\Request::$subfolders?><?=$cmsPrefix?>/documents/edit-document?slug=<?=$slugPrefix.$document->slug?>" title="Edit"> |
|
5 | 5 | <i class="fa fa-file-text-o"></i> |
6 | 6 | <small class="state <?=strtolower($document->state)?>"><i class="fa <?=$document->state == 'published' ? 'fa-check-circle-o' : 'fa-times-circle-o' ?>"></i></small> |
7 | 7 | <?=$document->title?> |
@@ -20,14 +20,14 @@ discard block |
||
20 | 20 | </div> |
21 | 21 | <div class="documentActions grid-box-2"> |
22 | 22 | <? if ($document->state == 'unpublished' || $document->unpublishedChanges) : ?> |
23 | - <a class="btn publish" title="Publish" href="<?=\library\cc\Request::$subfolders?><?=$cmsPrefix?>/documents/publish-document?slug=<?=$slugPrefix . $document->slug?>"><i class="fa fa-check"></i></a> |
|
23 | + <a class="btn publish" title="Publish" href="<?=\library\cc\Request::$subfolders?><?=$cmsPrefix?>/documents/publish-document?slug=<?=$slugPrefix.$document->slug?>"><i class="fa fa-check"></i></a> |
|
24 | 24 | <? endif ?> |
25 | 25 | <? if ($document->state == 'published') : ?> |
26 | - <a class="btn unpublish" title="Unpublish" href="<?=\library\cc\Request::$subfolders?><?=$cmsPrefix?>/documents/unpublish-document?slug=<?=$slugPrefix . $document->slug?>"><i class="fa fa-times"></i></a> |
|
26 | + <a class="btn unpublish" title="Unpublish" href="<?=\library\cc\Request::$subfolders?><?=$cmsPrefix?>/documents/unpublish-document?slug=<?=$slugPrefix.$document->slug?>"><i class="fa fa-times"></i></a> |
|
27 | 27 | <? endif ?> |
28 | - <a class="btn" href="<?=\library\cc\Request::$subfolders?><?=$cmsPrefix?>/documents/edit-document?slug=<?=$slugPrefix . $document->slug?>" title="Edit"><i class="fa fa-pencil"></i></a> |
|
28 | + <a class="btn" href="<?=\library\cc\Request::$subfolders?><?=$cmsPrefix?>/documents/edit-document?slug=<?=$slugPrefix.$document->slug?>" title="Edit"><i class="fa fa-pencil"></i></a> |
|
29 | 29 | <? if ($document->state == 'unpublished') : ?> |
30 | - <a onclick="return confirm('Are you sure you want to delete this item?');" class="btn error" href="<?=\library\cc\Request::$subfolders?><?=$cmsPrefix?>/documents/delete-document?slug=<?=$slugPrefix . $document->slug?>" title="Delete"><i class="fa fa-trash"></i></a> |
|
30 | + <a onclick="return confirm('Are you sure you want to delete this item?');" class="btn error" href="<?=\library\cc\Request::$subfolders?><?=$cmsPrefix?>/documents/delete-document?slug=<?=$slugPrefix.$document->slug?>" title="Delete"><i class="fa fa-trash"></i></a> |
|
31 | 31 | <? endif ?> |
32 | 32 | </div> |
33 | 33 | <?}?> |
34 | 34 | \ No newline at end of file |
@@ -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 | } |
@@ -22,134 +22,134 @@ 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'); |
|
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 $contentDbHandle; |
|
54 | - |
|
55 | - /** |
|
56 | - * Repository constructor. |
|
57 | - * @param $storagePath |
|
58 | - * @throws \Exception |
|
59 | - */ |
|
60 | - public function __construct($storagePath) |
|
61 | - { |
|
62 | - $storagePath = realpath($storagePath); |
|
63 | - if (is_dir($storagePath) && $storagePath !== false) { |
|
64 | - $this->storagePath = $storagePath; |
|
65 | - } else { |
|
66 | - throw new \Exception('Repository not yet initialized.'); |
|
67 | - } |
|
68 | - } |
|
69 | - |
|
70 | - /** |
|
71 | - * Creates the folder in which to create all storage related files |
|
72 | - * |
|
73 | - * @param $storagePath |
|
74 | - * @return bool |
|
75 | - */ |
|
76 | - public static function create($storagePath) |
|
77 | - { |
|
78 | - return mkdir($storagePath); |
|
79 | - } |
|
80 | - |
|
81 | - /** |
|
82 | - * Initiates default storage |
|
83 | - * @throws \Exception |
|
84 | - */ |
|
85 | - public function init() |
|
86 | - { |
|
87 | - $storageDefaultPath = realpath('../library/cc/install/_storage.json'); |
|
88 | - $contentSqlPath = realpath('../library/cc/install/content.sql'); |
|
89 | - |
|
90 | - $this->initConfigStorage($storageDefaultPath); |
|
91 | - $this->initContentDb($contentSqlPath); |
|
92 | - |
|
93 | - $this->save(); |
|
94 | - } |
|
95 | - |
|
96 | - /** |
|
97 | - * Load filebased subset and return it's contents |
|
98 | - * |
|
99 | - * @param $name |
|
100 | - * @return mixed|string |
|
101 | - * @throws \Exception |
|
102 | - */ |
|
103 | - public function __get($name) |
|
104 | - { |
|
105 | - if (isset($this->$name)) { |
|
106 | - if (in_array($name, $this->fileBasedSubsets)) { |
|
107 | - return $this->$name; |
|
108 | - } else { |
|
109 | - throw new \Exception('Trying to get undefined property from Repository: ' . $name); |
|
110 | - } |
|
111 | - } else { |
|
112 | - if (in_array($name, $this->fileBasedSubsets)) { |
|
113 | - return $this->loadSubset($name); |
|
114 | - } else { |
|
115 | - throw new \Exception('Trying to get undefined property from Repository: ' . $name); |
|
116 | - } |
|
117 | - } |
|
118 | - } |
|
119 | - |
|
120 | - /** |
|
121 | - * Set filebased subset contents |
|
122 | - * @param $name |
|
123 | - * @param $value |
|
124 | - * @throws \Exception |
|
125 | - */ |
|
126 | - public function __set($name, $value) |
|
127 | - { |
|
128 | - if (in_array($name, $this->fileBasedSubsets)) { |
|
129 | - $this->$name = $value; |
|
130 | - $changes = $name . 'Changes'; |
|
131 | - $this->$changes = true; |
|
132 | - } else { |
|
133 | - throw new \Exception('Trying to persist unknown subset in repository: ' . $name . ' <br /><pre>' . print_r($value, true) . '</pre>'); |
|
134 | - } |
|
135 | - } |
|
136 | - |
|
137 | - /** |
|
138 | - * Persist all subsets |
|
139 | - */ |
|
140 | - public function save() |
|
141 | - { |
|
142 | - array_map(function ($value) { |
|
143 | - $this->saveSubset($value); |
|
25 | + protected $storagePath; |
|
26 | + |
|
27 | + protected $fileBasedSubsets = array('sitemap', 'applicationComponents', 'documentTypes', 'bricks', 'imageSet', 'images', 'files', 'users'); |
|
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 $contentDbHandle; |
|
54 | + |
|
55 | + /** |
|
56 | + * Repository constructor. |
|
57 | + * @param $storagePath |
|
58 | + * @throws \Exception |
|
59 | + */ |
|
60 | + public function __construct($storagePath) |
|
61 | + { |
|
62 | + $storagePath = realpath($storagePath); |
|
63 | + if (is_dir($storagePath) && $storagePath !== false) { |
|
64 | + $this->storagePath = $storagePath; |
|
65 | + } else { |
|
66 | + throw new \Exception('Repository not yet initialized.'); |
|
67 | + } |
|
68 | + } |
|
69 | + |
|
70 | + /** |
|
71 | + * Creates the folder in which to create all storage related files |
|
72 | + * |
|
73 | + * @param $storagePath |
|
74 | + * @return bool |
|
75 | + */ |
|
76 | + public static function create($storagePath) |
|
77 | + { |
|
78 | + return mkdir($storagePath); |
|
79 | + } |
|
80 | + |
|
81 | + /** |
|
82 | + * Initiates default storage |
|
83 | + * @throws \Exception |
|
84 | + */ |
|
85 | + public function init() |
|
86 | + { |
|
87 | + $storageDefaultPath = realpath('../library/cc/install/_storage.json'); |
|
88 | + $contentSqlPath = realpath('../library/cc/install/content.sql'); |
|
89 | + |
|
90 | + $this->initConfigStorage($storageDefaultPath); |
|
91 | + $this->initContentDb($contentSqlPath); |
|
92 | + |
|
93 | + $this->save(); |
|
94 | + } |
|
95 | + |
|
96 | + /** |
|
97 | + * Load filebased subset and return it's contents |
|
98 | + * |
|
99 | + * @param $name |
|
100 | + * @return mixed|string |
|
101 | + * @throws \Exception |
|
102 | + */ |
|
103 | + public function __get($name) |
|
104 | + { |
|
105 | + if (isset($this->$name)) { |
|
106 | + if (in_array($name, $this->fileBasedSubsets)) { |
|
107 | + return $this->$name; |
|
108 | + } else { |
|
109 | + throw new \Exception('Trying to get undefined property from Repository: ' . $name); |
|
110 | + } |
|
111 | + } else { |
|
112 | + if (in_array($name, $this->fileBasedSubsets)) { |
|
113 | + return $this->loadSubset($name); |
|
114 | + } else { |
|
115 | + throw new \Exception('Trying to get undefined property from Repository: ' . $name); |
|
116 | + } |
|
117 | + } |
|
118 | + } |
|
119 | + |
|
120 | + /** |
|
121 | + * Set filebased subset contents |
|
122 | + * @param $name |
|
123 | + * @param $value |
|
124 | + * @throws \Exception |
|
125 | + */ |
|
126 | + public function __set($name, $value) |
|
127 | + { |
|
128 | + if (in_array($name, $this->fileBasedSubsets)) { |
|
129 | + $this->$name = $value; |
|
130 | + $changes = $name . 'Changes'; |
|
131 | + $this->$changes = true; |
|
132 | + } else { |
|
133 | + throw new \Exception('Trying to persist unknown subset in repository: ' . $name . ' <br /><pre>' . print_r($value, true) . '</pre>'); |
|
134 | + } |
|
135 | + } |
|
136 | + |
|
137 | + /** |
|
138 | + * Persist all subsets |
|
139 | + */ |
|
140 | + public function save() |
|
141 | + { |
|
142 | + array_map(function ($value) { |
|
143 | + $this->saveSubset($value); |
|
144 | 144 | }, $this->fileBasedSubsets); |
145 | - } |
|
146 | - |
|
147 | - /** |
|
148 | - * Persist subset to disk |
|
149 | - * @param $subset |
|
150 | - */ |
|
151 | - protected function saveSubset($subset) |
|
152 | - { |
|
145 | + } |
|
146 | + |
|
147 | + /** |
|
148 | + * Persist subset to disk |
|
149 | + * @param $subset |
|
150 | + */ |
|
151 | + protected function saveSubset($subset) |
|
152 | + { |
|
153 | 153 | $changes = $subset . 'Changes'; |
154 | 154 | if ($this->$changes === true) { |
155 | 155 | $json = json_encode($this->$subset, JSON_PRETTY_PRINT); |
@@ -158,67 +158,67 @@ discard block |
||
158 | 158 | |
159 | 159 | $this->$changes = false; |
160 | 160 | } |
161 | - } |
|
162 | - |
|
163 | - /** |
|
164 | - * Load subset from disk |
|
165 | - * @param $subset |
|
166 | - * @return mixed|string |
|
167 | - */ |
|
168 | - protected function loadSubset($subset) |
|
169 | - { |
|
170 | - $subsetStoragePath = $this->storagePath . DIRECTORY_SEPARATOR . $subset . '.json'; |
|
171 | - $json = file_get_contents($subsetStoragePath); |
|
172 | - $json = json_decode($json); |
|
173 | - $this->$subset = $json; |
|
174 | - return $json; |
|
175 | - } |
|
176 | - |
|
177 | - /** |
|
178 | - * @param $contentSqlPath |
|
179 | - */ |
|
180 | - protected function initContentDb($contentSqlPath) |
|
181 | - { |
|
182 | - $db = $this->getContentDbHandle(); |
|
183 | - $sql = file_get_contents($contentSqlPath); |
|
184 | - $db->exec($sql); |
|
185 | - } |
|
186 | - |
|
187 | - /** |
|
188 | - * @param $storageDefaultPath |
|
189 | - */ |
|
190 | - protected function initConfigStorage($storageDefaultPath) |
|
191 | - { |
|
192 | - $json = file_get_contents($storageDefaultPath); |
|
193 | - $json = json_decode($json); |
|
194 | - $this->sitemap = $json->sitemap; |
|
195 | - $this->sitemapChanges = true; |
|
196 | - $this->applicationComponents = $json->applicationComponents; |
|
197 | - $this->applicationComponentsChanges = true; |
|
198 | - $this->documentTypes = $json->documentTypes; |
|
199 | - $this->documentTypesChanges = true; |
|
200 | - $this->bricks = $json->bricks; |
|
201 | - $this->bricksChanges = true; |
|
202 | - $this->imageSet = $json->imageSet; |
|
203 | - $this->imageSetChanges = true; |
|
204 | - $this->images = $json->images; |
|
205 | - $this->imagesChanges = true; |
|
206 | - $this->files = $json->files; |
|
207 | - $this->filesChanges = true; |
|
208 | - $this->users = $json->users; |
|
209 | - $this->usersChanges = true; |
|
210 | - } |
|
211 | - |
|
212 | - /** |
|
213 | - * @return \PDO |
|
214 | - */ |
|
215 | - public function getContentDbHandle() |
|
216 | - { |
|
217 | - if ($this->contentDbHandle === null) { |
|
218 | - $this->contentDbHandle = new \PDO('sqlite:' . $this->storagePath . DIRECTORY_SEPARATOR . 'content.db'); |
|
219 | - } |
|
220 | - return $this->contentDbHandle; |
|
221 | - } |
|
161 | + } |
|
162 | + |
|
163 | + /** |
|
164 | + * Load subset from disk |
|
165 | + * @param $subset |
|
166 | + * @return mixed|string |
|
167 | + */ |
|
168 | + protected function loadSubset($subset) |
|
169 | + { |
|
170 | + $subsetStoragePath = $this->storagePath . DIRECTORY_SEPARATOR . $subset . '.json'; |
|
171 | + $json = file_get_contents($subsetStoragePath); |
|
172 | + $json = json_decode($json); |
|
173 | + $this->$subset = $json; |
|
174 | + return $json; |
|
175 | + } |
|
176 | + |
|
177 | + /** |
|
178 | + * @param $contentSqlPath |
|
179 | + */ |
|
180 | + protected function initContentDb($contentSqlPath) |
|
181 | + { |
|
182 | + $db = $this->getContentDbHandle(); |
|
183 | + $sql = file_get_contents($contentSqlPath); |
|
184 | + $db->exec($sql); |
|
185 | + } |
|
186 | + |
|
187 | + /** |
|
188 | + * @param $storageDefaultPath |
|
189 | + */ |
|
190 | + protected function initConfigStorage($storageDefaultPath) |
|
191 | + { |
|
192 | + $json = file_get_contents($storageDefaultPath); |
|
193 | + $json = json_decode($json); |
|
194 | + $this->sitemap = $json->sitemap; |
|
195 | + $this->sitemapChanges = true; |
|
196 | + $this->applicationComponents = $json->applicationComponents; |
|
197 | + $this->applicationComponentsChanges = true; |
|
198 | + $this->documentTypes = $json->documentTypes; |
|
199 | + $this->documentTypesChanges = true; |
|
200 | + $this->bricks = $json->bricks; |
|
201 | + $this->bricksChanges = true; |
|
202 | + $this->imageSet = $json->imageSet; |
|
203 | + $this->imageSetChanges = true; |
|
204 | + $this->images = $json->images; |
|
205 | + $this->imagesChanges = true; |
|
206 | + $this->files = $json->files; |
|
207 | + $this->filesChanges = true; |
|
208 | + $this->users = $json->users; |
|
209 | + $this->usersChanges = true; |
|
210 | + } |
|
211 | + |
|
212 | + /** |
|
213 | + * @return \PDO |
|
214 | + */ |
|
215 | + public function getContentDbHandle() |
|
216 | + { |
|
217 | + if ($this->contentDbHandle === null) { |
|
218 | + $this->contentDbHandle = new \PDO('sqlite:' . $this->storagePath . DIRECTORY_SEPARATOR . 'content.db'); |
|
219 | + } |
|
220 | + return $this->contentDbHandle; |
|
221 | + } |
|
222 | 222 | |
223 | 223 | /** |
224 | 224 | * Get all documents |
@@ -228,13 +228,13 @@ discard block |
||
228 | 228 | * @return array |
229 | 229 | * @throws \Exception |
230 | 230 | */ |
231 | - public function getDocuments($state = 'published') |
|
232 | - { |
|
231 | + public function getDocuments($state = 'published') |
|
232 | + { |
|
233 | 233 | if (!in_array($state, Document::$DOCUMENT_STATES)) { |
234 | 234 | throw new \Exception('Unsupported document state: ' . $state); |
235 | 235 | } |
236 | - return $this->getDocumentsByPath('/', $state); |
|
237 | - } |
|
236 | + return $this->getDocumentsByPath('/', $state); |
|
237 | + } |
|
238 | 238 | |
239 | 239 | public function getDocumentsWithState($folderPath = '/') |
240 | 240 | { |
@@ -281,51 +281,51 @@ discard block |
||
281 | 281 | * @return array |
282 | 282 | * @throws \Exception |
283 | 283 | */ |
284 | - public function getDocumentsByPath($folderPath, $state = 'published') |
|
285 | - { |
|
286 | - if (!in_array($state, Document::$DOCUMENT_STATES)) { |
|
287 | - throw new \Exception('Unsupported document state: ' . $state); |
|
284 | + public function getDocumentsByPath($folderPath, $state = 'published') |
|
285 | + { |
|
286 | + if (!in_array($state, Document::$DOCUMENT_STATES)) { |
|
287 | + throw new \Exception('Unsupported document state: ' . $state); |
|
288 | 288 | } |
289 | - $db = $this->getContentDbHandle(); |
|
290 | - $folderPathWithWildcard = $folderPath . '%'; |
|
289 | + $db = $this->getContentDbHandle(); |
|
290 | + $folderPathWithWildcard = $folderPath . '%'; |
|
291 | 291 | |
292 | - $sql = 'SELECT * |
|
292 | + $sql = 'SELECT * |
|
293 | 293 | FROM documents_' . $state . ' |
294 | 294 | WHERE `path` LIKE ' . $db->quote($folderPathWithWildcard) . ' |
295 | 295 | AND substr(`path`, ' . (strlen($folderPath) + 1) . ') NOT LIKE "%/%" |
296 | 296 | AND path != ' . $db->quote($folderPath) . ' |
297 | 297 | ORDER BY `type` DESC, `path` ASC'; |
298 | - $stmt = $this->getDbStatement($sql); |
|
298 | + $stmt = $this->getDbStatement($sql); |
|
299 | 299 | |
300 | - $documents = $stmt->fetchAll(\PDO::FETCH_CLASS, '\library\storage\Document'); |
|
301 | - foreach ($documents as $key => $document) { |
|
300 | + $documents = $stmt->fetchAll(\PDO::FETCH_CLASS, '\library\storage\Document'); |
|
301 | + foreach ($documents as $key => $document) { |
|
302 | 302 | $documents = $this->setAssetsToDocumentFolders($document, $db, $documents, $key); |
303 | - } |
|
304 | - return $documents; |
|
305 | - } |
|
306 | - |
|
307 | - |
|
308 | - /** |
|
309 | - * @param $path |
|
310 | - * @return bool|Document |
|
311 | - */ |
|
312 | - public function getDocumentContainerByPath($path) |
|
313 | - { |
|
314 | - $document = $this->getDocumentByPath($path, 'unpublished'); |
|
315 | - if ($document === false) { |
|
316 | - return false; |
|
317 | - } |
|
318 | - $slugLength = strlen($document->slug); |
|
319 | - $containerPath = substr($path, 0, -$slugLength); |
|
320 | - if ($containerPath === '/') { |
|
321 | - return $this->getRootFolder(); |
|
322 | - } |
|
323 | - if (substr($containerPath, -1) === '/'){ |
|
303 | + } |
|
304 | + return $documents; |
|
305 | + } |
|
306 | + |
|
307 | + |
|
308 | + /** |
|
309 | + * @param $path |
|
310 | + * @return bool|Document |
|
311 | + */ |
|
312 | + public function getDocumentContainerByPath($path) |
|
313 | + { |
|
314 | + $document = $this->getDocumentByPath($path, 'unpublished'); |
|
315 | + if ($document === false) { |
|
316 | + return false; |
|
317 | + } |
|
318 | + $slugLength = strlen($document->slug); |
|
319 | + $containerPath = substr($path, 0, -$slugLength); |
|
320 | + if ($containerPath === '/') { |
|
321 | + return $this->getRootFolder(); |
|
322 | + } |
|
323 | + if (substr($containerPath, -1) === '/'){ |
|
324 | 324 | $containerPath = substr($containerPath, 0, -1); |
325 | 325 | } |
326 | - $containerFolder = $this->getDocumentByPath($containerPath, 'unpublished'); |
|
327 | - return $containerFolder; |
|
328 | - } |
|
326 | + $containerFolder = $this->getDocumentByPath($containerPath, 'unpublished'); |
|
327 | + return $containerFolder; |
|
328 | + } |
|
329 | 329 | |
330 | 330 | /** |
331 | 331 | * @param $path |
@@ -334,23 +334,23 @@ discard block |
||
334 | 334 | * @return bool|\library\storage\Document |
335 | 335 | * @throws \Exception |
336 | 336 | */ |
337 | - public function getDocumentByPath($path, $state = 'published') |
|
338 | - { |
|
337 | + public function getDocumentByPath($path, $state = 'published') |
|
338 | + { |
|
339 | 339 | if (!in_array($state, Document::$DOCUMENT_STATES)) { |
340 | 340 | throw new \Exception('Unsupported document state: ' . $state); |
341 | 341 | } |
342 | - $db = $this->getContentDbHandle(); |
|
343 | - $document = $this->fetchDocument(' |
|
342 | + $db = $this->getContentDbHandle(); |
|
343 | + $document = $this->fetchDocument(' |
|
344 | 344 | SELECT * |
345 | 345 | FROM documents_' . $state . ' |
346 | 346 | WHERE path = ' . $db->quote($path) . ' |
347 | 347 | '); |
348 | - if ($document instanceof Document && $document->type === 'folder') { |
|
349 | - $document->dbHandle = $db; |
|
350 | - $document->documentStorage = new DocumentStorage($this); |
|
351 | - } |
|
352 | - return $document; |
|
353 | - } |
|
348 | + if ($document instanceof Document && $document->type === 'folder') { |
|
349 | + $document->dbHandle = $db; |
|
350 | + $document->documentStorage = new DocumentStorage($this); |
|
351 | + } |
|
352 | + return $document; |
|
353 | + } |
|
354 | 354 | |
355 | 355 | /** |
356 | 356 | * 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 |
@@ -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(); |
@@ -445,7 +445,7 @@ discard block |
||
445 | 445 | if ($stmt === false) { |
446 | 446 | $errorInfo = $db->errorInfo(); |
447 | 447 | $errorMsg = $errorInfo[2]; |
448 | - throw new \Exception('SQLite Exception: ' . $errorMsg . ' in SQL: <br /><pre>' . $sql . '</pre>'); |
|
448 | + throw new \Exception('SQLite Exception: '.$errorMsg.' in SQL: <br /><pre>'.$sql.'</pre>'); |
|
449 | 449 | } |
450 | 450 | $stmt->execute(); |
451 | 451 | } |
@@ -487,7 +487,7 @@ discard block |
||
487 | 487 | if ($stmt === false) { |
488 | 488 | $errorInfo = $db->errorInfo(); |
489 | 489 | $errorMsg = $errorInfo[2]; |
490 | - throw new \Exception('SQLite Exception: ' . $errorMsg . ' in SQL: <br /><pre>' . $sql . '</pre>'); |
|
490 | + throw new \Exception('SQLite Exception: '.$errorMsg.' in SQL: <br /><pre>'.$sql.'</pre>'); |
|
491 | 491 | } |
492 | 492 | return $stmt; |
493 | 493 | } |
@@ -517,25 +517,25 @@ discard block |
||
517 | 517 | public function saveDocument($documentObject, $state = 'published') |
518 | 518 | { |
519 | 519 | if (!in_array($state, Document::$DOCUMENT_STATES)) { |
520 | - throw new \Exception('Unsupported document state: ' . $state); |
|
520 | + throw new \Exception('Unsupported document state: '.$state); |
|
521 | 521 | } |
522 | 522 | $db = $this->getContentDbHandle(); |
523 | 523 | $stmt = $this->getDbStatement(' |
524 | - INSERT OR REPLACE INTO documents_' . $state . ' (`path`,`title`,`slug`,`type`,`documentType`,`documentTypeSlug`,`state`,`lastModificationDate`,`creationDate`,`lastModifiedBy`,`fields`,`bricks`,`dynamicBricks`) |
|
524 | + INSERT OR REPLACE INTO documents_' . $state.' (`path`,`title`,`slug`,`type`,`documentType`,`documentTypeSlug`,`state`,`lastModificationDate`,`creationDate`,`lastModifiedBy`,`fields`,`bricks`,`dynamicBricks`) |
|
525 | 525 | VALUES( |
526 | - ' . $db->quote($documentObject->path) . ', |
|
527 | - ' . $db->quote($documentObject->title) . ', |
|
528 | - ' . $db->quote($documentObject->slug) . ', |
|
529 | - ' . $db->quote($documentObject->type) . ', |
|
530 | - ' . $db->quote($documentObject->documentType) . ', |
|
531 | - ' . $db->quote($documentObject->documentTypeSlug) . ', |
|
532 | - ' . $db->quote($documentObject->state) . ', |
|
533 | - ' . $db->quote($documentObject->lastModificationDate) . ', |
|
534 | - ' . $db->quote($documentObject->creationDate) . ', |
|
535 | - ' . $db->quote($documentObject->lastModifiedBy) . ', |
|
536 | - ' . $db->quote(json_encode($documentObject->fields)) . ', |
|
537 | - ' . $db->quote(json_encode($documentObject->bricks)) . ', |
|
538 | - ' . $db->quote(json_encode($documentObject->dynamicBricks)) . ' |
|
526 | + ' . $db->quote($documentObject->path).', |
|
527 | + ' . $db->quote($documentObject->title).', |
|
528 | + ' . $db->quote($documentObject->slug).', |
|
529 | + ' . $db->quote($documentObject->type).', |
|
530 | + ' . $db->quote($documentObject->documentType).', |
|
531 | + ' . $db->quote($documentObject->documentTypeSlug).', |
|
532 | + ' . $db->quote($documentObject->state).', |
|
533 | + ' . $db->quote($documentObject->lastModificationDate).', |
|
534 | + ' . $db->quote($documentObject->creationDate).', |
|
535 | + ' . $db->quote($documentObject->lastModifiedBy).', |
|
536 | + ' . $db->quote(json_encode($documentObject->fields)).', |
|
537 | + ' . $db->quote(json_encode($documentObject->bricks)).', |
|
538 | + ' . $db->quote(json_encode($documentObject->dynamicBricks)).' |
|
539 | 539 | ) |
540 | 540 | '); |
541 | 541 | $result = $stmt->execute(); |
@@ -559,16 +559,16 @@ discard block |
||
559 | 559 | if ($documentToDelete->type == 'document') { |
560 | 560 | $stmt = $this->getDbStatement(' |
561 | 561 | DELETE FROM documents_unpublished |
562 | - WHERE path = ' . $db->quote($path) . ' |
|
562 | + WHERE path = ' . $db->quote($path).' |
|
563 | 563 | '); |
564 | 564 | $stmt->execute(); |
565 | 565 | } elseif ($documentToDelete->type == 'folder') { |
566 | - $folderPathWithWildcard = $path . '%'; |
|
566 | + $folderPathWithWildcard = $path.'%'; |
|
567 | 567 | $stmt = $this->getDbStatement(' |
568 | 568 | DELETE FROM documents_unpublished |
569 | - WHERE (path LIKE ' . $db->quote($folderPathWithWildcard) . ' |
|
570 | - AND substr(`path`, ' . (strlen($path) + 1) . ', 1) = "/") |
|
571 | - OR path = ' . $db->quote($path) . ' |
|
569 | + WHERE (path LIKE ' . $db->quote($folderPathWithWildcard).' |
|
570 | + AND substr(`path`, ' . (strlen($path) + 1).', 1) = "/") |
|
571 | + OR path = ' . $db->quote($path).' |
|
572 | 572 | '); |
573 | 573 | $stmt->execute(); |
574 | 574 | } |
@@ -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 |
@@ -12,32 +12,32 @@ discard block |
||
12 | 12 | |
13 | 13 | class DocumentRouting implements CmsRouting |
14 | 14 | { |
15 | - /** |
|
16 | - * DocumentRouting constructor. |
|
17 | - * @param $request |
|
18 | - * @param $relativeCmsUri |
|
19 | - * @param CmsComponent $cmsComponent |
|
20 | - */ |
|
21 | - public function __construct($request, $relativeCmsUri, $cmsComponent) |
|
22 | - { |
|
23 | - if ($relativeCmsUri == '/documents') { |
|
24 | - $cmsComponent->subTemplate = 'cms/documents'; |
|
25 | - $cmsComponent->setParameter(CmsComponent::PARAMETER_DOCUMENTS, $cmsComponent->storage->getDocuments()->getDocumentsWithState()); |
|
26 | - $cmsComponent->setParameter(CmsComponent::PARAMETER_MAIN_NAV_CLASS, CmsComponent::PARAMETER_DOCUMENTS); |
|
27 | - } |
|
28 | - $this->documentRouting($request, $relativeCmsUri, $cmsComponent); |
|
29 | - $this->folderRouting($request, $relativeCmsUri, $cmsComponent); |
|
30 | - } |
|
31 | - |
|
32 | - |
|
33 | - /** |
|
34 | - * @param $request |
|
35 | - * @param $relativeCmsUri |
|
36 | - * @param CmsComponent $cmsComponent |
|
37 | - * @throws \Exception |
|
38 | - */ |
|
39 | - private function documentRouting($request, $relativeCmsUri, $cmsComponent) |
|
40 | - { |
|
15 | + /** |
|
16 | + * DocumentRouting constructor. |
|
17 | + * @param $request |
|
18 | + * @param $relativeCmsUri |
|
19 | + * @param CmsComponent $cmsComponent |
|
20 | + */ |
|
21 | + public function __construct($request, $relativeCmsUri, $cmsComponent) |
|
22 | + { |
|
23 | + if ($relativeCmsUri == '/documents') { |
|
24 | + $cmsComponent->subTemplate = 'cms/documents'; |
|
25 | + $cmsComponent->setParameter(CmsComponent::PARAMETER_DOCUMENTS, $cmsComponent->storage->getDocuments()->getDocumentsWithState()); |
|
26 | + $cmsComponent->setParameter(CmsComponent::PARAMETER_MAIN_NAV_CLASS, CmsComponent::PARAMETER_DOCUMENTS); |
|
27 | + } |
|
28 | + $this->documentRouting($request, $relativeCmsUri, $cmsComponent); |
|
29 | + $this->folderRouting($request, $relativeCmsUri, $cmsComponent); |
|
30 | + } |
|
31 | + |
|
32 | + |
|
33 | + /** |
|
34 | + * @param $request |
|
35 | + * @param $relativeCmsUri |
|
36 | + * @param CmsComponent $cmsComponent |
|
37 | + * @throws \Exception |
|
38 | + */ |
|
39 | + private function documentRouting($request, $relativeCmsUri, $cmsComponent) |
|
40 | + { |
|
41 | 41 | if ($relativeCmsUri == '/documents/new-document' && isset($request::$get[CmsComponent::GET_PARAMETER_PATH])) { |
42 | 42 | $this->documentNewRoute($request, $cmsComponent); |
43 | 43 | } elseif (isset($request::$get[CmsComponent::GET_PARAMETER_SLUG])){ |
@@ -49,23 +49,23 @@ discard block |
||
49 | 49 | case '/documents/unpublish-document': $this->unpublishDocumentRoute($request, $cmsComponent); break; |
50 | 50 | } |
51 | 51 | } |
52 | - } |
|
53 | - |
|
54 | - /** |
|
55 | - * @param $request |
|
56 | - * @param $relativeCmsUri |
|
57 | - * @param CmsComponent $cmsComponent |
|
58 | - */ |
|
59 | - private function folderRouting($request, $relativeCmsUri, $cmsComponent) |
|
60 | - { |
|
61 | - if ($relativeCmsUri == '/documents/new-folder' && isset($request::$get[CmsComponent::GET_PARAMETER_PATH])) { |
|
52 | + } |
|
53 | + |
|
54 | + /** |
|
55 | + * @param $request |
|
56 | + * @param $relativeCmsUri |
|
57 | + * @param CmsComponent $cmsComponent |
|
58 | + */ |
|
59 | + private function folderRouting($request, $relativeCmsUri, $cmsComponent) |
|
60 | + { |
|
61 | + if ($relativeCmsUri == '/documents/new-folder' && isset($request::$get[CmsComponent::GET_PARAMETER_PATH])) { |
|
62 | 62 | $this->newFolderRoute($request, $cmsComponent); |
63 | - } else if ($relativeCmsUri == '/documents/edit-folder' && isset($request::$get[CmsComponent::GET_PARAMETER_SLUG])) { |
|
63 | + } else if ($relativeCmsUri == '/documents/edit-folder' && isset($request::$get[CmsComponent::GET_PARAMETER_SLUG])) { |
|
64 | 64 | $this->editFolderRoute($request, $cmsComponent); |
65 | - } else if ($relativeCmsUri == '/documents/delete-folder' && isset($request::$get[CmsComponent::GET_PARAMETER_SLUG])) { |
|
65 | + } else if ($relativeCmsUri == '/documents/delete-folder' && isset($request::$get[CmsComponent::GET_PARAMETER_SLUG])) { |
|
66 | 66 | $this->deleteFolderRoute($request, $cmsComponent); |
67 | - } |
|
68 | - } |
|
67 | + } |
|
68 | + } |
|
69 | 69 | |
70 | 70 | /** |
71 | 71 | * @param $request |
@@ -40,7 +40,7 @@ discard block |
||
40 | 40 | { |
41 | 41 | if ($relativeCmsUri == '/documents/new-document' && isset($request::$get[CmsComponent::GET_PARAMETER_PATH])) { |
42 | 42 | $this->documentNewRoute($request, $cmsComponent); |
43 | - } elseif (isset($request::$get[CmsComponent::GET_PARAMETER_SLUG])){ |
|
43 | + } elseif (isset($request::$get[CmsComponent::GET_PARAMETER_SLUG])) { |
|
44 | 44 | switch ($relativeCmsUri) { |
45 | 45 | case '/documents/edit-document': $this->editDocumentRoute($request, $cmsComponent); break; |
46 | 46 | case '/documents/get-brick': $this->getBrickRoute($request, $cmsComponent); break; |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | if (isset($request::$get[CmsComponent::PARAMETER_DOCUMENT_TYPE])) { |
82 | 82 | if (isset($request::$post[CmsComponent::POST_PARAMETER_TITLE], $request::$get[CmsComponent::PARAMETER_DOCUMENT_TYPE], $request::$get[CmsComponent::GET_PARAMETER_PATH])) { |
83 | 83 | $cmsComponent->storage->getDocuments()->addDocument($request::$post); |
84 | - header('Location: ' . $request::$subfolders . $cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX) . '/documents'); |
|
84 | + header('Location: '.$request::$subfolders.$cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX).'/documents'); |
|
85 | 85 | exit; |
86 | 86 | } |
87 | 87 | $cmsComponent->setParameter(CmsComponent::PARAMETER_DOCUMENT_TYPE, $cmsComponent->storage->getDocumentTypes()->getDocumentTypeBySlug($request::$get[CmsComponent::PARAMETER_DOCUMENT_TYPE], true)); |
@@ -89,7 +89,7 @@ discard block |
||
89 | 89 | } else { |
90 | 90 | $documentTypes = $cmsComponent->storage->getDocumentTypes()->getDocumentTypes(); |
91 | 91 | if (count($documentTypes) < 1) { |
92 | - throw new \Exception('No Document Types defined yet. <a href="' . $request::$subfolders . $cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX) . '/configuration/document-types/new">Please do so first.</a>'); |
|
92 | + throw new \Exception('No Document Types defined yet. <a href="'.$request::$subfolders.$cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX).'/configuration/document-types/new">Please do so first.</a>'); |
|
93 | 93 | } |
94 | 94 | $cmsComponent->setParameter(CmsComponent::PARAMETER_DOCUMENT_TYPES, $documentTypes); |
95 | 95 | } |
@@ -106,7 +106,7 @@ discard block |
||
106 | 106 | $cmsComponent->setParameter(CmsComponent::PARAMETER_SMALLEST_IMAGE, $cmsComponent->storage->getImageSet()->getSmallestImageSet()->slug); |
107 | 107 | if (isset($request::$post[CmsComponent::POST_PARAMETER_TITLE], $request::$get[CmsComponent::GET_PARAMETER_SLUG])) { |
108 | 108 | $cmsComponent->storage->getDocuments()->saveDocument($request::$post); |
109 | - header('Location: ' . $request::$subfolders . $cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX) . '/documents'); |
|
109 | + header('Location: '.$request::$subfolders.$cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX).'/documents'); |
|
110 | 110 | exit; |
111 | 111 | } |
112 | 112 | $cmsComponent->setParameter(CmsComponent::PARAMETER_DOCUMENT, $cmsComponent->storage->getDocuments()->getDocumentBySlug($request::$get[CmsComponent::GET_PARAMETER_SLUG], 'unpublished')); |
@@ -143,7 +143,7 @@ discard block |
||
143 | 143 | private function deleteDocumentRoute($request, $cmsComponent) |
144 | 144 | { |
145 | 145 | $cmsComponent->storage->getDocuments()->deleteDocumentBySlug($request::$get[CmsComponent::GET_PARAMETER_SLUG]); |
146 | - header('Location: ' . $request::$subfolders . $cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX) . '/documents'); |
|
146 | + header('Location: '.$request::$subfolders.$cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX).'/documents'); |
|
147 | 147 | exit; |
148 | 148 | } |
149 | 149 | |
@@ -157,7 +157,7 @@ discard block |
||
157 | 157 | $cmsComponent->setParameter(CmsComponent::PARAMETER_MAIN_NAV_CLASS, CmsComponent::PARAMETER_DOCUMENTS); |
158 | 158 | if (isset($request::$post[CmsComponent::POST_PARAMETER_TITLE], $request::$post[CmsComponent::GET_PARAMETER_PATH])) { |
159 | 159 | $cmsComponent->storage->addDocumentFolder($request::$post); |
160 | - header('Location: ' . $request::$subfolders . $cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX) . '/documents'); |
|
160 | + header('Location: '.$request::$subfolders.$cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX).'/documents'); |
|
161 | 161 | exit; |
162 | 162 | } |
163 | 163 | } |
@@ -176,11 +176,11 @@ discard block |
||
176 | 176 | array_pop($path); |
177 | 177 | $path = implode('/', $path); |
178 | 178 | |
179 | - $request::$get[CmsComponent::GET_PARAMETER_PATH] = '/' . $path; |
|
179 | + $request::$get[CmsComponent::GET_PARAMETER_PATH] = '/'.$path; |
|
180 | 180 | |
181 | 181 | if (isset($request::$post[CmsComponent::POST_PARAMETER_TITLE], $request::$post['content'])) { |
182 | 182 | $cmsComponent->storage->saveDocumentFolder($request::$post); |
183 | - header('Location: ' . $request::$subfolders . $cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX) . '/documents'); |
|
183 | + header('Location: '.$request::$subfolders.$cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX).'/documents'); |
|
184 | 184 | exit; |
185 | 185 | } |
186 | 186 | |
@@ -195,7 +195,7 @@ discard block |
||
195 | 195 | private function deleteFolderRoute($request, $cmsComponent) |
196 | 196 | { |
197 | 197 | $cmsComponent->storage->deleteDocumentFolderBySlug($request::$get[CmsComponent::GET_PARAMETER_SLUG]); |
198 | - header('Location: ' . $request::$subfolders . $cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX) . '/documents'); |
|
198 | + header('Location: '.$request::$subfolders.$cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX).'/documents'); |
|
199 | 199 | exit; |
200 | 200 | } |
201 | 201 | |
@@ -206,7 +206,7 @@ discard block |
||
206 | 206 | private function publishDocumentRoute($request, $cmsComponent) |
207 | 207 | { |
208 | 208 | $cmsComponent->storage->publishDocumentBySlug($request::$get[CmsComponent::GET_PARAMETER_SLUG]); |
209 | - header('Location: ' . $request::$subfolders . $cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX) . '/documents'); |
|
209 | + header('Location: '.$request::$subfolders.$cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX).'/documents'); |
|
210 | 210 | exit; |
211 | 211 | } |
212 | 212 | |
@@ -217,7 +217,7 @@ discard block |
||
217 | 217 | private function unpublishDocumentRoute($request, $cmsComponent) |
218 | 218 | { |
219 | 219 | $cmsComponent->storage->unpublishDocumentBySlug($request::$get[CmsComponent::GET_PARAMETER_SLUG]); |
220 | - header('Location: ' . $request::$subfolders . $cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX) . '/documents'); |
|
220 | + header('Location: '.$request::$subfolders.$cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX).'/documents'); |
|
221 | 221 | exit; |
222 | 222 | } |
223 | 223 | } |
224 | 224 | \ No newline at end of file |