@@ -133,7 +133,7 @@ |
||
| 133 | 133 | |
| 134 | 134 | /** |
| 135 | 135 | * @param string $version |
| 136 | - * @param string $filename |
|
| 136 | + * @param string $fileName |
|
| 137 | 137 | */ |
| 138 | 138 | public function setVersion(string $version, string $fileName = 'apps.json') { |
| 139 | 139 | parent::setVersion($version); |
@@ -34,110 +34,110 @@ |
||
| 34 | 34 | use OCP\ILogger; |
| 35 | 35 | |
| 36 | 36 | class AppFetcher extends Fetcher { |
| 37 | - /** |
|
| 38 | - * @param Factory $appDataFactory |
|
| 39 | - * @param IClientService $clientService |
|
| 40 | - * @param ITimeFactory $timeFactory |
|
| 41 | - * @param IConfig $config |
|
| 42 | - * @param ILogger $logger |
|
| 43 | - */ |
|
| 44 | - public function __construct(Factory $appDataFactory, |
|
| 45 | - IClientService $clientService, |
|
| 46 | - ITimeFactory $timeFactory, |
|
| 47 | - IConfig $config, |
|
| 48 | - ILogger $logger) { |
|
| 49 | - parent::__construct( |
|
| 50 | - $appDataFactory, |
|
| 51 | - $clientService, |
|
| 52 | - $timeFactory, |
|
| 53 | - $config, |
|
| 54 | - $logger |
|
| 55 | - ); |
|
| 37 | + /** |
|
| 38 | + * @param Factory $appDataFactory |
|
| 39 | + * @param IClientService $clientService |
|
| 40 | + * @param ITimeFactory $timeFactory |
|
| 41 | + * @param IConfig $config |
|
| 42 | + * @param ILogger $logger |
|
| 43 | + */ |
|
| 44 | + public function __construct(Factory $appDataFactory, |
|
| 45 | + IClientService $clientService, |
|
| 46 | + ITimeFactory $timeFactory, |
|
| 47 | + IConfig $config, |
|
| 48 | + ILogger $logger) { |
|
| 49 | + parent::__construct( |
|
| 50 | + $appDataFactory, |
|
| 51 | + $clientService, |
|
| 52 | + $timeFactory, |
|
| 53 | + $config, |
|
| 54 | + $logger |
|
| 55 | + ); |
|
| 56 | 56 | |
| 57 | - $this->fileName = 'apps.json'; |
|
| 58 | - $this->setEndpoint(); |
|
| 59 | - } |
|
| 57 | + $this->fileName = 'apps.json'; |
|
| 58 | + $this->setEndpoint(); |
|
| 59 | + } |
|
| 60 | 60 | |
| 61 | - /** |
|
| 62 | - * Only returns the latest compatible app release in the releases array |
|
| 63 | - * |
|
| 64 | - * @param string $ETag |
|
| 65 | - * @param string $content |
|
| 66 | - * |
|
| 67 | - * @return array |
|
| 68 | - */ |
|
| 69 | - protected function fetch($ETag, $content) { |
|
| 70 | - /** @var mixed[] $response */ |
|
| 71 | - $response = parent::fetch($ETag, $content); |
|
| 61 | + /** |
|
| 62 | + * Only returns the latest compatible app release in the releases array |
|
| 63 | + * |
|
| 64 | + * @param string $ETag |
|
| 65 | + * @param string $content |
|
| 66 | + * |
|
| 67 | + * @return array |
|
| 68 | + */ |
|
| 69 | + protected function fetch($ETag, $content) { |
|
| 70 | + /** @var mixed[] $response */ |
|
| 71 | + $response = parent::fetch($ETag, $content); |
|
| 72 | 72 | |
| 73 | - $ncVersion = $this->getVersion(); |
|
| 74 | - $ncMajorVersion = explode('.', $ncVersion)[0]; |
|
| 75 | - foreach($response['data'] as $dataKey => $app) { |
|
| 76 | - $releases = []; |
|
| 73 | + $ncVersion = $this->getVersion(); |
|
| 74 | + $ncMajorVersion = explode('.', $ncVersion)[0]; |
|
| 75 | + foreach($response['data'] as $dataKey => $app) { |
|
| 76 | + $releases = []; |
|
| 77 | 77 | |
| 78 | - // Filter all compatible releases |
|
| 79 | - foreach($app['releases'] as $release) { |
|
| 80 | - // Exclude all nightly and pre-releases |
|
| 81 | - if($release['isNightly'] === false |
|
| 82 | - && strpos($release['version'], '-') === false) { |
|
| 83 | - // Exclude all versions not compatible with the current version |
|
| 84 | - $versionParser = new VersionParser(); |
|
| 85 | - $version = $versionParser->getVersion($release['rawPlatformVersionSpec']); |
|
| 86 | - if ( |
|
| 87 | - // Major version is bigger or equals to the minimum version of the app |
|
| 88 | - version_compare($ncMajorVersion, $version->getMinimumVersion(), '>=') |
|
| 89 | - // Major version is smaller or equals to the maximum version of the app |
|
| 90 | - && version_compare($ncMajorVersion, $version->getMaximumVersion(), '<=') |
|
| 91 | - ) { |
|
| 92 | - $releases[] = $release; |
|
| 93 | - } |
|
| 94 | - } |
|
| 95 | - } |
|
| 78 | + // Filter all compatible releases |
|
| 79 | + foreach($app['releases'] as $release) { |
|
| 80 | + // Exclude all nightly and pre-releases |
|
| 81 | + if($release['isNightly'] === false |
|
| 82 | + && strpos($release['version'], '-') === false) { |
|
| 83 | + // Exclude all versions not compatible with the current version |
|
| 84 | + $versionParser = new VersionParser(); |
|
| 85 | + $version = $versionParser->getVersion($release['rawPlatformVersionSpec']); |
|
| 86 | + if ( |
|
| 87 | + // Major version is bigger or equals to the minimum version of the app |
|
| 88 | + version_compare($ncMajorVersion, $version->getMinimumVersion(), '>=') |
|
| 89 | + // Major version is smaller or equals to the maximum version of the app |
|
| 90 | + && version_compare($ncMajorVersion, $version->getMaximumVersion(), '<=') |
|
| 91 | + ) { |
|
| 92 | + $releases[] = $release; |
|
| 93 | + } |
|
| 94 | + } |
|
| 95 | + } |
|
| 96 | 96 | |
| 97 | - // Get the highest version |
|
| 98 | - $versions = []; |
|
| 99 | - foreach($releases as $release) { |
|
| 100 | - $versions[] = $release['version']; |
|
| 101 | - } |
|
| 102 | - usort($versions, 'version_compare'); |
|
| 103 | - $versions = array_reverse($versions); |
|
| 104 | - $compatible = false; |
|
| 105 | - if(isset($versions[0])) { |
|
| 106 | - $highestVersion = $versions[0]; |
|
| 107 | - foreach ($releases as $release) { |
|
| 108 | - if ((string)$release['version'] === (string)$highestVersion) { |
|
| 109 | - $compatible = true; |
|
| 110 | - $response['data'][$dataKey]['releases'] = [$release]; |
|
| 111 | - break; |
|
| 112 | - } |
|
| 113 | - } |
|
| 114 | - } |
|
| 115 | - if(!$compatible) { |
|
| 116 | - unset($response['data'][$dataKey]); |
|
| 117 | - } |
|
| 118 | - } |
|
| 97 | + // Get the highest version |
|
| 98 | + $versions = []; |
|
| 99 | + foreach($releases as $release) { |
|
| 100 | + $versions[] = $release['version']; |
|
| 101 | + } |
|
| 102 | + usort($versions, 'version_compare'); |
|
| 103 | + $versions = array_reverse($versions); |
|
| 104 | + $compatible = false; |
|
| 105 | + if(isset($versions[0])) { |
|
| 106 | + $highestVersion = $versions[0]; |
|
| 107 | + foreach ($releases as $release) { |
|
| 108 | + if ((string)$release['version'] === (string)$highestVersion) { |
|
| 109 | + $compatible = true; |
|
| 110 | + $response['data'][$dataKey]['releases'] = [$release]; |
|
| 111 | + break; |
|
| 112 | + } |
|
| 113 | + } |
|
| 114 | + } |
|
| 115 | + if(!$compatible) { |
|
| 116 | + unset($response['data'][$dataKey]); |
|
| 117 | + } |
|
| 118 | + } |
|
| 119 | 119 | |
| 120 | - $response['data'] = array_values($response['data']); |
|
| 121 | - return $response; |
|
| 122 | - } |
|
| 120 | + $response['data'] = array_values($response['data']); |
|
| 121 | + return $response; |
|
| 122 | + } |
|
| 123 | 123 | |
| 124 | - private function setEndpoint() { |
|
| 125 | - $versionArray = explode('.', $this->getVersion()); |
|
| 126 | - $this->endpointUrl = sprintf( |
|
| 127 | - 'https://apps.nextcloud.com/api/v1/platform/%d.%d.%d/apps.json', |
|
| 128 | - $versionArray[0], |
|
| 129 | - $versionArray[1], |
|
| 130 | - $versionArray[2] |
|
| 131 | - ); |
|
| 132 | - } |
|
| 124 | + private function setEndpoint() { |
|
| 125 | + $versionArray = explode('.', $this->getVersion()); |
|
| 126 | + $this->endpointUrl = sprintf( |
|
| 127 | + 'https://apps.nextcloud.com/api/v1/platform/%d.%d.%d/apps.json', |
|
| 128 | + $versionArray[0], |
|
| 129 | + $versionArray[1], |
|
| 130 | + $versionArray[2] |
|
| 131 | + ); |
|
| 132 | + } |
|
| 133 | 133 | |
| 134 | - /** |
|
| 135 | - * @param string $version |
|
| 136 | - * @param string $filename |
|
| 137 | - */ |
|
| 138 | - public function setVersion(string $version, string $fileName = 'apps.json') { |
|
| 139 | - parent::setVersion($version); |
|
| 140 | - $this->fileName = $fileName; |
|
| 141 | - $this->setEndpoint(); |
|
| 142 | - } |
|
| 134 | + /** |
|
| 135 | + * @param string $version |
|
| 136 | + * @param string $filename |
|
| 137 | + */ |
|
| 138 | + public function setVersion(string $version, string $fileName = 'apps.json') { |
|
| 139 | + parent::setVersion($version); |
|
| 140 | + $this->fileName = $fileName; |
|
| 141 | + $this->setEndpoint(); |
|
| 142 | + } |
|
| 143 | 143 | } |
@@ -39,162 +39,162 @@ |
||
| 39 | 39 | use OCP\Util; |
| 40 | 40 | |
| 41 | 41 | abstract class Fetcher { |
| 42 | - const INVALIDATE_AFTER_SECONDS = 300; |
|
| 43 | - |
|
| 44 | - /** @var IAppData */ |
|
| 45 | - protected $appData; |
|
| 46 | - /** @var IClientService */ |
|
| 47 | - protected $clientService; |
|
| 48 | - /** @var ITimeFactory */ |
|
| 49 | - protected $timeFactory; |
|
| 50 | - /** @var IConfig */ |
|
| 51 | - protected $config; |
|
| 52 | - /** @var Ilogger */ |
|
| 53 | - protected $logger; |
|
| 54 | - /** @var string */ |
|
| 55 | - protected $fileName; |
|
| 56 | - /** @var string */ |
|
| 57 | - protected $endpointUrl; |
|
| 58 | - /** @var string */ |
|
| 59 | - protected $version; |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * @param Factory $appDataFactory |
|
| 63 | - * @param IClientService $clientService |
|
| 64 | - * @param ITimeFactory $timeFactory |
|
| 65 | - * @param IConfig $config |
|
| 66 | - * @param ILogger $logger |
|
| 67 | - */ |
|
| 68 | - public function __construct(Factory $appDataFactory, |
|
| 69 | - IClientService $clientService, |
|
| 70 | - ITimeFactory $timeFactory, |
|
| 71 | - IConfig $config, |
|
| 72 | - ILogger $logger) { |
|
| 73 | - $this->appData = $appDataFactory->get('appstore'); |
|
| 74 | - $this->clientService = $clientService; |
|
| 75 | - $this->timeFactory = $timeFactory; |
|
| 76 | - $this->config = $config; |
|
| 77 | - $this->logger = $logger; |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - /** |
|
| 81 | - * Fetches the response from the server |
|
| 82 | - * |
|
| 83 | - * @param string $ETag |
|
| 84 | - * @param string $content |
|
| 85 | - * |
|
| 86 | - * @return array |
|
| 87 | - */ |
|
| 88 | - protected function fetch($ETag, $content) { |
|
| 89 | - $appstoreenabled = $this->config->getSystemValue('appstoreenabled', true); |
|
| 90 | - |
|
| 91 | - if (!$appstoreenabled) { |
|
| 92 | - return []; |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - $options = [ |
|
| 96 | - 'timeout' => 10, |
|
| 97 | - ]; |
|
| 98 | - |
|
| 99 | - if ($ETag !== '') { |
|
| 100 | - $options['headers'] = [ |
|
| 101 | - 'If-None-Match' => $ETag, |
|
| 102 | - ]; |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - $client = $this->clientService->newClient(); |
|
| 106 | - $response = $client->get($this->endpointUrl, $options); |
|
| 107 | - |
|
| 108 | - $responseJson = []; |
|
| 109 | - if ($response->getStatusCode() === Http::STATUS_NOT_MODIFIED) { |
|
| 110 | - $responseJson['data'] = json_decode($content, true); |
|
| 111 | - } else { |
|
| 112 | - $responseJson['data'] = json_decode($response->getBody(), true); |
|
| 113 | - $ETag = $response->getHeader('ETag'); |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - $responseJson['timestamp'] = $this->timeFactory->getTime(); |
|
| 117 | - $responseJson['ncversion'] = $this->getVersion(); |
|
| 118 | - if ($ETag !== '') { |
|
| 119 | - $responseJson['ETag'] = $ETag; |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - return $responseJson; |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - /** |
|
| 126 | - * Returns the array with the categories on the appstore server |
|
| 127 | - * |
|
| 128 | - * @return array |
|
| 129 | - */ |
|
| 130 | - public function get() { |
|
| 131 | - $appstoreenabled = $this->config->getSystemValue('appstoreenabled', true); |
|
| 132 | - $internetavailable = $this->config->getSystemValue('has_internet_connection', true); |
|
| 133 | - |
|
| 134 | - if (!$appstoreenabled || !$internetavailable) { |
|
| 135 | - return []; |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - $rootFolder = $this->appData->getFolder('/'); |
|
| 139 | - |
|
| 140 | - $ETag = ''; |
|
| 141 | - $content = ''; |
|
| 142 | - |
|
| 143 | - try { |
|
| 144 | - // File does already exists |
|
| 145 | - $file = $rootFolder->getFile($this->fileName); |
|
| 146 | - $jsonBlob = json_decode($file->getContent(), true); |
|
| 147 | - if (is_array($jsonBlob)) { |
|
| 148 | - |
|
| 149 | - // No caching when the version has been updated |
|
| 150 | - if (isset($jsonBlob['ncversion']) && $jsonBlob['ncversion'] === $this->getVersion()) { |
|
| 151 | - |
|
| 152 | - // If the timestamp is older than 300 seconds request the files new |
|
| 153 | - if ((int)$jsonBlob['timestamp'] > ($this->timeFactory->getTime() - self::INVALIDATE_AFTER_SECONDS)) { |
|
| 154 | - return $jsonBlob['data']; |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - if (isset($jsonBlob['ETag'])) { |
|
| 158 | - $ETag = $jsonBlob['ETag']; |
|
| 159 | - $content = json_encode($jsonBlob['data']); |
|
| 160 | - } |
|
| 161 | - } |
|
| 162 | - } |
|
| 163 | - } catch (NotFoundException $e) { |
|
| 164 | - // File does not already exists |
|
| 165 | - $file = $rootFolder->newFile($this->fileName); |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - // Refresh the file content |
|
| 169 | - try { |
|
| 170 | - $responseJson = $this->fetch($ETag, $content); |
|
| 171 | - $file->putContent(json_encode($responseJson)); |
|
| 172 | - return json_decode($file->getContent(), true)['data']; |
|
| 173 | - } catch (ConnectException $e) { |
|
| 174 | - $this->logger->logException($e, ['app' => 'appstoreFetcher', 'level' => Util::INFO, 'message' => 'Could not connect to appstore']); |
|
| 175 | - return []; |
|
| 176 | - } catch (\Exception $e) { |
|
| 177 | - $this->logger->logException($e, ['app' => 'appstoreFetcher', 'level' => Util::INFO]); |
|
| 178 | - return []; |
|
| 179 | - } |
|
| 180 | - } |
|
| 181 | - |
|
| 182 | - /** |
|
| 183 | - * Get the currently Nextcloud version |
|
| 184 | - * @return string |
|
| 185 | - */ |
|
| 186 | - protected function getVersion() { |
|
| 187 | - if ($this->version === null) { |
|
| 188 | - $this->version = $this->config->getSystemValue('version', '0.0.0'); |
|
| 189 | - } |
|
| 190 | - return $this->version; |
|
| 191 | - } |
|
| 192 | - |
|
| 193 | - /** |
|
| 194 | - * Set the current Nextcloud version |
|
| 195 | - * @param string $version |
|
| 196 | - */ |
|
| 197 | - public function setVersion(string $version) { |
|
| 198 | - $this->version = $version; |
|
| 199 | - } |
|
| 42 | + const INVALIDATE_AFTER_SECONDS = 300; |
|
| 43 | + |
|
| 44 | + /** @var IAppData */ |
|
| 45 | + protected $appData; |
|
| 46 | + /** @var IClientService */ |
|
| 47 | + protected $clientService; |
|
| 48 | + /** @var ITimeFactory */ |
|
| 49 | + protected $timeFactory; |
|
| 50 | + /** @var IConfig */ |
|
| 51 | + protected $config; |
|
| 52 | + /** @var Ilogger */ |
|
| 53 | + protected $logger; |
|
| 54 | + /** @var string */ |
|
| 55 | + protected $fileName; |
|
| 56 | + /** @var string */ |
|
| 57 | + protected $endpointUrl; |
|
| 58 | + /** @var string */ |
|
| 59 | + protected $version; |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * @param Factory $appDataFactory |
|
| 63 | + * @param IClientService $clientService |
|
| 64 | + * @param ITimeFactory $timeFactory |
|
| 65 | + * @param IConfig $config |
|
| 66 | + * @param ILogger $logger |
|
| 67 | + */ |
|
| 68 | + public function __construct(Factory $appDataFactory, |
|
| 69 | + IClientService $clientService, |
|
| 70 | + ITimeFactory $timeFactory, |
|
| 71 | + IConfig $config, |
|
| 72 | + ILogger $logger) { |
|
| 73 | + $this->appData = $appDataFactory->get('appstore'); |
|
| 74 | + $this->clientService = $clientService; |
|
| 75 | + $this->timeFactory = $timeFactory; |
|
| 76 | + $this->config = $config; |
|
| 77 | + $this->logger = $logger; |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + /** |
|
| 81 | + * Fetches the response from the server |
|
| 82 | + * |
|
| 83 | + * @param string $ETag |
|
| 84 | + * @param string $content |
|
| 85 | + * |
|
| 86 | + * @return array |
|
| 87 | + */ |
|
| 88 | + protected function fetch($ETag, $content) { |
|
| 89 | + $appstoreenabled = $this->config->getSystemValue('appstoreenabled', true); |
|
| 90 | + |
|
| 91 | + if (!$appstoreenabled) { |
|
| 92 | + return []; |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + $options = [ |
|
| 96 | + 'timeout' => 10, |
|
| 97 | + ]; |
|
| 98 | + |
|
| 99 | + if ($ETag !== '') { |
|
| 100 | + $options['headers'] = [ |
|
| 101 | + 'If-None-Match' => $ETag, |
|
| 102 | + ]; |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + $client = $this->clientService->newClient(); |
|
| 106 | + $response = $client->get($this->endpointUrl, $options); |
|
| 107 | + |
|
| 108 | + $responseJson = []; |
|
| 109 | + if ($response->getStatusCode() === Http::STATUS_NOT_MODIFIED) { |
|
| 110 | + $responseJson['data'] = json_decode($content, true); |
|
| 111 | + } else { |
|
| 112 | + $responseJson['data'] = json_decode($response->getBody(), true); |
|
| 113 | + $ETag = $response->getHeader('ETag'); |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + $responseJson['timestamp'] = $this->timeFactory->getTime(); |
|
| 117 | + $responseJson['ncversion'] = $this->getVersion(); |
|
| 118 | + if ($ETag !== '') { |
|
| 119 | + $responseJson['ETag'] = $ETag; |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + return $responseJson; |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + /** |
|
| 126 | + * Returns the array with the categories on the appstore server |
|
| 127 | + * |
|
| 128 | + * @return array |
|
| 129 | + */ |
|
| 130 | + public function get() { |
|
| 131 | + $appstoreenabled = $this->config->getSystemValue('appstoreenabled', true); |
|
| 132 | + $internetavailable = $this->config->getSystemValue('has_internet_connection', true); |
|
| 133 | + |
|
| 134 | + if (!$appstoreenabled || !$internetavailable) { |
|
| 135 | + return []; |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + $rootFolder = $this->appData->getFolder('/'); |
|
| 139 | + |
|
| 140 | + $ETag = ''; |
|
| 141 | + $content = ''; |
|
| 142 | + |
|
| 143 | + try { |
|
| 144 | + // File does already exists |
|
| 145 | + $file = $rootFolder->getFile($this->fileName); |
|
| 146 | + $jsonBlob = json_decode($file->getContent(), true); |
|
| 147 | + if (is_array($jsonBlob)) { |
|
| 148 | + |
|
| 149 | + // No caching when the version has been updated |
|
| 150 | + if (isset($jsonBlob['ncversion']) && $jsonBlob['ncversion'] === $this->getVersion()) { |
|
| 151 | + |
|
| 152 | + // If the timestamp is older than 300 seconds request the files new |
|
| 153 | + if ((int)$jsonBlob['timestamp'] > ($this->timeFactory->getTime() - self::INVALIDATE_AFTER_SECONDS)) { |
|
| 154 | + return $jsonBlob['data']; |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + if (isset($jsonBlob['ETag'])) { |
|
| 158 | + $ETag = $jsonBlob['ETag']; |
|
| 159 | + $content = json_encode($jsonBlob['data']); |
|
| 160 | + } |
|
| 161 | + } |
|
| 162 | + } |
|
| 163 | + } catch (NotFoundException $e) { |
|
| 164 | + // File does not already exists |
|
| 165 | + $file = $rootFolder->newFile($this->fileName); |
|
| 166 | + } |
|
| 167 | + |
|
| 168 | + // Refresh the file content |
|
| 169 | + try { |
|
| 170 | + $responseJson = $this->fetch($ETag, $content); |
|
| 171 | + $file->putContent(json_encode($responseJson)); |
|
| 172 | + return json_decode($file->getContent(), true)['data']; |
|
| 173 | + } catch (ConnectException $e) { |
|
| 174 | + $this->logger->logException($e, ['app' => 'appstoreFetcher', 'level' => Util::INFO, 'message' => 'Could not connect to appstore']); |
|
| 175 | + return []; |
|
| 176 | + } catch (\Exception $e) { |
|
| 177 | + $this->logger->logException($e, ['app' => 'appstoreFetcher', 'level' => Util::INFO]); |
|
| 178 | + return []; |
|
| 179 | + } |
|
| 180 | + } |
|
| 181 | + |
|
| 182 | + /** |
|
| 183 | + * Get the currently Nextcloud version |
|
| 184 | + * @return string |
|
| 185 | + */ |
|
| 186 | + protected function getVersion() { |
|
| 187 | + if ($this->version === null) { |
|
| 188 | + $this->version = $this->config->getSystemValue('version', '0.0.0'); |
|
| 189 | + } |
|
| 190 | + return $this->version; |
|
| 191 | + } |
|
| 192 | + |
|
| 193 | + /** |
|
| 194 | + * Set the current Nextcloud version |
|
| 195 | + * @param string $version |
|
| 196 | + */ |
|
| 197 | + public function setVersion(string $version) { |
|
| 198 | + $this->version = $version; |
|
| 199 | + } |
|
| 200 | 200 | } |
@@ -22,11 +22,11 @@ |
||
| 22 | 22 | */ |
| 23 | 23 | |
| 24 | 24 | return [ |
| 25 | - 'routes' => [ |
|
| 26 | - ['name' => 'Admin#createCredentials', 'url' => '/credentials', 'verb' => 'GET'], |
|
| 27 | - ['name' => 'Admin#setChannel', 'url' => '/channel', 'verb' => 'POST'], |
|
| 28 | - ], |
|
| 29 | - 'ocs' => [ |
|
| 30 | - ['name' => 'API#getAppList', 'url' => '/api/{apiVersion}/applist/{newVersion}', 'verb' => 'GET', 'requirements' => ['apiVersion' => 'v1']], |
|
| 31 | - ], |
|
| 25 | + 'routes' => [ |
|
| 26 | + ['name' => 'Admin#createCredentials', 'url' => '/credentials', 'verb' => 'GET'], |
|
| 27 | + ['name' => 'Admin#setChannel', 'url' => '/channel', 'verb' => 'POST'], |
|
| 28 | + ], |
|
| 29 | + 'ocs' => [ |
|
| 30 | + ['name' => 'API#getAppList', 'url' => '/api/{apiVersion}/applist/{newVersion}', 'verb' => 'GET', 'requirements' => ['apiVersion' => 'v1']], |
|
| 31 | + ], |
|
| 32 | 32 | ]; |
@@ -6,12 +6,12 @@ |
||
| 6 | 6 | $baseDir = $vendorDir; |
| 7 | 7 | |
| 8 | 8 | return array( |
| 9 | - 'OCA\\UpdateNotification\\AppInfo\\Application' => $baseDir . '/../lib/AppInfo/Application.php', |
|
| 10 | - 'OCA\\UpdateNotification\\Controller\\APIController' => $baseDir . '/../lib/Controller/APIController.php', |
|
| 11 | - 'OCA\\UpdateNotification\\Controller\\AdminController' => $baseDir . '/../lib/Controller/AdminController.php', |
|
| 12 | - 'OCA\\UpdateNotification\\Notification\\BackgroundJob' => $baseDir . '/../lib/Notification/BackgroundJob.php', |
|
| 13 | - 'OCA\\UpdateNotification\\Notification\\Notifier' => $baseDir . '/../lib/Notification/Notifier.php', |
|
| 14 | - 'OCA\\UpdateNotification\\ResetTokenBackgroundJob' => $baseDir . '/../lib/ResetTokenBackgroundJob.php', |
|
| 15 | - 'OCA\\UpdateNotification\\Settings\\Admin' => $baseDir . '/../lib/Settings/Admin.php', |
|
| 16 | - 'OCA\\UpdateNotification\\UpdateChecker' => $baseDir . '/../lib/UpdateChecker.php', |
|
| 9 | + 'OCA\\UpdateNotification\\AppInfo\\Application' => $baseDir.'/../lib/AppInfo/Application.php', |
|
| 10 | + 'OCA\\UpdateNotification\\Controller\\APIController' => $baseDir.'/../lib/Controller/APIController.php', |
|
| 11 | + 'OCA\\UpdateNotification\\Controller\\AdminController' => $baseDir.'/../lib/Controller/AdminController.php', |
|
| 12 | + 'OCA\\UpdateNotification\\Notification\\BackgroundJob' => $baseDir.'/../lib/Notification/BackgroundJob.php', |
|
| 13 | + 'OCA\\UpdateNotification\\Notification\\Notifier' => $baseDir.'/../lib/Notification/Notifier.php', |
|
| 14 | + 'OCA\\UpdateNotification\\ResetTokenBackgroundJob' => $baseDir.'/../lib/ResetTokenBackgroundJob.php', |
|
| 15 | + 'OCA\\UpdateNotification\\Settings\\Admin' => $baseDir.'/../lib/Settings/Admin.php', |
|
| 16 | + 'OCA\\UpdateNotification\\UpdateChecker' => $baseDir.'/../lib/UpdateChecker.php', |
|
| 17 | 17 | ); |
@@ -6,34 +6,34 @@ |
||
| 6 | 6 | |
| 7 | 7 | class ComposerStaticInitUpdateNotification |
| 8 | 8 | { |
| 9 | - public static $prefixLengthsPsr4 = array ( |
|
| 9 | + public static $prefixLengthsPsr4 = array( |
|
| 10 | 10 | 'O' => |
| 11 | - array ( |
|
| 11 | + array( |
|
| 12 | 12 | 'OCA\\UpdateNotification\\' => 23, |
| 13 | 13 | ), |
| 14 | 14 | ); |
| 15 | 15 | |
| 16 | - public static $prefixDirsPsr4 = array ( |
|
| 16 | + public static $prefixDirsPsr4 = array( |
|
| 17 | 17 | 'OCA\\UpdateNotification\\' => |
| 18 | - array ( |
|
| 19 | - 0 => __DIR__ . '/..' . '/../lib', |
|
| 18 | + array( |
|
| 19 | + 0 => __DIR__.'/..'.'/../lib', |
|
| 20 | 20 | ), |
| 21 | 21 | ); |
| 22 | 22 | |
| 23 | - public static $classMap = array ( |
|
| 24 | - 'OCA\\UpdateNotification\\AppInfo\\Application' => __DIR__ . '/..' . '/../lib/AppInfo/Application.php', |
|
| 25 | - 'OCA\\UpdateNotification\\Controller\\APIController' => __DIR__ . '/..' . '/../lib/Controller/APIController.php', |
|
| 26 | - 'OCA\\UpdateNotification\\Controller\\AdminController' => __DIR__ . '/..' . '/../lib/Controller/AdminController.php', |
|
| 27 | - 'OCA\\UpdateNotification\\Notification\\BackgroundJob' => __DIR__ . '/..' . '/../lib/Notification/BackgroundJob.php', |
|
| 28 | - 'OCA\\UpdateNotification\\Notification\\Notifier' => __DIR__ . '/..' . '/../lib/Notification/Notifier.php', |
|
| 29 | - 'OCA\\UpdateNotification\\ResetTokenBackgroundJob' => __DIR__ . '/..' . '/../lib/ResetTokenBackgroundJob.php', |
|
| 30 | - 'OCA\\UpdateNotification\\Settings\\Admin' => __DIR__ . '/..' . '/../lib/Settings/Admin.php', |
|
| 31 | - 'OCA\\UpdateNotification\\UpdateChecker' => __DIR__ . '/..' . '/../lib/UpdateChecker.php', |
|
| 23 | + public static $classMap = array( |
|
| 24 | + 'OCA\\UpdateNotification\\AppInfo\\Application' => __DIR__.'/..'.'/../lib/AppInfo/Application.php', |
|
| 25 | + 'OCA\\UpdateNotification\\Controller\\APIController' => __DIR__.'/..'.'/../lib/Controller/APIController.php', |
|
| 26 | + 'OCA\\UpdateNotification\\Controller\\AdminController' => __DIR__.'/..'.'/../lib/Controller/AdminController.php', |
|
| 27 | + 'OCA\\UpdateNotification\\Notification\\BackgroundJob' => __DIR__.'/..'.'/../lib/Notification/BackgroundJob.php', |
|
| 28 | + 'OCA\\UpdateNotification\\Notification\\Notifier' => __DIR__.'/..'.'/../lib/Notification/Notifier.php', |
|
| 29 | + 'OCA\\UpdateNotification\\ResetTokenBackgroundJob' => __DIR__.'/..'.'/../lib/ResetTokenBackgroundJob.php', |
|
| 30 | + 'OCA\\UpdateNotification\\Settings\\Admin' => __DIR__.'/..'.'/../lib/Settings/Admin.php', |
|
| 31 | + 'OCA\\UpdateNotification\\UpdateChecker' => __DIR__.'/..'.'/../lib/UpdateChecker.php', |
|
| 32 | 32 | ); |
| 33 | 33 | |
| 34 | 34 | public static function getInitializer(ClassLoader $loader) |
| 35 | 35 | { |
| 36 | - return \Closure::bind(function () use ($loader) { |
|
| 36 | + return \Closure::bind(function() use ($loader) { |
|
| 37 | 37 | $loader->prefixLengthsPsr4 = ComposerStaticInitUpdateNotification::$prefixLengthsPsr4; |
| 38 | 38 | $loader->prefixDirsPsr4 = ComposerStaticInitUpdateNotification::$prefixDirsPsr4; |
| 39 | 39 | $loader->classMap = ComposerStaticInitUpdateNotification::$classMap; |
@@ -33,102 +33,102 @@ |
||
| 33 | 33 | |
| 34 | 34 | class APIController extends OCSController { |
| 35 | 35 | |
| 36 | - /** @var IConfig */ |
|
| 37 | - protected $config; |
|
| 38 | - |
|
| 39 | - /** @var IAppManager */ |
|
| 40 | - protected $appManager; |
|
| 41 | - |
|
| 42 | - /** @var AppFetcher */ |
|
| 43 | - protected $appFetcher; |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * @param string $appName |
|
| 47 | - * @param IRequest $request |
|
| 48 | - * @param IConfig $config |
|
| 49 | - * @param IAppManager $appManager |
|
| 50 | - * @param AppFetcher $appFetcher |
|
| 51 | - */ |
|
| 52 | - public function __construct($appName, |
|
| 53 | - IRequest $request, |
|
| 54 | - IConfig $config, |
|
| 55 | - IAppManager $appManager, |
|
| 56 | - AppFetcher $appFetcher) { |
|
| 57 | - parent::__construct($appName, $request); |
|
| 58 | - |
|
| 59 | - $this->config = $config; |
|
| 60 | - $this->appManager = $appManager; |
|
| 61 | - $this->appFetcher = $appFetcher; |
|
| 62 | - } |
|
| 63 | - |
|
| 64 | - /** |
|
| 65 | - * @param string $newVersion |
|
| 66 | - * @return DataResponse |
|
| 67 | - */ |
|
| 68 | - public function getAppList(string $newVersion): DataResponse { |
|
| 69 | - if (!$this->config->getSystemValue('appstoreenabled', true)) { |
|
| 70 | - return new DataResponse([ |
|
| 71 | - 'appstore_disabled' => true, |
|
| 72 | - ], Http::STATUS_NOT_FOUND); |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - // Get list of installed custom apps |
|
| 76 | - $installedApps = $this->appManager->getInstalledApps(); |
|
| 77 | - $installedApps = array_filter($installedApps, function($app) { |
|
| 78 | - try { |
|
| 79 | - $this->appManager->getAppPath($app); |
|
| 80 | - } catch (AppPathNotFoundException $e) { |
|
| 81 | - return false; |
|
| 82 | - } |
|
| 83 | - return !$this->appManager->isShipped($app); |
|
| 84 | - }); |
|
| 85 | - |
|
| 86 | - if (empty($installedApps)) { |
|
| 87 | - return new DataResponse([ |
|
| 88 | - 'missing' => [], |
|
| 89 | - 'available' => [], |
|
| 90 | - ]); |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - $this->appFetcher->setVersion($newVersion, 'future-apps.json'); |
|
| 94 | - |
|
| 95 | - // Apps available on the app store for that version |
|
| 96 | - $availableApps = array_map(function(array $app) { |
|
| 97 | - return $app['id']; |
|
| 98 | - }, $this->appFetcher->get()); |
|
| 99 | - |
|
| 100 | - if (empty($availableApps)) { |
|
| 101 | - return new DataResponse([ |
|
| 102 | - 'appstore_disabled' => false, |
|
| 103 | - 'already_on_latest' => false, |
|
| 104 | - ], Http::STATUS_NOT_FOUND); |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - $missing = array_diff($installedApps, $availableApps); |
|
| 108 | - $missing = array_map([$this, 'getAppDetails'], $missing); |
|
| 109 | - sort($missing); |
|
| 110 | - |
|
| 111 | - $available = array_intersect($installedApps, $availableApps); |
|
| 112 | - $available = array_map([$this, 'getAppDetails'], $available); |
|
| 113 | - sort($available); |
|
| 114 | - |
|
| 115 | - return new DataResponse([ |
|
| 116 | - 'missing' => $missing, |
|
| 117 | - 'available' => $available, |
|
| 118 | - ]); |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - /** |
|
| 122 | - * Get translated app name |
|
| 123 | - * |
|
| 124 | - * @param string $appId |
|
| 125 | - * @return string[] |
|
| 126 | - */ |
|
| 127 | - protected function getAppDetails($appId): array { |
|
| 128 | - $app = $this->appManager->getAppInfo($appId); |
|
| 129 | - return [ |
|
| 130 | - 'appId' => $appId, |
|
| 131 | - 'appName' => $app['name'] ?? $appId, |
|
| 132 | - ]; |
|
| 133 | - } |
|
| 36 | + /** @var IConfig */ |
|
| 37 | + protected $config; |
|
| 38 | + |
|
| 39 | + /** @var IAppManager */ |
|
| 40 | + protected $appManager; |
|
| 41 | + |
|
| 42 | + /** @var AppFetcher */ |
|
| 43 | + protected $appFetcher; |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * @param string $appName |
|
| 47 | + * @param IRequest $request |
|
| 48 | + * @param IConfig $config |
|
| 49 | + * @param IAppManager $appManager |
|
| 50 | + * @param AppFetcher $appFetcher |
|
| 51 | + */ |
|
| 52 | + public function __construct($appName, |
|
| 53 | + IRequest $request, |
|
| 54 | + IConfig $config, |
|
| 55 | + IAppManager $appManager, |
|
| 56 | + AppFetcher $appFetcher) { |
|
| 57 | + parent::__construct($appName, $request); |
|
| 58 | + |
|
| 59 | + $this->config = $config; |
|
| 60 | + $this->appManager = $appManager; |
|
| 61 | + $this->appFetcher = $appFetcher; |
|
| 62 | + } |
|
| 63 | + |
|
| 64 | + /** |
|
| 65 | + * @param string $newVersion |
|
| 66 | + * @return DataResponse |
|
| 67 | + */ |
|
| 68 | + public function getAppList(string $newVersion): DataResponse { |
|
| 69 | + if (!$this->config->getSystemValue('appstoreenabled', true)) { |
|
| 70 | + return new DataResponse([ |
|
| 71 | + 'appstore_disabled' => true, |
|
| 72 | + ], Http::STATUS_NOT_FOUND); |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + // Get list of installed custom apps |
|
| 76 | + $installedApps = $this->appManager->getInstalledApps(); |
|
| 77 | + $installedApps = array_filter($installedApps, function($app) { |
|
| 78 | + try { |
|
| 79 | + $this->appManager->getAppPath($app); |
|
| 80 | + } catch (AppPathNotFoundException $e) { |
|
| 81 | + return false; |
|
| 82 | + } |
|
| 83 | + return !$this->appManager->isShipped($app); |
|
| 84 | + }); |
|
| 85 | + |
|
| 86 | + if (empty($installedApps)) { |
|
| 87 | + return new DataResponse([ |
|
| 88 | + 'missing' => [], |
|
| 89 | + 'available' => [], |
|
| 90 | + ]); |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + $this->appFetcher->setVersion($newVersion, 'future-apps.json'); |
|
| 94 | + |
|
| 95 | + // Apps available on the app store for that version |
|
| 96 | + $availableApps = array_map(function(array $app) { |
|
| 97 | + return $app['id']; |
|
| 98 | + }, $this->appFetcher->get()); |
|
| 99 | + |
|
| 100 | + if (empty($availableApps)) { |
|
| 101 | + return new DataResponse([ |
|
| 102 | + 'appstore_disabled' => false, |
|
| 103 | + 'already_on_latest' => false, |
|
| 104 | + ], Http::STATUS_NOT_FOUND); |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + $missing = array_diff($installedApps, $availableApps); |
|
| 108 | + $missing = array_map([$this, 'getAppDetails'], $missing); |
|
| 109 | + sort($missing); |
|
| 110 | + |
|
| 111 | + $available = array_intersect($installedApps, $availableApps); |
|
| 112 | + $available = array_map([$this, 'getAppDetails'], $available); |
|
| 113 | + sort($available); |
|
| 114 | + |
|
| 115 | + return new DataResponse([ |
|
| 116 | + 'missing' => $missing, |
|
| 117 | + 'available' => $available, |
|
| 118 | + ]); |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + /** |
|
| 122 | + * Get translated app name |
|
| 123 | + * |
|
| 124 | + * @param string $appId |
|
| 125 | + * @return string[] |
|
| 126 | + */ |
|
| 127 | + protected function getAppDetails($appId): array { |
|
| 128 | + $app = $this->appManager->getAppInfo($appId); |
|
| 129 | + return [ |
|
| 130 | + 'appId' => $appId, |
|
| 131 | + 'appName' => $app['name'] ?? $appId, |
|
| 132 | + ]; |
|
| 133 | + } |
|
| 134 | 134 | } |
@@ -1,5 +1,5 @@ |
||
| 1 | 1 | <?php |
| 2 | -declare(strict_types=1); |
|
| 2 | +declare(strict_types = 1); |
|
| 3 | 3 | /** |
| 4 | 4 | * @copyright Copyright (c) 2017 Joas Schilling <[email protected]> |
| 5 | 5 | * |