diff options
Diffstat (limited to 'application')
-rw-r--r-- | application/FileUtils.php | 2 | ||||
-rw-r--r-- | application/History.php | 4 | ||||
-rw-r--r-- | application/NetscapeBookmarkUtils.php | 1 | ||||
-rw-r--r-- | application/PageBuilder.php | 14 | ||||
-rw-r--r-- | application/Updater.php | 11 | ||||
-rw-r--r-- | application/api/ApiMiddleware.php | 5 | ||||
-rw-r--r-- | application/api/controllers/ApiController.php | 9 | ||||
-rw-r--r-- | application/api/controllers/History.php | 3 | ||||
-rw-r--r-- | application/api/controllers/Links.php | 5 |
9 files changed, 43 insertions, 11 deletions
diff --git a/application/FileUtils.php b/application/FileUtils.php index b8ad8970..a167f642 100644 --- a/application/FileUtils.php +++ b/application/FileUtils.php | |||
@@ -26,7 +26,7 @@ class FileUtils | |||
26 | * The file will be created if it doesn't exist. | 26 | * The file will be created if it doesn't exist. |
27 | * | 27 | * |
28 | * @param string $file File path. | 28 | * @param string $file File path. |
29 | * @param string $content Content to write. | 29 | * @param mixed $content Content to write. |
30 | * | 30 | * |
31 | * @return int|bool Number of bytes written or false if it fails. | 31 | * @return int|bool Number of bytes written or false if it fails. |
32 | * | 32 | * |
diff --git a/application/History.php b/application/History.php index f93b0356..116b9264 100644 --- a/application/History.php +++ b/application/History.php | |||
@@ -135,7 +135,7 @@ class History | |||
135 | 135 | ||
136 | $item = [ | 136 | $item = [ |
137 | 'event' => $status, | 137 | 'event' => $status, |
138 | 'datetime' => (new DateTime())->format(DateTime::ATOM), | 138 | 'datetime' => new DateTime(), |
139 | 'id' => $id !== null ? $id : '', | 139 | 'id' => $id !== null ? $id : '', |
140 | ]; | 140 | ]; |
141 | $this->history = array_merge([$item], $this->history); | 141 | $this->history = array_merge([$item], $this->history); |
@@ -177,7 +177,7 @@ class History | |||
177 | { | 177 | { |
178 | $comparaison = new DateTime('-'. $this->retentionTime . ' seconds'); | 178 | $comparaison = new DateTime('-'. $this->retentionTime . ' seconds'); |
179 | foreach ($this->history as $key => $value) { | 179 | foreach ($this->history as $key => $value) { |
180 | if (DateTime::createFromFormat(DateTime::ATOM, $value['datetime']) < $comparaison) { | 180 | if ($value['datetime'] < $comparaison) { |
181 | unset($this->history[$key]); | 181 | unset($this->history[$key]); |
182 | } | 182 | } |
183 | } | 183 | } |
diff --git a/application/NetscapeBookmarkUtils.php b/application/NetscapeBookmarkUtils.php index bbfde138..2a10ff22 100644 --- a/application/NetscapeBookmarkUtils.php +++ b/application/NetscapeBookmarkUtils.php | |||
@@ -180,6 +180,7 @@ class NetscapeBookmarkUtils | |||
180 | $newLink['id'] = $existingLink['id']; | 180 | $newLink['id'] = $existingLink['id']; |
181 | $newLink['created'] = $existingLink['created']; | 181 | $newLink['created'] = $existingLink['created']; |
182 | $newLink['updated'] = new DateTime(); | 182 | $newLink['updated'] = new DateTime(); |
183 | $newLink['shorturl'] = $existingLink['shorturl']; | ||
183 | $linkDb[$existingLink['id']] = $newLink; | 184 | $linkDb[$existingLink['id']] = $newLink; |
184 | $importCount++; | 185 | $importCount++; |
185 | $overwriteCount++; | 186 | $overwriteCount++; |
diff --git a/application/PageBuilder.php b/application/PageBuilder.php index 8e39455b..50e3f124 100644 --- a/application/PageBuilder.php +++ b/application/PageBuilder.php | |||
@@ -22,15 +22,22 @@ class PageBuilder | |||
22 | protected $conf; | 22 | protected $conf; |
23 | 23 | ||
24 | /** | 24 | /** |
25 | * @var LinkDB $linkDB instance. | ||
26 | */ | ||
27 | protected $linkDB; | ||
28 | |||
29 | /** | ||
25 | * PageBuilder constructor. | 30 | * PageBuilder constructor. |
26 | * $tpl is initialized at false for lazy loading. | 31 | * $tpl is initialized at false for lazy loading. |
27 | * | 32 | * |
28 | * @param ConfigManager $conf Configuration Manager instance (reference). | 33 | * @param ConfigManager $conf Configuration Manager instance (reference). |
34 | * @param LinkDB $linkDB instance. | ||
29 | */ | 35 | */ |
30 | public function __construct(&$conf) | 36 | public function __construct(&$conf, $linkDB = null) |
31 | { | 37 | { |
32 | $this->tpl = false; | 38 | $this->tpl = false; |
33 | $this->conf = $conf; | 39 | $this->conf = $conf; |
40 | $this->linkDB = $linkDB; | ||
34 | } | 41 | } |
35 | 42 | ||
36 | /** | 43 | /** |
@@ -81,6 +88,9 @@ class PageBuilder | |||
81 | $this->tpl->assign('feed_type', $this->conf->get('feed.show_atom', true) !== false ? 'atom' : 'rss'); | 88 | $this->tpl->assign('feed_type', $this->conf->get('feed.show_atom', true) !== false ? 'atom' : 'rss'); |
82 | $this->tpl->assign('hide_timestamps', $this->conf->get('privacy.hide_timestamps', false)); | 89 | $this->tpl->assign('hide_timestamps', $this->conf->get('privacy.hide_timestamps', false)); |
83 | $this->tpl->assign('token', getToken($this->conf)); | 90 | $this->tpl->assign('token', getToken($this->conf)); |
91 | if ($this->linkDB !== null) { | ||
92 | $this->tpl->assign('tags', $this->linkDB->allTags()); | ||
93 | } | ||
84 | // To be removed with a proper theme configuration. | 94 | // To be removed with a proper theme configuration. |
85 | $this->tpl->assign('conf', $this->conf); | 95 | $this->tpl->assign('conf', $this->conf); |
86 | } | 96 | } |
diff --git a/application/Updater.php b/application/Updater.php index 0fb68c5a..03d93a6f 100644 --- a/application/Updater.php +++ b/application/Updater.php | |||
@@ -440,6 +440,17 @@ class Updater | |||
440 | $this->conf->write($this->isLoggedIn); | 440 | $this->conf->write($this->isLoggedIn); |
441 | return true; | 441 | return true; |
442 | } | 442 | } |
443 | |||
444 | /** | ||
445 | * Reset history store file due to date format change. | ||
446 | */ | ||
447 | public function updateMethodResetHistoryFile() | ||
448 | { | ||
449 | if (is_file($this->conf->get('resource.history'))) { | ||
450 | unlink($this->conf->get('resource.history')); | ||
451 | } | ||
452 | return true; | ||
453 | } | ||
443 | } | 454 | } |
444 | 455 | ||
445 | /** | 456 | /** |
diff --git a/application/api/ApiMiddleware.php b/application/api/ApiMiddleware.php index 4120f7a9..ff209393 100644 --- a/application/api/ApiMiddleware.php +++ b/application/api/ApiMiddleware.php | |||
@@ -4,6 +4,7 @@ namespace Shaarli\Api; | |||
4 | use Shaarli\Api\Exceptions\ApiException; | 4 | use Shaarli\Api\Exceptions\ApiException; |
5 | use Shaarli\Api\Exceptions\ApiAuthorizationException; | 5 | use Shaarli\Api\Exceptions\ApiAuthorizationException; |
6 | 6 | ||
7 | use Shaarli\Config\ConfigManager; | ||
7 | use Slim\Container; | 8 | use Slim\Container; |
8 | use Slim\Http\Request; | 9 | use Slim\Http\Request; |
9 | use Slim\Http\Response; | 10 | use Slim\Http\Response; |
@@ -31,7 +32,7 @@ class ApiMiddleware | |||
31 | protected $container; | 32 | protected $container; |
32 | 33 | ||
33 | /** | 34 | /** |
34 | * @var \ConfigManager instance. | 35 | * @var ConfigManager instance. |
35 | */ | 36 | */ |
36 | protected $conf; | 37 | protected $conf; |
37 | 38 | ||
@@ -121,7 +122,7 @@ class ApiMiddleware | |||
121 | * | 122 | * |
122 | * FIXME! LinkDB could use a refactoring to avoid this trick. | 123 | * FIXME! LinkDB could use a refactoring to avoid this trick. |
123 | * | 124 | * |
124 | * @param \ConfigManager $conf instance. | 125 | * @param ConfigManager $conf instance. |
125 | */ | 126 | */ |
126 | protected function setLinkDb($conf) | 127 | protected function setLinkDb($conf) |
127 | { | 128 | { |
diff --git a/application/api/controllers/ApiController.php b/application/api/controllers/ApiController.php index f35b923a..3be85b98 100644 --- a/application/api/controllers/ApiController.php +++ b/application/api/controllers/ApiController.php | |||
@@ -2,6 +2,7 @@ | |||
2 | 2 | ||
3 | namespace Shaarli\Api\Controllers; | 3 | namespace Shaarli\Api\Controllers; |
4 | 4 | ||
5 | use Shaarli\Config\ConfigManager; | ||
5 | use \Slim\Container; | 6 | use \Slim\Container; |
6 | 7 | ||
7 | /** | 8 | /** |
@@ -19,7 +20,7 @@ abstract class ApiController | |||
19 | protected $ci; | 20 | protected $ci; |
20 | 21 | ||
21 | /** | 22 | /** |
22 | * @var \ConfigManager | 23 | * @var ConfigManager |
23 | */ | 24 | */ |
24 | protected $conf; | 25 | protected $conf; |
25 | 26 | ||
@@ -29,6 +30,11 @@ abstract class ApiController | |||
29 | protected $linkDb; | 30 | protected $linkDb; |
30 | 31 | ||
31 | /** | 32 | /** |
33 | * @var \History | ||
34 | */ | ||
35 | protected $history; | ||
36 | |||
37 | /** | ||
32 | * @var int|null JSON style option. | 38 | * @var int|null JSON style option. |
33 | */ | 39 | */ |
34 | protected $jsonStyle; | 40 | protected $jsonStyle; |
@@ -45,6 +51,7 @@ abstract class ApiController | |||
45 | $this->ci = $ci; | 51 | $this->ci = $ci; |
46 | $this->conf = $ci->get('conf'); | 52 | $this->conf = $ci->get('conf'); |
47 | $this->linkDb = $ci->get('db'); | 53 | $this->linkDb = $ci->get('db'); |
54 | $this->history = $ci->get('history'); | ||
48 | if ($this->conf->get('dev.debug', false)) { | 55 | if ($this->conf->get('dev.debug', false)) { |
49 | $this->jsonStyle = JSON_PRETTY_PRINT; | 56 | $this->jsonStyle = JSON_PRETTY_PRINT; |
50 | } else { | 57 | } else { |
diff --git a/application/api/controllers/History.php b/application/api/controllers/History.php index c4ff3e5d..2ff9deaf 100644 --- a/application/api/controllers/History.php +++ b/application/api/controllers/History.php | |||
@@ -28,8 +28,7 @@ class History extends ApiController | |||
28 | */ | 28 | */ |
29 | public function getHistory($request, $response) | 29 | public function getHistory($request, $response) |
30 | { | 30 | { |
31 | $history = (new \History($this->conf->get('resource.history')))->getHistory(); | 31 | $history = $this->history->getHistory(); |
32 | $history = array_reverse($history); | ||
33 | 32 | ||
34 | // Return history operations from the {offset}th, starting from {since}. | 33 | // Return history operations from the {offset}th, starting from {since}. |
35 | $since = \DateTime::createFromFormat(\DateTime::ATOM, $request->getParam('since')); | 34 | $since = \DateTime::createFromFormat(\DateTime::ATOM, $request->getParam('since')); |
diff --git a/application/api/controllers/Links.php b/application/api/controllers/Links.php index a40e974d..eb78dd26 100644 --- a/application/api/controllers/Links.php +++ b/application/api/controllers/Links.php | |||
@@ -141,6 +141,7 @@ class Links extends ApiController | |||
141 | 141 | ||
142 | $this->linkDb[$link['id']] = $link; | 142 | $this->linkDb[$link['id']] = $link; |
143 | $this->linkDb->save($this->conf->get('resource.page_cache')); | 143 | $this->linkDb->save($this->conf->get('resource.page_cache')); |
144 | $this->history->addLink($link); | ||
144 | $out = ApiUtils::formatLink($link, index_url($this->ci['environment'])); | 145 | $out = ApiUtils::formatLink($link, index_url($this->ci['environment'])); |
145 | $redirect = $this->ci->router->relativePathFor('getLink', ['id' => $link['id']]); | 146 | $redirect = $this->ci->router->relativePathFor('getLink', ['id' => $link['id']]); |
146 | return $response->withAddedHeader('Location', $redirect) | 147 | return $response->withAddedHeader('Location', $redirect) |
@@ -184,6 +185,7 @@ class Links extends ApiController | |||
184 | $responseLink = ApiUtils::updateLink($responseLink, $requestLink); | 185 | $responseLink = ApiUtils::updateLink($responseLink, $requestLink); |
185 | $this->linkDb[$responseLink['id']] = $responseLink; | 186 | $this->linkDb[$responseLink['id']] = $responseLink; |
186 | $this->linkDb->save($this->conf->get('resource.page_cache')); | 187 | $this->linkDb->save($this->conf->get('resource.page_cache')); |
188 | $this->history->updateLink($responseLink); | ||
187 | 189 | ||
188 | $out = ApiUtils::formatLink($responseLink, $index); | 190 | $out = ApiUtils::formatLink($responseLink, $index); |
189 | return $response->withJson($out, 200, $this->jsonStyle); | 191 | return $response->withJson($out, 200, $this->jsonStyle); |
@@ -205,9 +207,10 @@ class Links extends ApiController | |||
205 | if (! isset($this->linkDb[$args['id']])) { | 207 | if (! isset($this->linkDb[$args['id']])) { |
206 | throw new ApiLinkNotFoundException(); | 208 | throw new ApiLinkNotFoundException(); |
207 | } | 209 | } |
208 | 210 | $link = $this->linkDb[$args['id']]; | |
209 | unset($this->linkDb[(int) $args['id']]); | 211 | unset($this->linkDb[(int) $args['id']]); |
210 | $this->linkDb->save($this->conf->get('resource.page_cache')); | 212 | $this->linkDb->save($this->conf->get('resource.page_cache')); |
213 | $this->history->deleteLink($link); | ||
211 | 214 | ||
212 | return $response->withStatus(204); | 215 | return $response->withStatus(204); |
213 | } | 216 | } |