diff --git a/admin/include/updates.class.php b/admin/include/updates.class.php index d4e178f8a..7ce02f332 100644 --- a/admin/include/updates.class.php +++ b/admin/include/updates.class.php @@ -67,6 +67,72 @@ class updates } } + /** + * finds new versions of Piwigo on Piwigo.org. + * + * @since 2.9 + * @return array ( + * 'piwigo.org-checked' => has piwigo.org been checked?, + * 'is_dev' => are we on a dev version?, + * 'minor_version' => new minor version available, + * 'major_version' => new major version available, + * ) + */ + function get_piwigo_new_versions() + { + $new_versions = array( + 'piwigo.org-checked' => false, + 'is_dev' => true, + ); + + if (preg_match('/(\d+\.\d+)\.(\d+)/', PHPWG_VERSION)) + { + $new_versions['is_dev'] = false; + $actual_branch = get_branch_from_version(PHPWG_VERSION); + + $url = PHPWG_URL.'/download/all_versions.php'; + $url.= '?rand='.md5(uniqid(rand(), true)); // Avoid server cache + + if (@fetchRemote($url, $result) + and $all_versions = @explode("\n", $result) + and is_array($all_versions)) + { + $new_versions['piwigo.org-checked'] = true; + $last_version = trim($all_versions[0]); + + if (version_compare(PHPWG_VERSION, $last_version, '<')) + { + $last_branch = get_branch_from_version($last_version); + + if ($last_branch == $actual_branch) + { + $new_versions['minor'] = $last_version; + } + else + { + $new_versions['major'] = $last_version; + + // Check if new version exists in same branch + foreach ($all_versions as $version) + { + $branch = get_branch_from_version($version); + + if ($branch == $actual_branch) + { + if (version_compare(PHPWG_VERSION, $version, '<')) + { + $new_versions['minor'] = $version; + } + break; + } + } + } + } + } + } + return $new_versions; + } + function get_server_extensions($version=PHPWG_VERSION) { global $user; diff --git a/admin/updates_pwg.php b/admin/updates_pwg.php index 023ff8e48..b1b7a2afb 100644 --- a/admin/updates_pwg.php +++ b/admin/updates_pwg.php @@ -38,67 +38,40 @@ STEP: */ $step = isset($_GET['step']) ? $_GET['step'] : 0; $upgrade_to = isset($_GET['to']) ? $_GET['to'] : ''; +$updates = new updates(); // +-----------------------------------------------------------------------+ // | Step 0 | // +-----------------------------------------------------------------------+ if ($step == 0) { - $template->assign(array( - 'CHECK_VERSION' => false, - 'DEV_VERSION' => false, - ) - ); + $new_versions = $updates->get_piwigo_new_versions(); - if (preg_match('/(\d+\.\d+)\.(\d+)/', PHPWG_VERSION, $matches)) + if (isset($new_versions['minor']) and isset($new_versions['major'])) { - $url = PHPWG_URL.'/download/all_versions.php'; - $url .= '?rand='.md5(uniqid(rand(), true)); // Avoid server cache + $step = 1; + $upgrade_to = $new_versions['major']; - if (@fetchRemote($url, $result) - and $all_versions = @explode("\n", $result) - and is_array($all_versions)) - { - $template->assign('CHECK_VERSION', true); - - $last_version = trim($all_versions[0]); - $upgrade_to = $last_version; - - if (version_compare(PHPWG_VERSION, $last_version, '<')) - { - $new_branch = preg_replace('/(\d+\.\d+)\.\d+/', '$1', $last_version); - $actual_branch = $matches[1]; - - if ($new_branch == $actual_branch) - { - $step = 2; - } - else - { - $step = 3; - - // Check if new version exists in same branch - foreach ($all_versions as $version) - { - $new_branch = preg_replace('/(\d+\.\d+)\.\d+/', '$1', $version); - - if ($new_branch == $actual_branch) - { - if (version_compare(PHPWG_VERSION, $version, '<')) - { - $step = 1; - } - break; - } - } - } - } - } + $template->assign( + array( + 'MINOR_VERSION' => $new_versions['minor'], + 'MAJOR_VERSION' => $new_versions['major'], + ) + ); } - else + elseif (isset($new_versions['minor'])) { - $template->assign('DEV_VERSION', true); + $step = 2; + $upgrade_to = $new_versions['minor']; } + elseif (isset($new_versions['major'])) + { + $step = 3; + $upgrade_to = $new_versions['major']; + } + + $template->assign('CHECK_VERSION', $new_versions['piwigo.org-checked']); + $template->assign('DEV_VERSION', $new_versions['is_dev']); } // +-----------------------------------------------------------------------+ @@ -106,11 +79,7 @@ if ($step == 0) // +-----------------------------------------------------------------------+ if ($step == 1) { - $template->assign(array( - 'MINOR_VERSION' => $version, - 'MAJOR_VERSION' => $last_version, - ) - ); + // nothing to do here } // +-----------------------------------------------------------------------+ @@ -139,7 +108,6 @@ if ($step == 3 and is_webmaster()) updates::upgrade_to($_POST['upgrade_to'], $step); } - $updates = new updates(); $updates->get_merged_extensions($upgrade_to); $updates->get_server_extensions($upgrade_to); $template->assign('missing', $updates->missing);