diff options
Diffstat (limited to 'application/updater/Updater.php')
-rw-r--r-- | application/updater/Updater.php | 30 |
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 | } |