Skip to content

Commit

Permalink
Extract function that generates upgrade link for extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
mattwire committed Nov 29, 2020
1 parent 5d21967 commit a304caa
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 14 deletions.
3 changes: 2 additions & 1 deletion CRM/Admin/Page/Extensions.php
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ public function formatRemoteExtensionRows($localExtensionRows) {
// build list of available downloads
$remoteExtensionRows = [];
$compat = CRM_Extension_System::getCompatibilityInfo();
$mapper = CRM_Extension_System::singleton()->getMapper();

foreach ($remoteExtensions as $info) {
if (!empty($compat[$info->key]['obsolete'])) {
Expand All @@ -257,7 +258,7 @@ public function formatRemoteExtensionRows($localExtensionRows) {
if (isset($localExtensionRows[$info->key])) {
if (array_key_exists('version', $localExtensionRows[$info->key])) {
if (version_compare($localExtensionRows[$info->key]['version'], $info->version, '<')) {
$row['is_upgradeable'] = TRUE;
$row['upgradelink'] = $mapper->getUpgradeLink($remoteExtensions[$info->key], $localExtensionRows[$info->key]);
}
}
}
Expand Down
20 changes: 20 additions & 0 deletions CRM/Extension/Mapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -535,4 +535,24 @@ public function refresh() {
CRM_Extension_System::singleton()->getClassLoader()->refresh();
}

/**
* This returns a formatted string containing an extension upgrade link for the UI.
* @todo We should improve this to return more appropriate text. eg. when an extension is not installed
* it should not say "version xx is installed".
*
* @param array $remoteExtensionInfo
* @param array $localExtensionInfo
*
* @return string
*/
public function getUpgradeLink($remoteExtensionInfo, $localExtensionInfo) {
if (!empty($remoteExtensionInfo) && version_compare($localExtensionInfo['version'], $remoteExtensionInfo->version, '<')) {
return ts('Version %1 is installed. <a %2>Upgrade to version %3</a>.', [
1 => $localExtensionInfo['version'],
2 => 'href="' . CRM_Utils_System::url('civicrm/admin/extensions', "action=update&id={$localExtensionInfo['key']}&key={$localExtensionInfo['key']}") . '"',
3 => $remoteExtensionInfo->version,
]);
}
}

}
13 changes: 3 additions & 10 deletions CRM/Utils/Check/Component/Env.php
Original file line number Diff line number Diff line change
Expand Up @@ -620,23 +620,16 @@ public function checkExtensions() {

case CRM_Extension_Manager::STATUS_INSTALLED:
if (!empty($remotes[$key]) && version_compare($row['version'], $remotes[$key]->version, '<')) {
$updates[] = ts('%1 (%2) version %3 is installed. <a %4>Upgrade to version %5</a>.', [
1 => $row['label'] ?? NULL,
2 => $key,
3 => $row['version'],
4 => 'href="' . CRM_Utils_System::url('civicrm/admin/extensions', "action=update&id=$key&key=$key") . '"',
5 => $remotes[$key]->version,
]);
$updates[] = $row['label'] . ': ' . $mapper->getUpgradeLink($remotes[$key], $row);
}
else {
if (empty($row['label'])) {
$okextensions[] = $key;
}
else {
$okextensions[] = ts('%1 (%2) version %3', [
$okextensions[] = ts('%1: Version %2', [
1 => $row['label'],
2 => $key,
3 => $row['version'],
2 => $row['version'],
]);
}
}
Expand Down
5 changes: 2 additions & 3 deletions templates/CRM/Admin/Page/Extensions/Main.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@ Depends: CRM/common/enableDisableApi.tpl and CRM/common/jsortable.tpl
<tr id="extension-{$row.file}" class="crm-entity crm-extension-{$row.file}{if $row.status eq 'disabled'} disabled{/if}{if $row.status eq 'installed-missing' or $row.status eq 'disabled-missing'} extension-missing{/if}{if $row.upgradable} extension-upgradable{elseif $row.status eq 'installed'} extension-installed{/if}">
<td class="crm-extensions-label">
<a class="collapsed" href="#"></a>&nbsp;<strong>{$row.label}</strong><br/>{$row.description}
{if $extAddNewEnabled && $remoteExtensionRows[$extKey] && $remoteExtensionRows[$extKey].is_upgradeable}
{capture assign='upgradeURL'}{crmURL p='civicrm/admin/extensions' q="action=update&id=$extKey&key=$extKey"}{/capture}
<div class="crm-extensions-upgrade">{ts 1=$upgradeURL}Version {$remoteExtensionRows[$extKey].version} is available. <a href="%1">Upgrade</a>{/ts}</div>
{if $extAddNewEnabled && $remoteExtensionRows[$extKey] && $remoteExtensionRows[$extKey].upgradelink}
<div class="crm-extensions-upgrade">{$remoteExtensionRows[$extKey].upgradelink}</div>
{/if}
</td>
<td class="crm-extensions-label">{$row.statusLabel} {if $row.upgradable}<br/>({ts}Outdated{/ts}){/if}</td>
Expand Down

0 comments on commit a304caa

Please sign in to comment.