1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace CloudControl\Cms\storage { |
4
|
|
|
|
5
|
|
|
use CloudControl\Cms\storage\factories\DocumentFolderFactory; |
6
|
|
|
use CloudControl\Cms\storage\storage\ActivityLogStorage; |
7
|
|
|
use CloudControl\Cms\storage\storage\ApplicationComponentsStorage; |
8
|
|
|
use CloudControl\Cms\storage\storage\BricksStorage; |
9
|
|
|
use CloudControl\Cms\storage\storage\DocumentStorage; |
10
|
|
|
use CloudControl\Cms\storage\storage\DocumentTypesStorage; |
11
|
|
|
use CloudControl\Cms\storage\storage\FilesStorage; |
12
|
|
|
use CloudControl\Cms\storage\storage\ImageSetStorage; |
13
|
|
|
use CloudControl\Cms\storage\storage\ImagesStorage; |
14
|
|
|
use CloudControl\Cms\storage\storage\RedirectsStorage; |
15
|
|
|
use CloudControl\Cms\storage\storage\SitemapStorage; |
16
|
|
|
use CloudControl\Cms\storage\storage\UsersStorage; |
17
|
|
|
use CloudControl\Cms\storage\storage\ValuelistsStorage; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Class JsonStorage |
21
|
|
|
* @package CloudControl\Cms\storage |
22
|
|
|
*/ |
23
|
|
|
class Storage |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* @var SitemapStorage |
27
|
|
|
*/ |
28
|
|
|
protected $sitemap; |
29
|
|
|
/** |
30
|
|
|
* @var ImagesStorage |
31
|
|
|
*/ |
32
|
|
|
protected $images; |
33
|
|
|
/** |
34
|
|
|
* @var ImageSetStorage |
35
|
|
|
*/ |
36
|
|
|
protected $imageSet; |
37
|
|
|
/** |
38
|
|
|
* @var FilesStorage |
39
|
|
|
*/ |
40
|
|
|
protected $files; |
41
|
|
|
/** |
42
|
|
|
* @var UsersStorage |
43
|
|
|
*/ |
44
|
|
|
protected $users; |
45
|
|
|
/** |
46
|
|
|
* @var DocumentTypesStorage |
47
|
|
|
*/ |
48
|
|
|
protected $documentTypes; |
49
|
|
|
/** |
50
|
|
|
* @var BricksStorage |
51
|
|
|
*/ |
52
|
|
|
protected $bricks; |
53
|
|
|
/** |
54
|
|
|
* @var ApplicationComponentsStorage |
55
|
|
|
*/ |
56
|
|
|
protected $applicationComponents; |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @var ValuelistsStorage |
60
|
|
|
*/ |
61
|
|
|
protected $valuelists; |
62
|
|
|
/** |
63
|
|
|
* @var DocumentStorage |
64
|
|
|
*/ |
65
|
|
|
protected $documents; |
66
|
|
|
/** |
67
|
|
|
* @var RedirectsStorage |
68
|
|
|
*/ |
69
|
|
|
protected $redirects; |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @var ActivityLogStorage |
73
|
|
|
*/ |
74
|
|
|
protected $activityLog; |
75
|
|
|
/** |
76
|
|
|
* @var String |
77
|
|
|
*/ |
78
|
|
|
protected $imagesDir; |
79
|
|
|
/** |
80
|
|
|
* @var String |
81
|
|
|
*/ |
82
|
|
|
protected $filesDir; |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @var String |
86
|
|
|
*/ |
87
|
|
|
private $storageDir; |
88
|
|
|
/** |
89
|
|
|
* @var Repository |
90
|
|
|
*/ |
91
|
|
|
private $repository; |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* JsonStorage constructor. |
95
|
|
|
* |
96
|
|
|
* @param string $storageDir |
97
|
|
|
* @param $imagesDir |
98
|
|
|
* @param $filesDir |
99
|
|
|
*/ |
100
|
|
|
public function __construct($storageDir, $imagesDir, $filesDir) |
101
|
|
|
{ |
102
|
|
|
$this->storageDir = $storageDir; |
103
|
|
|
$this->imagesDir = $imagesDir; |
104
|
|
|
$this->filesDir = $filesDir; |
105
|
|
|
$this->config(); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* Retrieve the data from the storagepath |
110
|
|
|
* so it can be interacted with |
111
|
|
|
* |
112
|
|
|
* @throws \Exception |
113
|
|
|
*/ |
114
|
|
|
private function config() |
115
|
|
|
{ |
116
|
|
|
$storagePath = $this->storageDir; |
117
|
|
|
if (realpath($storagePath) === false) { |
118
|
|
|
throw new \Exception('Storage doesnt seem to be initialized, consider running composer install to do so.'); |
119
|
|
|
} else { |
120
|
|
|
$this->repository = new Repository($storagePath); |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* @return \CloudControl\Cms\storage\storage\UsersStorage |
127
|
|
|
*/ |
128
|
|
|
public function getUsers() |
129
|
|
|
{ |
130
|
|
|
if (!$this->users instanceof UsersStorage) { |
131
|
|
|
$this->users = new UsersStorage($this->repository); |
132
|
|
|
} |
133
|
|
|
return $this->users; |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
/** |
137
|
|
|
* Get documents |
138
|
|
|
* |
139
|
|
|
* @return DocumentStorage |
140
|
|
|
*/ |
141
|
|
|
public function getDocuments() |
142
|
|
|
{ |
143
|
|
|
if (!$this->documents instanceof DocumentStorage) { |
144
|
|
|
$this->documents = new DocumentStorage($this->repository); |
145
|
|
|
} |
146
|
|
|
return $this->documents; |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
/** |
150
|
|
|
* Add new document in given path |
151
|
|
|
* |
152
|
|
|
* @param array $postValues |
153
|
|
|
* |
154
|
|
|
* @throws \Exception |
155
|
|
|
*/ |
156
|
|
|
public function addDocumentFolder($postValues) |
157
|
|
|
{ |
158
|
|
|
$documentFolderObject = DocumentFolderFactory::createDocumentFolderFromPostValues($postValues); |
159
|
|
|
if ($postValues['path'] === '/') { |
160
|
|
|
$documentFolderObject->path = $postValues['path'] . $documentFolderObject->slug; |
161
|
|
|
} else { |
162
|
|
|
$documentFolderObject->path = $postValues['path'] . '/' . $documentFolderObject->slug; |
163
|
|
|
} |
164
|
|
|
$this->repository->saveDocument($documentFolderObject, 'published'); |
165
|
|
|
$this->repository->saveDocument($documentFolderObject, 'unpublished'); |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
/** |
169
|
|
|
* Delete a folder by its compound slug |
170
|
|
|
* |
171
|
|
|
* @param $slug |
172
|
|
|
* |
173
|
|
|
* @throws \Exception |
174
|
|
|
*/ |
175
|
|
|
public function deleteDocumentFolderBySlug($slug) |
176
|
|
|
{ |
177
|
|
|
$path = '/' . $slug; |
178
|
|
|
$this->repository->deleteDocumentByPath($path, 'published'); |
|
|
|
|
179
|
|
|
$this->repository->deleteDocumentByPath($path, 'unpublished'); |
|
|
|
|
180
|
|
|
$this->repository->cleanPublishedDeletedDocuments(); |
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
public function publishDocumentBySlug($slug) |
184
|
|
|
{ |
185
|
|
|
$path = '/' . $slug; |
186
|
|
|
$this->repository->publishDocumentByPath($path); |
187
|
|
|
} |
188
|
|
|
|
189
|
|
|
public function unpublishDocumentBySlug($slug) |
190
|
|
|
{ |
191
|
|
|
$path = '/' . $slug; |
192
|
|
|
$this->repository->unpublishDocumentByPath($path); |
193
|
|
|
} |
194
|
|
|
|
195
|
|
|
/** |
196
|
|
|
* Retrieve a folder by its compound slug |
197
|
|
|
* |
198
|
|
|
* @param $slug |
199
|
|
|
* |
200
|
|
|
* @return mixed |
201
|
|
|
* @throws \Exception |
202
|
|
|
*/ |
203
|
|
|
public function getDocumentFolderBySlug($slug) |
204
|
|
|
{ |
205
|
|
|
$path = '/' . $slug; |
206
|
|
|
|
207
|
|
|
return $this->repository->getDocumentByPath($path); |
208
|
|
|
} |
209
|
|
|
|
210
|
|
|
/** |
211
|
|
|
* Save changes to folder |
212
|
|
|
* |
213
|
|
|
* @param $postValues |
214
|
|
|
* |
215
|
|
|
* @throws \Exception |
216
|
|
|
*/ |
217
|
|
|
public function saveDocumentFolder($postValues) |
218
|
|
|
{ |
219
|
|
|
$this->addDocumentFolder($postValues); |
220
|
|
|
} |
221
|
|
|
|
222
|
|
|
/** |
223
|
|
|
* @return SitemapStorage |
224
|
|
|
*/ |
225
|
|
|
public function getSitemap() |
226
|
|
|
{ |
227
|
|
|
if (!$this->sitemap instanceof SitemapStorage) { |
228
|
|
|
$this->sitemap = new SitemapStorage($this->repository); |
229
|
|
|
} |
230
|
|
|
return $this->sitemap; |
231
|
|
|
} |
232
|
|
|
|
233
|
|
|
/** |
234
|
|
|
* Get all images |
235
|
|
|
* |
236
|
|
|
* @return ImagesStorage |
237
|
|
|
*/ |
238
|
|
|
public function getImages() |
239
|
|
|
{ |
240
|
|
|
if (!$this->images instanceof ImagesStorage) { |
241
|
|
|
|
242
|
|
|
$this->images = new ImagesStorage($this->repository, $this->imagesDir); |
243
|
|
|
} |
244
|
|
|
return $this->images; |
245
|
|
|
} |
246
|
|
|
|
247
|
|
|
/** |
248
|
|
|
* Get all files |
249
|
|
|
* |
250
|
|
|
* @return FilesStorage |
251
|
|
|
*/ |
252
|
|
|
public function getFiles() |
253
|
|
|
{ |
254
|
|
|
if (!$this->files instanceof FilesStorage) { |
255
|
|
|
$this->files = new FilesStorage($this->repository, $this->filesDir); |
256
|
|
|
} |
257
|
|
|
return $this->files; |
258
|
|
|
} |
259
|
|
|
|
260
|
|
|
/** |
261
|
|
|
* @return string |
262
|
|
|
*/ |
263
|
|
|
public function getStorageDir() |
264
|
|
|
{ |
265
|
|
|
return $this->storageDir; |
266
|
|
|
} |
267
|
|
|
|
268
|
|
|
/** |
269
|
|
|
* @return \PDO |
270
|
|
|
*/ |
271
|
|
|
public function getContentDbHandle() |
272
|
|
|
{ |
273
|
|
|
return $this->repository->getContentDbHandle(); |
274
|
|
|
} |
275
|
|
|
|
276
|
|
|
/** |
277
|
|
|
* @return DocumentTypesStorage |
278
|
|
|
*/ |
279
|
|
|
public function getDocumentTypes() |
280
|
|
|
{ |
281
|
|
|
if (!$this->documentTypes instanceof DocumentTypesStorage) { |
282
|
|
|
$this->documentTypes = new DocumentTypesStorage($this->repository); |
283
|
|
|
} |
284
|
|
|
return $this->documentTypes; |
285
|
|
|
} |
286
|
|
|
|
287
|
|
|
/** |
288
|
|
|
* @return BricksStorage |
289
|
|
|
*/ |
290
|
|
View Code Duplication |
public function getBricks() |
|
|
|
|
291
|
|
|
{ |
292
|
|
|
if (!$this->bricks instanceof BricksStorage) { |
293
|
|
|
$this->bricks = new BricksStorage($this->repository); |
294
|
|
|
} |
295
|
|
|
return $this->bricks; |
296
|
|
|
} |
297
|
|
|
|
298
|
|
|
/** |
299
|
|
|
* Get the image set |
300
|
|
|
* |
301
|
|
|
* @return ImageSetStorage |
302
|
|
|
*/ |
303
|
|
View Code Duplication |
public function getImageSet() |
|
|
|
|
304
|
|
|
{ |
305
|
|
|
if (!$this->imageSet instanceof ImageSetStorage) { |
306
|
|
|
$this->imageSet = new ImageSetStorage($this->repository); |
307
|
|
|
} |
308
|
|
|
return $this->imageSet; |
309
|
|
|
} |
310
|
|
|
|
311
|
|
|
/** |
312
|
|
|
* @return ApplicationComponentsStorage |
313
|
|
|
*/ |
314
|
|
|
public function getApplicationComponents() |
315
|
|
|
{ |
316
|
|
|
if (!$this->applicationComponents instanceof ApplicationComponentsStorage) { |
317
|
|
|
$this->applicationComponents = new ApplicationComponentsStorage($this->repository); |
318
|
|
|
} |
319
|
|
|
return $this->applicationComponents; |
320
|
|
|
} |
321
|
|
|
|
322
|
|
|
/** |
323
|
|
|
* @return \CloudControl\Cms\storage\Repository |
324
|
|
|
*/ |
325
|
|
|
public function getRepository() |
326
|
|
|
{ |
327
|
|
|
return $this->repository; |
328
|
|
|
} |
329
|
|
|
|
330
|
|
|
/** |
331
|
|
|
* @return \CloudControl\Cms\storage\storage\ValuelistsStorage |
332
|
|
|
*/ |
333
|
|
|
public function getValuelists() |
334
|
|
|
{ |
335
|
|
|
if (!$this->valuelists instanceof ValuelistsStorage) { |
336
|
|
|
$this->valuelists = new ValuelistsStorage($this->repository); |
337
|
|
|
} |
338
|
|
|
return $this->valuelists; |
339
|
|
|
} |
340
|
|
|
|
341
|
|
|
/** |
342
|
|
|
* @return \CloudControl\Cms\storage\storage\RedirectsStorage |
343
|
|
|
*/ |
344
|
|
|
public function getRedirects() |
345
|
|
|
{ |
346
|
|
|
if (!$this->redirects instanceof RedirectsStorage) { |
347
|
|
|
$this->redirects = new RedirectsStorage($this->repository); |
348
|
|
|
} |
349
|
|
|
return $this->redirects; |
350
|
|
|
} |
351
|
|
|
|
352
|
|
|
/** |
353
|
|
|
* @return ActivityLogStorage |
354
|
|
|
*/ |
355
|
|
|
public function getActivityLog() |
356
|
|
|
{ |
357
|
|
|
if (!$this->activityLog instanceof ActivityLogStorage) { |
358
|
|
|
$this->activityLog = new ActivityLogStorage($this->repository); |
359
|
|
|
} |
360
|
|
|
return $this->activityLog; |
361
|
|
|
} |
362
|
|
|
|
363
|
|
|
|
364
|
|
|
} |
365
|
|
|
} |
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.
In this case you can add the
@ignore
PhpDoc annotation to the duplicate definition and it will be ignored.