aboutsummaryrefslogtreecommitdiffhomepage
path: root/application/updater/Updater.php
diff options
context:
space:
mode:
authorArthurHoaro <arthur.hoareau@wizacha.com>2020-07-07 10:15:56 +0200
committerArthurHoaro <arthur@hoa.ro>2020-07-23 21:19:21 +0200
commitc4ad3d4f061d05a01db25aa54dda830ba776792d (patch)
tree691d91a5b0bbac62cee41f7b95ad1daa38d610b3 /application/updater/Updater.php
parent1a8ac737e52cb25a5c346232ee398f5908cee7d7 (diff)
downloadShaarli-c4ad3d4f061d05a01db25aa54dda830ba776792d.tar.gz
Shaarli-c4ad3d4f061d05a01db25aa54dda830ba776792d.tar.zst
Shaarli-c4ad3d4f061d05a01db25aa54dda830ba776792d.zip
Process Shaarli install through Slim controller
Diffstat (limited to 'application/updater/Updater.php')
-rw-r--r--application/updater/Updater.php30
1 files changed, 21 insertions, 9 deletions
diff --git a/application/updater/Updater.php b/application/updater/Updater.php
index f73a7452..4c578528 100644
--- a/application/updater/Updater.php
+++ b/application/updater/Updater.php
@@ -39,6 +39,11 @@ class Updater
39 protected $methods; 39 protected $methods;
40 40
41 /** 41 /**
42 * @var string $basePath Shaarli root directory (from HTTP Request)
43 */
44 protected $basePath = null;
45
46 /**
42 * Object constructor. 47 * Object constructor.
43 * 48 *
44 * @param array $doneUpdates Updates which are already done. 49 * @param array $doneUpdates Updates which are already done.
@@ -62,11 +67,13 @@ class Updater
62 * Run all new updates. 67 * Run all new updates.
63 * Update methods have to start with 'updateMethod' and return true (on success). 68 * Update methods have to start with 'updateMethod' and return true (on success).
64 * 69 *
70 * @param string $basePath Shaarli root directory (from HTTP Request)
71 *
65 * @return array An array containing ran updates. 72 * @return array An array containing ran updates.
66 * 73 *
67 * @throws UpdaterException If something went wrong. 74 * @throws UpdaterException If something went wrong.
68 */ 75 */
69 public function update() 76 public function update(string $basePath = null)
70 { 77 {
71 $updatesRan = []; 78 $updatesRan = [];
72 79
@@ -123,16 +130,14 @@ class Updater
123 } 130 }
124 131
125 /** 132 /**
126 * With the Slim routing system, default header link should be `./` instead of `?`. 133 * With the Slim routing system, default header link should be `/subfolder/` instead of `?`.
127 * Otherwise you can not go back to the home page. Example: `/picture-wall` -> `/picture-wall?` instead of `/`. 134 * Otherwise you can not go back to the home page.
135 * Example: `/subfolder/picture-wall` -> `/subfolder/picture-wall?` instead of `/subfolder/`.
128 */ 136 */
129 public function updateMethodRelativeHomeLink(): bool 137 public function updateMethodRelativeHomeLink(): bool
130 { 138 {
131 $link = trim($this->conf->get('general.header_link')); 139 if ('?' === trim($this->conf->get('general.header_link'))) {
132 if ($link[0] === '?') { 140 $this->conf->set('general.header_link', $this->basePath . '/', true, true);
133 $link = './'. ltrim($link, '?');
134
135 $this->conf->set('general.header_link', $link, true, true);
136 } 141 }
137 142
138 return true; 143 return true;
@@ -152,7 +157,7 @@ class Updater
152 && 1 === preg_match('/^\?([a-zA-Z0-9-_@]{6})($|&|#)/', $bookmark->getUrl(), $match) 157 && 1 === preg_match('/^\?([a-zA-Z0-9-_@]{6})($|&|#)/', $bookmark->getUrl(), $match)
153 ) { 158 ) {
154 $updated = true; 159 $updated = true;
155 $bookmark = $bookmark->setUrl('/shaare/' . $match[1]); 160 $bookmark = $bookmark->setUrl($this->basePath . '/shaare/' . $match[1]);
156 161
157 $this->bookmarkService->set($bookmark, false); 162 $this->bookmarkService->set($bookmark, false);
158 } 163 }
@@ -164,4 +169,11 @@ class Updater
164 169
165 return true; 170 return true;
166 } 171 }
172
173 public function setBasePath(string $basePath): self
174 {
175 $this->basePath = $basePath;
176
177 return $this;
178 }
167} 179}