Passed
Push — develop ( f5d3ab...1cfb3a )
by Jens
03:36
created
cloudcontrol/library/storage/Document.php 1 patch
Indentation   +67 added lines, -67 removed lines patch added patch discarded remove patch
@@ -20,60 +20,60 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
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,134 +22,134 @@  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');
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
 block discarded – undo
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
 block discarded – undo
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
 	{
@@ -285,55 +285,55 @@  discard block
 block discarded – undo
285 285
 	 * @return array
286 286
 	 * @throws \Exception
287 287
 	 */
288
-    public function getDocumentsByPath($folderPath, $state = 'published')
289
-    {
290
-    	if (!in_array($state, Document::$DOCUMENT_STATES)) {
291
-    		throw new \Exception('Unsupported document state: ' . $state);
288
+	public function getDocumentsByPath($folderPath, $state = 'published')
289
+	{
290
+		if (!in_array($state, Document::$DOCUMENT_STATES)) {
291
+			throw new \Exception('Unsupported document state: ' . $state);
292 292
 		}
293
-        $db = $this->getContentDbHandle();
294
-        $folderPathWithWildcard = $folderPath . '%';
293
+		$db = $this->getContentDbHandle();
294
+		$folderPathWithWildcard = $folderPath . '%';
295 295
 
296
-        $sql = 'SELECT *
296
+		$sql = 'SELECT *
297 297
               FROM documents_' . $state . '
298 298
              WHERE `path` LIKE ' . $db->quote($folderPathWithWildcard) . '
299 299
                AND substr(`path`, ' . (strlen($folderPath) + 1) . ') NOT LIKE "%/%"
300 300
                AND path != ' . $db->quote($folderPath) . '
301 301
           ORDER BY `type` DESC, `path` ASC';
302
-        $stmt = $this->getDbStatement($sql);
303
-
304
-        $documents = $stmt->fetchAll(\PDO::FETCH_CLASS, '\library\storage\Document');
305
-        foreach ($documents as $key => $document) {
306
-            if ($document->type === 'folder') {
307
-                $document->dbHandle = $db;
308
-                $document->documentStorage = new DocumentStorage($this);
309
-                $documents[$key] = $document;
310
-            }
311
-        }
312
-        return $documents;
313
-    }
314
-
315
-
316
-    /**
317
-     * @param $path
318
-     * @return bool|Document
319
-     */
320
-    public function getDocumentContainerByPath($path)
321
-    {
322
-        $document = $this->getDocumentByPath($path, 'unpublished');
323
-        if ($document === false) {
324
-            return false;
325
-        }
326
-        $slugLength = strlen($document->slug);
327
-        $containerPath = substr($path, 0, -$slugLength);
328
-        if ($containerPath === '/') {
329
-            return $this->getRootFolder();
330
-        }
331
-        if (substr($containerPath, -1) === '/'){
302
+		$stmt = $this->getDbStatement($sql);
303
+
304
+		$documents = $stmt->fetchAll(\PDO::FETCH_CLASS, '\library\storage\Document');
305
+		foreach ($documents as $key => $document) {
306
+			if ($document->type === 'folder') {
307
+				$document->dbHandle = $db;
308
+				$document->documentStorage = new DocumentStorage($this);
309
+				$documents[$key] = $document;
310
+			}
311
+		}
312
+		return $documents;
313
+	}
314
+
315
+
316
+	/**
317
+	 * @param $path
318
+	 * @return bool|Document
319
+	 */
320
+	public function getDocumentContainerByPath($path)
321
+	{
322
+		$document = $this->getDocumentByPath($path, 'unpublished');
323
+		if ($document === false) {
324
+			return false;
325
+		}
326
+		$slugLength = strlen($document->slug);
327
+		$containerPath = substr($path, 0, -$slugLength);
328
+		if ($containerPath === '/') {
329
+			return $this->getRootFolder();
330
+		}
331
+		if (substr($containerPath, -1) === '/'){
332 332
 			$containerPath = substr($containerPath, 0, -1);
333 333
 		}
334
-        $containerFolder = $this->getDocumentByPath($containerPath, 'unpublished');
335
-        return $containerFolder;
336
-    }
334
+		$containerFolder = $this->getDocumentByPath($containerPath, 'unpublished');
335
+		return $containerFolder;
336
+	}
337 337
 
338 338
 	/**
339 339
 	 * @param        $path
@@ -342,23 +342,23 @@  discard block
 block discarded – undo
342 342
 	 * @return bool|\library\storage\Document
343 343
 	 * @throws \Exception
344 344
 	 */
345
-    public function getDocumentByPath($path, $state = 'published')
346
-    {
345
+	public function getDocumentByPath($path, $state = 'published')
346
+	{
347 347
 		if (!in_array($state, Document::$DOCUMENT_STATES)) {
348 348
 			throw new \Exception('Unsupported document state: ' . $state);
349 349
 		}
350
-        $db = $this->getContentDbHandle();
351
-        $document = $this->fetchDocument('
350
+		$db = $this->getContentDbHandle();
351
+		$document = $this->fetchDocument('
352 352
             SELECT *
353 353
               FROM documents_' .  $state . '
354 354
              WHERE path = ' . $db->quote($path) . '
355 355
         ');
356
-        if ($document instanceof Document && $document->type === 'folder') {
357
-            $document->dbHandle = $db;
358
-            $document->documentStorage = new DocumentStorage($this);
359
-        }
360
-        return $document;
361
-    }
356
+		if ($document instanceof Document && $document->type === 'folder') {
357
+			$document->dbHandle = $db;
358
+			$document->documentStorage = new DocumentStorage($this);
359
+		}
360
+		return $document;
361
+	}
362 362
 
363 363
 	/**
364 364
 	 * Returns the count of all documents stored in the db
@@ -440,58 +440,58 @@  discard block
 block discarded – undo
440 440
 	}
441 441
 
442 442
 	/**
443
-     * Return the results of the query as array of Documents
444
-     * @param $sql
445
-     * @return array
446
-     * @throws \Exception
447
-     */
448
-    protected function fetchAllDocuments($sql)
449
-    {
450
-        $stmt = $this->getDbStatement($sql);
451
-        return $stmt->fetchAll(\PDO::FETCH_CLASS, '\library\storage\Document');
452
-    }
453
-
454
-    /**
455
-     * Return the result of the query as Document
456
-     * @param $sql
457
-     * @return mixed
458
-     * @throws \Exception
459
-     */
460
-    protected function fetchDocument($sql)
461
-    {
462
-        $stmt = $this->getDbStatement($sql);
463
-        return $stmt->fetchObject('\library\storage\Document');
464
-    }
465
-
466
-    /**
467
-     * Prepare the sql statement
468
-     * @param $sql
469
-     * @return \PDOStatement
470
-     * @throws \Exception
471
-     */
472
-    protected function getDbStatement($sql)
473
-    {
474
-        $db = $this->getContentDbHandle();
475
-        $stmt = $db->query($sql);
476
-        if ($stmt === false) {
477
-            $errorInfo = $db->errorInfo();
478
-            $errorMsg = $errorInfo[2];
479
-            throw new \Exception('SQLite Exception: ' . $errorMsg . ' in SQL: <br /><pre>' . $sql . '</pre>');
480
-        }
481
-        return $stmt;
482
-    }
483
-
484
-    /**
485
-     * Create a (non-existent) root folder Document and return it
486
-     * @return Document
487
-     */
488
-    protected function getRootFolder()
489
-    {
490
-        $rootFolder = new Document();
491
-        $rootFolder->path = '/';
492
-        $rootFolder->type = 'folder';
493
-        return $rootFolder;
494
-    }
443
+	 * Return the results of the query as array of Documents
444
+	 * @param $sql
445
+	 * @return array
446
+	 * @throws \Exception
447
+	 */
448
+	protected function fetchAllDocuments($sql)
449
+	{
450
+		$stmt = $this->getDbStatement($sql);
451
+		return $stmt->fetchAll(\PDO::FETCH_CLASS, '\library\storage\Document');
452
+	}
453
+
454
+	/**
455
+	 * Return the result of the query as Document
456
+	 * @param $sql
457
+	 * @return mixed
458
+	 * @throws \Exception
459
+	 */
460
+	protected function fetchDocument($sql)
461
+	{
462
+		$stmt = $this->getDbStatement($sql);
463
+		return $stmt->fetchObject('\library\storage\Document');
464
+	}
465
+
466
+	/**
467
+	 * Prepare the sql statement
468
+	 * @param $sql
469
+	 * @return \PDOStatement
470
+	 * @throws \Exception
471
+	 */
472
+	protected function getDbStatement($sql)
473
+	{
474
+		$db = $this->getContentDbHandle();
475
+		$stmt = $db->query($sql);
476
+		if ($stmt === false) {
477
+			$errorInfo = $db->errorInfo();
478
+			$errorMsg = $errorInfo[2];
479
+			throw new \Exception('SQLite Exception: ' . $errorMsg . ' in SQL: <br /><pre>' . $sql . '</pre>');
480
+		}
481
+		return $stmt;
482
+	}
483
+
484
+	/**
485
+	 * Create a (non-existent) root folder Document and return it
486
+	 * @return Document
487
+	 */
488
+	protected function getRootFolder()
489
+	{
490
+		$rootFolder = new Document();
491
+		$rootFolder->path = '/';
492
+		$rootFolder->type = 'folder';
493
+		return $rootFolder;
494
+	}
495 495
 
496 496
 	/**
497 497
 	 * Save the document to the database
@@ -503,13 +503,13 @@  discard block
 block discarded – undo
503 503
 	 * @throws \Exception
504 504
 	 * @internal param $path
505 505
 	 */
506
-    public function saveDocument($documentObject, $state = 'published')
507
-    {
506
+	public function saveDocument($documentObject, $state = 'published')
507
+	{
508 508
 		if (!in_array($state, Document::$DOCUMENT_STATES)) {
509 509
 			throw new \Exception('Unsupported document state: ' . $state);
510 510
 		}
511
-        $db = $this->getContentDbHandle();
512
-        $stmt = $this->getDbStatement('
511
+		$db = $this->getContentDbHandle();
512
+		$stmt = $this->getDbStatement('
513 513
             INSERT OR REPLACE INTO documents_' . $state . ' (`path`,`title`,`slug`,`type`,`documentType`,`documentTypeSlug`,`state`,`lastModificationDate`,`creationDate`,`lastModifiedBy`,`fields`,`bricks`,`dynamicBricks`)
514 514
             VALUES(
515 515
               ' . $db->quote($documentObject->path) . ',
@@ -527,9 +527,9 @@  discard block
 block discarded – undo
527 527
               ' . $db->quote(json_encode($documentObject->dynamicBricks)) . '
528 528
             )
529 529
         ');
530
-        $result = $stmt->execute();
531
-        return $result;
532
-    }
530
+		$result = $stmt->execute();
531
+		return $result;
532
+	}
533 533
 
534 534
 	/**
535 535
 	 * Delete the document from the database
@@ -540,27 +540,27 @@  discard block
 block discarded – undo
540 540
 	 * @internal param string $state
541 541
 	 *
542 542
 	 */
543
-    public function deleteDocumentByPath($path)
544
-    {
545
-        $db = $this->getContentDbHandle();
546
-        $documentToDelete = $this->getDocumentByPath($path, 'unpublished');
547
-        if ($documentToDelete instanceof Document) {
548
-            if ($documentToDelete->type == 'document') {
549
-                $stmt = $this->getDbStatement('
543
+	public function deleteDocumentByPath($path)
544
+	{
545
+		$db = $this->getContentDbHandle();
546
+		$documentToDelete = $this->getDocumentByPath($path, 'unpublished');
547
+		if ($documentToDelete instanceof Document) {
548
+			if ($documentToDelete->type == 'document') {
549
+				$stmt = $this->getDbStatement('
550 550
                     DELETE FROM documents_unpublished
551 551
                           WHERE path = ' . $db->quote($path) . '
552 552
                 ');
553
-                $stmt->execute();
554
-            } elseif ($documentToDelete->type == 'folder') {
555
-                $folderPathWithWildcard = $path . '%';
556
-                $stmt = $this->getDbStatement('
553
+				$stmt->execute();
554
+			} elseif ($documentToDelete->type == 'folder') {
555
+				$folderPathWithWildcard = $path . '%';
556
+				$stmt = $this->getDbStatement('
557 557
                     DELETE FROM documents_unpublished
558 558
                           WHERE (path LIKE ' . $db->quote($folderPathWithWildcard) . '
559 559
                             AND substr(`path`, ' . (strlen($path) + 1) . ', 1) = "/")
560 560
                             OR path = ' . $db->quote($path) . '
561 561
                 ');
562
-                $stmt->execute();
563
-            }
564
-        }
565
-    }
562
+				$stmt->execute();
563
+			}
564
+		}
565
+	}
566 566
 }
567 567
\ No newline at end of file
Please login to merge, or discard this patch.
cloudcontrol/library/components/cms/DocumentRouting.php 1 patch
Indentation   +45 added lines, -45 removed lines patch added patch discarded remove patch
@@ -12,62 +12,62 @@
 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);
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
-        if ($relativeCmsUri == '/documents/new-document' && isset($request::$get[CmsComponent::GET_PARAMETER_PATH])) {
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
+		if ($relativeCmsUri == '/documents/new-document' && isset($request::$get[CmsComponent::GET_PARAMETER_PATH])) {
42 42
 			$this->documentNewRoute($request, $cmsComponent);
43
-        } elseif ($relativeCmsUri == '/documents/edit-document' && isset($request::$get[CmsComponent::GET_PARAMETER_SLUG])) {
43
+		} elseif ($relativeCmsUri == '/documents/edit-document' && isset($request::$get[CmsComponent::GET_PARAMETER_SLUG])) {
44 44
 			$this->editDocumentRoute($request, $cmsComponent);
45
-        } elseif ($relativeCmsUri == '/documents/get-brick' && isset($request::$get[CmsComponent::GET_PARAMETER_SLUG])) {
45
+		} elseif ($relativeCmsUri == '/documents/get-brick' && isset($request::$get[CmsComponent::GET_PARAMETER_SLUG])) {
46 46
 			$this->getBrickRoute($request, $cmsComponent);
47
-        } else if ($relativeCmsUri == '/documents/delete-document' && isset($request::$get[CmsComponent::GET_PARAMETER_SLUG])) {
47
+		} else if ($relativeCmsUri == '/documents/delete-document' && isset($request::$get[CmsComponent::GET_PARAMETER_SLUG])) {
48 48
 			$this->deleteDocumentRoute($request, $cmsComponent);
49
-        } else if ($relativeCmsUri == '/documents/publish-document' && isset($request::$get[CmsComponent::GET_PARAMETER_SLUG])) {
49
+		} else if ($relativeCmsUri == '/documents/publish-document' && isset($request::$get[CmsComponent::GET_PARAMETER_SLUG])) {
50 50
 			$this->publishDocumentRoute($request, $cmsComponent);
51 51
 		} else if ($relativeCmsUri == '/documents/unpublish-document' && isset($request::$get[CmsComponent::GET_PARAMETER_SLUG])) {
52 52
 			$this->unpublishDocumentRoute($request, $cmsComponent);
53 53
 		}
54
-    }
55
-
56
-    /**
57
-     * @param $request
58
-     * @param $relativeCmsUri
59
-     * @param CmsComponent $cmsComponent
60
-     */
61
-    private function folderRouting($request, $relativeCmsUri, $cmsComponent)
62
-    {
63
-        if ($relativeCmsUri == '/documents/new-folder' && isset($request::$get[CmsComponent::GET_PARAMETER_PATH])) {
54
+	}
55
+
56
+	/**
57
+	 * @param $request
58
+	 * @param $relativeCmsUri
59
+	 * @param CmsComponent $cmsComponent
60
+	 */
61
+	private function folderRouting($request, $relativeCmsUri, $cmsComponent)
62
+	{
63
+		if ($relativeCmsUri == '/documents/new-folder' && isset($request::$get[CmsComponent::GET_PARAMETER_PATH])) {
64 64
 			$this->newFolderRoute($request, $cmsComponent);
65
-        } else if ($relativeCmsUri == '/documents/edit-folder' && isset($request::$get[CmsComponent::GET_PARAMETER_SLUG])) {
65
+		} else if ($relativeCmsUri == '/documents/edit-folder' && isset($request::$get[CmsComponent::GET_PARAMETER_SLUG])) {
66 66
 			$this->editFolderRoute($request, $cmsComponent);
67
-        } else if ($relativeCmsUri == '/documents/delete-folder' && isset($request::$get[CmsComponent::GET_PARAMETER_SLUG])) {
67
+		} else if ($relativeCmsUri == '/documents/delete-folder' && isset($request::$get[CmsComponent::GET_PARAMETER_SLUG])) {
68 68
 			$this->deleteFolderRoute($request, $cmsComponent);
69
-        }
70
-    }
69
+		}
70
+	}
71 71
 
72 72
 	/**
73 73
 	 * @param $request
Please login to merge, or discard this patch.