From f5e8d5e9be7873132fbfddf74ef8ff68f01fccae Mon Sep 17 00:00:00 2001 From: cash Date: Mon, 2 Jan 2012 17:01:18 -0500 Subject: updated the upgrade system --- actions/admin/upgrade.php | 48 ----------------------------- actions/photos/admin/upgrade.php | 50 +++++++++++++++++++++++++++++++ lib/tidypics.php | 32 ++++++++++++++++++++ start.php | 2 +- views/default/admin/settings/tidypics.php | 12 ++++++++ 5 files changed, 95 insertions(+), 49 deletions(-) delete mode 100644 actions/admin/upgrade.php create mode 100644 actions/photos/admin/upgrade.php diff --git a/actions/admin/upgrade.php b/actions/admin/upgrade.php deleted file mode 100644 index 334e9588e..000000000 --- a/actions/admin/upgrade.php +++ /dev/null @@ -1,48 +0,0 @@ -pluginspath}tidypics/version.php"; - -$local_version = get_plugin_setting('version', 'tidypics'); - -if ($version <= $local_version) { - register_error('No upgrade required'); - forward($_SERVER['HTTP_REFERER']); -} - -set_time_limit(0); - -$base_dir = $CONFIG->pluginspath . 'tidypics/upgrades'; - -// taken from engine/lib/version.php -if ($handle = opendir($base_dir)) { - $upgrades = array(); - - while ($updatefile = readdir($handle)) { - // Look for upgrades and add to upgrades list - if (!is_dir("$base_dir/$updatefile")) { - if (preg_match('/^([0-9]{10})\.(php)$/', $updatefile, $matches)) { - $plugin_version = (int) $matches[1]; - if ($plugin_version > $local_version) { - $upgrades[] = "$base_dir/$updatefile"; - } - } - } - } - - // Sort and execute - asort($upgrades); - - if (sizeof($upgrades) > 0) { - foreach ($upgrades as $upgrade) { - include($upgrade); - } - } -} - -set_plugin_setting('version', $version, 'tidypics'); - -system_message("Tidypics has been upgraded"); - -forward($_SERVER['HTTP_REFERER']); diff --git a/actions/photos/admin/upgrade.php b/actions/photos/admin/upgrade.php new file mode 100644 index 000000000..c9ae1da48 --- /dev/null +++ b/actions/photos/admin/upgrade.php @@ -0,0 +1,50 @@ + $local_version) { + $upgrades[] = "$base_dir/$updatefile"; + } + } + } + } + + // Sort and execute + asort($upgrades); + + if (sizeof($upgrades) > 0) { + foreach ($upgrades as $upgrade) { + include($upgrade); + } + } +} + +elgg_set_plugin_setting('version', $version, 'tidypics'); + +system_message("Tidypics has been upgraded"); +forward(REFERER); diff --git a/lib/tidypics.php b/lib/tidypics.php index 0a4586c29..4e56ae829 100644 --- a/lib/tidypics.php +++ b/lib/tidypics.php @@ -109,6 +109,38 @@ function tidypics_get_image_libraries() { return $options; } +/** + * Are there upgrade scripts to be run? + * + * @return bool + */ +function tidypics_is_upgrade_available() { + // sets $version based on code + require_once elgg_get_plugins_path() . "tidypics/version.php"; + + $local_version = elgg_get_plugin_setting('version', 'tidypics'); + if ($local_version === false) { + // no version set so either new install or really old one + if (!get_subtype_class('object', 'image') || !get_subtype_class('object', 'album')) { + $local_version = 0; + } else { + // set initial version for new install + elgg_set_plugin_setting('version', $version, 'tidypics'); + $local_version = $version; + } + } elseif ($local_version === '1.62') { + // special work around to handle old upgrade system + $local_version = 2010010101; + elgg_set_plugin_setting('version', $local_version, 'tidypics'); + } + + if ($local_version == $version) { + return false; + } else { + return true; + } +} + /********************************************************************* * the functions below replace broken core functions or add functions * that could/should exist in the core diff --git a/start.php b/start.php index a81c1d854..630068874 100644 --- a/start.php +++ b/start.php @@ -100,7 +100,7 @@ function tidypics_init() { //register_action("tidypics/deletetag", false, "$base_dir/deletetag.php"); elgg_register_action("photos/admin/settings", "$base_dir/admin/settings.php", 'admin'); - //register_action("tidypics/admin/upgrade", false, "$base_dir/admin/upgrade.php", true); + elgg_register_action("photos/admin/upgrade", "$base_dir/admin/upgrade.php", 'admin'); // Register libraries $base_dir = elgg_get_plugins_path() . 'tidypics/lib'; diff --git a/views/default/admin/settings/tidypics.php b/views/default/admin/settings/tidypics.php index aaaebd371..2e7d79942 100644 --- a/views/default/admin/settings/tidypics.php +++ b/views/default/admin/settings/tidypics.php @@ -6,6 +6,18 @@ * @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License v2 */ +if (tidypics_is_upgrade_available()) { + echo '
'; + echo '

'; + echo elgg_view('output/url', array( + 'text' => elgg_echo('tidypics:upgrade'), + 'href' => 'action/photos/admin/upgrade', + 'is_action' => true, + )); + echo '

'; + echo '
'; +} + echo elgg_view('output/longtext', array('value' => elgg_echo('tidypics:admin:instructions'))); echo elgg_view_form('photos/admin/settings'); -- cgit v1.2.3