Passed
Push — develop ( 0713b1...90b6a5 )
by Jens
03:00
created
cloudcontrol/library/storage/storage/ValuelistsStorage.php 1 patch
Indentation   +73 added lines, -73 removed lines patch added patch discarded remove patch
@@ -12,83 +12,83 @@
 block discarded – undo
12 12
 
13 13
 class ValuelistsStorage extends AbstractStorage
14 14
 {
15
-    /**
16
-     * Get all valuelists
17
-     *
18
-     * @return mixed
19
-     */
20
-    public function getValuelists()
21
-    {
22
-        return $this->repository->valuelists;
23
-    }
15
+	/**
16
+	 * Get all valuelists
17
+	 *
18
+	 * @return mixed
19
+	 */
20
+	public function getValuelists()
21
+	{
22
+		return $this->repository->valuelists;
23
+	}
24 24
 
25
-    public function addValuelist($postValues)
26
-    {
27
-        $valueListObject = ValuelistFactory::createValuelistFromPostValues($postValues);
28
-        $valuelists = $this->repository->valuelists;
29
-        $valuelists[] = $valueListObject;
30
-        $this->repository->valuelists = $valuelists;
31
-        $this->save();
32
-    }
25
+	public function addValuelist($postValues)
26
+	{
27
+		$valueListObject = ValuelistFactory::createValuelistFromPostValues($postValues);
28
+		$valuelists = $this->repository->valuelists;
29
+		$valuelists[] = $valueListObject;
30
+		$this->repository->valuelists = $valuelists;
31
+		$this->save();
32
+	}
33 33
 
34
-    /**
35
-     * Save changes to a valuelist
36
-     *
37
-     * @param $slug
38
-     * @param $postValues
39
-     *
40
-     * @throws \Exception
41
-     */
42
-    public function saveValuelist($slug, $postValues)
43
-    {
44
-        $valuelistObject = ValuelistFactory::createValuelistFromPostValues($postValues);
34
+	/**
35
+	 * Save changes to a valuelist
36
+	 *
37
+	 * @param $slug
38
+	 * @param $postValues
39
+	 *
40
+	 * @throws \Exception
41
+	 */
42
+	public function saveValuelist($slug, $postValues)
43
+	{
44
+		$valuelistObject = ValuelistFactory::createValuelistFromPostValues($postValues);
45 45
 
46
-        $valuelists = $this->repository->valuelists;
47
-        foreach ($valuelists as $key => $valuelist) {
48
-            if ($valuelist->slug == $slug) {
49
-                $valuelists[$key] = $valuelistObject;
50
-            }
51
-        }
52
-        $this->repository->valuelists = $valuelists;
53
-        $this->save();
54
-    }
46
+		$valuelists = $this->repository->valuelists;
47
+		foreach ($valuelists as $key => $valuelist) {
48
+			if ($valuelist->slug == $slug) {
49
+				$valuelists[$key] = $valuelistObject;
50
+			}
51
+		}
52
+		$this->repository->valuelists = $valuelists;
53
+		$this->save();
54
+	}
55 55
 
56
-    /**
57
-     * Get a valuelist by its slug
58
-     *
59
-     * @param $slug
60
-     *
61
-     * @return mixed
62
-     */
63
-    public function getValuelistBySlug($slug)
64
-    {
65
-        $valuelists = $this->repository->valuelists;
66
-        foreach ($valuelists as $valuelist) {
67
-            if ($valuelist->slug == $slug) {
68
-                return $valuelist;
69
-            }
70
-        }
56
+	/**
57
+	 * Get a valuelist by its slug
58
+	 *
59
+	 * @param $slug
60
+	 *
61
+	 * @return mixed
62
+	 */
63
+	public function getValuelistBySlug($slug)
64
+	{
65
+		$valuelists = $this->repository->valuelists;
66
+		foreach ($valuelists as $valuelist) {
67
+			if ($valuelist->slug == $slug) {
68
+				return $valuelist;
69
+			}
70
+		}
71 71
 
72
-        return null;
73
-    }
72
+		return null;
73
+	}
74 74
 
75
-    /**
76
-     * Delete a sitemap item by its slug
77
-     *
78
-     * @param $slug
79
-     *
80
-     * @throws \Exception
81
-     */
82
-    public function deleteValuelistBySlug($slug)
83
-    {
84
-        $valuelists = $this->repository->valuelists;
85
-        foreach ($valuelists as $key => $valuelist) {
86
-            if ($valuelist->slug == $slug) {
87
-                unset($valuelists[$key]);
88
-            }
89
-        }
90
-        $valuelists = array_values($valuelists);
91
-        $this->repository->valuelists = $valuelists;
92
-        $this->save();
93
-    }
75
+	/**
76
+	 * Delete a sitemap item by its slug
77
+	 *
78
+	 * @param $slug
79
+	 *
80
+	 * @throws \Exception
81
+	 */
82
+	public function deleteValuelistBySlug($slug)
83
+	{
84
+		$valuelists = $this->repository->valuelists;
85
+		foreach ($valuelists as $key => $valuelist) {
86
+			if ($valuelist->slug == $slug) {
87
+				unset($valuelists[$key]);
88
+			}
89
+		}
90
+		$valuelists = array_values($valuelists);
91
+		$this->repository->valuelists = $valuelists;
92
+		$this->save();
93
+	}
94 94
 }
95 95
\ No newline at end of file
Please login to merge, or discard this patch.
cloudcontrol/library/storage/factories/ValuelistFactory.php 1 patch
Indentation   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -12,34 +12,34 @@
 block discarded – undo
12 12
 
13 13
 class ValuelistFactory
14 14
 {
15
-    /**
16
-     * Create a sitemap item from post values
17
-     *
18
-     * @param $postValues
19
-     *
20
-     * @return \stdClass
21
-     * @throws \Exception
22
-     */
23
-    public static function createValuelistFromPostValues($postValues)
24
-    {
25
-        if (isset($postValues['title'])) {
26
-            $valuelistObject = new \stdClass();
27
-            $valuelistObject->title = $postValues['title'];
28
-            $valuelistObject->slug = StringUtil::slugify($postValues['title']);
29
-            $valuelistObject->pairs = new \stdClass();
30
-            if (isset($postValues['keys'], $postValues['values'])) {
31
-                foreach ($postValues['keys'] as $key => $value) {
32
-                    $valuelistObject->pairs->$value = $postValues['values'][$key];
33
-                }
34
-            }
35
-            $object_vars = get_object_vars($valuelistObject->pairs);
36
-            ksort($object_vars);
37
-            $valuelistObject->pairs = (object) $object_vars;
15
+	/**
16
+	 * Create a sitemap item from post values
17
+	 *
18
+	 * @param $postValues
19
+	 *
20
+	 * @return \stdClass
21
+	 * @throws \Exception
22
+	 */
23
+	public static function createValuelistFromPostValues($postValues)
24
+	{
25
+		if (isset($postValues['title'])) {
26
+			$valuelistObject = new \stdClass();
27
+			$valuelistObject->title = $postValues['title'];
28
+			$valuelistObject->slug = StringUtil::slugify($postValues['title']);
29
+			$valuelistObject->pairs = new \stdClass();
30
+			if (isset($postValues['keys'], $postValues['values'])) {
31
+				foreach ($postValues['keys'] as $key => $value) {
32
+					$valuelistObject->pairs->$value = $postValues['values'][$key];
33
+				}
34
+			}
35
+			$object_vars = get_object_vars($valuelistObject->pairs);
36
+			ksort($object_vars);
37
+			$valuelistObject->pairs = (object) $object_vars;
38 38
 
39
-            return $valuelistObject;
40
-        } else {
41
-            throw new \Exception('Trying to create valuelist with invalid data.');
42
-        }
43
-    }
39
+			return $valuelistObject;
40
+		} else {
41
+			throw new \Exception('Trying to create valuelist with invalid data.');
42
+		}
43
+	}
44 44
 
45 45
 }
46 46
\ No newline at end of file
Please login to merge, or discard this patch.
cloudcontrol/library/storage/Repository.php 1 patch
Indentation   +316 added lines, -316 removed lines patch added patch discarded remove patch
@@ -22,138 +22,138 @@  discard block
 block discarded – undo
22 22
  */
23 23
 class Repository
24 24
 {
25
-    protected $storagePath;
26
-
27
-    protected $fileBasedSubsets = array('sitemap', 'applicationComponents', 'documentTypes', 'bricks', 'imageSet', 'images', 'files', 'users', 'valuelists');
28
-
29
-    protected $sitemap;
30
-    protected $sitemapChanges = false;
31
-
32
-    protected $applicationComponents;
33
-    protected $applicationComponentsChanges = false;
34
-
35
-    protected $documentTypes;
36
-    protected $documentTypesChanges = false;
37
-
38
-    protected $bricks;
39
-    protected $bricksChanges = false;
40
-
41
-    protected $imageSet;
42
-    protected $imageSetChanges = false;
43
-
44
-    protected $images;
45
-    protected $imagesChanges = false;
46
-
47
-    protected $files;
48
-    protected $filesChanges = false;
49
-
50
-    protected $users;
51
-    protected $usersChanges = false;
52
-
53
-    protected $valuelists;
54
-    protected $valuelistsChanges = false;
55
-
56
-    protected $contentDbHandle;
57
-
58
-
59
-    /**
60
-     * Repository constructor.
61
-     * @param $storagePath
62
-     * @throws \Exception
63
-     */
64
-    public function __construct($storagePath)
65
-    {
66
-        $storagePath = realpath($storagePath);
67
-        if (is_dir($storagePath) && $storagePath !== false) {
68
-            $this->storagePath = $storagePath;
69
-        } else {
70
-            throw new \Exception('Repository not yet initialized.');
71
-        }
72
-    }
73
-
74
-    /**
75
-     * Creates the folder in which to create all storage related files
76
-     *
77
-     * @param $storagePath
78
-     * @return bool
79
-     */
80
-    public static function create($storagePath)
81
-    {
82
-        return mkdir($storagePath);
83
-    }
84
-
85
-    /**
86
-     * Initiates default storage
87
-     * @throws \Exception
88
-     */
89
-    public function init()
90
-    {
91
-        $storageDefaultPath = realpath('../library/cc/install/_storage.json');
92
-        $contentSqlPath = realpath('../library/cc/install/content.sql');
93
-
94
-        $this->initConfigStorage($storageDefaultPath);
95
-        $this->initContentDb($contentSqlPath);
96
-
97
-        $this->save();
98
-    }
99
-
100
-    /**
101
-     * Load filebased subset and return it's contents
102
-     *
103
-     * @param $name
104
-     * @return mixed|string
105
-     * @throws \Exception
106
-     */
107
-    public function __get($name)
108
-    {
109
-        if (isset($this->$name)) {
110
-            if (in_array($name, $this->fileBasedSubsets)) {
111
-                return $this->$name;
112
-            } else {
113
-                throw new \Exception('Trying to get undefined property from Repository: ' . $name);
114
-            }
115
-        } else {
116
-            if (in_array($name, $this->fileBasedSubsets)) {
117
-                return $this->loadSubset($name);
118
-            } else {
119
-                throw new \Exception('Trying to get undefined property from Repository: ' . $name);
120
-            }
121
-        }
122
-    }
123
-
124
-    /**
125
-     * Set filebased subset contents
126
-     * @param $name
127
-     * @param $value
128
-     * @throws \Exception
129
-     */
130
-    public function __set($name, $value)
131
-    {
132
-        if (in_array($name, $this->fileBasedSubsets)) {
133
-            $this->$name = $value;
134
-            $changes = $name . 'Changes';
135
-            $this->$changes = true;
136
-        } else {
137
-            throw new \Exception('Trying to persist unknown subset in repository: ' . $name . ' <br /><pre>' . print_r($value, true) . '</pre>');
138
-        }
139
-    }
140
-
141
-    /**
142
-     * Persist all subsets
143
-     */
144
-    public function save()
145
-    {
146
-        array_map(function ($value) {
147
-        	$this->saveSubset($value);
25
+	protected $storagePath;
26
+
27
+	protected $fileBasedSubsets = array('sitemap', 'applicationComponents', 'documentTypes', 'bricks', 'imageSet', 'images', 'files', 'users', 'valuelists');
28
+
29
+	protected $sitemap;
30
+	protected $sitemapChanges = false;
31
+
32
+	protected $applicationComponents;
33
+	protected $applicationComponentsChanges = false;
34
+
35
+	protected $documentTypes;
36
+	protected $documentTypesChanges = false;
37
+
38
+	protected $bricks;
39
+	protected $bricksChanges = false;
40
+
41
+	protected $imageSet;
42
+	protected $imageSetChanges = false;
43
+
44
+	protected $images;
45
+	protected $imagesChanges = false;
46
+
47
+	protected $files;
48
+	protected $filesChanges = false;
49
+
50
+	protected $users;
51
+	protected $usersChanges = false;
52
+
53
+	protected $valuelists;
54
+	protected $valuelistsChanges = false;
55
+
56
+	protected $contentDbHandle;
57
+
58
+
59
+	/**
60
+	 * Repository constructor.
61
+	 * @param $storagePath
62
+	 * @throws \Exception
63
+	 */
64
+	public function __construct($storagePath)
65
+	{
66
+		$storagePath = realpath($storagePath);
67
+		if (is_dir($storagePath) && $storagePath !== false) {
68
+			$this->storagePath = $storagePath;
69
+		} else {
70
+			throw new \Exception('Repository not yet initialized.');
71
+		}
72
+	}
73
+
74
+	/**
75
+	 * Creates the folder in which to create all storage related files
76
+	 *
77
+	 * @param $storagePath
78
+	 * @return bool
79
+	 */
80
+	public static function create($storagePath)
81
+	{
82
+		return mkdir($storagePath);
83
+	}
84
+
85
+	/**
86
+	 * Initiates default storage
87
+	 * @throws \Exception
88
+	 */
89
+	public function init()
90
+	{
91
+		$storageDefaultPath = realpath('../library/cc/install/_storage.json');
92
+		$contentSqlPath = realpath('../library/cc/install/content.sql');
93
+
94
+		$this->initConfigStorage($storageDefaultPath);
95
+		$this->initContentDb($contentSqlPath);
96
+
97
+		$this->save();
98
+	}
99
+
100
+	/**
101
+	 * Load filebased subset and return it's contents
102
+	 *
103
+	 * @param $name
104
+	 * @return mixed|string
105
+	 * @throws \Exception
106
+	 */
107
+	public function __get($name)
108
+	{
109
+		if (isset($this->$name)) {
110
+			if (in_array($name, $this->fileBasedSubsets)) {
111
+				return $this->$name;
112
+			} else {
113
+				throw new \Exception('Trying to get undefined property from Repository: ' . $name);
114
+			}
115
+		} else {
116
+			if (in_array($name, $this->fileBasedSubsets)) {
117
+				return $this->loadSubset($name);
118
+			} else {
119
+				throw new \Exception('Trying to get undefined property from Repository: ' . $name);
120
+			}
121
+		}
122
+	}
123
+
124
+	/**
125
+	 * Set filebased subset contents
126
+	 * @param $name
127
+	 * @param $value
128
+	 * @throws \Exception
129
+	 */
130
+	public function __set($name, $value)
131
+	{
132
+		if (in_array($name, $this->fileBasedSubsets)) {
133
+			$this->$name = $value;
134
+			$changes = $name . 'Changes';
135
+			$this->$changes = true;
136
+		} else {
137
+			throw new \Exception('Trying to persist unknown subset in repository: ' . $name . ' <br /><pre>' . print_r($value, true) . '</pre>');
138
+		}
139
+	}
140
+
141
+	/**
142
+	 * Persist all subsets
143
+	 */
144
+	public function save()
145
+	{
146
+		array_map(function ($value) {
147
+			$this->saveSubset($value);
148 148
 		}, $this->fileBasedSubsets);
149
-    }
150
-
151
-    /**
152
-     * Persist subset to disk
153
-     * @param $subset
154
-     */
155
-    protected function saveSubset($subset)
156
-    {
149
+	}
150
+
151
+	/**
152
+	 * Persist subset to disk
153
+	 * @param $subset
154
+	 */
155
+	protected function saveSubset($subset)
156
+	{
157 157
 		$changes = $subset . 'Changes';
158 158
 		if ($this->$changes === true) {
159 159
 			$json = json_encode($this->$subset, JSON_PRETTY_PRINT);
@@ -162,69 +162,69 @@  discard block
 block discarded – undo
162 162
 
163 163
 			$this->$changes = false;
164 164
 		}
165
-    }
166
-
167
-    /**
168
-     * Load subset from disk
169
-     * @param $subset
170
-     * @return mixed|string
171
-     */
172
-    protected function loadSubset($subset)
173
-    {
174
-        $subsetStoragePath = $this->storagePath . DIRECTORY_SEPARATOR . $subset . '.json';
175
-        $json = file_get_contents($subsetStoragePath);
176
-        $json = json_decode($json);
177
-        $this->$subset = $json;
178
-        return $json;
179
-    }
180
-
181
-    /**
182
-     * @param $contentSqlPath
183
-     */
184
-    protected function initContentDb($contentSqlPath)
185
-    {
186
-        $db = $this->getContentDbHandle();
187
-        $sql = file_get_contents($contentSqlPath);
188
-        $db->exec($sql);
189
-    }
190
-
191
-    /**
192
-     * @param $storageDefaultPath
193
-     */
194
-    protected function initConfigStorage($storageDefaultPath)
195
-    {
196
-        $json = file_get_contents($storageDefaultPath);
197
-        $json = json_decode($json);
198
-        $this->sitemap = $json->sitemap;
199
-        $this->sitemapChanges = true;
200
-        $this->applicationComponents = $json->applicationComponents;
201
-        $this->applicationComponentsChanges = true;
202
-        $this->documentTypes = $json->documentTypes;
203
-        $this->documentTypesChanges = true;
204
-        $this->bricks = $json->bricks;
205
-        $this->bricksChanges = true;
206
-        $this->imageSet = $json->imageSet;
207
-        $this->imageSetChanges = true;
208
-        $this->images = $json->images;
209
-        $this->imagesChanges = true;
210
-        $this->files = $json->files;
211
-        $this->filesChanges = true;
212
-        $this->users = $json->users;
213
-        $this->usersChanges = true;
214
-        $this->valuelists = $json->valuelists;
215
-        $this->valuelistsChanges = true;
216
-    }
217
-
218
-    /**
219
-     * @return \PDO
220
-     */
221
-    public function getContentDbHandle()
222
-    {
223
-        if ($this->contentDbHandle === null) {
224
-            $this->contentDbHandle = new \PDO('sqlite:' . $this->storagePath . DIRECTORY_SEPARATOR . 'content.db');
225
-        }
226
-        return $this->contentDbHandle;
227
-    }
165
+	}
166
+
167
+	/**
168
+	 * Load subset from disk
169
+	 * @param $subset
170
+	 * @return mixed|string
171
+	 */
172
+	protected function loadSubset($subset)
173
+	{
174
+		$subsetStoragePath = $this->storagePath . DIRECTORY_SEPARATOR . $subset . '.json';
175
+		$json = file_get_contents($subsetStoragePath);
176
+		$json = json_decode($json);
177
+		$this->$subset = $json;
178
+		return $json;
179
+	}
180
+
181
+	/**
182
+	 * @param $contentSqlPath
183
+	 */
184
+	protected function initContentDb($contentSqlPath)
185
+	{
186
+		$db = $this->getContentDbHandle();
187
+		$sql = file_get_contents($contentSqlPath);
188
+		$db->exec($sql);
189
+	}
190
+
191
+	/**
192
+	 * @param $storageDefaultPath
193
+	 */
194
+	protected function initConfigStorage($storageDefaultPath)
195
+	{
196
+		$json = file_get_contents($storageDefaultPath);
197
+		$json = json_decode($json);
198
+		$this->sitemap = $json->sitemap;
199
+		$this->sitemapChanges = true;
200
+		$this->applicationComponents = $json->applicationComponents;
201
+		$this->applicationComponentsChanges = true;
202
+		$this->documentTypes = $json->documentTypes;
203
+		$this->documentTypesChanges = true;
204
+		$this->bricks = $json->bricks;
205
+		$this->bricksChanges = true;
206
+		$this->imageSet = $json->imageSet;
207
+		$this->imageSetChanges = true;
208
+		$this->images = $json->images;
209
+		$this->imagesChanges = true;
210
+		$this->files = $json->files;
211
+		$this->filesChanges = true;
212
+		$this->users = $json->users;
213
+		$this->usersChanges = true;
214
+		$this->valuelists = $json->valuelists;
215
+		$this->valuelistsChanges = true;
216
+	}
217
+
218
+	/**
219
+	 * @return \PDO
220
+	 */
221
+	public function getContentDbHandle()
222
+	{
223
+		if ($this->contentDbHandle === null) {
224
+			$this->contentDbHandle = new \PDO('sqlite:' . $this->storagePath . DIRECTORY_SEPARATOR . 'content.db');
225
+		}
226
+		return $this->contentDbHandle;
227
+	}
228 228
 
229 229
 	/**
230 230
 	 * Get all documents
@@ -234,13 +234,13 @@  discard block
 block discarded – undo
234 234
 	 * @return array
235 235
 	 * @throws \Exception
236 236
 	 */
237
-    public function getDocuments($state = 'published')
238
-    {
237
+	public function getDocuments($state = 'published')
238
+	{
239 239
 		if (!in_array($state, Document::$DOCUMENT_STATES)) {
240 240
 			throw new \Exception('Unsupported document state: ' . $state);
241 241
 		}
242
-        return $this->getDocumentsByPath('/', $state);
243
-    }
242
+		return $this->getDocumentsByPath('/', $state);
243
+	}
244 244
 
245 245
 	public function getDocumentsWithState($folderPath = '/')
246 246
 	{
@@ -287,51 +287,51 @@  discard block
 block discarded – undo
287 287
 	 * @return array
288 288
 	 * @throws \Exception
289 289
 	 */
290
-    public function getDocumentsByPath($folderPath, $state = 'published')
291
-    {
292
-    	if (!in_array($state, Document::$DOCUMENT_STATES)) {
293
-    		throw new \Exception('Unsupported document state: ' . $state);
290
+	public function getDocumentsByPath($folderPath, $state = 'published')
291
+	{
292
+		if (!in_array($state, Document::$DOCUMENT_STATES)) {
293
+			throw new \Exception('Unsupported document state: ' . $state);
294 294
 		}
295
-        $db = $this->getContentDbHandle();
296
-        $folderPathWithWildcard = $folderPath . '%';
295
+		$db = $this->getContentDbHandle();
296
+		$folderPathWithWildcard = $folderPath . '%';
297 297
 
298
-        $sql = 'SELECT *
298
+		$sql = 'SELECT *
299 299
               FROM documents_' . $state . '
300 300
              WHERE `path` LIKE ' . $db->quote($folderPathWithWildcard) . '
301 301
                AND substr(`path`, ' . (strlen($folderPath) + 1) . ') NOT LIKE "%/%"
302 302
                AND path != ' . $db->quote($folderPath) . '
303 303
           ORDER BY `type` DESC, `path` ASC';
304
-        $stmt = $this->getDbStatement($sql);
304
+		$stmt = $this->getDbStatement($sql);
305 305
 
306
-        $documents = $stmt->fetchAll(\PDO::FETCH_CLASS, '\library\storage\Document');
307
-        foreach ($documents as $key => $document) {
306
+		$documents = $stmt->fetchAll(\PDO::FETCH_CLASS, '\library\storage\Document');
307
+		foreach ($documents as $key => $document) {
308 308
 			$documents = $this->setAssetsToDocumentFolders($document, $db, $documents, $key);
309
-        }
310
-        return $documents;
311
-    }
312
-
313
-
314
-    /**
315
-     * @param $path
316
-     * @return bool|Document
317
-     */
318
-    public function getDocumentContainerByPath($path)
319
-    {
320
-        $document = $this->getDocumentByPath($path, 'unpublished');
321
-        if ($document === false) {
322
-            return false;
323
-        }
324
-        $slugLength = strlen($document->slug);
325
-        $containerPath = substr($path, 0, -$slugLength);
326
-        if ($containerPath === '/') {
327
-            return $this->getRootFolder();
328
-        }
329
-        if (substr($containerPath, -1) === '/'){
309
+		}
310
+		return $documents;
311
+	}
312
+
313
+
314
+	/**
315
+	 * @param $path
316
+	 * @return bool|Document
317
+	 */
318
+	public function getDocumentContainerByPath($path)
319
+	{
320
+		$document = $this->getDocumentByPath($path, 'unpublished');
321
+		if ($document === false) {
322
+			return false;
323
+		}
324
+		$slugLength = strlen($document->slug);
325
+		$containerPath = substr($path, 0, -$slugLength);
326
+		if ($containerPath === '/') {
327
+			return $this->getRootFolder();
328
+		}
329
+		if (substr($containerPath, -1) === '/'){
330 330
 			$containerPath = substr($containerPath, 0, -1);
331 331
 		}
332
-        $containerFolder = $this->getDocumentByPath($containerPath, 'unpublished');
333
-        return $containerFolder;
334
-    }
332
+		$containerFolder = $this->getDocumentByPath($containerPath, 'unpublished');
333
+		return $containerFolder;
334
+	}
335 335
 
336 336
 	/**
337 337
 	 * @param        $path
@@ -340,23 +340,23 @@  discard block
 block discarded – undo
340 340
 	 * @return bool|\library\storage\Document
341 341
 	 * @throws \Exception
342 342
 	 */
343
-    public function getDocumentByPath($path, $state = 'published')
344
-    {
343
+	public function getDocumentByPath($path, $state = 'published')
344
+	{
345 345
 		if (!in_array($state, Document::$DOCUMENT_STATES)) {
346 346
 			throw new \Exception('Unsupported document state: ' . $state);
347 347
 		}
348
-        $db = $this->getContentDbHandle();
349
-        $document = $this->fetchDocument('
348
+		$db = $this->getContentDbHandle();
349
+		$document = $this->fetchDocument('
350 350
             SELECT *
351 351
               FROM documents_' .  $state . '
352 352
              WHERE path = ' . $db->quote($path) . '
353 353
         ');
354
-        if ($document instanceof Document && $document->type === 'folder') {
355
-            $document->dbHandle = $db;
356
-            $document->documentStorage = new DocumentStorage($this);
357
-        }
358
-        return $document;
359
-    }
354
+		if ($document instanceof Document && $document->type === 'folder') {
355
+			$document->dbHandle = $db;
356
+			$document->documentStorage = new DocumentStorage($this);
357
+		}
358
+		return $document;
359
+	}
360 360
 
361 361
 	/**
362 362
 	 * Returns the count of all documents stored in the db
@@ -451,58 +451,58 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
Please login to merge, or discard this patch.
cloudcontrol/library/components/cms/DocumentRouting.php 1 patch
Indentation   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -12,33 +12,33 @@  discard block
 block discarded – undo
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);
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 30
 		$this->valuelistsRouting($request, $relativeCmsUri, $cmsComponent);
31
-    }
31
+	}
32 32
 
33 33
 
34
-    /**
35
-     * @param $request
36
-     * @param $relativeCmsUri
37
-     * @param CmsComponent $cmsComponent
38
-     * @throws \Exception
39
-     */
40
-    private function documentRouting($request, $relativeCmsUri, $cmsComponent)
41
-    {
34
+	/**
35
+	 * @param $request
36
+	 * @param $relativeCmsUri
37
+	 * @param CmsComponent $cmsComponent
38
+	 * @throws \Exception
39
+	 */
40
+	private function documentRouting($request, $relativeCmsUri, $cmsComponent)
41
+	{
42 42
 		if ($relativeCmsUri == '/documents/new-document' && isset($request::$get[CmsComponent::GET_PARAMETER_PATH])) {
43 43
 			$this->documentNewRoute($request, $cmsComponent);
44 44
 		} elseif (isset($request::$get[CmsComponent::GET_PARAMETER_SLUG])){
@@ -50,23 +50,23 @@  discard block
 block discarded – undo
50 50
 				case '/documents/unpublish-document': $this->unpublishDocumentRoute($request, $cmsComponent); break;
51 51
 			}
52 52
 		}
53
-    }
53
+	}
54 54
 
55
-    /**
56
-     * @param $request
57
-     * @param $relativeCmsUri
58
-     * @param CmsComponent $cmsComponent
59
-     */
60
-    private function folderRouting($request, $relativeCmsUri, $cmsComponent)
61
-    {
62
-        if ($relativeCmsUri == '/documents/new-folder' && isset($request::$get[CmsComponent::GET_PARAMETER_PATH])) {
55
+	/**
56
+	 * @param $request
57
+	 * @param $relativeCmsUri
58
+	 * @param CmsComponent $cmsComponent
59
+	 */
60
+	private function folderRouting($request, $relativeCmsUri, $cmsComponent)
61
+	{
62
+		if ($relativeCmsUri == '/documents/new-folder' && isset($request::$get[CmsComponent::GET_PARAMETER_PATH])) {
63 63
 			$this->newFolderRoute($request, $cmsComponent);
64
-        } else if ($relativeCmsUri == '/documents/edit-folder' && isset($request::$get[CmsComponent::GET_PARAMETER_SLUG])) {
64
+		} else if ($relativeCmsUri == '/documents/edit-folder' && isset($request::$get[CmsComponent::GET_PARAMETER_SLUG])) {
65 65
 			$this->editFolderRoute($request, $cmsComponent);
66
-        } else if ($relativeCmsUri == '/documents/delete-folder' && isset($request::$get[CmsComponent::GET_PARAMETER_SLUG])) {
66
+		} else if ($relativeCmsUri == '/documents/delete-folder' && isset($request::$get[CmsComponent::GET_PARAMETER_SLUG])) {
67 67
 			$this->deleteFolderRoute($request, $cmsComponent);
68
-        }
69
-    }
68
+		}
69
+	}
70 70
 
71 71
 	private function valuelistsRouting($request, $relativeCmsUri, $cmsComponent)
72 72
 	{
Please login to merge, or discard this patch.