diff --git a/admin/include/updates.class.php b/admin/include/updates.class.php index 68e0ecc9c..03e767c66 100644 --- a/admin/include/updates.class.php +++ b/admin/include/updates.class.php @@ -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; + } } ?> \ No newline at end of file diff --git a/admin/themes/default/template/updates_pwg.tpl b/admin/themes/default/template/updates_pwg.tpl index 682114d8b..a9f2d36a3 100644 --- a/admin/themes/default/template/updates_pwg.tpl +++ b/admin/themes/default/template/updates_pwg.tpl @@ -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} {/literal} @@ -57,14 +63,16 @@ p.release .errors {margin:0} {/if} -{if isset($PIWIGO_CURRENT_VERSION)} -

{'Currently running version %s'|translate:$PIWIGO_CURRENT_VERSION}

+{if isset($PIWIGO_CURRENT_VERSION) and !isset($CONTAINER_VERSION)} +

{'Currently running version %s'|translate:$PIWIGO_CURRENT_VERSION}

+{elseif isset($CONTAINER_VERSION)} +

{'Currently running version %s'|translate:$CONTAINER_VERSION} (Docker)

{/if} {if $STEP == 0} {if $CHECK_VERSION}

{'You are running the latest version of Piwigo.'|@translate}

- {elseif $DEV_VERSION} + {elseif $DEV_VERSION}

{'You are running on development sources, no check possible.'|@translate}

{else}

{'Check for update failed for unknown reasons.'|@translate}

@@ -73,19 +81,27 @@ p.release .errors {margin:0} {if $STEP == 1}
- {'Two updates are available'|@translate} + {if isset($CONTAINER_VERSION)} + {'Two container updates are available'|@translate} + {else} + {'Two updates are available'|@translate} + {/if}

{$MINOR_VERSION} {'This is a minor update, with only bug corrections.'|@translate} {if isset($MINOR_RELEASE_PHP_REQUIRED)} {'Requires PHP %s'|translate:$MINOR_RELEASE_PHP_REQUIRED} {else} - {'Update to Piwigo %s'|@translate:$MINOR_VERSION} + {if isset($CONTAINER_VERSION)} + {'Follow the update guide'|@translate} + {else} + {'Update to Piwigo %s'|@translate:$MINOR_VERSION} + {/if} {/if}

- {$MAJOR_VERSION} +{$MAJOR_VERSION} {'This is a major update, with new exciting features.'|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}

- -{if isset($MINOR_RELEASE_PHP_REQUIRED)} - {'Requires PHP %s'|translate:$MINOR_RELEASE_PHP_REQUIRED} -{/if} + {if isset($CONTAINER_VERSION)} + {'Follow the update guide'|@translate} + {else} + + {if isset($MINOR_RELEASE_PHP_REQUIRED)} + {'Requires PHP %s'|translate:$MINOR_RELEASE_PHP_REQUIRED} + {/if} + {/if}

@@ -123,7 +143,7 @@ p.release .errors {margin:0} {if $STEP == 3}

- {$MAJOR_VERSION} + {$MAJOR_VERSION}

{'A new version of Piwigo is available.'|@translate}
@@ -156,7 +176,11 @@ p.release .errors {margin:0} {if !empty($missing.plugins) or !empty($missing.themes)}

{/if} -

+ {if isset($CONTAINER_VERSION)} +

{'Follow the update guide'|@translate} + {else} +

+ {/if} {if isset($MAJOR_RELEASE_PHP_REQUIRED)} {'Requires PHP %s'|translate:$MAJOR_RELEASE_PHP_REQUIRED} {/if} @@ -166,4 +190,4 @@ p.release .errors {margin:0}

-{/if} \ No newline at end of file +{/if} diff --git a/admin/updates_pwg.php b/admin/updates_pwg.php index 6d494c1f3..ae336c6fe 100644 --- a/admin/updates_pwg.php +++ b/admin/updates_pwg.php @@ -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 + ) ); } diff --git a/language/en_UK/admin.lang.php b/language/en_UK/admin.lang.php index 92399473e..429e9d6f9 100644 --- a/language/en_UK/admin.lang.php +++ b/language/en_UK/admin.lang.php @@ -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"; diff --git a/language/fr_FR/admin.lang.php b/language/fr_FR/admin.lang.php index 096c86d33..d65411763 100644 --- a/language/fr_FR/admin.lang.php +++ b/language/fr_FR/admin.lang.php @@ -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 new exciting features.'] = 'Ceci est une mise à jour majeure, qui contient un tas de nouveautés.'; $lang['Some themes and plugins may be not available yet.'] = 'Certains thèmes ou plugins ne sont peut-être pas encore disponibles.';