Completed
Pull Request — master (#7863)
by Joas
35:34 queued 18:18
created
apps/updatenotification/lib/ResetTokenBackgroundJob.php 1 patch
Indentation   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -33,31 +33,31 @@
 block discarded – undo
33 33
  * @package OCA\UpdateNotification
34 34
  */
35 35
 class ResetTokenBackgroundJob extends TimedJob {
36
-	/** @var IConfig */
37
-	private $config;
38
-	/** @var ITimeFactory */
39
-	private $timeFactory;
36
+    /** @var IConfig */
37
+    private $config;
38
+    /** @var ITimeFactory */
39
+    private $timeFactory;
40 40
 
41
-	/**
42
-	 * @param IConfig $config
43
-	 * @param ITimeFactory $timeFactory
44
-	 */
45
-	public function __construct(IConfig $config,
46
-								ITimeFactory $timeFactory) {
47
-		// Run all 10 minutes
48
-		$this->setInterval(60 * 10);
49
-		$this->config = $config;
50
-		$this->timeFactory = $timeFactory;
51
-	}
41
+    /**
42
+     * @param IConfig $config
43
+     * @param ITimeFactory $timeFactory
44
+     */
45
+    public function __construct(IConfig $config,
46
+                                ITimeFactory $timeFactory) {
47
+        // Run all 10 minutes
48
+        $this->setInterval(60 * 10);
49
+        $this->config = $config;
50
+        $this->timeFactory = $timeFactory;
51
+    }
52 52
 
53
-	/**
54
-	 * @param $argument
55
-	 */
56
-	protected function run($argument) {
57
-		// Delete old tokens after 2 days
58
-		if($this->timeFactory->getTime() - $this->config->getAppValue('core', 'updater.secret.created', $this->timeFactory->getTime()) >= 172800) {
59
-			$this->config->deleteSystemValue('updater.secret');
60
-		}
61
-	}
53
+    /**
54
+     * @param $argument
55
+     */
56
+    protected function run($argument) {
57
+        // Delete old tokens after 2 days
58
+        if($this->timeFactory->getTime() - $this->config->getAppValue('core', 'updater.secret.created', $this->timeFactory->getTime()) >= 172800) {
59
+            $this->config->deleteSystemValue('updater.secret');
60
+        }
61
+    }
62 62
 
63 63
 }
Please login to merge, or discard this patch.
apps/updatenotification/lib/UpdateChecker.php 2 patches
Indentation   +38 added lines, -38 removed lines patch added patch discarded remove patch
@@ -27,48 +27,48 @@
 block discarded – undo
27 27
 use OC\Updater\VersionCheck;
28 28
 
29 29
 class UpdateChecker {
30
-	/** @var VersionCheck */
31
-	private $updater;
30
+    /** @var VersionCheck */
31
+    private $updater;
32 32
 
33
-	/**
34
-	 * @param VersionCheck $updater
35
-	 */
36
-	public function __construct(VersionCheck $updater) {
37
-		$this->updater = $updater;
38
-	}
33
+    /**
34
+     * @param VersionCheck $updater
35
+     */
36
+    public function __construct(VersionCheck $updater) {
37
+        $this->updater = $updater;
38
+    }
39 39
 
40
-	/**
41
-	 * @return array
42
-	 */
43
-	public function getUpdateState() {
44
-		$data = $this->updater->check();
45
-		$result = [];
40
+    /**
41
+     * @return array
42
+     */
43
+    public function getUpdateState() {
44
+        $data = $this->updater->check();
45
+        $result = [];
46 46
 
47
-		if(isset($data['version']) && $data['version'] !== '' && $data['version'] !== []) {
48
-			$result['updateAvailable'] = true;
49
-			$result['updateVersion'] = $data['versionstring'];
50
-			$result['updaterEnabled'] = $data['autoupdater'] === '1';
51
-			if(substr($data['web'], 0, 8) === 'https://') {
52
-				$result['updateLink'] = $data['web'];
53
-			}
54
-			if(substr($data['url'], 0, 8) === 'https://') {
55
-				$result['downloadLink'] = $data['url'];
56
-			}
47
+        if(isset($data['version']) && $data['version'] !== '' && $data['version'] !== []) {
48
+            $result['updateAvailable'] = true;
49
+            $result['updateVersion'] = $data['versionstring'];
50
+            $result['updaterEnabled'] = $data['autoupdater'] === '1';
51
+            if(substr($data['web'], 0, 8) === 'https://') {
52
+                $result['updateLink'] = $data['web'];
53
+            }
54
+            if(substr($data['url'], 0, 8) === 'https://') {
55
+                $result['downloadLink'] = $data['url'];
56
+            }
57 57
 
58
-			return $result;
59
-		}
58
+            return $result;
59
+        }
60 60
 
61
-		return [];
62
-	}
61
+        return [];
62
+    }
63 63
 
64
-	/**
65
-	 * @param array $data
66
-	 */
67
-	public function populateJavaScriptVariables(array $data) {
68
-		$data['array']['oc_updateState'] =  json_encode([
69
-			'updateAvailable' => true,
70
-			'updateVersion' => $this->getUpdateState()['updateVersion'],
71
-			'updateLink' => isset($this->getUpdateState()['updateLink']) ? $this->getUpdateState()['updateLink'] : '',
72
-		]);
73
-	}
64
+    /**
65
+     * @param array $data
66
+     */
67
+    public function populateJavaScriptVariables(array $data) {
68
+        $data['array']['oc_updateState'] =  json_encode([
69
+            'updateAvailable' => true,
70
+            'updateVersion' => $this->getUpdateState()['updateVersion'],
71
+            'updateLink' => isset($this->getUpdateState()['updateLink']) ? $this->getUpdateState()['updateLink'] : '',
72
+        ]);
73
+    }
74 74
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -44,14 +44,14 @@  discard block
 block discarded – undo
44 44
 		$data = $this->updater->check();
45 45
 		$result = [];
46 46
 
47
-		if(isset($data['version']) && $data['version'] !== '' && $data['version'] !== []) {
47
+		if (isset($data['version']) && $data['version'] !== '' && $data['version'] !== []) {
48 48
 			$result['updateAvailable'] = true;
49 49
 			$result['updateVersion'] = $data['versionstring'];
50 50
 			$result['updaterEnabled'] = $data['autoupdater'] === '1';
51
-			if(substr($data['web'], 0, 8) === 'https://') {
51
+			if (substr($data['web'], 0, 8) === 'https://') {
52 52
 				$result['updateLink'] = $data['web'];
53 53
 			}
54
-			if(substr($data['url'], 0, 8) === 'https://') {
54
+			if (substr($data['url'], 0, 8) === 'https://') {
55 55
 				$result['downloadLink'] = $data['url'];
56 56
 			}
57 57
 
@@ -65,7 +65,7 @@  discard block
 block discarded – undo
65 65
 	 * @param array $data
66 66
 	 */
67 67
 	public function populateJavaScriptVariables(array $data) {
68
-		$data['array']['oc_updateState'] =  json_encode([
68
+		$data['array']['oc_updateState'] = json_encode([
69 69
 			'updateAvailable' => true,
70 70
 			'updateVersion' => $this->getUpdateState()['updateVersion'],
71 71
 			'updateLink' => isset($this->getUpdateState()['updateLink']) ? $this->getUpdateState()['updateLink'] : '',
Please login to merge, or discard this patch.
apps/updatenotification/lib/AppInfo/Application.php 1 patch
Indentation   +43 added lines, -43 removed lines patch added patch discarded remove patch
@@ -31,53 +31,53 @@
 block discarded – undo
31 31
 use OCP\Util;
32 32
 
33 33
 class Application extends App {
34
-	public function __construct() {
35
-		parent::__construct('updatenotification', []);
36
-	}
34
+    public function __construct() {
35
+        parent::__construct('updatenotification', []);
36
+    }
37 37
 
38
-	public function register() {
39
-		$server = $this->getContainer()->getServer();
38
+    public function register() {
39
+        $server = $this->getContainer()->getServer();
40 40
 
41
-		if ($server->getConfig()->getSystemValue('updatechecker', true) !== true) {
42
-			// Updater check is disabled
43
-			return;
44
-		}
41
+        if ($server->getConfig()->getSystemValue('updatechecker', true) !== true) {
42
+            // Updater check is disabled
43
+            return;
44
+        }
45 45
 
46
-		$user = $server->getUserSession()->getUser();
47
-		if (!$user instanceof IUser) {
48
-			// Nothing to do for guests
49
-			return;
50
-		}
46
+        $user = $server->getUserSession()->getUser();
47
+        if (!$user instanceof IUser) {
48
+            // Nothing to do for guests
49
+            return;
50
+        }
51 51
 
52
-		if ($server->getAppManager()->isEnabledForUser('notifications')) {
53
-			// Notifications app is available, so we register.
54
-			// Since notifications also work for non-admins we don't check this here.
55
-			$this->registerNotifier();
56
-		} else if ($server->getGroupManager()->isAdmin($user->getUID())) {
57
-			try {
58
-				$updateChecker = $this->getContainer()->query(UpdateChecker::class);
59
-			} catch (QueryException $e) {
60
-				$server->getLogger()->logException($e);
61
-				return;
62
-			}
52
+        if ($server->getAppManager()->isEnabledForUser('notifications')) {
53
+            // Notifications app is available, so we register.
54
+            // Since notifications also work for non-admins we don't check this here.
55
+            $this->registerNotifier();
56
+        } else if ($server->getGroupManager()->isAdmin($user->getUID())) {
57
+            try {
58
+                $updateChecker = $this->getContainer()->query(UpdateChecker::class);
59
+            } catch (QueryException $e) {
60
+                $server->getLogger()->logException($e);
61
+                return;
62
+            }
63 63
 
64
-			if ($updateChecker->getUpdateState() !== []) {
65
-				Util::addScript('updatenotification', 'notification');
66
-				\OC_Hook::connect('\OCP\Config', 'js', $updateChecker, 'populateJavaScriptVariables');
67
-			}
68
-		}
69
-	}
64
+            if ($updateChecker->getUpdateState() !== []) {
65
+                Util::addScript('updatenotification', 'notification');
66
+                \OC_Hook::connect('\OCP\Config', 'js', $updateChecker, 'populateJavaScriptVariables');
67
+            }
68
+        }
69
+    }
70 70
 
71
-	public function registerNotifier() {
72
-		$notificationsManager = $this->getContainer()->getServer()->getNotificationManager();
73
-		$notificationsManager->registerNotifier(function() {
74
-			return  $this->getContainer()->query(Notifier::class);
75
-		}, function() {
76
-			$l = $this->getContainer()->getServer()->getL10N('updatenotification');
77
-			return [
78
-				'id' => 'updatenotification',
79
-				'name' => $l->t('Update notifications'),
80
-			];
81
-		});
82
-	}
71
+    public function registerNotifier() {
72
+        $notificationsManager = $this->getContainer()->getServer()->getNotificationManager();
73
+        $notificationsManager->registerNotifier(function() {
74
+            return  $this->getContainer()->query(Notifier::class);
75
+        }, function() {
76
+            $l = $this->getContainer()->getServer()->getL10N('updatenotification');
77
+            return [
78
+                'id' => 'updatenotification',
79
+                'name' => $l->t('Update notifications'),
80
+            ];
81
+        });
82
+    }
83 83
 }
Please login to merge, or discard this patch.
apps/updatenotification/lib/Controller/AdminController.php 2 patches
Indentation   +130 added lines, -130 removed lines patch added patch discarded remove patch
@@ -41,134 +41,134 @@
 block discarded – undo
41 41
 use OCP\Util;
42 42
 
43 43
 class AdminController extends Controller implements ISettings {
44
-	/** @var IJobList */
45
-	private $jobList;
46
-	/** @var ISecureRandom */
47
-	private $secureRandom;
48
-	/** @var IConfig */
49
-	private $config;
50
-	/** @var ITimeFactory */
51
-	private $timeFactory;
52
-	/** @var UpdateChecker */
53
-	private $updateChecker;
54
-	/** @var IL10N */
55
-	private $l10n;
56
-	/** @var IDateTimeFormatter */
57
-	private $dateTimeFormatter;
58
-
59
-	/**
60
-	 * @param string $appName
61
-	 * @param IRequest $request
62
-	 * @param IJobList $jobList
63
-	 * @param ISecureRandom $secureRandom
64
-	 * @param IConfig $config
65
-	 * @param ITimeFactory $timeFactory
66
-	 * @param IL10N $l10n
67
-	 * @param UpdateChecker $updateChecker
68
-	 * @param IDateTimeFormatter $dateTimeFormatter
69
-	 */
70
-	public function __construct($appName,
71
-								IRequest $request,
72
-								IJobList $jobList,
73
-								ISecureRandom $secureRandom,
74
-								IConfig $config,
75
-								ITimeFactory $timeFactory,
76
-								IL10N $l10n,
77
-								UpdateChecker $updateChecker,
78
-								IDateTimeFormatter $dateTimeFormatter) {
79
-		parent::__construct($appName, $request);
80
-		$this->jobList = $jobList;
81
-		$this->secureRandom = $secureRandom;
82
-		$this->config = $config;
83
-		$this->timeFactory = $timeFactory;
84
-		$this->l10n = $l10n;
85
-		$this->updateChecker = $updateChecker;
86
-		$this->dateTimeFormatter = $dateTimeFormatter;
87
-	}
88
-
89
-	/**
90
-	 * @return TemplateResponse
91
-	 */
92
-	public function getForm() {
93
-		$lastUpdateCheckTimestamp = $this->config->getAppValue('core', 'lastupdatedat');
94
-		$lastUpdateCheck = $this->dateTimeFormatter->formatDateTime($lastUpdateCheckTimestamp);
95
-
96
-		$channels = [
97
-			'daily',
98
-			'beta',
99
-			'stable',
100
-			'production',
101
-		];
102
-		$currentChannel = Util::getChannel();
103
-
104
-		// Remove the currently used channel from the channels list
105
-		if(($key = array_search($currentChannel, $channels)) !== false) {
106
-			unset($channels[$key]);
107
-		}
108
-		$updateState = $this->updateChecker->getUpdateState();
109
-
110
-		$notifyGroups = json_decode($this->config->getAppValue('updatenotification', 'notify_groups', '["admin"]'), true);
111
-
112
-		$defaultUpdateServerURL = 'https://updates.nextcloud.com/server/';
113
-		$updateServerURL = $this->config->getSystemValue('updater.server.url', $defaultUpdateServerURL);
114
-
115
-		$params = [
116
-			'isNewVersionAvailable' => !empty($updateState['updateAvailable']),
117
-			'isUpdateChecked' => $lastUpdateCheckTimestamp > 0,
118
-			'lastChecked' => $lastUpdateCheck,
119
-			'currentChannel' => $currentChannel,
120
-			'channels' => $channels,
121
-			'newVersionString' => (empty($updateState['updateVersion'])) ? '' : $updateState['updateVersion'],
122
-			'downloadLink' => (empty($updateState['downloadLink'])) ? '' : $updateState['downloadLink'],
123
-			'updaterEnabled' => (empty($updateState['updaterEnabled'])) ? false : $updateState['updaterEnabled'],
124
-			'isDefaultUpdateServerURL' => $updateServerURL === $defaultUpdateServerURL,
125
-			'updateServerURL' => $updateServerURL,
126
-			'notify_groups' => implode('|', $notifyGroups),
127
-		];
128
-
129
-		return new TemplateResponse($this->appName, 'admin', $params, '');
130
-	}
131
-
132
-	/**
133
-	 * @param string $channel
134
-	 * @return DataResponse
135
-	 */
136
-	public function setChannel($channel) {
137
-		Util::setChannel($channel);
138
-		$this->config->setAppValue('core', 'lastupdatedat', 0);
139
-		return new DataResponse(['status' => 'success', 'data' => ['message' => $this->l10n->t('Channel updated')]]);
140
-	}
141
-
142
-	/**
143
-	 * @return DataResponse
144
-	 */
145
-	public function createCredentials() {
146
-		// Create a new job and store the creation date
147
-		$this->jobList->add(ResetTokenBackgroundJob::class);
148
-		$this->config->setAppValue('core', 'updater.secret.created', $this->timeFactory->getTime());
149
-
150
-		// Create a new token
151
-		$newToken = $this->secureRandom->generate(64);
152
-		$this->config->setSystemValue('updater.secret', password_hash($newToken, PASSWORD_DEFAULT));
153
-
154
-		return new DataResponse($newToken);
155
-	}
156
-
157
-	/**
158
-	 * @return string the section ID, e.g. 'sharing'
159
-	 */
160
-	public function getSection() {
161
-		return 'server';
162
-	}
163
-
164
-	/**
165
-	 * @return int whether the form should be rather on the top or bottom of
166
-	 * the admin section. The forms are arranged in ascending order of the
167
-	 * priority values. It is required to return a value between 0 and 100.
168
-	 *
169
-	 * E.g.: 70
170
-	 */
171
-	public function getPriority() {
172
-		return 1;
173
-	}
44
+    /** @var IJobList */
45
+    private $jobList;
46
+    /** @var ISecureRandom */
47
+    private $secureRandom;
48
+    /** @var IConfig */
49
+    private $config;
50
+    /** @var ITimeFactory */
51
+    private $timeFactory;
52
+    /** @var UpdateChecker */
53
+    private $updateChecker;
54
+    /** @var IL10N */
55
+    private $l10n;
56
+    /** @var IDateTimeFormatter */
57
+    private $dateTimeFormatter;
58
+
59
+    /**
60
+     * @param string $appName
61
+     * @param IRequest $request
62
+     * @param IJobList $jobList
63
+     * @param ISecureRandom $secureRandom
64
+     * @param IConfig $config
65
+     * @param ITimeFactory $timeFactory
66
+     * @param IL10N $l10n
67
+     * @param UpdateChecker $updateChecker
68
+     * @param IDateTimeFormatter $dateTimeFormatter
69
+     */
70
+    public function __construct($appName,
71
+                                IRequest $request,
72
+                                IJobList $jobList,
73
+                                ISecureRandom $secureRandom,
74
+                                IConfig $config,
75
+                                ITimeFactory $timeFactory,
76
+                                IL10N $l10n,
77
+                                UpdateChecker $updateChecker,
78
+                                IDateTimeFormatter $dateTimeFormatter) {
79
+        parent::__construct($appName, $request);
80
+        $this->jobList = $jobList;
81
+        $this->secureRandom = $secureRandom;
82
+        $this->config = $config;
83
+        $this->timeFactory = $timeFactory;
84
+        $this->l10n = $l10n;
85
+        $this->updateChecker = $updateChecker;
86
+        $this->dateTimeFormatter = $dateTimeFormatter;
87
+    }
88
+
89
+    /**
90
+     * @return TemplateResponse
91
+     */
92
+    public function getForm() {
93
+        $lastUpdateCheckTimestamp = $this->config->getAppValue('core', 'lastupdatedat');
94
+        $lastUpdateCheck = $this->dateTimeFormatter->formatDateTime($lastUpdateCheckTimestamp);
95
+
96
+        $channels = [
97
+            'daily',
98
+            'beta',
99
+            'stable',
100
+            'production',
101
+        ];
102
+        $currentChannel = Util::getChannel();
103
+
104
+        // Remove the currently used channel from the channels list
105
+        if(($key = array_search($currentChannel, $channels)) !== false) {
106
+            unset($channels[$key]);
107
+        }
108
+        $updateState = $this->updateChecker->getUpdateState();
109
+
110
+        $notifyGroups = json_decode($this->config->getAppValue('updatenotification', 'notify_groups', '["admin"]'), true);
111
+
112
+        $defaultUpdateServerURL = 'https://updates.nextcloud.com/server/';
113
+        $updateServerURL = $this->config->getSystemValue('updater.server.url', $defaultUpdateServerURL);
114
+
115
+        $params = [
116
+            'isNewVersionAvailable' => !empty($updateState['updateAvailable']),
117
+            'isUpdateChecked' => $lastUpdateCheckTimestamp > 0,
118
+            'lastChecked' => $lastUpdateCheck,
119
+            'currentChannel' => $currentChannel,
120
+            'channels' => $channels,
121
+            'newVersionString' => (empty($updateState['updateVersion'])) ? '' : $updateState['updateVersion'],
122
+            'downloadLink' => (empty($updateState['downloadLink'])) ? '' : $updateState['downloadLink'],
123
+            'updaterEnabled' => (empty($updateState['updaterEnabled'])) ? false : $updateState['updaterEnabled'],
124
+            'isDefaultUpdateServerURL' => $updateServerURL === $defaultUpdateServerURL,
125
+            'updateServerURL' => $updateServerURL,
126
+            'notify_groups' => implode('|', $notifyGroups),
127
+        ];
128
+
129
+        return new TemplateResponse($this->appName, 'admin', $params, '');
130
+    }
131
+
132
+    /**
133
+     * @param string $channel
134
+     * @return DataResponse
135
+     */
136
+    public function setChannel($channel) {
137
+        Util::setChannel($channel);
138
+        $this->config->setAppValue('core', 'lastupdatedat', 0);
139
+        return new DataResponse(['status' => 'success', 'data' => ['message' => $this->l10n->t('Channel updated')]]);
140
+    }
141
+
142
+    /**
143
+     * @return DataResponse
144
+     */
145
+    public function createCredentials() {
146
+        // Create a new job and store the creation date
147
+        $this->jobList->add(ResetTokenBackgroundJob::class);
148
+        $this->config->setAppValue('core', 'updater.secret.created', $this->timeFactory->getTime());
149
+
150
+        // Create a new token
151
+        $newToken = $this->secureRandom->generate(64);
152
+        $this->config->setSystemValue('updater.secret', password_hash($newToken, PASSWORD_DEFAULT));
153
+
154
+        return new DataResponse($newToken);
155
+    }
156
+
157
+    /**
158
+     * @return string the section ID, e.g. 'sharing'
159
+     */
160
+    public function getSection() {
161
+        return 'server';
162
+    }
163
+
164
+    /**
165
+     * @return int whether the form should be rather on the top or bottom of
166
+     * the admin section. The forms are arranged in ascending order of the
167
+     * priority values. It is required to return a value between 0 and 100.
168
+     *
169
+     * E.g.: 70
170
+     */
171
+    public function getPriority() {
172
+        return 1;
173
+    }
174 174
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -102,7 +102,7 @@
 block discarded – undo
102 102
 		$currentChannel = Util::getChannel();
103 103
 
104 104
 		// Remove the currently used channel from the channels list
105
-		if(($key = array_search($currentChannel, $channels)) !== false) {
105
+		if (($key = array_search($currentChannel, $channels)) !== false) {
106 106
 			unset($channels[$key]);
107 107
 		}
108 108
 		$updateState = $this->updateChecker->getUpdateState();
Please login to merge, or discard this patch.