summaryrefslogtreecommitdiffstats
path: root/apps/updatenotification/lib
diff options
context:
space:
mode:
authorLukas Reschke <lukas@owncloud.com>2016-02-09 13:06:48 +0100
committerLukas Reschke <lukas@owncloud.com>2016-02-09 18:05:51 +0100
commitabc675d87e6ffc49fad608d5b2e8d280e385cc61 (patch)
tree558a752af5c3d9936cbd597ea76607f57e22c32c /apps/updatenotification/lib
parent29820176825c41acef30fa6942922aeb36cfcec3 (diff)
downloadnextcloud-server-abc675d87e6ffc49fad608d5b2e8d280e385cc61.tar.gz
nextcloud-server-abc675d87e6ffc49fad608d5b2e8d280e385cc61.zip
Move update notification code into app
Moves the update notification code in a single app. This is required since we want to use SSO for the new updater and for this have some code running in ownCloud as well (and we don't want that in core neccessarily). This app can provide that in the future, right now it's only the update notification itself. Will continue working on the SSO right away but wanted to keep the PR small. Furthermore also makes some more code unit-testable...
Diffstat (limited to 'apps/updatenotification/lib')
-rw-r--r--apps/updatenotification/lib/updatechecker.php67
1 files changed, 67 insertions, 0 deletions
diff --git a/apps/updatenotification/lib/updatechecker.php b/apps/updatenotification/lib/updatechecker.php
new file mode 100644
index 00000000000..965e21617e7
--- /dev/null
+++ b/apps/updatenotification/lib/updatechecker.php
@@ -0,0 +1,67 @@
+<?php
+/**
+ * @author Lukas Reschke <lukas@owncloud.com>
+ *
+ * @copyright Copyright (c) 2016, ownCloud, Inc.
+ * @license AGPL-3.0
+ *
+ * This code is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License, version 3,
+ * along with this program. If not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+namespace OCA\UpdateNotification;
+
+use OC\Updater;
+
+class UpdateChecker {
+ /** @var Updater */
+ private $updater;
+
+ /**
+ * @param Updater $updater
+ */
+ public function __construct(Updater $updater) {
+ $this->updater = $updater;
+ }
+
+ /**
+ * @return array
+ */
+ public function getUpdateState() {
+ $data = $this->updater->check();
+ $result = [];
+
+ if(isset($data['version']) && $data['version'] !== '' && $data['version'] !== []) {
+ $result['updateAvailable'] = true;
+ $result['updateVersion'] = $data['versionstring'];
+ if(substr($data['web'], 0, 8) === 'https://') {
+ $result['updateLink'] = $data['web'];
+ }
+
+ return $result;
+ }
+
+ return [];
+ }
+
+ /**
+ * @param array $data
+ */
+ public function getJavaScript(array $data) {
+ $data['array']['oc_updateState'] = json_encode([
+ 'updateAvailable' => true,
+ 'updateVersion' => $this->getUpdateState()['updateVersion'],
+ 'updateLink' => isset($this->getUpdateState()['updateLink']) ? $this->getUpdateState()['updateLink'] : '',
+ ]);
+ }
+}