Completed
Pull Request — master (#9705)
by Blizzz
19:05
created
lib/private/Updater/VersionCheck.php 2 patches
Indentation   +92 added lines, -92 removed lines patch added patch discarded remove patch
@@ -31,98 +31,98 @@
 block discarded – undo
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['changelog'] = isset($data->changelog) ? (string)$data->changelog : null;
101
-				// TODO: one's it is decided, use the proper field…
102
-				$tmp['whatsNew'] = isset($data->whatsNew) ? ((array)$data->whatsNew)['item'] : null;
103
-				$tmp['whatsNew'] = isset($data->whatsNew_admin) ? ((array)$data->whatsNew_admin)['item'] : (string)$data->whatsNew;
104
-				$tmp['autoupdater'] = (string)$data->autoupdater;
105
-				$tmp['eol'] = isset($data->eol) ? (string)$data->eol : '0';
106
-			} else {
107
-				libxml_clear_errors();
108
-			}
109
-		}
110
-
111
-		// Cache the result
112
-		$this->config->setAppValue('core', 'lastupdateResult', json_encode($tmp));
113
-		return $tmp;
114
-	}
115
-
116
-	/**
117
-	 * @codeCoverageIgnore
118
-	 * @param string $url
119
-	 * @return resource|string
120
-	 * @throws \Exception
121
-	 */
122
-	protected function getUrlContent($url) {
123
-		$client = $this->clientService->newClient();
124
-		$response = $client->get($url);
125
-		return $response->getBody();
126
-	}
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['changelog'] = isset($data->changelog) ? (string)$data->changelog : null;
101
+                // TODO: one's it is decided, use the proper field…
102
+                $tmp['whatsNew'] = isset($data->whatsNew) ? ((array)$data->whatsNew)['item'] : null;
103
+                $tmp['whatsNew'] = isset($data->whatsNew_admin) ? ((array)$data->whatsNew_admin)['item'] : (string)$data->whatsNew;
104
+                $tmp['autoupdater'] = (string)$data->autoupdater;
105
+                $tmp['eol'] = isset($data->eol) ? (string)$data->eol : '0';
106
+            } else {
107
+                libxml_clear_errors();
108
+            }
109
+        }
110
+
111
+        // Cache the result
112
+        $this->config->setAppValue('core', 'lastupdateResult', json_encode($tmp));
113
+        return $tmp;
114
+    }
115
+
116
+    /**
117
+     * @codeCoverageIgnore
118
+     * @param string $url
119
+     * @return resource|string
120
+     * @throws \Exception
121
+     */
122
+    protected function getUrlContent($url) {
123
+        $client = $this->clientService->newClient();
124
+        $response = $client->get($url);
125
+        return $response->getBody();
126
+    }
127 127
 }
128 128
 
Please login to merge, or discard this patch.
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -55,7 +55,7 @@  discard block
 block discarded – undo
55 55
 	 */
56 56
 	public function check() {
57 57
 		// Look up the cache - it is invalidated all 30 minutes
58
-		if (((int)$this->config->getAppValue('core', 'lastupdatedat') + 1800) > time()) {
58
+		if (((int) $this->config->getAppValue('core', 'lastupdatedat') + 1800) > time()) {
59 59
 			return json_decode($this->config->getAppValue('core', 'lastupdateResult'), true);
60 60
 		}
61 61
 
@@ -79,7 +79,7 @@  discard block
 block discarded – undo
79 79
 		$versionString = implode('x', $version);
80 80
 
81 81
 		//fetch xml data from updater
82
-		$url = $updaterUrl . '?version=' . $versionString;
82
+		$url = $updaterUrl.'?version='.$versionString;
83 83
 
84 84
 		$tmp = [];
85 85
 		try {
@@ -93,16 +93,16 @@  discard block
 block discarded – undo
93 93
 			$data = @simplexml_load_string($xml);
94 94
 			libxml_disable_entity_loader($loadEntities);
95 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['changelog'] = isset($data->changelog) ? (string)$data->changelog : null;
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['changelog'] = isset($data->changelog) ? (string) $data->changelog : null;
101 101
 				// TODO: one's it is decided, use the proper field…
102
-				$tmp['whatsNew'] = isset($data->whatsNew) ? ((array)$data->whatsNew)['item'] : null;
103
-				$tmp['whatsNew'] = isset($data->whatsNew_admin) ? ((array)$data->whatsNew_admin)['item'] : (string)$data->whatsNew;
104
-				$tmp['autoupdater'] = (string)$data->autoupdater;
105
-				$tmp['eol'] = isset($data->eol) ? (string)$data->eol : '0';
102
+				$tmp['whatsNew'] = isset($data->whatsNew) ? ((array) $data->whatsNew)['item'] : null;
103
+				$tmp['whatsNew'] = isset($data->whatsNew_admin) ? ((array) $data->whatsNew_admin)['item'] : (string) $data->whatsNew;
104
+				$tmp['autoupdater'] = (string) $data->autoupdater;
105
+				$tmp['eol'] = isset($data->eol) ? (string) $data->eol : '0';
106 106
 			} else {
107 107
 				libxml_clear_errors();
108 108
 			}
Please login to merge, or discard this patch.
apps/updatenotification/lib/Settings/Admin.php 1 patch
Indentation   +110 added lines, -110 removed lines patch added patch discarded remove patch
@@ -35,114 +35,114 @@
 block discarded – undo
35 35
 use OCP\Util;
36 36
 
37 37
 class Admin implements ISettings {
38
-	/** @var IConfig */
39
-	private $config;
40
-	/** @var UpdateChecker */
41
-	private $updateChecker;
42
-	/** @var IGroupManager */
43
-	private $groupManager;
44
-	/** @var IDateTimeFormatter */
45
-	private $dateTimeFormatter;
46
-
47
-	/**
48
-	 * @param IConfig $config
49
-	 * @param UpdateChecker $updateChecker
50
-	 * @param IGroupManager $groupManager
51
-	 * @param IDateTimeFormatter $dateTimeFormatter
52
-	 */
53
-	public function __construct(IConfig $config,
54
-								UpdateChecker $updateChecker,
55
-								IGroupManager $groupManager,
56
-								IDateTimeFormatter $dateTimeFormatter) {
57
-		$this->config = $config;
58
-		$this->updateChecker = $updateChecker;
59
-		$this->groupManager = $groupManager;
60
-		$this->dateTimeFormatter = $dateTimeFormatter;
61
-	}
62
-
63
-	/**
64
-	 * @return TemplateResponse
65
-	 */
66
-	public function getForm(): TemplateResponse {
67
-		$lastUpdateCheckTimestamp = $this->config->getAppValue('core', 'lastupdatedat');
68
-		$lastUpdateCheck = $this->dateTimeFormatter->formatDateTime($lastUpdateCheckTimestamp);
69
-
70
-		$channels = [
71
-			'daily',
72
-			'beta',
73
-			'stable',
74
-			'production',
75
-		];
76
-		$currentChannel = Util::getChannel();
77
-		if ($currentChannel === 'git') {
78
-			$channels[] = 'git';
79
-		}
80
-
81
-		$updateState = $this->updateChecker->getUpdateState();
82
-
83
-		$notifyGroups = json_decode($this->config->getAppValue('updatenotification', 'notify_groups', '["admin"]'), true);
84
-
85
-		$defaultUpdateServerURL = 'https://updates.nextcloud.com/updater_server/';
86
-		$updateServerURL = $this->config->getSystemValue('updater.server.url', $defaultUpdateServerURL);
87
-
88
-		$params = [
89
-			'isNewVersionAvailable' => !empty($updateState['updateAvailable']),
90
-			'isUpdateChecked' => $lastUpdateCheckTimestamp > 0,
91
-			'lastChecked' => $lastUpdateCheck,
92
-			'currentChannel' => $currentChannel,
93
-			'channels' => $channels,
94
-			'newVersionString' => empty($updateState['updateVersion']) ? '' : $updateState['updateVersion'],
95
-			'downloadLink' => empty($updateState['downloadLink']) ? '' : $updateState['downloadLink'],
96
-			'changelogURL' => empty($updateState['changelog']) ? false : $updateState['changelog'],
97
-			'whatsNew' => empty($updateState['whatsNew']) ? false : $updateState['whatsNew'],
98
-			'updaterEnabled' => empty($updateState['updaterEnabled']) ? false : $updateState['updaterEnabled'],
99
-			'versionIsEol' => empty($updateState['versionIsEol']) ? false : $updateState['versionIsEol'],
100
-			'isDefaultUpdateServerURL' => $updateServerURL === $defaultUpdateServerURL,
101
-			'updateServerURL' => $updateServerURL,
102
-			'notifyGroups' => $this->getSelectedGroups($notifyGroups),
103
-		];
104
-
105
-		$params = [
106
-			'json' => json_encode($params),
107
-		];
108
-
109
-		return new TemplateResponse('updatenotification', 'admin', $params, '');
110
-	}
111
-
112
-	/**
113
-	 * @param array $groupIds
114
-	 * @return array
115
-	 */
116
-	protected function getSelectedGroups(array $groupIds): array {
117
-		$result = [];
118
-		foreach ($groupIds as $groupId) {
119
-			$group = $this->groupManager->get($groupId);
120
-
121
-			if ($group === null) {
122
-				continue;
123
-			}
124
-
125
-			$result[] = ['value' => $group->getGID(), 'label' => $group->getDisplayName()];
126
-		}
127
-
128
-		return $result;
129
-	}
130
-
131
-	/**
132
-	 * @return string the section ID, e.g. 'sharing'
133
-	 */
134
-	public function getSection(): string {
135
-		return 'overview';
136
-	}
137
-
138
-	/**
139
-	 * @return int whether the form should be rather on the top or bottom of
140
-	 * the admin section. The forms are arranged in ascending order of the
141
-	 * priority values. It is required to return a value between 0 and 100.
142
-	 *
143
-	 * E.g.: 70
144
-	 */
145
-	public function getPriority(): int {
146
-		return 11;
147
-	}
38
+    /** @var IConfig */
39
+    private $config;
40
+    /** @var UpdateChecker */
41
+    private $updateChecker;
42
+    /** @var IGroupManager */
43
+    private $groupManager;
44
+    /** @var IDateTimeFormatter */
45
+    private $dateTimeFormatter;
46
+
47
+    /**
48
+     * @param IConfig $config
49
+     * @param UpdateChecker $updateChecker
50
+     * @param IGroupManager $groupManager
51
+     * @param IDateTimeFormatter $dateTimeFormatter
52
+     */
53
+    public function __construct(IConfig $config,
54
+                                UpdateChecker $updateChecker,
55
+                                IGroupManager $groupManager,
56
+                                IDateTimeFormatter $dateTimeFormatter) {
57
+        $this->config = $config;
58
+        $this->updateChecker = $updateChecker;
59
+        $this->groupManager = $groupManager;
60
+        $this->dateTimeFormatter = $dateTimeFormatter;
61
+    }
62
+
63
+    /**
64
+     * @return TemplateResponse
65
+     */
66
+    public function getForm(): TemplateResponse {
67
+        $lastUpdateCheckTimestamp = $this->config->getAppValue('core', 'lastupdatedat');
68
+        $lastUpdateCheck = $this->dateTimeFormatter->formatDateTime($lastUpdateCheckTimestamp);
69
+
70
+        $channels = [
71
+            'daily',
72
+            'beta',
73
+            'stable',
74
+            'production',
75
+        ];
76
+        $currentChannel = Util::getChannel();
77
+        if ($currentChannel === 'git') {
78
+            $channels[] = 'git';
79
+        }
80
+
81
+        $updateState = $this->updateChecker->getUpdateState();
82
+
83
+        $notifyGroups = json_decode($this->config->getAppValue('updatenotification', 'notify_groups', '["admin"]'), true);
84
+
85
+        $defaultUpdateServerURL = 'https://updates.nextcloud.com/updater_server/';
86
+        $updateServerURL = $this->config->getSystemValue('updater.server.url', $defaultUpdateServerURL);
87
+
88
+        $params = [
89
+            'isNewVersionAvailable' => !empty($updateState['updateAvailable']),
90
+            'isUpdateChecked' => $lastUpdateCheckTimestamp > 0,
91
+            'lastChecked' => $lastUpdateCheck,
92
+            'currentChannel' => $currentChannel,
93
+            'channels' => $channels,
94
+            'newVersionString' => empty($updateState['updateVersion']) ? '' : $updateState['updateVersion'],
95
+            'downloadLink' => empty($updateState['downloadLink']) ? '' : $updateState['downloadLink'],
96
+            'changelogURL' => empty($updateState['changelog']) ? false : $updateState['changelog'],
97
+            'whatsNew' => empty($updateState['whatsNew']) ? false : $updateState['whatsNew'],
98
+            'updaterEnabled' => empty($updateState['updaterEnabled']) ? false : $updateState['updaterEnabled'],
99
+            'versionIsEol' => empty($updateState['versionIsEol']) ? false : $updateState['versionIsEol'],
100
+            'isDefaultUpdateServerURL' => $updateServerURL === $defaultUpdateServerURL,
101
+            'updateServerURL' => $updateServerURL,
102
+            'notifyGroups' => $this->getSelectedGroups($notifyGroups),
103
+        ];
104
+
105
+        $params = [
106
+            'json' => json_encode($params),
107
+        ];
108
+
109
+        return new TemplateResponse('updatenotification', 'admin', $params, '');
110
+    }
111
+
112
+    /**
113
+     * @param array $groupIds
114
+     * @return array
115
+     */
116
+    protected function getSelectedGroups(array $groupIds): array {
117
+        $result = [];
118
+        foreach ($groupIds as $groupId) {
119
+            $group = $this->groupManager->get($groupId);
120
+
121
+            if ($group === null) {
122
+                continue;
123
+            }
124
+
125
+            $result[] = ['value' => $group->getGID(), 'label' => $group->getDisplayName()];
126
+        }
127
+
128
+        return $result;
129
+    }
130
+
131
+    /**
132
+     * @return string the section ID, e.g. 'sharing'
133
+     */
134
+    public function getSection(): string {
135
+        return 'overview';
136
+    }
137
+
138
+    /**
139
+     * @return int whether the form should be rather on the top or bottom of
140
+     * the admin section. The forms are arranged in ascending order of the
141
+     * priority values. It is required to return a value between 0 and 100.
142
+     *
143
+     * E.g.: 70
144
+     */
145
+    public function getPriority(): int {
146
+        return 11;
147
+    }
148 148
 }
Please login to merge, or discard this patch.
apps/updatenotification/lib/UpdateChecker.php 1 patch
Indentation   +45 added lines, -45 removed lines patch added patch discarded remove patch
@@ -28,55 +28,55 @@
 block discarded – undo
28 28
 use OC\Updater\VersionCheck;
29 29
 
30 30
 class UpdateChecker {
31
-	/** @var VersionCheck */
32
-	private $updater;
31
+    /** @var VersionCheck */
32
+    private $updater;
33 33
 
34
-	/**
35
-	 * @param VersionCheck $updater
36
-	 */
37
-	public function __construct(VersionCheck $updater) {
38
-		$this->updater = $updater;
39
-	}
34
+    /**
35
+     * @param VersionCheck $updater
36
+     */
37
+    public function __construct(VersionCheck $updater) {
38
+        $this->updater = $updater;
39
+    }
40 40
 
41
-	/**
42
-	 * @return array
43
-	 */
44
-	public function getUpdateState(): array {
45
-		$data = $this->updater->check();
46
-		$result = [];
41
+    /**
42
+     * @return array
43
+     */
44
+    public function getUpdateState(): array {
45
+        $data = $this->updater->check();
46
+        $result = [];
47 47
 
48
-		if (isset($data['version']) && $data['version'] !== '' && $data['version'] !== []) {
49
-			$result['updateAvailable'] = true;
50
-			$result['updateVersion'] = $data['versionstring'];
51
-			$result['updaterEnabled'] = $data['autoupdater'] === '1';
52
-			$result['versionIsEol'] = $data['eol'] === '1';
53
-			if (strpos($data['web'], 'https://') === 0) {
54
-				$result['updateLink'] = $data['web'];
55
-			}
56
-			if (strpos($data['url'], 'https://') === 0) {
57
-				$result['downloadLink'] = $data['url'];
58
-			}
59
-			if (strpos($data['changelog'], 'https://') === 0) {
60
-				$result['changelog'] = $data['changelog'];
61
-			}
62
-			if (is_array($data['whatsNew']) && count($data['whatsNew']) <= 3) {
63
-				$result['whatsNew'] = $data['whatsNew'];
64
-			}
48
+        if (isset($data['version']) && $data['version'] !== '' && $data['version'] !== []) {
49
+            $result['updateAvailable'] = true;
50
+            $result['updateVersion'] = $data['versionstring'];
51
+            $result['updaterEnabled'] = $data['autoupdater'] === '1';
52
+            $result['versionIsEol'] = $data['eol'] === '1';
53
+            if (strpos($data['web'], 'https://') === 0) {
54
+                $result['updateLink'] = $data['web'];
55
+            }
56
+            if (strpos($data['url'], 'https://') === 0) {
57
+                $result['downloadLink'] = $data['url'];
58
+            }
59
+            if (strpos($data['changelog'], 'https://') === 0) {
60
+                $result['changelog'] = $data['changelog'];
61
+            }
62
+            if (is_array($data['whatsNew']) && count($data['whatsNew']) <= 3) {
63
+                $result['whatsNew'] = $data['whatsNew'];
64
+            }
65 65
 
66
-			return $result;
67
-		}
66
+            return $result;
67
+        }
68 68
 
69
-		return [];
70
-	}
69
+        return [];
70
+    }
71 71
 
72
-	/**
73
-	 * @param array $data
74
-	 */
75
-	public function populateJavaScriptVariables(array $data) {
76
-		$data['array']['oc_updateState'] =  json_encode([
77
-			'updateAvailable' => true,
78
-			'updateVersion' => $this->getUpdateState()['updateVersion'],
79
-			'updateLink' => $this->getUpdateState()['updateLink'] ?? '',
80
-		]);
81
-	}
72
+    /**
73
+     * @param array $data
74
+     */
75
+    public function populateJavaScriptVariables(array $data) {
76
+        $data['array']['oc_updateState'] =  json_encode([
77
+            'updateAvailable' => true,
78
+            'updateVersion' => $this->getUpdateState()['updateVersion'],
79
+            'updateLink' => $this->getUpdateState()['updateLink'] ?? '',
80
+        ]);
81
+    }
82 82
 }
Please login to merge, or discard this patch.