@@ -21,7 +21,7 @@ class ProcessWireUpgrade extends Process {
21
21
return array(
22
22
'title' => 'Upgrades',
23
23
'summary' => 'Tool that helps you identify and install core and module upgrades.',
24
- 'version' => 8 ,
24
+ 'version' => 9 ,
25
25
'author' => 'Ryan Cramer',
26
26
'installs' => 'ProcessWireUpgradeCheck',
27
27
'requires' => 'ProcessWire>=3.0.0',
@@ -156,7 +156,10 @@ class ProcessWireUpgrade extends Process {
156
156
}
157
157
158
158
if(!class_exists('\ZipArchive')) {
159
- $this->error("Your PHP does not have ZipArchive support. This is required to install core or module upgrades with this tool.");
159
+ $this->warning(
160
+ "Your PHP does not have ZipArchive support. This is required to install core or module upgrades with this tool. " .
161
+ "You can still use this tool to identify new versions and install them manually."
162
+ );
160
163
}
161
164
162
165
$upgradePaths = array($this->cachePath, $this->tempPath);
@@ -166,15 +169,27 @@ class ProcessWireUpgrade extends Process {
166
169
}
167
170
168
171
if(count($upgradePaths)) {
169
- $out = $this->h('Upgrade files are already present. Please remove them before continuing.') . $this->ul($upgradePaths);
170
- $btn = $this->wire()->modules->get('InputfieldButton'); /** @var InputfieldButton $btn */
172
+ $btn = $this->modules->get('InputfieldButton'); /** @var InputfieldButton $btn */
171
173
$btn->href = "./remove";
172
174
$btn->value = $this->_('Remove');
173
175
$btn->icon = 'trash-o';
174
- $out .= $btn->render();
175
- return $out;
176
+ return
177
+ $this->h('Upgrade files are already present. Please remove them before continuing.') . $this->ul($upgradePaths) .
178
+ $this->p($btn->render());
176
179
}
177
180
181
+ $lastRefresh = $this->session->getFor($this, 'lastRefresh');
182
+
183
+ if(!$lastRefresh && method_exists($this->modules, 'resetCache')) {
184
+ $btn = $this->refreshButton();
185
+ $btn->value = $this->_('Continue');
186
+ $btn->icon = 'angle-right';
187
+ return
188
+ $this->h('We need to load the latest core and module versions from the ProcessWire modules directory.') .
189
+ $this->p('This may take a few seconds to complete. Please click the button below to continue.') .
190
+ $this->p($btn->render());
191
+ }
192
+
178
193
return '';
179
194
}
180
195
@@ -187,20 +202,10 @@ class ProcessWireUpgrade extends Process {
187
202
$sanitizer = $this->sanitizer;
188
203
$config = $this->config;
189
204
$modules = $this->modules;
190
- $session = $this->session;
191
- $input = $this->input;
192
- $out = '';
193
-
194
- $lastRefresh = $session->getFor($this, 'lastRefresh');
195
- $refresh = $input->get('refresh') !== null || !$lastRefresh;
196
- if($refresh) $session->setFor($this, 'lastRefresh', time());
205
+
197
206
$preflight = $this->preflight();
198
207
if($preflight) return $preflight;
199
208
200
- if($refresh && method_exists($modules, 'resetCache')) {
201
- $modules->resetCache();
202
- }
203
-
204
209
/** @var MarkupAdminDataTable $table */
205
210
$table = $modules->get('MarkupAdminDataTable');
206
211
$table->setEncodeEntities(false);
@@ -213,22 +218,20 @@ class ProcessWireUpgrade extends Process {
213
218
$this->_('Links'),
214
219
));
215
220
216
- $items = $this->checker->getVersions($refresh);
217
-
218
- if($refresh) {
219
- $this->message($this->_('Refreshed module versions data'));
220
- $session->redirect('./');
221
- }
221
+ $items = $this->checker->getVersions();
222
+ $numPro = 0;
222
223
223
224
if(count($items)) {
224
225
foreach($items as $name => $item) {
225
226
if(empty($item['remote'])) {
226
227
// not in directory
227
228
}
229
+
228
230
$remote = $sanitizer->entities($item['remote']);
231
+ $installer = empty($item['installer']) ? '' : $sanitizer->entities($item['installer']);
229
232
$upgradeLabel = $this->_('Up-to-date');
230
233
$links = [];
231
-
234
+
232
235
if($item['new'] > 0) {
233
236
$upgradeLabel = $this->_('Upgrade available');
234
237
$remote = $this->b($remote);
@@ -240,12 +243,13 @@ class ProcessWireUpgrade extends Process {
240
243
$upgradeLabel = "";
241
244
}
242
245
if(empty($item['branch'])) {
243
- $upgradeURL = $config->urls->admin . "module/?update=$ name" ;
246
+ $upgradeURL = $config->urls->admin . "module/?update=" . ($installer ? $installer : $ name) ;
244
247
} else {
245
248
$upgradeURL = "./check?branch=$item[branch]";
246
249
}
247
250
if($item['new'] > 0) {
248
- $upgrade = $this->a($upgradeURL, $this->icon('lightbulb-o') . ' ' . $this->b($upgradeLabel));
251
+ $upgradeLabel = $this->icon('lightbulb-o') . $upgradeLabel;
252
+ $upgrade = $this->a($upgradeURL, $upgradeLabel);
249
253
} else {
250
254
$upgrade = $this->span($upgradeLabel, 'detail');
251
255
}
@@ -264,33 +268,62 @@ class ProcessWireUpgrade extends Process {
264
268
if(!empty($urls['dir'])) {
265
269
$links[] = $this->iconLink('share-alt', $urls['dir'], 'Directory');
266
270
}
267
- // else if(!$item['remote']) $upgrade = "<span class='detail'>" . $this->_('Not in directory') . "</span>";
268
- $icon = empty($item['icon']) ? wireIconMarkup('plug', 'fw') : wireIconMarkup($item['icon'], 'fw');
269
- $title = $sanitizer->entities($item['title']);
271
+
270
272
if(empty($remote) && empty($links)) continue;
273
+
274
+ // else if(!$item['remote']) $upgrade = "<span class='detail'>" . $this->_('Not in directory') . "</span>";
275
+ $icon = empty($item['icon']) ? wireIconMarkup('plug', 'fw') : wireIconMarkup($this->sanitizer->entities($item['icon']), 'fw');
276
+ $title = $icon . ' ' . $sanitizer->entities($item['title']);
277
+ $proLabel = ' ' . $this->span('PRO', 'pro');
278
+
279
+ if($installer && empty($remote)) {
280
+ $title = $this->tooltip("Upgraded with $installer", $title);
281
+ if(!empty($item['pro'])) $title .= $proLabel;
282
+
283
+ } else if(!empty($item['pro'])) {
284
+ if($item['new'] > 0) {
285
+ if(!empty($urls['support'])) $upgradeURL = $urls['support'];
286
+ $protip = 'PRO module upgrade available in ProcessWire VIP support board (login required)';
287
+ $upgrade = $this->tooltip($protip, $this->aa($upgradeURL, $upgradeLabel));
288
+ $title = $this->tooltip($protip, $this->aa($upgradeURL, $title) . $proLabel);
289
+ } else {
290
+ $title = $this->a($upgradeURL, $title) . $proLabel;
291
+ }
292
+ $numPro++;
293
+
294
+ } else {
295
+ $title = $this->a($upgradeURL, $title);
296
+ }
297
+
271
298
$table->row(array(
272
- $this->a($upgradeURL, "$icon $ title") ,
299
+ $title,
273
300
$sanitizer->entities($name),
274
301
$sanitizer->entities($item['local']),
275
302
$remote,
276
303
$upgrade,
277
- implode(' ', $links)
304
+ $this->span( implode(' ', $links), 'links' )
278
305
));
279
306
}
280
307
}
281
308
282
- $out .= $table->render();
283
- $out .= $this->p(sprintf($this->_('Last refresh: %s'), wireRelativeTimeStr($lastRefresh)), 'description');
284
-
285
-
286
- /** @var InputfieldButton $btn */
287
- $btn = $modules->get('InputfieldButton');
288
- $btn->href = './?refresh=1';
289
- $btn->value = $this->_('Refresh');
290
- $btn->icon = 'refresh';
291
- $out .= $btn->render();
309
+ $lastRefresh = $this->session->getFor($this, 'lastRefresh');
310
+
311
+ return
312
+ $table->render() .
313
+ $this->p(sprintf($this->_('Last refresh: %s'), wireRelativeTimeStr($lastRefresh)), 'description') .
314
+ $this->refreshButton(true)->render();
315
+ }
292
316
293
- return $out;
317
+ /**
318
+ * Refresh module versions data
319
+ *
320
+ */
321
+ public function executeRefresh() {
322
+ $this->session->setFor($this, 'lastRefresh', time());
323
+ $this->modules->resetCache();
324
+ $this->checker->getVersions(true);
325
+ $this->message($this->_('Refreshed module versions data'));
326
+ $this->session->redirect('./');
294
327
}
295
328
296
329
/**
@@ -836,6 +869,21 @@ class ProcessWireUpgrade extends Process {
836
869
$this->headline($this->_('Core upgrade'));
837
870
}
838
871
872
+ /**
873
+ * @param bool $showInHeader
874
+ * @return InputfieldButton
875
+ *
876
+ */
877
+ protected function refreshButton($showInHeader = false) {
878
+ /** @var InputfieldButton $btn */
879
+ $btn = $this->modules->get('InputfieldButton');
880
+ $btn->href = './refresh';
881
+ $btn->value = $this->_('Refresh');
882
+ $btn->icon = 'refresh';
883
+ if($showInHeader && method_exists($btn, 'showInHeader')) $btn->showInHeader(true);
884
+ return $btn;
885
+ }
886
+
839
887
/**
840
888
* Process rename operations
841
889
*
@@ -866,14 +914,15 @@ class ProcessWireUpgrade extends Process {
866
914
867
915
public function h($str, $h = 2) { return "<h$h>$str</h$h>"; }
868
916
public function p($str, $class = '') { return $class ? "<p class='$class'>$str</p>" : "<p>$str</p>"; }
869
- public function a($href, $label, $class = '') { return ($class ? "<a class='$class' " : "<a ") . "href='$ href'>$label</a>"; }
870
- public function aa($href, $label, $class = '') { return str_replace('<a', ' <a target=" _blank"' , $this->a($href, $label, $class)); }
917
+ public function a($href, $label, $class = '') { return ($class ? "<a class='$class' " : "<a ") . "href='" . $this->sanitizer->entities($ href) . " '>$label</a>"; }
918
+ public function aa($href, $label, $class = '') { return str_replace('<a', " <a target=' _blank'" , $this->a($href, $label, $class)); }
871
919
public function span($str, $class = '') { return $class ? "<span class='$class'>$str</span>" : "<span>$str</span>"; }
872
920
public function b($str, $class = '') { return $class ? "<strong class='$class'>$str</strong>" : "<strong>$str</strong>"; }
873
921
public function ul(array $items) { return "<ul class='bullets'><li>" . implode('</li><li>', $items) . '</li></ul>'; }
874
922
public function form($action, $content) { return "<form action='$action' method='post'>$content</form>"; }
875
923
public function icon($name, $fw = true) { return wireIconMarkup($name, ($fw ? 'fw' : '')); }
876
- public function iconLink($icon, $href, $tooltip) { return str_replace('<a', "<a title='$tooltip", $this->aa($href, $this->icon($icon), 'pw-tooltip')); }
924
+ public function iconLink($icon, $href, $tooltip) { return str_replace('<a', "<a title='$tooltip'", $this->aa($href, $this->icon($icon), 'pw-tooltip')); }
925
+ public function tooltip($tooltip, $markup) { return "<span class='pw-tooltip' title='$tooltip'>$markup</span>"; }
877
926
878
927
public function checkbox($name, $label, $note = '', $checked = false) {
879
928
$adminTheme = $this->wire()->adminTheme;
0 commit comments