From 813849e5216cb87121e0f778a734575be6a36052 Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Sun, 7 May 2017 16:50:20 +0200 Subject: Add history entries for API endpoint CHANGED: datetime is now store as an object in history store file --- application/api/controllers/ApiController.php | 9 ++++++++- application/api/controllers/History.php | 2 +- application/api/controllers/Links.php | 5 ++++- 3 files changed, 13 insertions(+), 3 deletions(-) (limited to 'application/api/controllers') 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 @@ namespace Shaarli\Api\Controllers; +use Shaarli\Config\ConfigManager; use \Slim\Container; /** @@ -19,7 +20,7 @@ abstract class ApiController protected $ci; /** - * @var \ConfigManager + * @var ConfigManager */ protected $conf; @@ -28,6 +29,11 @@ abstract class ApiController */ protected $linkDb; + /** + * @var \History + */ + protected $history; + /** * @var int|null JSON style option. */ @@ -45,6 +51,7 @@ abstract class ApiController $this->ci = $ci; $this->conf = $ci->get('conf'); $this->linkDb = $ci->get('db'); + $this->history = $ci->get('history'); if ($this->conf->get('dev.debug', false)) { $this->jsonStyle = JSON_PRETTY_PRINT; } 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 */ public function getHistory($request, $response) { - $history = (new \History($this->conf->get('resource.history')))->getHistory(); + $history = $this->history->getHistory(); $history = array_reverse($history); // 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 $this->linkDb[$link['id']] = $link; $this->linkDb->save($this->conf->get('resource.page_cache')); + $this->history->addLink($link); $out = ApiUtils::formatLink($link, index_url($this->ci['environment'])); $redirect = $this->ci->router->relativePathFor('getLink', ['id' => $link['id']]); return $response->withAddedHeader('Location', $redirect) @@ -184,6 +185,7 @@ class Links extends ApiController $responseLink = ApiUtils::updateLink($responseLink, $requestLink); $this->linkDb[$responseLink['id']] = $responseLink; $this->linkDb->save($this->conf->get('resource.page_cache')); + $this->history->updateLink($responseLink); $out = ApiUtils::formatLink($responseLink, $index); return $response->withJson($out, 200, $this->jsonStyle); @@ -205,9 +207,10 @@ class Links extends ApiController if (! isset($this->linkDb[$args['id']])) { throw new ApiLinkNotFoundException(); } - + $link = $this->linkDb[$args['id']]; unset($this->linkDb[(int) $args['id']]); $this->linkDb->save($this->conf->get('resource.page_cache')); + $this->history->deleteLink($link); return $response->withStatus(204); } -- cgit v1.2.3 From 6bc90f50af611a1674ee1118587feddd4f625d44 Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Sun, 7 May 2017 16:56:20 +0200 Subject: History: fix entries order --- application/api/controllers/History.php | 1 - 1 file changed, 1 deletion(-) (limited to 'application/api/controllers') diff --git a/application/api/controllers/History.php b/application/api/controllers/History.php index da034eb2..2ff9deaf 100644 --- a/application/api/controllers/History.php +++ b/application/api/controllers/History.php @@ -29,7 +29,6 @@ class History extends ApiController public function getHistory($request, $response) { $history = $this->history->getHistory(); - $history = array_reverse($history); // Return history operations from the {offset}th, starting from {since}. $since = \DateTime::createFromFormat(\DateTime::ATOM, $request->getParam('since')); -- cgit v1.2.3