1 | <?php |
||
2 | /** |
||
3 | * Analytics |
||
4 | * |
||
5 | * SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors, 2019-2022 Marcel Scherello |
||
6 | * SPDX-License-Identifier: AGPL-3.0-or-later |
||
7 | */ |
||
8 | |||
9 | namespace OCA\Analytics\Controller; |
||
10 | |||
11 | use OCA\Analytics\WhatsNew\WhatsNewCheck; |
||
12 | use OCP\AppFramework\Controller; |
||
0 ignored issues
–
show
|
|||
13 | use OCP\AppFramework\Db\DoesNotExistException; |
||
0 ignored issues
–
show
The type
OCP\AppFramework\Db\DoesNotExistException was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||
14 | use OCP\AppFramework\Http; |
||
0 ignored issues
–
show
The type
OCP\AppFramework\Http was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||
15 | use OCP\AppFramework\Http\DataResponse; |
||
0 ignored issues
–
show
The type
OCP\AppFramework\Http\DataResponse was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||
16 | use OCP\IConfig; |
||
0 ignored issues
–
show
The type
OCP\IConfig was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||
17 | use OCP\IRequest; |
||
0 ignored issues
–
show
The type
OCP\IRequest was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||
18 | use OCP\IUserSession; |
||
0 ignored issues
–
show
The type
OCP\IUserSession was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||
19 | use OCP\L10N\IFactory; |
||
0 ignored issues
–
show
The type
OCP\L10N\IFactory was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||
20 | use Psr\Log\LoggerInterface; |
||
0 ignored issues
–
show
The type
Psr\Log\LoggerInterface was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||
21 | |||
22 | class WhatsNewController extends Controller |
||
23 | { |
||
24 | |||
25 | /** @var IConfig */ |
||
26 | protected $config; |
||
27 | /** @var IUserSession */ |
||
28 | private $userSession; |
||
29 | /** @var WhatsNewCheck */ |
||
30 | private $whatsNewService; |
||
31 | /** @var IFactory */ |
||
32 | private $langFactory; |
||
33 | private $logger; |
||
34 | |||
35 | public function __construct( |
||
36 | string $appName, |
||
37 | IRequest $request, |
||
38 | IUserSession $userSession, |
||
39 | IConfig $config, |
||
40 | WhatsNewCheck $whatsNewService, |
||
41 | IFactory $langFactory, |
||
42 | LoggerInterface $logger |
||
43 | ) |
||
44 | { |
||
45 | parent::__construct($appName, $request); |
||
46 | $this->appName = $appName; |
||
0 ignored issues
–
show
|
|||
47 | $this->config = $config; |
||
48 | $this->userSession = $userSession; |
||
49 | $this->whatsNewService = $whatsNewService; |
||
50 | $this->langFactory = $langFactory; |
||
51 | $this->logger = $logger; |
||
52 | } |
||
53 | |||
54 | /** |
||
55 | * @NoAdminRequired |
||
56 | */ |
||
57 | public function get(): DataResponse |
||
58 | { |
||
59 | $user = $this->userSession->getUser(); |
||
60 | if ($user === null) { |
||
61 | throw new \RuntimeException("Acting user cannot be resolved"); |
||
62 | } |
||
63 | $lastRead = $this->config->getUserValue($user->getUID(), $this->appName, 'whatsNewLastRead', 0); |
||
64 | $currentVersion = $this->whatsNewService->normalizeVersion($this->config->getAppValue($this->appName, 'installed_version')); |
||
65 | |||
66 | if (version_compare($lastRead, $currentVersion, '>=')) { |
||
67 | return new DataResponse([], Http::STATUS_NO_CONTENT); |
||
68 | } |
||
69 | |||
70 | try { |
||
71 | $iterator = $this->langFactory->getLanguageIterator(); |
||
72 | $whatsNew = $this->whatsNewService->getChangesForVersion($currentVersion); |
||
73 | |||
74 | $resultData = [ |
||
75 | 'changelogURL' => $whatsNew['changelogURL'], |
||
76 | 'product' => 'Analytics', |
||
77 | 'version' => $currentVersion, |
||
78 | ]; |
||
79 | do { |
||
80 | $lang = $iterator->current(); |
||
81 | if (isset($whatsNew['whatsNew'][$lang])) { |
||
82 | $resultData['whatsNew'] = $whatsNew['whatsNew'][$lang]; |
||
83 | break; |
||
84 | } |
||
85 | $iterator->next(); |
||
86 | } while ($lang !== 'en' && $iterator->valid()); |
||
87 | return new DataResponse($resultData); |
||
88 | } catch (DoesNotExistException $e) { |
||
89 | return new DataResponse([], Http::STATUS_NO_CONTENT); |
||
90 | } |
||
91 | } |
||
92 | |||
93 | /** |
||
94 | * @NoAdminRequired |
||
95 | * |
||
96 | * @throws \OCP\PreConditionNotMetException |
||
97 | * @throws DoesNotExistException |
||
98 | */ |
||
99 | public function dismiss(string $version): DataResponse |
||
100 | { |
||
101 | $user = $this->userSession->getUser(); |
||
102 | if ($user === null) { |
||
103 | throw new \RuntimeException("Acting user cannot be resolved"); |
||
104 | } |
||
105 | $version = $this->whatsNewService->normalizeVersion($version); |
||
106 | // checks whether it's a valid version, throws an Exception otherwise |
||
107 | $this->whatsNewService->getChangesForVersion($version); |
||
108 | $this->config->setUserValue($user->getUID(), $this->appName, 'whatsNewLastRead', $version); |
||
109 | return new DataResponse(); |
||
110 | } |
||
111 | } |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths