[geeklog-cvs] geeklog: Introduced new plugin API function PLG_migrate
geeklog-cvs at lists.geeklog.net
geeklog-cvs at lists.geeklog.net
Sun Mar 22 05:53:31 EDT 2009
details: http://project.geeklog.net/cgi-bin/hgweb.cgi/rev/d734244b9ef5
changeset: 6850:d734244b9ef5
user: Dirk Haun <dirk at haun-online.de>
date: Sun Mar 22 10:49:26 2009 +0100
description:
Introduced new plugin API function PLG_migrate
diffstat:
9 files changed, 176 insertions(+), 6 deletions(-)
plugins/calendar/functions.inc | 24 ++++++++++++++++++++++++
plugins/links/functions.inc | 24 ++++++++++++++++++++++++
plugins/polls/functions.inc | 24 ++++++++++++++++++++++++
plugins/spamx/functions.inc | 28 ++++++++++++++++++++++++++++
plugins/staticpages/functions.inc | 21 +++++++++++++++++++++
public_html/admin/install/lib-upgrade.php | 18 +++++++++++++++---
public_html/admin/install/migrate.php | 13 ++++++++++++-
public_html/docs/history | 6 ++++++
system/lib-plugins.php | 24 ++++++++++++++++++++++--
diffs (truncated from 333 to 300 lines):
diff -r fa9ae71649c2 -r d734244b9ef5 plugins/calendar/functions.inc
--- a/plugins/calendar/functions.inc Sun Mar 22 09:05:08 2009 +0100
+++ b/plugins/calendar/functions.inc Sun Mar 22 10:49:26 2009 +0100
@@ -1464,6 +1464,30 @@
}
/**
+* Called during site migration - handle changed URLs or paths
+*
+* @param array $old_conf contents of the $_CONF array on the old site
+* @param boolean true on success, otherwise false
+*
+*/
+function plugin_migrate_calendar($old_conf)
+{
+ global $_CONF;
+
+ $tables = array(
+ 'events' => 'eid, description, url',
+ 'eventsubmission' => 'eid, description, url',
+ 'personal_events' => 'eid, description, url'
+ );
+
+ if ($old_conf['site_url'] != $_CONF['site_url']) {
+ INST_updateSiteUrl($old_conf['site_url'], $_CONF['site_url'], $tables);
+ }
+
+ return true;
+}
+
+/**
* Geeklog informs us that we're about to be enabled or disabled
*
* @param boolean $enabled true = we're being enabled, false = disabled
diff -r fa9ae71649c2 -r d734244b9ef5 plugins/links/functions.inc
--- a/plugins/links/functions.inc Sun Mar 22 09:05:08 2009 +0100
+++ b/plugins/links/functions.inc Sun Mar 22 10:49:26 2009 +0100
@@ -663,6 +663,30 @@
}
DB_query("UPDATE {$_TABLES['plugins']} SET pi_version = '$code_version', pi_gl_version = '$pi_gl_version' WHERE pi_name = 'links'");
+
+ return true;
+}
+
+/**
+* Called during site migration - handle changed URLs or paths
+*
+* @param array $old_conf contents of the $_CONF array on the old site
+* @param boolean true on success, otherwise false
+*
+*/
+function plugin_migrate_links($old_conf)
+{
+ global $_CONF;
+
+ $tables = array(
+ 'linkcategories' => 'cid, description',
+ 'links' => 'lid, description, url',
+ 'linksubmission' => 'lid, description, url'
+ );
+
+ if ($old_conf['site_url'] != $_CONF['site_url']) {
+ INST_updateSiteUrl($old_conf['site_url'], $_CONF['site_url'], $tables);
+ }
return true;
}
diff -r fa9ae71649c2 -r d734244b9ef5 plugins/polls/functions.inc
--- a/plugins/polls/functions.inc Sun Mar 22 09:05:08 2009 +0100
+++ b/plugins/polls/functions.inc Sun Mar 22 10:49:26 2009 +0100
@@ -1165,6 +1165,30 @@
}
/**
+* Called during site migration - handle changed URLs or paths
+*
+* @param array $old_conf contents of the $_CONF array on the old site
+* @param boolean true on success, otherwise false
+*
+*/
+function plugin_migrate_polls($old_conf)
+{
+ global $_CONF;
+
+ $tables = array(
+ 'pollanswers' => 'aid, answer',
+ 'pollquestions' => 'qid, question',
+ 'polltopics' => 'pid, topic'
+ );
+
+ if ($old_conf['site_url'] != $_CONF['site_url']) {
+ INST_updateSiteUrl($old_conf['site_url'], $_CONF['site_url'], $tables);
+ }
+
+ return true;
+}
+
+/**
* Return information for a poll
*
* @param string $pid poll ID or '*'
diff -r fa9ae71649c2 -r d734244b9ef5 plugins/spamx/functions.inc
--- a/plugins/spamx/functions.inc Sun Mar 22 09:05:08 2009 +0100
+++ b/plugins/spamx/functions.inc Sun Mar 22 10:49:26 2009 +0100
@@ -187,6 +187,34 @@
$pi_gl_version = $inst_parms['info']['pi_gl_version'];
DB_query("UPDATE {$_TABLES['plugins']} SET pi_version = '$code_version', pi_gl_version = '$pi_gl_version' WHERE pi_name = 'spamx'");
+
+ return true;
+}
+
+/**
+* Called during site migration - handle changed URLs or paths
+*
+* @param array $old_conf contents of the $_CONF array on the old site
+* @param boolean true on success, otherwise false
+*
+*/
+function plugin_migrate_spamx($old_conf)
+{
+ global $_CONF, $_TABLES;
+
+ // only update the SLV whitelist, so we don't use INST_updateSiteUrl
+ $old_url = addslashes($old_conf['site_url']);
+ $result = DB_query("SELECT name, value FROM {$_TABLES['spamx']} WHERE name = 'SLVwhitelist' AND value LIKE '{$old_url}%'");
+ $num = DB_numRows($result);
+
+ for ($i = 0; $i < $num; $i++) {
+ list($name, $value) = DB_fetchArray($result);
+ $new_value = addslashes(str_replace($old_conf['site_url'],
+ $_CONF['site_url'], $value));
+ $old_value = addslashes($value);
+
+ DB_query("UPDATE {$_TABLES['spamx']} SET value = '$new_value' WHERE name = 'SLVwhitelist' AND value = '$old_value'");
+ }
return true;
}
diff -r fa9ae71649c2 -r d734244b9ef5 plugins/staticpages/functions.inc
--- a/plugins/staticpages/functions.inc Sun Mar 22 09:05:08 2009 +0100
+++ b/plugins/staticpages/functions.inc Sun Mar 22 10:49:26 2009 +0100
@@ -1011,6 +1011,27 @@
return true;
}
+/**
+* Called during site migration - handle changed URLs or paths
+*
+* @param array $old_conf contents of the $_CONF array on the old site
+* @param boolean true on success, otherwise false
+*
+*/
+function plugin_migrate_staticpages($old_conf)
+{
+ global $_CONF;
+
+ $tables = array(
+ 'staticpage' => 'sp_id, sp_content'
+ );
+
+ if ($old_conf['site_url'] != $_CONF['site_url']) {
+ INST_updateSiteUrl($old_conf['site_url'], $_CONF['site_url'], $tables);
+ }
+
+ return true;
+}
/**
* Automatic uninstall function for plugins
diff -r fa9ae71649c2 -r d734244b9ef5 public_html/admin/install/lib-upgrade.php
--- a/public_html/admin/install/lib-upgrade.php Sun Mar 22 09:05:08 2009 +0100
+++ b/public_html/admin/install/lib-upgrade.php Sun Mar 22 10:49:26 2009 +0100
@@ -786,10 +786,11 @@
* NOTE: Needs a fully working Geeklog, so can only be done late in the upgrade
* process!
*
+* @param boolean $migration whether the upgrade is part of a site migration
* @return int number of failed plugin updates (0 = everything's fine)
*
*/
-function INST_pluginUpgrades()
+function INST_pluginUpgrades($migration = false, $old_conf = array())
{
global $_CONF, $_TABLES;
@@ -803,9 +804,20 @@
$code_version = PLG_chkVersion($pi_name);
if (! empty($code_version) && ($code_version != $pi_version)) {
- if (PLG_upgrade($pi_name) !== true) {
+ $success = true;
+
+ if ($migration) {
+ $success = PLG_migrate($pi_name, $old_conf);
+ }
+
+ if ($success === true) {
+ $success = PLG_upgrade($pi_name);
+ }
+
+ if ($success !== true) {
// upgrade failed - disable plugin
- DB_query("UPDATE {$_TABLES['plugins']} SET pi_enabled = 0 WHERE pi_name = '$pi_name'");
+ DB_change($_TABLES['plugins'], 'pi_enabled', 0,
+ 'pi_name', $pi_name);
COM_errorLog("Upgrade for '$pi_name' plugin failed - plugin disabled");
$failed++;
}
diff -r fa9ae71649c2 -r d734244b9ef5 public_html/admin/install/migrate.php
--- a/public_html/admin/install/migrate.php Sun Mar 22 09:05:08 2009 +0100
+++ b/public_html/admin/install/migrate.php Sun Mar 22 10:49:26 2009 +0100
@@ -48,6 +48,9 @@
* list contains the text fields to be searched and the table's index field
* as the first(!) entry.
*
+* NOTE: This function may be used by plugins during PLG_migrate. Changes should
+* ensure backward compatibility.
+*
*/
function INST_updateSiteUrl($old_url, $new_url, $tablespec = '')
{
@@ -64,6 +67,14 @@
if (empty($tablespec) || (! is_array($tablespec))) {
$tablespec = $tables;
+ }
+
+ if (empty($old_url) || empty($new_url)) {
+ return;
+ }
+
+ if ($old_url == $new_url) {
+ return;
}
foreach ($tablespec as $table => $fieldlist) {
@@ -825,7 +836,7 @@
// We did a database upgrade above. Now that any missing plugins
// have been disabled and we've loaded lib-common.php, perform
// upgrades for the remaining plugins.
- $disabled_plugins = INST_pluginUpgrades();
+ $disabled_plugins = INST_pluginUpgrades(true, $_OLD_CONF);
}
diff -r fa9ae71649c2 -r d734244b9ef5 public_html/docs/history
--- a/public_html/docs/history Sun Mar 22 09:05:08 2009 +0100
+++ b/public_html/docs/history Sun Mar 22 10:49:26 2009 +0100
@@ -11,6 +11,7 @@
+ (TBD) Comment moderation and editable comments, by Jared Wenerd
Other changes:
+- Introduced new plugin API function PLG_migrate [Dirk]
- Allow switching the DOCTYPE from the Configuration. Requires a theme that
uses {doctype} instead of a hard-coded DOCTYPE declaration (feature request
#0000745) [Dirk]
@@ -80,12 +81,14 @@
Calendar plugin
---------------
+- Added migration support [Dirk]
- Removed extra double quote from upcoming events block (bug #0000827)
- Added auto installation support [Dirk]
- Added support for PLG_getItemInfo, PLG_itemSaved, PLG_itemDeleted [Dirk]
Links plugin
------------
+- Added migration support [Dirk]
- Added category default permissions [Dirk]
- Added auto installation support [Dirk]
- Added support for PLG_getItemInfo, PLG_itemSaved, PLG_itemDeleted [Dirk]
@@ -97,6 +100,7 @@
Polls plugin
------------
+- Added migration support [Dirk]
- Set the page title when viewing a poll [Dirk]
- Added auto installation support [Dirk]
- Added support for PLG_getItemInfo, PLG_itemSaved, PLG_itemDeleted [Dirk]
@@ -104,10 +108,12 @@
Spam-X
------
+- Added migration support [Dirk]
- Added auto installation support [Dirk]
Static Pages plugin
-------------------
+- Added migration support [Dirk]
- The printable.thtml template file now uses the {xmlns} variable [Dirk]
- Added canonical link [Dirk]
- Added auto installation support [Dirk]
diff -r fa9ae71649c2 -r d734244b9ef5 system/lib-plugins.php
--- a/system/lib-plugins.php Sun Mar 22 09:05:08 2009 +0100
+++ b/system/lib-plugins.php Sun Mar 22 10:49:26 2009 +0100
@@ -154,13 +154,33 @@
/**
* Upgrades a plugin. Tells a plugin to upgrade itself.
More information about the geeklog-cvs
mailing list