From bfca0c79030d5b8a18e41e8b80f5560ebaf6f202 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Tue, 23 Jun 2009 12:00:49 -0700 Subject: Refactor the install/upgrade code to be more flexible. Add xxx_installer::upgrade($version) method so that upgrade stanzas are separate from install stanzas. In the old code, to do an upgrade meant that you had to re-evolve everything from the initial install because we'd step through each version's changes. But what we really want is for the initial install to start off in the perfect initial state, and the upgrades to do the work behind the scenes. So now the install() function gets things set up properly the first time, and the upgrade() function does any work to catch you up to the latest code. See gallery_installer.php for a good example. --- modules/g2_import/helpers/g2_import_installer.php | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) (limited to 'modules/g2_import/helpers') diff --git a/modules/g2_import/helpers/g2_import_installer.php b/modules/g2_import/helpers/g2_import_installer.php index 5f414d42..0f87da6c 100644 --- a/modules/g2_import/helpers/g2_import_installer.php +++ b/modules/g2_import/helpers/g2_import_installer.php @@ -20,19 +20,16 @@ class g2_import_installer { static function install() { $db = Database::instance(); - $version = module::get_version("g2_import"); - if ($version == 0) { - $db->query("CREATE TABLE IF NOT EXISTS {g2_maps} ( - `id` int(9) NOT NULL auto_increment, - `g2_id` int(9) NOT NULL, - `g3_id` int(9) NOT NULL, - PRIMARY KEY (`id`), - KEY (`g2_id`)) - ENGINE=InnoDB DEFAULT CHARSET=utf8;"); + $db->query("CREATE TABLE IF NOT EXISTS {g2_maps} ( + `id` int(9) NOT NULL auto_increment, + `g2_id` int(9) NOT NULL, + `g3_id` int(9) NOT NULL, + PRIMARY KEY (`id`), + KEY (`g2_id`)) + ENGINE=InnoDB DEFAULT CHARSET=utf8;"); - module::set_version("g2_import", 1); - mkdir(VARPATH . "modules/g2_import"); - } + module::set_version("g2_import", 1); + mkdir(VARPATH . "modules/g2_import"); } static function uninstall() { -- cgit v1.2.3 From 2a190660baeff8cd708926cea79f94f1630418b7 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Tue, 23 Jun 2009 17:09:37 -0700 Subject: Gracefully handle the case when the gallery2 instances moves somewhere else (or gets deleted). Fixes ticket #458 --- modules/g2_import/controllers/admin_g2_import.php | 3 +++ modules/g2_import/helpers/g2_import_task.php | 8 ++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) (limited to 'modules/g2_import/helpers') diff --git a/modules/g2_import/controllers/admin_g2_import.php b/modules/g2_import/controllers/admin_g2_import.php index f2969f49..18d09363 100644 --- a/modules/g2_import/controllers/admin_g2_import.php +++ b/modules/g2_import/controllers/admin_g2_import.php @@ -21,6 +21,9 @@ class Admin_g2_import_Controller extends Admin_Controller { public function index() { if (g2_import::is_configured()) { g2_import::init(); + } + + if (class_exists("GalleryCoreApi")) { $g2_stats = g2_import::stats(); $g2_sizes = g2_import::common_sizes(); } diff --git a/modules/g2_import/helpers/g2_import_task.php b/modules/g2_import/helpers/g2_import_task.php index 4cd95581..3961097d 100644 --- a/modules/g2_import/helpers/g2_import_task.php +++ b/modules/g2_import/helpers/g2_import_task.php @@ -21,15 +21,19 @@ class g2_import_task_Core { static function available_tasks() { if (g2_import::is_configured()) { g2_import::init(); + } + + + if (class_exists("GalleryCoreApi")) { return array(Task_Definition::factory() ->callback("g2_import_task::import") ->name(t("Import from Gallery 2")) ->description( t("Gallery %version detected", array("version" => g2_import::version()))) ->severity(log::SUCCESS)); - } else { - return array(); } + + return array(); } static function import($task) { -- cgit v1.2.3 From 53284ec5b892915c5905ea4f1e3fe76b18d3b576 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Tue, 23 Jun 2009 18:39:00 -0700 Subject: Add support for Gallery 2.2.2 style bootstrap syntax. --- modules/g2_import/helpers/g2_import.php | 2 ++ 1 file changed, 2 insertions(+) (limited to 'modules/g2_import/helpers') diff --git a/modules/g2_import/helpers/g2_import.php b/modules/g2_import/helpers/g2_import.php index 2eee564a..91ca1e63 100644 --- a/modules/g2_import/helpers/g2_import.php +++ b/modules/g2_import/helpers/g2_import.php @@ -113,11 +113,13 @@ class g2_import_Core { "require_once(dirname(__FILE__) . '/modules/core/classes/GalleryDataCache.class');", "define('GALLERY_CONFIG_DIR', dirname(__FILE__));", "\$gallery =& new Gallery();", + "\$GLOBALS['gallery'] =& new Gallery();", "\$gallery = new Gallery();"), array("require_once(dirname(__FILE__) . '/Gallery.class');", "require_once('$base_dir/modules/core/classes/GalleryDataCache.class');", "define('GALLERY_CONFIG_DIR', '$config_dir');", "\$gallery =& new G2_Gallery();", + "\$GLOBALS['gallery'] =& new G2_Gallery();", "\$gallery = new G2_Gallery();"), array_merge(array("\n"), file("$base_dir/bootstrap.inc")))); -- cgit v1.2.3