diff options
Diffstat (limited to 'application/bookmark/BookmarkFileService.php')
-rw-r--r-- | application/bookmark/BookmarkFileService.php | 26 |
1 files changed, 20 insertions, 6 deletions
diff --git a/application/bookmark/BookmarkFileService.php b/application/bookmark/BookmarkFileService.php index 3d15d4c9..6e04f3b7 100644 --- a/application/bookmark/BookmarkFileService.php +++ b/application/bookmark/BookmarkFileService.php | |||
@@ -46,6 +46,9 @@ class BookmarkFileService implements BookmarkServiceInterface | |||
46 | /** @var bool true for logged in users. Default value to retrieve private bookmarks. */ | 46 | /** @var bool true for logged in users. Default value to retrieve private bookmarks. */ |
47 | protected $isLoggedIn; | 47 | protected $isLoggedIn; |
48 | 48 | ||
49 | /** @var bool Allow datastore alteration from not logged in users. */ | ||
50 | protected $anonymousPermission = false; | ||
51 | |||
49 | /** | 52 | /** |
50 | * @inheritDoc | 53 | * @inheritDoc |
51 | */ | 54 | */ |
@@ -64,7 +67,7 @@ class BookmarkFileService implements BookmarkServiceInterface | |||
64 | $this->bookmarks = $this->bookmarksIO->read(); | 67 | $this->bookmarks = $this->bookmarksIO->read(); |
65 | } catch (EmptyDataStoreException $e) { | 68 | } catch (EmptyDataStoreException $e) { |
66 | $this->bookmarks = new BookmarkArray(); | 69 | $this->bookmarks = new BookmarkArray(); |
67 | if ($isLoggedIn) { | 70 | if ($this->isLoggedIn) { |
68 | $this->save(); | 71 | $this->save(); |
69 | } | 72 | } |
70 | } | 73 | } |
@@ -154,7 +157,7 @@ class BookmarkFileService implements BookmarkServiceInterface | |||
154 | */ | 157 | */ |
155 | public function set($bookmark, $save = true) | 158 | public function set($bookmark, $save = true) |
156 | { | 159 | { |
157 | if ($this->isLoggedIn !== true) { | 160 | if (true !== $this->isLoggedIn && true !== $this->anonymousPermission) { |
158 | throw new Exception(t('You\'re not authorized to alter the datastore')); | 161 | throw new Exception(t('You\'re not authorized to alter the datastore')); |
159 | } | 162 | } |
160 | if (! $bookmark instanceof Bookmark) { | 163 | if (! $bookmark instanceof Bookmark) { |
@@ -179,7 +182,7 @@ class BookmarkFileService implements BookmarkServiceInterface | |||
179 | */ | 182 | */ |
180 | public function add($bookmark, $save = true) | 183 | public function add($bookmark, $save = true) |
181 | { | 184 | { |
182 | if ($this->isLoggedIn !== true) { | 185 | if (true !== $this->isLoggedIn && true !== $this->anonymousPermission) { |
183 | throw new Exception(t('You\'re not authorized to alter the datastore')); | 186 | throw new Exception(t('You\'re not authorized to alter the datastore')); |
184 | } | 187 | } |
185 | if (! $bookmark instanceof Bookmark) { | 188 | if (! $bookmark instanceof Bookmark) { |
@@ -204,7 +207,7 @@ class BookmarkFileService implements BookmarkServiceInterface | |||
204 | */ | 207 | */ |
205 | public function addOrSet($bookmark, $save = true) | 208 | public function addOrSet($bookmark, $save = true) |
206 | { | 209 | { |
207 | if ($this->isLoggedIn !== true) { | 210 | if (true !== $this->isLoggedIn && true !== $this->anonymousPermission) { |
208 | throw new Exception(t('You\'re not authorized to alter the datastore')); | 211 | throw new Exception(t('You\'re not authorized to alter the datastore')); |
209 | } | 212 | } |
210 | if (! $bookmark instanceof Bookmark) { | 213 | if (! $bookmark instanceof Bookmark) { |
@@ -221,7 +224,7 @@ class BookmarkFileService implements BookmarkServiceInterface | |||
221 | */ | 224 | */ |
222 | public function remove($bookmark, $save = true) | 225 | public function remove($bookmark, $save = true) |
223 | { | 226 | { |
224 | if ($this->isLoggedIn !== true) { | 227 | if (true !== $this->isLoggedIn && true !== $this->anonymousPermission) { |
225 | throw new Exception(t('You\'re not authorized to alter the datastore')); | 228 | throw new Exception(t('You\'re not authorized to alter the datastore')); |
226 | } | 229 | } |
227 | if (! $bookmark instanceof Bookmark) { | 230 | if (! $bookmark instanceof Bookmark) { |
@@ -274,10 +277,11 @@ class BookmarkFileService implements BookmarkServiceInterface | |||
274 | */ | 277 | */ |
275 | public function save() | 278 | public function save() |
276 | { | 279 | { |
277 | if (!$this->isLoggedIn) { | 280 | if (true !== $this->isLoggedIn && true !== $this->anonymousPermission) { |
278 | // TODO: raise an Exception instead | 281 | // TODO: raise an Exception instead |
279 | die('You are not authorized to change the database.'); | 282 | die('You are not authorized to change the database.'); |
280 | } | 283 | } |
284 | |||
281 | $this->bookmarks->reorder(); | 285 | $this->bookmarks->reorder(); |
282 | $this->bookmarksIO->write($this->bookmarks); | 286 | $this->bookmarksIO->write($this->bookmarks); |
283 | $this->pageCacheManager->invalidateCaches(); | 287 | $this->pageCacheManager->invalidateCaches(); |
@@ -357,6 +361,16 @@ class BookmarkFileService implements BookmarkServiceInterface | |||
357 | $initializer->initialize(); | 361 | $initializer->initialize(); |
358 | } | 362 | } |
359 | 363 | ||
364 | public function enableAnonymousPermission(): void | ||
365 | { | ||
366 | $this->anonymousPermission = true; | ||
367 | } | ||
368 | |||
369 | public function disableAnonymousPermission(): void | ||
370 | { | ||
371 | $this->anonymousPermission = false; | ||
372 | } | ||
373 | |||
360 | /** | 374 | /** |
361 | * Handles migration to the new database format (BookmarksArray). | 375 | * Handles migration to the new database format (BookmarksArray). |
362 | */ | 376 | */ |