aboutsummaryrefslogtreecommitdiffhomepage
path: root/application/updater
diff options
context:
space:
mode:
authorArthurHoaro <arthur@hoa.ro>2020-07-06 08:04:35 +0200
committerArthurHoaro <arthur@hoa.ro>2020-07-23 21:19:21 +0200
commit1a8ac737e52cb25a5c346232ee398f5908cee7d7 (patch)
tree31954c4e106b5743e2005d72c2d548a0be8d6dce /application/updater
parent6132d64748dfc6806ed25f71d2e078a5ed29d071 (diff)
downloadShaarli-1a8ac737e52cb25a5c346232ee398f5908cee7d7.tar.gz
Shaarli-1a8ac737e52cb25a5c346232ee398f5908cee7d7.tar.zst
Shaarli-1a8ac737e52cb25a5c346232ee398f5908cee7d7.zip
Process main page (linklist) through Slim controller
Including a bunch of improvements on the container, and helper used across new controllers.
Diffstat (limited to 'application/updater')
-rw-r--r--application/updater/Updater.php43
1 files changed, 40 insertions, 3 deletions
diff --git a/application/updater/Updater.php b/application/updater/Updater.php
index 4bbcb9f2..f73a7452 100644
--- a/application/updater/Updater.php
+++ b/application/updater/Updater.php
@@ -21,7 +21,7 @@ class Updater
21 /** 21 /**
22 * @var BookmarkServiceInterface instance. 22 * @var BookmarkServiceInterface instance.
23 */ 23 */
24 protected $linkServices; 24 protected $bookmarkService;
25 25
26 /** 26 /**
27 * @var ConfigManager $conf Configuration Manager instance. 27 * @var ConfigManager $conf Configuration Manager instance.
@@ -49,7 +49,7 @@ class Updater
49 public function __construct($doneUpdates, $linkDB, $conf, $isLoggedIn) 49 public function __construct($doneUpdates, $linkDB, $conf, $isLoggedIn)
50 { 50 {
51 $this->doneUpdates = $doneUpdates; 51 $this->doneUpdates = $doneUpdates;
52 $this->linkServices = $linkDB; 52 $this->bookmarkService = $linkDB;
53 $this->conf = $conf; 53 $this->conf = $conf;
54 $this->isLoggedIn = $isLoggedIn; 54 $this->isLoggedIn = $isLoggedIn;
55 55
@@ -68,7 +68,7 @@ class Updater
68 */ 68 */
69 public function update() 69 public function update()
70 { 70 {
71 $updatesRan = array(); 71 $updatesRan = [];
72 72
73 // If the user isn't logged in, exit without updating. 73 // If the user isn't logged in, exit without updating.
74 if ($this->isLoggedIn !== true) { 74 if ($this->isLoggedIn !== true) {
@@ -112,6 +112,16 @@ class Updater
112 return $this->doneUpdates; 112 return $this->doneUpdates;
113 } 113 }
114 114
115 public function readUpdates(string $updatesFilepath): array
116 {
117 return UpdaterUtils::read_updates_file($updatesFilepath);
118 }
119
120 public function writeUpdates(string $updatesFilepath, array $updates): void
121 {
122 UpdaterUtils::write_updates_file($updatesFilepath, $updates);
123 }
124
115 /** 125 /**
116 * With the Slim routing system, default header link should be `./` instead of `?`. 126 * With the Slim routing system, default header link should be `./` instead of `?`.
117 * Otherwise you can not go back to the home page. Example: `/picture-wall` -> `/picture-wall?` instead of `/`. 127 * Otherwise you can not go back to the home page. Example: `/picture-wall` -> `/picture-wall?` instead of `/`.
@@ -127,4 +137,31 @@ class Updater
127 137
128 return true; 138 return true;
129 } 139 }
140
141 /**
142 * With the Slim routing system, note bookmarks URL formatted `?abcdef`
143 * should be replaced with `/shaare/abcdef`
144 */
145 public function updateMethodMigrateExistingNotesUrl(): bool
146 {
147 $updated = false;
148
149 foreach ($this->bookmarkService->search() as $bookmark) {
150 if ($bookmark->isNote()
151 && startsWith($bookmark->getUrl(), '?')
152 && 1 === preg_match('/^\?([a-zA-Z0-9-_@]{6})($|&|#)/', $bookmark->getUrl(), $match)
153 ) {
154 $updated = true;
155 $bookmark = $bookmark->setUrl('/shaare/' . $match[1]);
156
157 $this->bookmarkService->set($bookmark, false);
158 }
159 }
160
161 if ($updated) {
162 $this->bookmarkService->save();
163 }
164
165 return true;
166 }
130} 167}