Skip to content

Commit c404308

Browse files
Additional updates and improvements
1 parent 4124bf6 commit c404308

File tree

3 files changed

+143
-55
lines changed

3 files changed

+143
-55
lines changed

ProcessWireUpgrade.css

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,10 @@ body.AdminThemeReno .content ul.bullets li {
77
margin-top: 0;
88
margin-bottom: 0;
99
}
10+
span.pro {
11+
font-size: 12px;
12+
color: #999;
13+
}
14+
span.links {
15+
white-space: nowrap;
16+
}

ProcessWireUpgrade.module

Lines changed: 94 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class ProcessWireUpgrade extends Process {
2121
return array(
2222
'title' => 'Upgrades',
2323
'summary' => 'Tool that helps you identify and install core and module upgrades.',
24-
'version' => 8,
24+
'version' => 9,
2525
'author' => 'Ryan Cramer',
2626
'installs' => 'ProcessWireUpgradeCheck',
2727
'requires' => 'ProcessWire>=3.0.0',
@@ -156,7 +156,10 @@ class ProcessWireUpgrade extends Process {
156156
}
157157

158158
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+
);
160163
}
161164

162165
$upgradePaths = array($this->cachePath, $this->tempPath);
@@ -166,15 +169,27 @@ class ProcessWireUpgrade extends Process {
166169
}
167170

168171
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 */
171173
$btn->href = "./remove";
172174
$btn->value = $this->_('Remove');
173175
$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());
176179
}
177180

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+
178193
return '';
179194
}
180195

@@ -187,20 +202,10 @@ class ProcessWireUpgrade extends Process {
187202
$sanitizer = $this->sanitizer;
188203
$config = $this->config;
189204
$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+
197206
$preflight = $this->preflight();
198207
if($preflight) return $preflight;
199208

200-
if($refresh && method_exists($modules, 'resetCache')) {
201-
$modules->resetCache();
202-
}
203-
204209
/** @var MarkupAdminDataTable $table */
205210
$table = $modules->get('MarkupAdminDataTable');
206211
$table->setEncodeEntities(false);
@@ -213,22 +218,20 @@ class ProcessWireUpgrade extends Process {
213218
$this->_('Links'),
214219
));
215220

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;
222223

223224
if(count($items)) {
224225
foreach($items as $name => $item) {
225226
if(empty($item['remote'])) {
226227
// not in directory
227228
}
229+
228230
$remote = $sanitizer->entities($item['remote']);
231+
$installer = empty($item['installer']) ? '' : $sanitizer->entities($item['installer']);
229232
$upgradeLabel = $this->_('Up-to-date');
230233
$links = [];
231-
234+
232235
if($item['new'] > 0) {
233236
$upgradeLabel = $this->_('Upgrade available');
234237
$remote = $this->b($remote);
@@ -240,12 +243,13 @@ class ProcessWireUpgrade extends Process {
240243
$upgradeLabel = "";
241244
}
242245
if(empty($item['branch'])) {
243-
$upgradeURL = $config->urls->admin . "module/?update=$name";
246+
$upgradeURL = $config->urls->admin . "module/?update=" . ($installer ? $installer : $name);
244247
} else {
245248
$upgradeURL = "./check?branch=$item[branch]";
246249
}
247250
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);
249253
} else {
250254
$upgrade = $this->span($upgradeLabel, 'detail');
251255
}
@@ -264,33 +268,62 @@ class ProcessWireUpgrade extends Process {
264268
if(!empty($urls['dir'])) {
265269
$links[] = $this->iconLink('share-alt', $urls['dir'], 'Directory');
266270
}
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+
270272
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+
271298
$table->row(array(
272-
$this->a($upgradeURL, "$icon $title"),
299+
$title,
273300
$sanitizer->entities($name),
274301
$sanitizer->entities($item['local']),
275302
$remote,
276303
$upgrade,
277-
implode(' ', $links)
304+
$this->span(implode(' ', $links), 'links')
278305
));
279306
}
280307
}
281308

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+
}
292316

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('./');
294327
}
295328

296329
/**
@@ -836,6 +869,21 @@ class ProcessWireUpgrade extends Process {
836869
$this->headline($this->_('Core upgrade'));
837870
}
838871

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+
839887
/**
840888
* Process rename operations
841889
*
@@ -866,14 +914,15 @@ class ProcessWireUpgrade extends Process {
866914

867915
public function h($str, $h = 2) { return "<h$h>$str</h$h>"; }
868916
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)); }
871919
public function span($str, $class = '') { return $class ? "<span class='$class'>$str</span>" : "<span>$str</span>"; }
872920
public function b($str, $class = '') { return $class ? "<strong class='$class'>$str</strong>" : "<strong>$str</strong>"; }
873921
public function ul(array $items) { return "<ul class='bullets'><li>" . implode('</li><li>', $items) . '</li></ul>'; }
874922
public function form($action, $content) { return "<form action='$action' method='post'>$content</form>"; }
875923
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>"; }
877926

878927
public function checkbox($name, $label, $note = '', $checked = false) {
879928
$adminTheme = $this->wire()->adminTheme;

ProcessWireUpgradeCheck.module

Lines changed: 42 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class ProcessWireUpgradeCheck extends WireData implements Module {
2626
return array(
2727
'title' => 'Upgrades Checker',
2828
'summary' => 'Automatically checks for core and installed module upgrades at routine intervals.',
29-
'version' => 8,
29+
'version' => 9,
3030
'autoload' => "template=admin",
3131
'singular' => true,
3232
'author' => 'Ryan Cramer',
@@ -244,11 +244,15 @@ class ProcessWireUpgradeCheck extends WireData implements Module {
244244
'local' => $modules->formatVersion($info['version']),
245245
'remote' => false,
246246
'new' => 0,
247-
'requiresVersions' => $info['requiresVersions']
247+
'requiresVersions' => $info['requiresVersions'],
248+
'installs' => $info['installs'],
248249
);
249250
}
250251

251252
if(!count($names)) return array();
253+
254+
ksort($versions);
255+
252256
$url .= implode(',', $names);
253257

254258
$data = $refresh ? null : $this->session->getFor($this, 'moduleVersionsData');
@@ -268,28 +272,56 @@ class ProcessWireUpgradeCheck extends WireData implements Module {
268272
return array();
269273
}
270274
}
275+
276+
$newVersions = array();
277+
$installedBy = array(); // moduleName => installedByModuleName
271278

272279
foreach($data['items'] as $item) {
273280
$name = $item['class_name'];
274281
$versions[$name]['remote'] = $item['version'];
275282
$new = version_compare($versions[$name]['remote'], $versions[$name]['local']);
276283
$versions[$name]['new'] = $new;
277284
$versions[$name]['urls'] = $item['urls'];
285+
$versions[$name]['installer'] = '';
286+
$versions[$name]['pro'] = !empty($item['pro']);
287+
288+
if(!empty($versions[$name]['installs'])) {
289+
foreach($versions[$name]['installs'] as $installsName) {
290+
$installedBy[$installsName] = $name;
291+
}
292+
}
293+
278294
if($new <= 0) {
279295
// local is up-to-date or newer than remote
280-
if($onlyNew) unset($versions[$name]);
281-
} else {
282-
// remote is newer than local
283-
$versions[$name]['requiresVersions'] = $item['requires'];
296+
if($onlyNew) unset($versions[$name]);
297+
continue;
298+
}
299+
300+
// remote is newer than local
301+
$versions[$name]['requiresVersions'] = $item['requires'];
302+
303+
if($new > 0 && !$onlyNew) {
304+
$newVersions[$name] = $versions[$name];
305+
unset($versions[$name]);
284306
}
285307
}
286-
308+
287309
if($onlyNew) {
288-
foreach($versions as $name => $data) {
289-
if($data['remote'] === false) unset($versions[$name]);
310+
foreach($versions as $name => $item) {
311+
if($item['remote'] === false) unset($versions[$name]);
290312
}
313+
} else if(count($newVersions)) {
314+
$versions = $newVersions + $versions;
291315
}
292-
316+
317+
foreach($versions as $name => $item) {
318+
if(!empty($versions[$name]['remote'])) continue;
319+
if(!isset($installedBy[$name])) continue;
320+
$versions[$name]['installer'] = $installedBy[$name];
321+
$installer = $versions[$installedBy[$name]];
322+
if(!empty($installer['pro'])) $versions[$name]['pro'] = true;
323+
}
324+
293325
return $versions;
294326
}
295327

0 commit comments

Comments
 (0)