1
1
<?php
2
2
3
3
/**
4
- * Tool to Upgrade ProcessWire Core
4
+ * Tool to display available core and module upgrades for ProcessWire
5
5
*
6
6
* ProcessWire 2.x
7
7
* Copyright (C) 2014 by Ryan Cramer
@@ -19,16 +19,17 @@ class ProcessWireUpgrade extends Process {
19
19
*/
20
20
public static function getModuleInfo() {
21
21
return array(
22
- 'title' => 'Core Upgrade ',
23
- 'summary' => 'Upgrade ProcessWire core to latest master or dev version automatically in the admin .',
24
- 'version' => 1 ,
22
+ 'title' => 'Upgrades ',
23
+ 'summary' => 'Tool that helps you identify and install core and module upgrades .',
24
+ 'version' => 2 ,
25
25
'author' => 'Ryan Cramer',
26
+ 'installs' => 'ProcessWireUpgradeCheck',
26
27
'icon' => 'coffee'
27
28
);
28
29
}
29
30
30
31
const debug = false;
31
- const pageName = 'core-upgrade ';
32
+ const pageName = 'upgrades ';
32
33
const branchesURL = 'https://api.github.com/repos/ryancramerdesign/Processwire/branches';
33
34
const versionURL = 'https://raw.githubusercontent.com/ryancramerdesign/ProcessWire/{branch}/wire/core/ProcessWire.php';
34
35
const zipURL = 'https://github.com/ryancramerdesign/ProcessWire/archive/{branch}.zip';
@@ -67,6 +68,12 @@ class ProcessWireUpgrade extends Process {
67
68
*/
68
69
protected $renames = array(); // scheduled renames to occur after page render
69
70
71
+ /**
72
+ * Instance of ProcessWireUpgradeCheck
73
+ *
74
+ */
75
+ protected $checker = null;
76
+
70
77
/**
71
78
* Construct
72
79
*
@@ -86,75 +93,23 @@ class ProcessWireUpgrade extends Process {
86
93
if($this->config->demo) throw new WireException("This module cannot be used in demo mode");
87
94
if(!$this->user->isSuperuser()) throw new WireException("This module requires superuser");
88
95
set_time_limit(3600);
96
+ $this->checker = $this->modules->getInstall('ProcessWireUpgradeCheck');
97
+ if(!$this->checker) throw new WireException("Please go to Modules and click 'Check for new modules' - this will auto-update ProcessWireUpgrade.");
89
98
parent::init();
90
99
}
91
100
92
101
/**
93
- * Get all available branches with info for each
94
- *
95
- */
96
- protected function getBranches() {
97
-
98
- if(!$this->input->get->refresh_branches) {
99
- $branches = $this->session->get('ProcessWireUpgrade_branches');
100
- if($branches && count($branches)) return $branches;
101
- }
102
-
103
- $branches = array();
104
- $http = new WireHttp();
105
- $http->setHeader('User-Agent', 'ProcessWireUpgrade');
106
- $json = $http->get(self::branchesURL);
107
- if(!$json) throw new WireException("Error loading GitHub branches " . self::branchesURL);
108
-
109
- $data = json_decode($json, true);
110
- if(!$data) throw new WireException("Error JSON decoding GitHub branches $json " . self::branchesURL);
111
-
112
- $this->message("Retrieved " . count($data) . " branches from GitHub");
113
-
114
- foreach($data as $key => $info) {
115
- $name = $info['name'];
116
- $branch = array(
117
- 'name' => $name,
118
- 'title' => ucfirst($name),
119
- 'zipURL' => str_replace('{branch}', $name, self::zipURL),
120
- 'version' => '',
121
- 'versionURL' => str_replace('{branch}', $name, self::versionURL),
122
- );
123
-
124
- if($name == 'dev') $branch['title'] = 'Development';
125
- if($name == 'master') $branch['title'] = 'Stable/Master';
126
-
127
- $content = $http->get($branch['versionURL']);
128
- if(!preg_match_all('/const\s+version(Major|Minor|Revision)\s*=\s*(\d+)/', $content, $matches)) {
129
- $branch['version'] = '?';
130
- continue;
131
- }
132
-
133
- $version = array();
134
- foreach($matches[1] as $key => $var) {
135
- $version[$var] = (int) $matches[2][$key];
136
- }
137
-
138
- $branch['version'] = "$version[Major].$version[Minor].$version[Revision]";
139
- $branches[$name] = $branch;
140
- }
141
-
142
- $this->session->set('ProcessWireUpgrade_branches', $branches);
143
- return $branches;
144
- }
145
-
146
- /**
147
- * Get info for either a specific branch, or for the currently selected branch
102
+ * Get info for either a specific core branch, or for the currently selected core branch
148
103
*
149
104
*/
150
105
protected function getBranch($name = '') {
151
- $branches = $this->getBranches ();
106
+ $branches = $this->checker->getCoreBranches ();
152
107
if(empty($name)) $name = $this->session->get('ProcessWireUpgrade_branch');
153
108
return isset($branches[$name]) ? $branches[$name] : array();
154
109
}
155
110
156
111
/**
157
- * Set the current branch
112
+ * Set the current core branch
158
113
*
159
114
*/
160
115
protected function setBranch($name) {
@@ -178,16 +133,10 @@ class ProcessWireUpgrade extends Process {
178
133
$this->error("Please note that your current PHP version (" . PHP_VERSION . ") is not adequate to upgrade to the latest ProcessWire.");
179
134
}
180
135
181
- $out = '';
136
+ if(!extension_loaded('pdo_mysql')) $this->error("Your PHP is not compiled with PDO support. PDO is required by ProcessWire 2.4+.");
137
+ if(!class_exists('ZipArchive')) $this->error("Your PHP does not have ZipArchive support. This is required to install core or module upgrades with this tool.");
182
138
183
- if(!$this->config->debug) {
184
- $this->error(
185
- "While optional, we recommend that you enable debug mode during the upgrade " .
186
- "so that you will see detailed error messages, should they occur. " .
187
- "Do this by editing /site/config.php and setting the debug " .
188
- "option to true. Example: \$config->debug = true;"
189
- );
190
- }
139
+ $out = '';
191
140
192
141
if(file_exists($this->cachePath) || file_exists($this->tempPath)) {
193
142
$out = "<h2>Upgrade files are already present. Please remove them before continuing.</h2>";
@@ -198,23 +147,51 @@ class ProcessWireUpgrade extends Process {
198
147
return $out;
199
148
}
200
149
201
- $out = "<h2>Please select a branch:</h2><p>";
202
- foreach($this->getBranches() as $name => $info) {
203
- $btn = $this->modules->get('InputfieldButton');
204
- $btn->href = "./check?branch=$name";
205
- $btn->icon = 'code-fork';
206
- $btn->value = "$info[title] - $info[version]";
207
- $out .= $btn->render();
150
+ $table = $this->modules->get('MarkupAdminDataTable');
151
+ $table->setEncodeEntities(false);
152
+ $table->headerRow(array(
153
+ $this->_('Module'),
154
+ $this->_('Class'),
155
+ $this->_('Installed'),
156
+ $this->_('Latest'),
157
+ $this->_('Status')
158
+ ));
159
+
160
+ $items = $this->checker->getVersions();
161
+ if(count($items)) {
162
+ foreach($items as $name => $item) {
163
+ if(empty($item['remote'])) continue; // not in directory
164
+ $remote = $this->sanitizer->entities($item['remote']);
165
+
166
+ if($item['new'] > 0) {
167
+ $upgradeLabel = $this->_('Upgrade available');
168
+ $remote = "<strong>$remote</strong>";
169
+ } else if($item['new'] < 0) {
170
+ $upgradeLabel = $this->_('Older than current');
171
+ } else {
172
+ $upgradeLabel = $this->_('Up-to-date');
173
+ }
174
+ if(empty($item['branch'])) {
175
+ $upgradeURL = $this->wire('config')->urls->admin . "module/?update=$name";
176
+ } else {
177
+ $upgradeURL = "./check?branch=$item[branch]";
178
+ }
179
+ if($item['new'] > 0) $upgrade = "<a href='$upgradeURL'><i class='fa fa-lightbulb-o'></i> <strong>$upgradeLabel</strong></a>";
180
+ else $upgrade = "<span class='detail'>$upgradeLabel</span>";
181
+ // else if(!$item['remote']) $upgrade = "<span class='detail'>" . $this->_('Not in directory') . "</span>";
182
+ $table->row(array(
183
+ "<a href='$upgradeURL'>" . $this->sanitizer->entities($item['title']) . "</a>",
184
+ $this->sanitizer->entities($name),
185
+ $this->sanitizer->entities($item['local']),
186
+ $remote,
187
+ $upgrade
188
+ ));
189
+ }
190
+ } else {
208
191
}
209
192
210
- $btn = $this->modules->get('InputfieldButton');
211
- $btn->href = "./?refresh_branches=1";
212
- $btn->icon = 'refresh';
213
- $btn->value = "Refresh";
214
- $btn->addClass('ui-priority-secondary');
215
- $out .= $btn->render();
193
+ $out .= $table->render();
216
194
217
- $out .= "</p>";
218
195
return $out;
219
196
}
220
197
@@ -233,6 +210,16 @@ class ProcessWireUpgrade extends Process {
233
210
*
234
211
*/
235
212
public function executeCheck() {
213
+
214
+ if(!$this->config->debug) {
215
+ $this->error(
216
+ "While optional, we recommend that you enable debug mode during the upgrade " .
217
+ "so that you will see detailed error messages, should they occur. " .
218
+ "Do this by editing /site/config.php and setting the debug " .
219
+ "option to true. Example: \$config->debug = true;"
220
+ );
221
+ }
222
+
236
223
$name = $this->input->get->branch;
237
224
if(empty($name)) throw new WireException("No branch selected");
238
225
$branch = $this->getBranch($name);
@@ -743,7 +730,7 @@ class ProcessWireUpgrade extends Process {
743
730
// find the page we installed, locating it by the process field (which has the module ID)
744
731
// it would probably be sufficient just to locate by name, but this is just to be extra sure.
745
732
$moduleID = $this->modules->getModuleID($this);
746
- $page = $this->pages->get("template=admin, process=$moduleID, name=" . self::pageName);
733
+ $page = $this->pages->get("template=admin, process=$moduleID, name=" . self::pageName . "|core-upgrade" );
747
734
748
735
if($page->id) {
749
736
// if we found the page, let the user know and delete it
0 commit comments