fixes #583 check PHP version requirement before update

* piwigo.org can now tell Piwigo which version of PHP is required for each version of Piwigo. If the installed version of PHP is too old, do not let the user update.
* slight visual enhancements on the update page
This commit is contained in:
plegall
2020-11-04 17:38:09 +01:00
parent f09e3e7c0a
commit d651fe38cd
5 changed files with 131 additions and 28 deletions
+13 -7
View File
@@ -77,6 +77,7 @@ class updates
$url = PHPWG_URL.'/download/all_versions.php';
$url.= '?rand='.md5(uniqid(rand(), true)); // Avoid server cache
$url.= '&show_requirements';
if (@fetchRemote($url, $result)
and $all_versions = @explode("\n", $result)
@@ -84,29 +85,34 @@ class updates
{
$new_versions['piwigo.org-checked'] = true;
$last_version = trim($all_versions[0]);
list($last_version_number, $last_version_php) = explode('/', trim($all_versions[0]));
if (version_compare(PHPWG_VERSION, $last_version, '<'))
if (version_compare(PHPWG_VERSION, $last_version_number, '<'))
{
$last_branch = get_branch_from_version($last_version);
$last_branch = get_branch_from_version($last_version_number);
if ($last_branch == $actual_branch)
{
$new_versions['minor'] = $last_version;
$new_versions['minor'] = $last_version_number;
$new_versions['minor_php'] = $last_version_php;
}
else
{
$new_versions['major'] = $last_version;
$new_versions['major'] = $last_version_number;
$new_versions['major_php'] = $last_version_php;
// Check if new version exists in same branch
foreach ($all_versions as $version)
{
$branch = get_branch_from_version($version);
list($version_number, $version_php) = explode('/', trim($version));
$branch = get_branch_from_version($version_number);
if ($branch == $actual_branch)
{
if (version_compare(PHPWG_VERSION, $version, '<'))
if (version_compare(PHPWG_VERSION, $version_number, '<'))
{
$new_versions['minor'] = $version;
$new_versions['minor'] = $version_number;
$new_versions['minor_php'] = $version_php;
}
break;
}
+78 -11
View File
@@ -19,10 +19,44 @@ form { width: 750px; }
fieldset { padding-bottom: 30px; }
p, form p { text-align: left; margin-left:20px; }
li { margin: 5px; }
.badge-release {
padding:5px 10px;
border-radius: 5px;
}
a.badge-release:hover {
text-decoration:none;
color: currentColor;
}
.goto-update-page {
padding:5px 10px;
font-weight:bold;
}
.goto-update-page:hover {
text-decoration:none;
}
.update-recommendation {
margin-top:30px;
}
p.release .errors {margin:0}
</style>
{/literal}
{/html_head}
{if isset($MINOR_RELEASE_PHP_REQUIRED) and isset($MAJOR_RELEASE_PHP_REQUIRED)}
<div class="warnings">
<i class="eiw-icon icon-attention"></i>
<ul>
<li> {'Please upgrade your PHP version before any update.'|translate} </li>
</ul>
</div>
{/if}
<div class="titrePage">
<h2>{'Updates'|@translate}</h2>
</div>
@@ -38,29 +72,59 @@ li { margin: 5px; }
{/if}
{if $STEP == 1}
<h4>{'Two updates are available'|@translate}:</h4>
<p>
<ul>
<li><a href="admin.php?page=updates&amp;step=2&amp;to={$MINOR_VERSION}"><strong>{'Update to Piwigo %s'|@translate:$MINOR_VERSION}</strong></a>: {'This is a minor update, with only bug corrections.'|@translate}</li>
<li><a href="admin.php?page=updates&amp;step=3&amp;to={$MAJOR_VERSION}"><strong>{'Update to Piwigo %s'|@translate:$MAJOR_VERSION}</strong></a>: {'This is a major update, with <a href="%s">new exciting features</a>.'|@translate:$RELEASE_URL} {'Some themes and plugins may be not available yet.'|@translate}</li>
</ul>
<fieldset>
<legend><span class="icon-ok icon-purple"></span>{'Two updates are available'|@translate}</legend>
<p class="release release-minor">
<a href="{$MINOR_RELEASE_URL}" target="_blank" class="badge-release icon-green icon-tags">{$MINOR_VERSION}</a>
{'This is a minor update, with only bug corrections.'|@translate}
{if isset($MINOR_RELEASE_PHP_REQUIRED)}
<span class="errors icon-block">{'Requires PHP %s'|translate:$MINOR_RELEASE_PHP_REQUIRED}</span>
{else}
<a href="admin.php?page=updates&amp;step=2&amp;to={$MINOR_VERSION}" class="icon-arrows-cw goto-update-page">{'Update to Piwigo %s'|@translate:$MINOR_VERSION}</a>
{/if}
</p>
<p>{'You can update to Piwigo %s directly, without upgrading to Piwigo %s (recommended).'|@translate:$MAJOR_VERSION:$MINOR_VERSION}</p>
<p class="release release-major">
<a href="{$MAJOR_RELEASE_URL}" target="_blank" class="badge-release icon-blue icon-tags">{$MAJOR_VERSION}</a>
{'This is a major update, with <a href="%s">new exciting features</a>.'|translate:$MAJOR_RELEASE_URL}
{'Some themes and plugins may be not available yet.'|translate}
{if isset($MAJOR_RELEASE_PHP_REQUIRED)}
<span class="errors icon-block">{'Requires PHP %s'|translate:$MAJOR_RELEASE_PHP_REQUIRED}</span>
{else}
<a href="admin.php?page=updates&amp;step=3&amp;to={$MAJOR_VERSION}" class="icon-arrows-cw goto-update-page">{'Update to Piwigo %s'|@translate:$MAJOR_VERSION}</a>
{/if}
</p>
<p class="update-recommendation">
<span class="icon-info-circled-1"></span>
{'You can update to Piwigo %s directly, without upgrading to Piwigo %s (recommended).'|@translate:$MAJOR_VERSION:$MINOR_VERSION}
</p>
</fieldset>
{/if}
{if $STEP == 2}
<p>
<a href="{$MINOR_RELEASE_URL}" target="_blank" class="badge-release icon-green icon-tags">{$MINOR_VERSION}</a>
</p>
<p>
{'A new version of Piwigo is available.'|@translate}<br>
{'This is a minor update, with only bug corrections.'|@translate}
</p>
<form action="" method="post">
<p><input type="submit" name="submit" value="{'Update to Piwigo %s'|@translate:$UPGRADE_TO}"></p>
<p>
<input type="submit" name="submit" value="{'Update to Piwigo %s'|@translate:$UPGRADE_TO}"{if isset($MINOR_RELEASE_PHP_REQUIRED)} disabled{/if}>
{if isset($MINOR_RELEASE_PHP_REQUIRED)}
<span class="errors icon-block">{'Requires PHP %s'|translate:$MINOR_RELEASE_PHP_REQUIRED}</span>
{/if}
</p>
<p class="autoupdate_bar" style="display:none;">&nbsp; {'Update in progress...'|@translate}<br><img src="admin/themes/default/images/ajax-loader-bar.gif"></p>
<p><input type="hidden" name="upgrade_to" value="{$UPGRADE_TO}"></p>
</form>
{/if}
{if $STEP == 3}
<p>
<a href="{$MAJOR_RELEASE_URL}" target="_blank" class="badge-release icon-blue icon-tags">{$MAJOR_VERSION}</a>
</p>
<p>
{'A new version of Piwigo is available.'|@translate}<br>
{'This is a major update, with <a href="%s">new exciting features</a>.'|@translate:$RELEASE_URL} {'Some themes and plugins may be not available yet.'|@translate}
@@ -69,7 +133,7 @@ li { margin: 5px; }
{counter assign=i}
<fieldset>
<legend>{'Backup'|@translate}</legend>
<legend><span class="icon-floppy icon-red"></span>{'Backup'|@translate}</legend>
<p>
{'Always have a backup of your database and files.'|translate}
{'The best is to have them made automatically on a regular basis.'|translate}
@@ -79,7 +143,7 @@ li { margin: 5px; }
{counter assign=i}
<fieldset>
<legend>{'Update to Piwigo %s'|@translate:$UPGRADE_TO}</legend>
<legend><span class="icon-cog icon-purple"></span>{'Update to Piwigo %s'|@translate:$UPGRADE_TO}</legend>
{if !empty($missing.plugins)}
<p><i>{'Following plugins may not be compatible with the new version of Piwigo:'|@translate}</i></p>
<p><ul>{foreach from=$missing.plugins item=plugin}<li><a href="{$plugin.uri}" class="externalLink">{$plugin.name}</a></li>{/foreach}</ul><br></p>
@@ -92,7 +156,10 @@ li { margin: 5px; }
{if !empty($missing.plugins) or !empty($missing.themes)}
<p><label><input type="checkbox" name="understand"> &nbsp;{'I decide to update anyway'|@translate}</label></p>
{/if}
<p><input type="submit" name="submit" value="{'Update to Piwigo %s'|@translate:$UPGRADE_TO}" {if !empty($missing.plugins) or !empty($missing.themes)}disabled="disabled"{/if}>
<p><input type="submit" name="submit" value="{'Update to Piwigo %s'|@translate:$UPGRADE_TO}" {if !empty($missing.plugins) or !empty($missing.themes) or isset($MAJOR_RELEASE_PHP_REQUIRED)}disabled="disabled"{/if}>
{if isset($MAJOR_RELEASE_PHP_REQUIRED)}
<span class="errors icon-block">{'Requires PHP %s'|translate:$MAJOR_RELEASE_PHP_REQUIRED}</span>
{/if}
</p>
<p class="autoupdate_bar" style="display:none;">&nbsp; {'Update in progress...'|@translate}<br><img src="admin/themes/default/images/ajax-loader-bar.gif"></p>
</fieldset>
+35 -10
View File
@@ -27,25 +27,17 @@ check_input_parameter('to', $_GET, false, '/^\d+\.\d+\.\d+$/');
$upgrade_to = isset($_GET['to']) ? $_GET['to'] : '';
$updates = new updates();
$new_versions = $updates->get_piwigo_new_versions();
// +-----------------------------------------------------------------------+
// | Step 0 |
// +-----------------------------------------------------------------------+
if ($step == 0)
{
$new_versions = $updates->get_piwigo_new_versions();
if (isset($new_versions['minor']) and isset($new_versions['major']))
{
$step = 1;
$upgrade_to = $new_versions['major'];
$template->assign(
array(
'MINOR_VERSION' => $new_versions['minor'],
'MAJOR_VERSION' => $new_versions['major'],
)
);
}
elseif (isset($new_versions['minor']))
{
@@ -96,6 +88,20 @@ if ($step == 3 and is_webmaster())
$template->assign('missing', $updates->missing);
}
// +-----------------------------------------------------------------------+
// | Check for requirements |
// +-----------------------------------------------------------------------+
if (isset($new_versions['minor_php']) and version_compare(phpversion(), $new_versions['minor_php'], '<'))
{
$template->assign('MINOR_RELEASE_PHP_REQUIRED', $new_versions['minor_php']);
}
if (isset($new_versions['major_php']) and version_compare(phpversion(), $new_versions['major_php'], '<'))
{
$template->assign('MAJOR_RELEASE_PHP_REQUIRED', $new_versions['major_php']);
}
// +-----------------------------------------------------------------------+
// | Process template |
// +-----------------------------------------------------------------------+
@@ -109,10 +115,29 @@ $template->assign(array(
'STEP' => $step,
'PHPWG_VERSION' => PHPWG_VERSION,
'UPGRADE_TO' => $upgrade_to,
'RELEASE_URL' => PHPWG_URL.'/releases/'.$upgrade_to,
)
);
if (isset($new_versions['minor']))
{
$template->assign(
array(
'MINOR_VERSION' => $new_versions['minor'],
'MINOR_RELEASE_URL' => PHPWG_URL.'/releases/'.$new_versions['minor'],
)
);
}
if (isset($new_versions['major']))
{
$template->assign(
array(
'MAJOR_VERSION' => $new_versions['major'],
'MAJOR_RELEASE_URL' => PHPWG_URL.'/releases/'.$new_versions['major'],
)
);
}
$template->set_filename('plugin_admin_content', 'updates_pwg.tpl');
$template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content');