mirror of
https://github.com/Piwigo/Piwigo.git
synced 2026-03-28 17:42:57 +01:00
Add docker updates support
Detect if running in a official container and replace updates buttons by links to the documentation
This commit is contained in:
@@ -8,6 +8,8 @@
|
||||
|
||||
if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
|
||||
|
||||
include_once(PHPWG_ROOT_PATH.'include/functions.inc.php');
|
||||
|
||||
class updates
|
||||
{
|
||||
var $types = array();
|
||||
@@ -72,14 +74,18 @@ class updates
|
||||
'is_dev' => true,
|
||||
);
|
||||
|
||||
list($env, $build_version) = get_container_info();
|
||||
if (preg_match('/^(\d+\.\d+)\.(\d+)$/', PHPWG_VERSION))
|
||||
{
|
||||
$new_versions['is_dev'] = false;
|
||||
$actual_branch = get_branch_from_version(PHPWG_VERSION);
|
||||
|
||||
$actual_branch = get_branch_from_version(('Official' === $env)
|
||||
? substr($build_version, 0, -1)
|
||||
: PHPWG_VERSION
|
||||
);
|
||||
|
||||
$url = PHPWG_URL.'/download/all_versions.php';
|
||||
$url.= '?rand='.md5(uniqid(rand(), true)); // Avoid server cache
|
||||
$url.= '&show_requirements';
|
||||
$url .= ('Official' === $env) ? '&docker' : '&show_requirements'; // Check docker version if in container
|
||||
$url.= '&origin_hash='.sha1($conf['secret_key'].get_absolute_root_url());
|
||||
|
||||
if (@fetchRemote($url, $result)
|
||||
@@ -88,36 +94,66 @@ 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_number, '<'))
|
||||
if ('Official' === $env)
|
||||
{
|
||||
$last_branch = get_branch_from_version($last_version_number);
|
||||
|
||||
if ($last_branch == $actual_branch)
|
||||
if ($this->container_version_compare($build_version, $last_version))
|
||||
{
|
||||
$new_versions['minor'] = $last_version_number;
|
||||
$new_versions['minor_php'] = $last_version_php;
|
||||
}
|
||||
else
|
||||
{
|
||||
$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)
|
||||
$last_branch = get_branch_from_version(substr($last_version, 0, -1));
|
||||
if ($last_branch == $actual_branch)
|
||||
{
|
||||
list($version_number, $version_php) = explode('/', trim($version));
|
||||
$branch = get_branch_from_version($version_number);
|
||||
|
||||
if ($branch == $actual_branch)
|
||||
$new_versions['minor'] = $last_version;
|
||||
}
|
||||
else
|
||||
{
|
||||
$new_versions['major'] = $last_version;
|
||||
foreach ($all_versions as $version)
|
||||
{
|
||||
if (version_compare(PHPWG_VERSION, $version_number, '<'))
|
||||
$branch = get_branch_from_version(substr($version, 0, -1));
|
||||
if ($branch == $actual_branch)
|
||||
{
|
||||
$new_versions['minor'] = $version_number;
|
||||
$new_versions['minor_php'] = $version_php;
|
||||
if ($this->container_version_compare($build_version, $version))
|
||||
{
|
||||
$new_versions['minor'] = $version;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
list($last_version_number, $last_version_php) = explode('/', trim($all_versions[0]));
|
||||
|
||||
if (version_compare(PHPWG_VERSION, $last_version_number, '<'))
|
||||
{
|
||||
$last_branch = get_branch_from_version($last_version_number);
|
||||
|
||||
if ($last_branch == $actual_branch)
|
||||
{
|
||||
$new_versions['minor'] = $last_version_number;
|
||||
$new_versions['minor_php'] = $last_version_php;
|
||||
}
|
||||
else
|
||||
{
|
||||
$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)
|
||||
{
|
||||
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_number, '<'))
|
||||
{
|
||||
$new_versions['minor'] = $version_number;
|
||||
$new_versions['minor_php'] = $version_php;
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -606,6 +642,27 @@ class updates
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Compare version number with a letter suffix
|
||||
// Similar to version_compare with "<" sign
|
||||
function container_version_compare($v1,$v2)
|
||||
{
|
||||
// Split 16.2.0d into "16.2.0" as semantic_ver and "d" as sub_ver
|
||||
$v1_semantic_ver = substr($v1, 0, -1);
|
||||
$v1_sub_ver = substr($v1, -1);
|
||||
$v2_semantic_ver = substr($v2, 0, -1);
|
||||
$v2_sub_ver = substr($v2, -1);
|
||||
|
||||
$res = version_compare($v1_semantic_ver, $v2_semantic_ver);
|
||||
|
||||
// Return for any
|
||||
if ($res === 0)
|
||||
{
|
||||
return strcmp($v1_sub_ver, $v2_sub_ver) < 0;
|
||||
}
|
||||
|
||||
return $res;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -43,6 +43,12 @@ a.badge-release:hover {
|
||||
margin-top:30px;
|
||||
}
|
||||
|
||||
.goto-update-guide {
|
||||
background-color: #F0F0F0;
|
||||
padding: 10px;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
p.release .errors {margin:0}
|
||||
</style>
|
||||
{/literal}
|
||||
@@ -57,14 +63,16 @@ p.release .errors {margin:0}
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
{if isset($PIWIGO_CURRENT_VERSION)}
|
||||
<p><i class="icon-info-circled-1"></i> {'Currently running version %s'|translate:$PIWIGO_CURRENT_VERSION}</p>
|
||||
{if isset($PIWIGO_CURRENT_VERSION) and !isset($CONTAINER_VERSION)}
|
||||
<p><i class="icon-info-circled-1"></i> {'Currently running version %s'|translate:$PIWIGO_CURRENT_VERSION}</p>
|
||||
{elseif isset($CONTAINER_VERSION)}
|
||||
<p><i class="icon-info-circled-1"></i> {'Currently running version %s'|translate:$CONTAINER_VERSION} (Docker)</p>
|
||||
{/if}
|
||||
|
||||
{if $STEP == 0}
|
||||
{if $CHECK_VERSION}
|
||||
<p>{'You are running the latest version of Piwigo.'|@translate}</p>
|
||||
{elseif $DEV_VERSION}
|
||||
{elseif $DEV_VERSION}
|
||||
<p>{'You are running on development sources, no check possible.'|@translate}</p>
|
||||
{else}
|
||||
<p>{'Check for update failed for unknown reasons.'|@translate}</p>
|
||||
@@ -73,19 +81,27 @@ p.release .errors {margin:0}
|
||||
|
||||
{if $STEP == 1}
|
||||
<fieldset>
|
||||
<legend><span class="icon-ok icon-purple"></span>{'Two updates are available'|@translate}</legend>
|
||||
{if isset($CONTAINER_VERSION)}
|
||||
<legend><span class="icon-ok icon-purple"></span>{'Two container updates are available'|@translate}</legend>
|
||||
{else}
|
||||
<legend><span class="icon-ok icon-purple"></span>{'Two updates are available'|@translate}</legend>
|
||||
{/if}
|
||||
<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&step=2&to={$MINOR_VERSION}" class="icon-arrows-cw goto-update-page">{'Update to Piwigo %s'|@translate:$MINOR_VERSION}</a>
|
||||
{if isset($CONTAINER_VERSION)}
|
||||
<a href="{$DOCKER_UPDATE_GUIDE_URL}" target="_blank" class="icon-arrows-cw goto-update-page">{'Follow the update guide'|@translate}</a>
|
||||
{else}
|
||||
<a href="admin.php?page=updates&step=2&to={$MINOR_VERSION}" class="icon-arrows-cw goto-update-page">{'Update to Piwigo %s'|@translate:$MINOR_VERSION}</a>
|
||||
{/if}
|
||||
{/if}
|
||||
</p>
|
||||
|
||||
<p class="release release-major">
|
||||
<a href="{$MAJOR_RELEASE_URL}" target="_blank" class="badge-release icon-blue icon-tags">{$MAJOR_VERSION}</a>
|
||||
<a href="{if isset($CONTAINER_VERSION)} {$MAJOR_DOCKER_RELEASE_URL} {else} {$MAJOR_RELEASE_URL} {/if}" 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)}
|
||||
@@ -111,10 +127,14 @@ p.release .errors {margin:0}
|
||||
</p>
|
||||
<form action="" method="post">
|
||||
<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}
|
||||
{if isset($CONTAINER_VERSION)}
|
||||
<a class="icon-right goto-update-guide" href="{$DOCKER_UPDATE_GUIDE_URL}" target="_blank"> {'Follow the update guide'|@translate}</a>
|
||||
{else}
|
||||
<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}
|
||||
{/if}
|
||||
</p>
|
||||
<p class="autoupdate_bar" style="display:none;"> {'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>
|
||||
@@ -123,7 +143,7 @@ p.release .errors {margin:0}
|
||||
|
||||
{if $STEP == 3}
|
||||
<p>
|
||||
<a href="{$MAJOR_RELEASE_URL}" target="_blank" class="badge-release icon-blue icon-tags">{$MAJOR_VERSION}</a>
|
||||
<a href="{if isset($CONTAINER_VERSION)} {$MAJOR_DOCKER_RELEASE_URL} {else} {$MAJOR_RELEASE_URL} {/if}" target="_blank" class="badge-release icon-blue icon-tags">{$MAJOR_VERSION}</a>
|
||||
</p>
|
||||
<p>
|
||||
{'A new version of Piwigo is available.'|@translate}<br>
|
||||
@@ -156,7 +176,11 @@ p.release .errors {margin:0}
|
||||
{if !empty($missing.plugins) or !empty($missing.themes)}
|
||||
<p><label><input type="checkbox" name="understand"> {'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) or isset($MAJOR_RELEASE_PHP_REQUIRED)}disabled="disabled"{/if}>
|
||||
{if isset($CONTAINER_VERSION)}
|
||||
<p><a class="icon-right goto-update-guide {if !empty($missing.plugins) or !empty($missing.themes)} goto-update-guide-disabled{/if}" href="{$DOCKER_UPDATE_GUIDE_URL}" target="_blank"> {'Follow the update guide'|@translate}</a>
|
||||
{else}
|
||||
<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}
|
||||
{if isset($MAJOR_RELEASE_PHP_REQUIRED)}
|
||||
<span class="errors icon-block">{'Requires PHP %s'|translate:$MAJOR_RELEASE_PHP_REQUIRED}</span>
|
||||
{/if}
|
||||
@@ -166,4 +190,4 @@ p.release .errors {margin:0}
|
||||
|
||||
<p><input type="hidden" name="upgrade_to" value="{$UPGRADE_TO}"></p>
|
||||
</form>
|
||||
{/if}
|
||||
{/if}
|
||||
|
||||
@@ -16,6 +16,7 @@ if (!$conf['enable_core_update'])
|
||||
die('Piwigo core update system is disabled');
|
||||
}
|
||||
|
||||
include_once(PHPWG_ROOT_PATH.'include/functions.inc.php');
|
||||
include_once(PHPWG_ROOT_PATH.'admin/include/updates.class.php');
|
||||
include_once(PHPWG_ROOT_PATH.'admin/include/pclzip.lib.php');
|
||||
|
||||
@@ -28,8 +29,24 @@ STEP:
|
||||
*/
|
||||
$step = isset($_GET['step']) ? $_GET['step'] : 0;
|
||||
|
||||
check_input_parameter('to', $_GET, false, '/^\d+\.\d+\.\d+$/');
|
||||
$upgrade_to = isset($_GET['to']) ? $_GET['to'] : '';
|
||||
[$ct_env, $ct_build_version] = get_container_info();
|
||||
|
||||
if( 'Official' === $ct_env)
|
||||
{
|
||||
$template->assign([
|
||||
'CONTAINER_VERSION' => $ct_build_version,
|
||||
'DOCKER_UPDATE_GUIDE_URL' => PHPWG_URL . '/guide-update-docker'
|
||||
]);
|
||||
// Remove optional ? on [a-z]? since it will only be available on piwigo 16.3
|
||||
// Docker images started to use letter suffix in 16.2
|
||||
check_input_parameter('to', $_GET, false, '/^\d+\.\d+\.\d+[a-z]?$/');
|
||||
$upgrade_to = isset($_GET['to']) ? preg_replace('/[a-z]$/','',$_GET['to']) : '';
|
||||
}
|
||||
else
|
||||
{
|
||||
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();
|
||||
@@ -40,19 +57,19 @@ $new_versions = $updates->get_piwigo_new_versions();
|
||||
if ($step == 0)
|
||||
{
|
||||
if (isset($new_versions['minor']) and isset($new_versions['major']))
|
||||
{
|
||||
$step = 1;
|
||||
$upgrade_to = $new_versions['major'];
|
||||
{
|
||||
$step = 1;
|
||||
$upgrade_to = $new_versions['major'];
|
||||
}
|
||||
elseif (isset($new_versions['minor']))
|
||||
{
|
||||
$step = 2;
|
||||
$upgrade_to = $new_versions['minor'];
|
||||
{
|
||||
$step = 2;
|
||||
$upgrade_to = $new_versions['minor'];
|
||||
}
|
||||
elseif (isset($new_versions['major']))
|
||||
{
|
||||
$step = 3;
|
||||
$upgrade_to = $new_versions['major'];
|
||||
{
|
||||
$step = 3;
|
||||
$upgrade_to = $new_versions['major'];
|
||||
}
|
||||
|
||||
$template->assign('CHECK_VERSION', $new_versions['piwigo.org-checked']);
|
||||
@@ -73,7 +90,7 @@ if ($step == 1)
|
||||
if ($step == 2 and is_webmaster())
|
||||
{
|
||||
if (isset($_POST['submit']) and isset($_POST['upgrade_to']))
|
||||
{
|
||||
{
|
||||
updates::upgrade_to($_POST['upgrade_to'], $step);
|
||||
}
|
||||
}
|
||||
@@ -84,7 +101,7 @@ if ($step == 2 and is_webmaster())
|
||||
if ($step == 3 and is_webmaster())
|
||||
{
|
||||
if (isset($_POST['submit']) and isset($_POST['upgrade_to']))
|
||||
{
|
||||
{
|
||||
updates::upgrade_to($_POST['upgrade_to'], $step);
|
||||
}
|
||||
|
||||
@@ -126,9 +143,12 @@ $template->assign(array(
|
||||
if (isset($new_versions['minor']))
|
||||
{
|
||||
$template->assign(
|
||||
array(
|
||||
array(
|
||||
'MINOR_VERSION' => $new_versions['minor'],
|
||||
'MINOR_RELEASE_URL' => PHPWG_URL.'/releases/'.$new_versions['minor'],
|
||||
'MINOR_RELEASE_URL' => (('Official' === $ct_env)
|
||||
? 'https://github.com/Piwigo/piwigo-docker/wiki/Changelog#' . preg_replace('/\./','',$new_versions['minor'])
|
||||
: PHPWG_URL . '/releases/' . $new_versions['minor']
|
||||
),
|
||||
)
|
||||
);
|
||||
}
|
||||
@@ -138,8 +158,11 @@ if (isset($new_versions['major']))
|
||||
$template->assign(
|
||||
array(
|
||||
'MAJOR_VERSION' => $new_versions['major'],
|
||||
'MAJOR_RELEASE_URL' => PHPWG_URL.'/releases/'.$new_versions['major'],
|
||||
)
|
||||
'MAJOR_RELEASE_URL' => PHPWG_URL . '/releases/' .
|
||||
( ('Official' === $ct_env) ? substr($new_versions['major'], 0, -1) : $new_versions['major']),
|
||||
'MAJOR_DOCKER_RELEASE_URL' => 'https://github.com/Piwigo/piwigo-docker/wiki/Changelog#' . preg_replace('/\./','',$new_versions['major']),
|
||||
'MAJOR_VERSION_PWG' => preg_replace('/[a-z]$/','',$new_versions['major']) // Remove container build ver
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -852,6 +852,8 @@ $lang['Update in progress... Please wait.'] = 'Update in progress... Please wait
|
||||
$lang['Update photos information'] = 'Update photos\' information';
|
||||
$lang['update the database from files'] = "update the database with files";
|
||||
$lang['Update to Piwigo %s'] = 'Update to Piwigo %s';
|
||||
$lang['Follow the update guide'] = 'Follow the update guide';
|
||||
$lang['Two container updates are available'] = 'Two container updates are available';
|
||||
$lang['Updates'] = 'Updates';
|
||||
$lang['Upload Photos'] = 'Upload Photos';
|
||||
$lang['Upload'] = "Upload";
|
||||
|
||||
@@ -720,6 +720,8 @@ $lang['Following themes may not be compatible with the new version of Piwigo:']
|
||||
$lang['I decide to update anyway'] = 'Je décide de migrer quand même';
|
||||
$lang['Update to Piwigo %s'] = 'Mettre à jour vers Piwigo %s';
|
||||
$lang['Two updates are available'] = 'Deux mises à jour sont disponibles';
|
||||
$lang['Follow the update guide'] = 'Suivre le guide de mise à jour';
|
||||
$lang['Two container updates are available'] = 'Deux mises à jour de conteneur sont disponibles';
|
||||
$lang['This is a minor update, with only bug corrections.'] = 'Ceci est une mise à jour mineure, avec uniquement des corrections de bugs.';
|
||||
$lang['This is a major update, with <a href="%s">new exciting features</a>.'] = 'Ceci est une mise à jour majeure, qui contient <a href="%s">un tas de nouveautés</a>.';
|
||||
$lang['Some themes and plugins may be not available yet.'] = 'Certains thèmes ou plugins ne sont peut-être pas encore disponibles.';
|
||||
|
||||
Reference in New Issue
Block a user