Passed
Push — master ( da57aa...b7a59f )
by Morris
12:15
created
apps/updatenotification/lib/Settings/Admin.php 1 patch
Indentation   +136 added lines, -136 removed lines patch added patch discarded remove patch
@@ -37,140 +37,140 @@
 block discarded – undo
37 37
 use OCP\Util;
38 38
 
39 39
 class Admin implements ISettings {
40
-	/** @var IConfig */
41
-	private $config;
42
-	/** @var UpdateChecker */
43
-	private $updateChecker;
44
-	/** @var IGroupManager */
45
-	private $groupManager;
46
-	/** @var IDateTimeFormatter */
47
-	private $dateTimeFormatter;
48
-	/** @var IUserSession */
49
-	private $session;
50
-	/** @var IFactory */
51
-	private $l10nFactory;
52
-
53
-	public function __construct(
54
-		IConfig $config,
55
-		UpdateChecker $updateChecker,
56
-		IGroupManager $groupManager,
57
-		IDateTimeFormatter $dateTimeFormatter,
58
-		IUserSession $session,
59
-		IFactory $l10nFactory
60
-	) {
61
-		$this->config = $config;
62
-		$this->updateChecker = $updateChecker;
63
-		$this->groupManager = $groupManager;
64
-		$this->dateTimeFormatter = $dateTimeFormatter;
65
-		$this->session = $session;
66
-		$this->l10nFactory = $l10nFactory;
67
-	}
68
-
69
-	/**
70
-	 * @return TemplateResponse
71
-	 */
72
-	public function getForm(): TemplateResponse {
73
-		$lastUpdateCheckTimestamp = $this->config->getAppValue('core', 'lastupdatedat');
74
-		$lastUpdateCheck = $this->dateTimeFormatter->formatDateTime($lastUpdateCheckTimestamp);
75
-
76
-		$channels = [
77
-			'daily',
78
-			'beta',
79
-			'stable',
80
-			'production',
81
-		];
82
-		$currentChannel = Util::getChannel();
83
-		if ($currentChannel === 'git') {
84
-			$channels[] = 'git';
85
-		}
86
-
87
-		$updateState = $this->updateChecker->getUpdateState();
88
-
89
-		$notifyGroups = json_decode($this->config->getAppValue('updatenotification', 'notify_groups', '["admin"]'), true);
90
-
91
-		$defaultUpdateServerURL = 'https://updates.nextcloud.com/updater_server/';
92
-		$updateServerURL = $this->config->getSystemValue('updater.server.url', $defaultUpdateServerURL);
93
-
94
-		$params = [
95
-			'isNewVersionAvailable' => !empty($updateState['updateAvailable']),
96
-			'isUpdateChecked' => $lastUpdateCheckTimestamp > 0,
97
-			'lastChecked' => $lastUpdateCheck,
98
-			'currentChannel' => $currentChannel,
99
-			'channels' => $channels,
100
-			'newVersion' => empty($updateState['updateVersion']) ? '' : $updateState['updateVersion'],
101
-			'newVersionString' => empty($updateState['updateVersionString']) ? '' : $updateState['updateVersionString'],
102
-			'downloadLink' => empty($updateState['downloadLink']) ? '' : $updateState['downloadLink'],
103
-			'changes' => $this->filterChanges($updateState['changes'] ?? []),
104
-			'updaterEnabled' => empty($updateState['updaterEnabled']) ? false : $updateState['updaterEnabled'],
105
-			'versionIsEol' => empty($updateState['versionIsEol']) ? false : $updateState['versionIsEol'],
106
-			'isDefaultUpdateServerURL' => $updateServerURL === $defaultUpdateServerURL,
107
-			'updateServerURL' => $updateServerURL,
108
-			'notifyGroups' => $this->getSelectedGroups($notifyGroups),
109
-		];
110
-
111
-		$params = [
112
-			'json' => json_encode($params),
113
-		];
114
-
115
-		return new TemplateResponse('updatenotification', 'admin', $params, '');
116
-	}
117
-
118
-	protected function filterChanges(array $changes): array {
119
-		$filtered = [];
120
-		if(isset($changes['changelogURL'])) {
121
-			$filtered['changelogURL'] = $changes['changelogURL'];
122
-		}
123
-		if(!isset($changes['whatsNew'])) {
124
-			return $filtered;
125
-		}
126
-
127
-		$iterator = $this->l10nFactory->getLanguageIterator();
128
-		do {
129
-			$lang = $iterator->current();
130
-			if(isset($changes['whatsNew'][$lang])) {
131
-				$filtered['whatsNew'] = $changes['whatsNew'][$lang];
132
-				return $filtered;
133
-			}
134
-			$iterator->next();
135
-		} while($lang !== 'en' && $iterator->valid());
136
-
137
-		return $filtered;
138
-	}
139
-
140
-	/**
141
-	 * @param array $groupIds
142
-	 * @return array
143
-	 */
144
-	protected function getSelectedGroups(array $groupIds): array {
145
-		$result = [];
146
-		foreach ($groupIds as $groupId) {
147
-			$group = $this->groupManager->get($groupId);
148
-
149
-			if ($group === null) {
150
-				continue;
151
-			}
152
-
153
-			$result[] = ['value' => $group->getGID(), 'label' => $group->getDisplayName()];
154
-		}
155
-
156
-		return $result;
157
-	}
158
-
159
-	/**
160
-	 * @return string the section ID, e.g. 'sharing'
161
-	 */
162
-	public function getSection(): string {
163
-		return 'overview';
164
-	}
165
-
166
-	/**
167
-	 * @return int whether the form should be rather on the top or bottom of
168
-	 * the admin section. The forms are arranged in ascending order of the
169
-	 * priority values. It is required to return a value between 0 and 100.
170
-	 *
171
-	 * E.g.: 70
172
-	 */
173
-	public function getPriority(): int {
174
-		return 11;
175
-	}
40
+    /** @var IConfig */
41
+    private $config;
42
+    /** @var UpdateChecker */
43
+    private $updateChecker;
44
+    /** @var IGroupManager */
45
+    private $groupManager;
46
+    /** @var IDateTimeFormatter */
47
+    private $dateTimeFormatter;
48
+    /** @var IUserSession */
49
+    private $session;
50
+    /** @var IFactory */
51
+    private $l10nFactory;
52
+
53
+    public function __construct(
54
+        IConfig $config,
55
+        UpdateChecker $updateChecker,
56
+        IGroupManager $groupManager,
57
+        IDateTimeFormatter $dateTimeFormatter,
58
+        IUserSession $session,
59
+        IFactory $l10nFactory
60
+    ) {
61
+        $this->config = $config;
62
+        $this->updateChecker = $updateChecker;
63
+        $this->groupManager = $groupManager;
64
+        $this->dateTimeFormatter = $dateTimeFormatter;
65
+        $this->session = $session;
66
+        $this->l10nFactory = $l10nFactory;
67
+    }
68
+
69
+    /**
70
+     * @return TemplateResponse
71
+     */
72
+    public function getForm(): TemplateResponse {
73
+        $lastUpdateCheckTimestamp = $this->config->getAppValue('core', 'lastupdatedat');
74
+        $lastUpdateCheck = $this->dateTimeFormatter->formatDateTime($lastUpdateCheckTimestamp);
75
+
76
+        $channels = [
77
+            'daily',
78
+            'beta',
79
+            'stable',
80
+            'production',
81
+        ];
82
+        $currentChannel = Util::getChannel();
83
+        if ($currentChannel === 'git') {
84
+            $channels[] = 'git';
85
+        }
86
+
87
+        $updateState = $this->updateChecker->getUpdateState();
88
+
89
+        $notifyGroups = json_decode($this->config->getAppValue('updatenotification', 'notify_groups', '["admin"]'), true);
90
+
91
+        $defaultUpdateServerURL = 'https://updates.nextcloud.com/updater_server/';
92
+        $updateServerURL = $this->config->getSystemValue('updater.server.url', $defaultUpdateServerURL);
93
+
94
+        $params = [
95
+            'isNewVersionAvailable' => !empty($updateState['updateAvailable']),
96
+            'isUpdateChecked' => $lastUpdateCheckTimestamp > 0,
97
+            'lastChecked' => $lastUpdateCheck,
98
+            'currentChannel' => $currentChannel,
99
+            'channels' => $channels,
100
+            'newVersion' => empty($updateState['updateVersion']) ? '' : $updateState['updateVersion'],
101
+            'newVersionString' => empty($updateState['updateVersionString']) ? '' : $updateState['updateVersionString'],
102
+            'downloadLink' => empty($updateState['downloadLink']) ? '' : $updateState['downloadLink'],
103
+            'changes' => $this->filterChanges($updateState['changes'] ?? []),
104
+            'updaterEnabled' => empty($updateState['updaterEnabled']) ? false : $updateState['updaterEnabled'],
105
+            'versionIsEol' => empty($updateState['versionIsEol']) ? false : $updateState['versionIsEol'],
106
+            'isDefaultUpdateServerURL' => $updateServerURL === $defaultUpdateServerURL,
107
+            'updateServerURL' => $updateServerURL,
108
+            'notifyGroups' => $this->getSelectedGroups($notifyGroups),
109
+        ];
110
+
111
+        $params = [
112
+            'json' => json_encode($params),
113
+        ];
114
+
115
+        return new TemplateResponse('updatenotification', 'admin', $params, '');
116
+    }
117
+
118
+    protected function filterChanges(array $changes): array {
119
+        $filtered = [];
120
+        if(isset($changes['changelogURL'])) {
121
+            $filtered['changelogURL'] = $changes['changelogURL'];
122
+        }
123
+        if(!isset($changes['whatsNew'])) {
124
+            return $filtered;
125
+        }
126
+
127
+        $iterator = $this->l10nFactory->getLanguageIterator();
128
+        do {
129
+            $lang = $iterator->current();
130
+            if(isset($changes['whatsNew'][$lang])) {
131
+                $filtered['whatsNew'] = $changes['whatsNew'][$lang];
132
+                return $filtered;
133
+            }
134
+            $iterator->next();
135
+        } while($lang !== 'en' && $iterator->valid());
136
+
137
+        return $filtered;
138
+    }
139
+
140
+    /**
141
+     * @param array $groupIds
142
+     * @return array
143
+     */
144
+    protected function getSelectedGroups(array $groupIds): array {
145
+        $result = [];
146
+        foreach ($groupIds as $groupId) {
147
+            $group = $this->groupManager->get($groupId);
148
+
149
+            if ($group === null) {
150
+                continue;
151
+            }
152
+
153
+            $result[] = ['value' => $group->getGID(), 'label' => $group->getDisplayName()];
154
+        }
155
+
156
+        return $result;
157
+    }
158
+
159
+    /**
160
+     * @return string the section ID, e.g. 'sharing'
161
+     */
162
+    public function getSection(): string {
163
+        return 'overview';
164
+    }
165
+
166
+    /**
167
+     * @return int whether the form should be rather on the top or bottom of
168
+     * the admin section. The forms are arranged in ascending order of the
169
+     * priority values. It is required to return a value between 0 and 100.
170
+     *
171
+     * E.g.: 70
172
+     */
173
+    public function getPriority(): int {
174
+        return 11;
175
+    }
176 176
 }
Please login to merge, or discard this patch.
apps/updatenotification/lib/UpdateChecker.php 2 patches
Indentation   +50 added lines, -50 removed lines patch added patch discarded remove patch
@@ -29,60 +29,60 @@
 block discarded – undo
29 29
 use OC\Updater\VersionCheck;
30 30
 
31 31
 class UpdateChecker {
32
-	/** @var VersionCheck */
33
-	private $updater;
34
-	/** @var ChangesCheck */
35
-	private $changesCheck;
32
+    /** @var VersionCheck */
33
+    private $updater;
34
+    /** @var ChangesCheck */
35
+    private $changesCheck;
36 36
 
37
-	/**
38
-	 * @param VersionCheck $updater
39
-	 */
40
-	public function __construct(VersionCheck $updater, ChangesCheck $changesCheck) {
41
-		$this->updater = $updater;
42
-		$this->changesCheck = $changesCheck;
43
-	}
37
+    /**
38
+     * @param VersionCheck $updater
39
+     */
40
+    public function __construct(VersionCheck $updater, ChangesCheck $changesCheck) {
41
+        $this->updater = $updater;
42
+        $this->changesCheck = $changesCheck;
43
+    }
44 44
 
45
-	/**
46
-	 * @return array
47
-	 */
48
-	public function getUpdateState(): array {
49
-		$data = $this->updater->check();
50
-		$result = [];
45
+    /**
46
+     * @return array
47
+     */
48
+    public function getUpdateState(): array {
49
+        $data = $this->updater->check();
50
+        $result = [];
51 51
 
52
-		if (isset($data['version']) && $data['version'] !== '' && $data['version'] !== []) {
53
-			$result['updateAvailable'] = true;
54
-			$result['updateVersion'] = $data['version'];
55
-			$result['updateVersionString'] = $data['versionstring'];
56
-			$result['updaterEnabled'] = $data['autoupdater'] === '1';
57
-			$result['versionIsEol'] = $data['eol'] === '1';
58
-			if (strpos($data['web'], 'https://') === 0) {
59
-				$result['updateLink'] = $data['web'];
60
-			}
61
-			if (strpos($data['url'], 'https://') === 0) {
62
-				$result['downloadLink'] = $data['url'];
63
-			}
64
-			if (strpos($data['changes'], 'https://') === 0) {
65
-				try {
66
-					$result['changes'] = $this->changesCheck->check($data['changes'], $data['version']);
67
-				} catch (\Exception $e) {
68
-					// no info, not a problem
69
-				}
70
-			}
52
+        if (isset($data['version']) && $data['version'] !== '' && $data['version'] !== []) {
53
+            $result['updateAvailable'] = true;
54
+            $result['updateVersion'] = $data['version'];
55
+            $result['updateVersionString'] = $data['versionstring'];
56
+            $result['updaterEnabled'] = $data['autoupdater'] === '1';
57
+            $result['versionIsEol'] = $data['eol'] === '1';
58
+            if (strpos($data['web'], 'https://') === 0) {
59
+                $result['updateLink'] = $data['web'];
60
+            }
61
+            if (strpos($data['url'], 'https://') === 0) {
62
+                $result['downloadLink'] = $data['url'];
63
+            }
64
+            if (strpos($data['changes'], 'https://') === 0) {
65
+                try {
66
+                    $result['changes'] = $this->changesCheck->check($data['changes'], $data['version']);
67
+                } catch (\Exception $e) {
68
+                    // no info, not a problem
69
+                }
70
+            }
71 71
 
72
-			return $result;
73
-		}
72
+            return $result;
73
+        }
74 74
 
75
-		return [];
76
-	}
75
+        return [];
76
+    }
77 77
 
78
-	/**
79
-	 * @param array $data
80
-	 */
81
-	public function populateJavaScriptVariables(array $data) {
82
-		$data['array']['oc_updateState'] =  json_encode([
83
-			'updateAvailable' => true,
84
-			'updateVersion' => $this->getUpdateState()['updateVersionString'],
85
-			'updateLink' => $this->getUpdateState()['updateLink'] ?? '',
86
-		]);
87
-	}
78
+    /**
79
+     * @param array $data
80
+     */
81
+    public function populateJavaScriptVariables(array $data) {
82
+        $data['array']['oc_updateState'] =  json_encode([
83
+            'updateAvailable' => true,
84
+            'updateVersion' => $this->getUpdateState()['updateVersionString'],
85
+            'updateLink' => $this->getUpdateState()['updateLink'] ?? '',
86
+        ]);
87
+    }
88 88
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -79,7 +79,7 @@
 block discarded – undo
79 79
 	 * @param array $data
80 80
 	 */
81 81
 	public function populateJavaScriptVariables(array $data) {
82
-		$data['array']['oc_updateState'] =  json_encode([
82
+		$data['array']['oc_updateState'] = json_encode([
83 83
 			'updateAvailable' => true,
84 84
 			'updateVersion' => $this->getUpdateState()['updateVersionString'],
85 85
 			'updateLink' => $this->getUpdateState()['updateLink'] ?? '',
Please login to merge, or discard this patch.
apps/updatenotification/lib/Command/Check.php 2 patches
Indentation   +51 added lines, -51 removed lines patch added patch discarded remove patch
@@ -32,65 +32,65 @@
 block discarded – undo
32 32
 
33 33
 class Check extends Command {
34 34
 
35
-	/**
36
-	 * @var Installer $installer
37
-	 */
38
-	private $installer;
35
+    /**
36
+     * @var Installer $installer
37
+     */
38
+    private $installer;
39 39
 
40
-	/**
41
-	 * @var AppManager $appManager
42
-	 */
43
-	private $appManager;
40
+    /**
41
+     * @var AppManager $appManager
42
+     */
43
+    private $appManager;
44 44
 
45
-	/**
46
-	 * @var UpdateChecker $updateChecker
47
-	 */
48
-	private $updateChecker;
45
+    /**
46
+     * @var UpdateChecker $updateChecker
47
+     */
48
+    private $updateChecker;
49 49
 
50
-	public function __construct(AppManager $appManager, UpdateChecker $updateChecker, Installer $installer) {
51
-		parent::__construct();
52
-		$this->installer = $installer;
53
-		$this->appManager = $appManager;
54
-		$this->updateChecker = $updateChecker;
55
-	}
50
+    public function __construct(AppManager $appManager, UpdateChecker $updateChecker, Installer $installer) {
51
+        parent::__construct();
52
+        $this->installer = $installer;
53
+        $this->appManager = $appManager;
54
+        $this->updateChecker = $updateChecker;
55
+    }
56 56
 
57
-	protected function configure() {
58
-		$this
59
-			->setName('update:check')
60
-			->setDescription('Check for server and app updates')
61
-		;
62
-	}
57
+    protected function configure() {
58
+        $this
59
+            ->setName('update:check')
60
+            ->setDescription('Check for server and app updates')
61
+        ;
62
+    }
63 63
 
64
-	protected function execute(InputInterface $input, OutputInterface $output) {
65
-		$updatesAvailableCount = 0;
64
+    protected function execute(InputInterface $input, OutputInterface $output) {
65
+        $updatesAvailableCount = 0;
66 66
 
67
-		// Server
68
-		$r = $this->updateChecker->getUpdateState();
69
-		if (isset($r['updateAvailable']) && $r['updateAvailable']) {
70
-			$output->writeln($r['updateVersionString'] . ' is available. Get more information on how to update at '. $r['updateLink'] . '.');
71
-			$updatesAvailableCount += 1;
72
-		}
67
+        // Server
68
+        $r = $this->updateChecker->getUpdateState();
69
+        if (isset($r['updateAvailable']) && $r['updateAvailable']) {
70
+            $output->writeln($r['updateVersionString'] . ' is available. Get more information on how to update at '. $r['updateLink'] . '.');
71
+            $updatesAvailableCount += 1;
72
+        }
73 73
 
74 74
 
75
-		// Apps
76
-		$apps = $this->appManager->getInstalledApps();
77
-		foreach ($apps as $app) {
78
-			$update = $this->installer->isUpdateAvailable($app);
79
-			if ($update !== false) {
80
-				$output->writeln('Update for ' . $app . ' to version ' . $update . ' is available.');
81
-				$updatesAvailableCount += 1;
82
-			}
83
-		}
75
+        // Apps
76
+        $apps = $this->appManager->getInstalledApps();
77
+        foreach ($apps as $app) {
78
+            $update = $this->installer->isUpdateAvailable($app);
79
+            if ($update !== false) {
80
+                $output->writeln('Update for ' . $app . ' to version ' . $update . ' is available.');
81
+                $updatesAvailableCount += 1;
82
+            }
83
+        }
84 84
 
85
-		// Report summary
86
-		if ($updatesAvailableCount === 0) {
87
-			$output->writeln('<info>Everything up to date</info>');
88
-		} else if ($updatesAvailableCount === 1) {
89
-			$output->writeln('<comment>1 update available</comment>');
90
-		} else {
91
-			$output->writeln('<comment>' . $updatesAvailableCount . ' updates available</comment>');
92
-		}
85
+        // Report summary
86
+        if ($updatesAvailableCount === 0) {
87
+            $output->writeln('<info>Everything up to date</info>');
88
+        } else if ($updatesAvailableCount === 1) {
89
+            $output->writeln('<comment>1 update available</comment>');
90
+        } else {
91
+            $output->writeln('<comment>' . $updatesAvailableCount . ' updates available</comment>');
92
+        }
93 93
 
94
-		return 0;
95
-	}
94
+        return 0;
95
+    }
96 96
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -67,7 +67,7 @@  discard block
 block discarded – undo
67 67
 		// Server
68 68
 		$r = $this->updateChecker->getUpdateState();
69 69
 		if (isset($r['updateAvailable']) && $r['updateAvailable']) {
70
-			$output->writeln($r['updateVersionString'] . ' is available. Get more information on how to update at '. $r['updateLink'] . '.');
70
+			$output->writeln($r['updateVersionString'].' is available. Get more information on how to update at '.$r['updateLink'].'.');
71 71
 			$updatesAvailableCount += 1;
72 72
 		}
73 73
 
@@ -77,7 +77,7 @@  discard block
 block discarded – undo
77 77
 		foreach ($apps as $app) {
78 78
 			$update = $this->installer->isUpdateAvailable($app);
79 79
 			if ($update !== false) {
80
-				$output->writeln('Update for ' . $app . ' to version ' . $update . ' is available.');
80
+				$output->writeln('Update for '.$app.' to version '.$update.' is available.');
81 81
 				$updatesAvailableCount += 1;
82 82
 			}
83 83
 		}
@@ -88,7 +88,7 @@  discard block
 block discarded – undo
88 88
 		} else if ($updatesAvailableCount === 1) {
89 89
 			$output->writeln('<comment>1 update available</comment>');
90 90
 		} else {
91
-			$output->writeln('<comment>' . $updatesAvailableCount . ' updates available</comment>');
91
+			$output->writeln('<comment>'.$updatesAvailableCount.' updates available</comment>');
92 92
 		}
93 93
 
94 94
 		return 0;
Please login to merge, or discard this patch.