diff options
author | Arthur Schiwon <blizzz@arthur-schiwon.de> | 2018-06-26 17:25:37 +0200 |
---|---|---|
committer | Morris Jobke <hey@morrisjobke.de> | 2018-06-29 09:11:04 +0200 |
commit | 25d9c3e52921b107383e5d05f3649178bd7cd1cf (patch) | |
tree | 837fb580784174aa14a1d412056b1e9bf4f61772 /apps/updatenotification/lib | |
parent | 4ed8ee1c1e8ada0e5d26f6e014896accc89d4d6a (diff) | |
download | nextcloud-server-25d9c3e52921b107383e5d05f3649178bd7cd1cf.tar.gz nextcloud-server-25d9c3e52921b107383e5d05f3649178bd7cd1cf.zip |
adjust backend and gui to update and changelog server
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
Diffstat (limited to 'apps/updatenotification/lib')
-rw-r--r-- | apps/updatenotification/lib/Settings/Admin.php | 73 | ||||
-rw-r--r-- | apps/updatenotification/lib/UpdateChecker.php | 17 |
2 files changed, 71 insertions, 19 deletions
diff --git a/apps/updatenotification/lib/Settings/Admin.php b/apps/updatenotification/lib/Settings/Admin.php index 1696e97d3ae..b859ca79f62 100644 --- a/apps/updatenotification/lib/Settings/Admin.php +++ b/apps/updatenotification/lib/Settings/Admin.php @@ -31,6 +31,8 @@ use OCP\AppFramework\Http\TemplateResponse; use OCP\IConfig; use OCP\IDateTimeFormatter; use OCP\IGroupManager; +use OCP\IUserSession; +use OCP\L10N\IFactory; use OCP\Settings\ISettings; use OCP\Util; @@ -43,21 +45,25 @@ class Admin implements ISettings { private $groupManager; /** @var IDateTimeFormatter */ private $dateTimeFormatter; - - /** - * @param IConfig $config - * @param UpdateChecker $updateChecker - * @param IGroupManager $groupManager - * @param IDateTimeFormatter $dateTimeFormatter - */ - public function __construct(IConfig $config, - UpdateChecker $updateChecker, - IGroupManager $groupManager, - IDateTimeFormatter $dateTimeFormatter) { + /** @var IUserSession */ + private $session; + /** @var IFactory */ + private $l10nFactory; + + public function __construct( + IConfig $config, + UpdateChecker $updateChecker, + IGroupManager $groupManager, + IDateTimeFormatter $dateTimeFormatter, + IUserSession $session, + IFactory $l10nFactory + ) { $this->config = $config; $this->updateChecker = $updateChecker; $this->groupManager = $groupManager; $this->dateTimeFormatter = $dateTimeFormatter; + $this->session = $session; + $this->l10nFactory = $l10nFactory; } /** @@ -93,8 +99,7 @@ class Admin implements ISettings { 'channels' => $channels, 'newVersionString' => empty($updateState['updateVersion']) ? '' : $updateState['updateVersion'], 'downloadLink' => empty($updateState['downloadLink']) ? '' : $updateState['downloadLink'], - 'changelogURL' => empty($updateState['changelog']) ? false : $updateState['changelog'], - 'whatsNew' => empty($updateState['whatsNew']) ? false : $updateState['whatsNew'], + 'changes' => $this->filterChanges($updateState['changes'] ?? []), 'updaterEnabled' => empty($updateState['updaterEnabled']) ? false : $updateState['updaterEnabled'], 'versionIsEol' => empty($updateState['versionIsEol']) ? false : $updateState['versionIsEol'], 'isDefaultUpdateServerURL' => $updateServerURL === $defaultUpdateServerURL, @@ -109,6 +114,48 @@ class Admin implements ISettings { return new TemplateResponse('updatenotification', 'admin', $params, ''); } + protected function filterChanges(array $changes) { + $filtered = []; + if(isset($changes['changelogURL'])) { + $filtered['changelogURL'] = $changes['changelogURL']; + } + if(!isset($changes['whatsNew'])) { + return $filtered; + } + + $isFirstCall = true; + do { + $lang = $this->l10nFactory->iterateLanguage($isFirstCall); + if($this->findWhatsNewTranslation($lang, $filtered, $changes['whatsNew'])) { + return $filtered; + } + $isFirstCall = false; + } while($lang !== 'en'); + + return $filtered; + } + + protected function getLangTrunk(string $lang):string { + $pos = strpos($lang, '_'); + if($pos !== false) { + $lang = substr($lang, 0, $pos); + } + return $lang; + } + + protected function findWhatsNewTranslation(string $lang, array &$result, array $whatsNew): bool { + if(isset($whatsNew[$lang])) { + $result['whatsNew'] = $whatsNew[$lang]; + return true; + } + $trunkedLang = $this->getLangTrunk($lang); + if($trunkedLang !== $lang && isset($whatsNew[$trunkedLang])) { + $result['whatsNew'] = $whatsNew[$trunkedLang]; + return true; + } + return false; + } + /** * @param array $groupIds * @return array diff --git a/apps/updatenotification/lib/UpdateChecker.php b/apps/updatenotification/lib/UpdateChecker.php index ec8e119049b..bd03cb442be 100644 --- a/apps/updatenotification/lib/UpdateChecker.php +++ b/apps/updatenotification/lib/UpdateChecker.php @@ -25,17 +25,21 @@ declare(strict_types=1); namespace OCA\UpdateNotification; +use OC\Updater\ChangesCheck; use OC\Updater\VersionCheck; class UpdateChecker { /** @var VersionCheck */ private $updater; + /** @var ChangesCheck */ + private $changesCheck; /** * @param VersionCheck $updater */ - public function __construct(VersionCheck $updater) { + public function __construct(VersionCheck $updater, ChangesCheck $changesCheck) { $this->updater = $updater; + $this->changesCheck = $changesCheck; } /** @@ -56,11 +60,12 @@ class UpdateChecker { if (strpos($data['url'], 'https://') === 0) { $result['downloadLink'] = $data['url']; } - if (strpos($data['changelog'], 'https://') === 0) { - $result['changelog'] = $data['changelog']; - } - if (is_array($data['whatsNew']) && count($data['whatsNew']) <= 3) { - $result['whatsNew'] = $data['whatsNew']; + if (strpos($data['changes'], 'https://') === 0) { + try { + $result['changes'] = $this->changesCheck->check($data['changes'], $data['version']); + } catch (\Exception $e) { + // no info, not a problem + } } return $result; |