@@ -31,93 +31,93 @@ |
||
| 31 | 31 | |
| 32 | 32 | class VersionCheck { |
| 33 | 33 | |
| 34 | - /** @var IClientService */ |
|
| 35 | - private $clientService; |
|
| 34 | + /** @var IClientService */ |
|
| 35 | + private $clientService; |
|
| 36 | 36 | |
| 37 | - /** @var IConfig */ |
|
| 38 | - private $config; |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * @param IClientService $clientService |
|
| 42 | - * @param IConfig $config |
|
| 43 | - */ |
|
| 44 | - public function __construct(IClientService $clientService, |
|
| 45 | - IConfig $config) { |
|
| 46 | - $this->clientService = $clientService; |
|
| 47 | - $this->config = $config; |
|
| 48 | - } |
|
| 49 | - |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * Check if a new version is available |
|
| 53 | - * |
|
| 54 | - * @return array|bool |
|
| 55 | - */ |
|
| 56 | - public function check() { |
|
| 57 | - // Look up the cache - it is invalidated all 30 minutes |
|
| 58 | - if (((int)$this->config->getAppValue('core', 'lastupdatedat') + 1800) > time()) { |
|
| 59 | - return json_decode($this->config->getAppValue('core', 'lastupdateResult'), true); |
|
| 60 | - } |
|
| 61 | - |
|
| 62 | - $updaterUrl = $this->config->getSystemValue('updater.server.url', 'https://updates.nextcloud.com/updater_server/'); |
|
| 63 | - |
|
| 64 | - $this->config->setAppValue('core', 'lastupdatedat', time()); |
|
| 65 | - |
|
| 66 | - if ($this->config->getAppValue('core', 'installedat', '') === '') { |
|
| 67 | - $this->config->setAppValue('core', 'installedat', microtime(true)); |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - $version = Util::getVersion(); |
|
| 71 | - $version['installed'] = $this->config->getAppValue('core', 'installedat'); |
|
| 72 | - $version['updated'] = $this->config->getAppValue('core', 'lastupdatedat'); |
|
| 73 | - $version['updatechannel'] = \OC_Util::getChannel(); |
|
| 74 | - $version['edition'] = ''; |
|
| 75 | - $version['build'] = \OC_Util::getBuild(); |
|
| 76 | - $version['php_major'] = PHP_MAJOR_VERSION; |
|
| 77 | - $version['php_minor'] = PHP_MINOR_VERSION; |
|
| 78 | - $version['php_release'] = PHP_RELEASE_VERSION; |
|
| 79 | - $versionString = implode('x', $version); |
|
| 80 | - |
|
| 81 | - //fetch xml data from updater |
|
| 82 | - $url = $updaterUrl . '?version=' . $versionString; |
|
| 83 | - |
|
| 84 | - $tmp = []; |
|
| 85 | - try { |
|
| 86 | - $xml = $this->getUrlContent($url); |
|
| 87 | - } catch (\Exception $e) { |
|
| 88 | - return false; |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - if ($xml) { |
|
| 92 | - $loadEntities = libxml_disable_entity_loader(true); |
|
| 93 | - $data = @simplexml_load_string($xml); |
|
| 94 | - libxml_disable_entity_loader($loadEntities); |
|
| 95 | - if ($data !== false) { |
|
| 96 | - $tmp['version'] = (string)$data->version; |
|
| 97 | - $tmp['versionstring'] = (string)$data->versionstring; |
|
| 98 | - $tmp['url'] = (string)$data->url; |
|
| 99 | - $tmp['web'] = (string)$data->web; |
|
| 100 | - $tmp['autoupdater'] = (string)$data->autoupdater; |
|
| 101 | - } else { |
|
| 102 | - libxml_clear_errors(); |
|
| 103 | - } |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - // Cache the result |
|
| 107 | - $this->config->setAppValue('core', 'lastupdateResult', json_encode($tmp)); |
|
| 108 | - return $tmp; |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - /** |
|
| 112 | - * @codeCoverageIgnore |
|
| 113 | - * @param string $url |
|
| 114 | - * @return resource|string |
|
| 115 | - * @throws \Exception |
|
| 116 | - */ |
|
| 117 | - protected function getUrlContent($url) { |
|
| 118 | - $client = $this->clientService->newClient(); |
|
| 119 | - $response = $client->get($url); |
|
| 120 | - return $response->getBody(); |
|
| 121 | - } |
|
| 37 | + /** @var IConfig */ |
|
| 38 | + private $config; |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * @param IClientService $clientService |
|
| 42 | + * @param IConfig $config |
|
| 43 | + */ |
|
| 44 | + public function __construct(IClientService $clientService, |
|
| 45 | + IConfig $config) { |
|
| 46 | + $this->clientService = $clientService; |
|
| 47 | + $this->config = $config; |
|
| 48 | + } |
|
| 49 | + |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * Check if a new version is available |
|
| 53 | + * |
|
| 54 | + * @return array|bool |
|
| 55 | + */ |
|
| 56 | + public function check() { |
|
| 57 | + // Look up the cache - it is invalidated all 30 minutes |
|
| 58 | + if (((int)$this->config->getAppValue('core', 'lastupdatedat') + 1800) > time()) { |
|
| 59 | + return json_decode($this->config->getAppValue('core', 'lastupdateResult'), true); |
|
| 60 | + } |
|
| 61 | + |
|
| 62 | + $updaterUrl = $this->config->getSystemValue('updater.server.url', 'https://updates.nextcloud.com/updater_server/'); |
|
| 63 | + |
|
| 64 | + $this->config->setAppValue('core', 'lastupdatedat', time()); |
|
| 65 | + |
|
| 66 | + if ($this->config->getAppValue('core', 'installedat', '') === '') { |
|
| 67 | + $this->config->setAppValue('core', 'installedat', microtime(true)); |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + $version = Util::getVersion(); |
|
| 71 | + $version['installed'] = $this->config->getAppValue('core', 'installedat'); |
|
| 72 | + $version['updated'] = $this->config->getAppValue('core', 'lastupdatedat'); |
|
| 73 | + $version['updatechannel'] = \OC_Util::getChannel(); |
|
| 74 | + $version['edition'] = ''; |
|
| 75 | + $version['build'] = \OC_Util::getBuild(); |
|
| 76 | + $version['php_major'] = PHP_MAJOR_VERSION; |
|
| 77 | + $version['php_minor'] = PHP_MINOR_VERSION; |
|
| 78 | + $version['php_release'] = PHP_RELEASE_VERSION; |
|
| 79 | + $versionString = implode('x', $version); |
|
| 80 | + |
|
| 81 | + //fetch xml data from updater |
|
| 82 | + $url = $updaterUrl . '?version=' . $versionString; |
|
| 83 | + |
|
| 84 | + $tmp = []; |
|
| 85 | + try { |
|
| 86 | + $xml = $this->getUrlContent($url); |
|
| 87 | + } catch (\Exception $e) { |
|
| 88 | + return false; |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + if ($xml) { |
|
| 92 | + $loadEntities = libxml_disable_entity_loader(true); |
|
| 93 | + $data = @simplexml_load_string($xml); |
|
| 94 | + libxml_disable_entity_loader($loadEntities); |
|
| 95 | + if ($data !== false) { |
|
| 96 | + $tmp['version'] = (string)$data->version; |
|
| 97 | + $tmp['versionstring'] = (string)$data->versionstring; |
|
| 98 | + $tmp['url'] = (string)$data->url; |
|
| 99 | + $tmp['web'] = (string)$data->web; |
|
| 100 | + $tmp['autoupdater'] = (string)$data->autoupdater; |
|
| 101 | + } else { |
|
| 102 | + libxml_clear_errors(); |
|
| 103 | + } |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + // Cache the result |
|
| 107 | + $this->config->setAppValue('core', 'lastupdateResult', json_encode($tmp)); |
|
| 108 | + return $tmp; |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + /** |
|
| 112 | + * @codeCoverageIgnore |
|
| 113 | + * @param string $url |
|
| 114 | + * @return resource|string |
|
| 115 | + * @throws \Exception |
|
| 116 | + */ |
|
| 117 | + protected function getUrlContent($url) { |
|
| 118 | + $client = $this->clientService->newClient(); |
|
| 119 | + $response = $client->get($url); |
|
| 120 | + return $response->getBody(); |
|
| 121 | + } |
|
| 122 | 122 | } |
| 123 | 123 | |