diff options
author | ArthurHoaro <arthur@hoa.ro> | 2017-05-07 16:50:20 +0200 |
---|---|---|
committer | ArthurHoaro <arthur@hoa.ro> | 2017-05-07 17:11:22 +0200 |
commit | 813849e5216cb87121e0f778a734575be6a36052 (patch) | |
tree | 45605ad43e3f751eba51d19f8c6955c3824e8d32 /application/api | |
parent | a4af59f47103a3f9c903eeddb1e30ab9cb7344f0 (diff) | |
download | Shaarli-813849e5216cb87121e0f778a734575be6a36052.tar.gz Shaarli-813849e5216cb87121e0f778a734575be6a36052.tar.zst Shaarli-813849e5216cb87121e0f778a734575be6a36052.zip |
Add history entries for API endpoint
CHANGED: datetime is now store as an object in history store file
Diffstat (limited to 'application/api')
-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 | 2 | ||||
-rw-r--r-- | application/api/controllers/Links.php | 5 |
4 files changed, 16 insertions, 5 deletions
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..da034eb2 100644 --- a/application/api/controllers/History.php +++ b/application/api/controllers/History.php | |||
@@ -28,7 +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); | 32 | $history = array_reverse($history); |
33 | 33 | ||
34 | // Return history operations from the {offset}th, starting from {since}. | 34 | // Return history operations from the {offset}th, starting from {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 | } |