aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--actions/photos/admin/upgrade.php (renamed from actions/admin/upgrade.php)16
-rw-r--r--lib/tidypics.php32
-rw-r--r--start.php2
-rw-r--r--views/default/admin/settings/tidypics.php12
4 files changed, 54 insertions, 8 deletions
diff --git a/actions/admin/upgrade.php b/actions/photos/admin/upgrade.php
index 334e9588e..c9ae1da48 100644
--- a/actions/admin/upgrade.php
+++ b/actions/photos/admin/upgrade.php
@@ -2,18 +2,21 @@
/**
* Tidypics upgrade action
*/
-require_once "{$CONFIG->pluginspath}tidypics/version.php";
-$local_version = get_plugin_setting('version', 'tidypics');
+$plugins_path = elgg_get_plugins_path();
+
+require_once "{$plugins_path}tidypics/version.php";
+
+$local_version = elgg_get_plugin_setting('version', 'tidypics');
if ($version <= $local_version) {
register_error('No upgrade required');
- forward($_SERVER['HTTP_REFERER']);
+ forward(REFERER);
}
set_time_limit(0);
-$base_dir = $CONFIG->pluginspath . 'tidypics/upgrades';
+$base_dir = "{$plugins_path}tidypics/upgrades";
// taken from engine/lib/version.php
if ($handle = opendir($base_dir)) {
@@ -41,8 +44,7 @@ if ($handle = opendir($base_dir)) {
}
}
-set_plugin_setting('version', $version, 'tidypics');
+elgg_set_plugin_setting('version', $version, 'tidypics');
system_message("Tidypics has been upgraded");
-
-forward($_SERVER['HTTP_REFERER']);
+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 '<div class="elgg-admin-notices">';
+ echo '<p>';
+ echo elgg_view('output/url', array(
+ 'text' => elgg_echo('tidypics:upgrade'),
+ 'href' => 'action/photos/admin/upgrade',
+ 'is_action' => true,
+ ));
+ echo '</p>';
+ echo '</div>';
+}
+
echo elgg_view('output/longtext', array('value' => elgg_echo('tidypics:admin:instructions')));
echo elgg_view_form('photos/admin/settings');