diff options
author | ArthurHoaro <arthur@hoa.ro> | 2020-10-13 12:07:13 +0200 |
---|---|---|
committer | ArthurHoaro <arthur@hoa.ro> | 2020-10-13 12:07:13 +0200 |
commit | d9f6275ebca035fec8331652c677981056793ccc (patch) | |
tree | 37a64baf4f0eba6b781040605965383d8aded2cc /application/api/controllers/History.php | |
parent | 38672ba0d1c722e5d6d33a58255ceb55e9410e46 (diff) | |
parent | d63ff87a009313141ae684ec447b902562ff6ee7 (diff) | |
download | Shaarli-stable.tar.gz Shaarli-stable.tar.zst Shaarli-stable.zip |
Merge branch 'v0.11' into stablestable
Diffstat (limited to 'application/api/controllers/History.php')
-rw-r--r-- | application/api/controllers/History.php | 69 |
1 files changed, 0 insertions, 69 deletions
diff --git a/application/api/controllers/History.php b/application/api/controllers/History.php deleted file mode 100644 index 4582e8b2..00000000 --- a/application/api/controllers/History.php +++ /dev/null | |||
@@ -1,69 +0,0 @@ | |||
1 | <?php | ||
2 | |||
3 | |||
4 | namespace Shaarli\Api\Controllers; | ||
5 | |||
6 | use Shaarli\Api\Exceptions\ApiBadParametersException; | ||
7 | use Slim\Http\Request; | ||
8 | use Slim\Http\Response; | ||
9 | |||
10 | /** | ||
11 | * Class History | ||
12 | * | ||
13 | * REST API Controller: /history | ||
14 | * | ||
15 | * @package Shaarli\Api\Controllers | ||
16 | */ | ||
17 | class History extends ApiController | ||
18 | { | ||
19 | /** | ||
20 | * Service providing operation regarding Shaarli datastore and settings. | ||
21 | * | ||
22 | * @param Request $request Slim request. | ||
23 | * @param Response $response Slim response. | ||
24 | * | ||
25 | * @return Response response. | ||
26 | * | ||
27 | * @throws ApiBadParametersException Invalid parameters. | ||
28 | */ | ||
29 | public function getHistory($request, $response) | ||
30 | { | ||
31 | $history = $this->history->getHistory(); | ||
32 | |||
33 | // Return history operations from the {offset}th, starting from {since}. | ||
34 | $since = \DateTime::createFromFormat(\DateTime::ATOM, $request->getParam('since')); | ||
35 | $offset = $request->getParam('offset'); | ||
36 | if (empty($offset)) { | ||
37 | $offset = 0; | ||
38 | } elseif (ctype_digit($offset)) { | ||
39 | $offset = (int) $offset; | ||
40 | } else { | ||
41 | throw new ApiBadParametersException('Invalid offset'); | ||
42 | } | ||
43 | |||
44 | // limit parameter is either a number of links or 'all' for everything. | ||
45 | $limit = $request->getParam('limit'); | ||
46 | if (empty($limit)) { | ||
47 | $limit = count($history); | ||
48 | } elseif (ctype_digit($limit)) { | ||
49 | $limit = (int) $limit; | ||
50 | } else { | ||
51 | throw new ApiBadParametersException('Invalid limit'); | ||
52 | } | ||
53 | |||
54 | $out = []; | ||
55 | $i = 0; | ||
56 | foreach ($history as $entry) { | ||
57 | if ((! empty($since) && $entry['datetime'] <= $since) || count($out) >= $limit) { | ||
58 | break; | ||
59 | } | ||
60 | if (++$i > $offset) { | ||
61 | $out[$i] = $entry; | ||
62 | $out[$i]['datetime'] = $out[$i]['datetime']->format(\DateTime::ATOM); | ||
63 | } | ||
64 | } | ||
65 | $out = array_values($out); | ||
66 | |||
67 | return $response->withJson($out, 200, $this->jsonStyle); | ||
68 | } | ||
69 | } | ||