From 7fd6fcaf9b4d814455758963acf1236034494362 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Thu, 28 May 2009 17:46:17 -0700 Subject: Force modules/gallery to be at the end of the module load path, so that all other modules can override the core code. --- modules/gallery/helpers/module.php | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) (limited to 'modules') diff --git a/modules/gallery/helpers/module.php b/modules/gallery/helpers/module.php index ad46b2ff..d684033b 100644 --- a/modules/gallery/helpers/module.php +++ b/modules/gallery/helpers/module.php @@ -107,7 +107,7 @@ class module_Core { */ static function install($module_name) { $kohana_modules = Kohana::config("core.modules"); - $kohana_modules[] = MODPATH . $module_name; + array_unshift($kohana_modules, MODPATH . $module_name); Kohana::config_set("core.modules", $kohana_modules); $installer_class = "{$module_name}_installer"; @@ -116,7 +116,7 @@ class module_Core { } // Now the module is installed but inactive, so don't leave it in the active path - array_pop($kohana_modules); + array_shift($kohana_modules); Kohana::config_set("core.modules", $kohana_modules); log::success( @@ -131,7 +131,7 @@ class module_Core { */ static function activate($module_name) { $kohana_modules = Kohana::config("core.modules"); - $kohana_modules[] = MODPATH . $module_name; + array_unshift($kohana_modules, MODPATH . $module_name); Kohana::config_set("core.modules", $kohana_modules); $installer_class = "{$module_name}_installer"; @@ -145,15 +145,15 @@ class module_Core { $module->save(); } - self::load_modules(); graphics::activate_rules($module_name); log::success( "module", t("Activated module %module_name", array("module_name" => $module_name))); } /** - * Deactivate an installed module. This will call _installer::deactivate() which - * should take any cleanup steps to make sure that the module isn't visible in any way. + * Deactivate an installed module. This will call _installer::deactivate() which should + * take any cleanup steps to make sure that the module isn't visible in any way. Note that the + * module remains available in Kohana's cascading file system until the end of the request! * @param string $module_name */ static function deactivate($module_name) { @@ -168,7 +168,6 @@ class module_Core { $module->save(); } - self::load_modules(); graphics::deactivate_rules($module_name); log::success( "module", t("Deactivated module %module_name", array("module_name" => $module_name))); @@ -194,7 +193,6 @@ class module_Core { // We could delete the module vars here too, but it's nice to leave them around // in case the module gets reinstalled. - self::load_modules(); log::success( "module", t("Uninstalled module %module_name", array("module_name" => $module_name))); } @@ -203,23 +201,19 @@ class module_Core { * Load the active modules. This is called at bootstrap time. */ static function load_modules() { - // Reload module list from the config file since we'll do a refresh after calling install() - $core = Kohana::config_load("core"); - $kohana_modules = $core["modules"]; - $modules = ORM::factory("module")->find_all(); - self::$modules = array(); self::$active = array(); - foreach ($modules as $module) { + $kohana_modules = array(); + foreach (ORM::factory("module")->where("name <>", "gallery")->find_all() as $module) { self::$modules[$module->name] = $module; if ($module->active) { self::$active[] = $module; } $kohana_modules[] = MODPATH . $module->name; - // @todo: force 'gallery' to be at the end } - Kohana::config_set("core.modules", $kohana_modules); + Kohana::config_set( + "core.modules", array_merge($kohana_modules, Kohana::config("core.modules"))); } /** -- cgit v1.2.3 From 3da5ee2f4c46947d8fcd5fe54d012ec3d6fa7312 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Thu, 28 May 2009 18:21:39 -0700 Subject: Print out exception traces for most errors --- .../controllers/gallery_unit_test.php | 75 ++++++++++++---------- 1 file changed, 40 insertions(+), 35 deletions(-) (limited to 'modules') diff --git a/modules/gallery_unit_test/controllers/gallery_unit_test.php b/modules/gallery_unit_test/controllers/gallery_unit_test.php index c1457b12..d0760332 100644 --- a/modules/gallery_unit_test/controllers/gallery_unit_test.php +++ b/modules/gallery_unit_test/controllers/gallery_unit_test.php @@ -69,48 +69,53 @@ class Gallery_Unit_Test_Controller extends Controller { } } - // Find all tests, excluding sample tests that come with the unit_test module. - foreach (glob(MODPATH . "*/tests") as $path) { - if ($path != MODPATH . "unit_test/tests") { - $paths[] = $path; + try { + // Find all tests, excluding sample tests that come with the unit_test module. + foreach (glob(MODPATH . "*/tests") as $path) { + if ($path != MODPATH . "unit_test/tests") { + $paths[] = $path; + } } - } - Kohana::config_set('unit_test.paths', $paths); + Kohana::config_set('unit_test.paths', $paths); - // Clean out the database - if ($tables = $db->list_tables()) { - foreach ($db->list_tables() as $table) { - $db->query("DROP TABLE $table"); + // Clean out the database + if ($tables = $db->list_tables()) { + foreach ($db->list_tables() as $table) { + $db->query("DROP TABLE $table"); + } } - } - // Clean out the filesystem - @system("rm -rf test/var"); - @mkdir('test/var/logs', 0777, true); + // Clean out the filesystem + @system("rm -rf test/var"); + @mkdir('test/var/logs', 0777, true); - // Reset our caches - module::$modules = array(); - module::$active = array(); - module::$var_cache = array(); - $db->clear_cache(); + // Reset our caches + module::$modules = array(); + module::$active = array(); + module::$var_cache = array(); + $db->clear_cache(); - // Install all modules - // Force gallery and user to be installed first to resolve dependencies. - gallery_installer::install(true); - module::load_modules(); - module::install("user"); - module::activate("user"); - $modules = array(); - foreach (glob(MODPATH . "*/helpers/*_installer.php") as $file) { - $module_name = basename(dirname(dirname($file))); - if (in_array($module_name, array("gallery", "user"))) { - continue; + // Install all modules + // Force gallery and user to be installed first to resolve dependencies. + gallery_installer::install(true); + module::load_modules(); + module::install("user"); + module::activate("user"); + $modules = array(); + foreach (glob(MODPATH . "*/helpers/*_installer.php") as $file) { + $module_name = basename(dirname(dirname($file))); + if (in_array($module_name, array("gallery", "user"))) { + continue; + } + module::install($module_name); + module::activate($module_name); } - module::install($module_name); - module::activate($module_name); - } - $filter = count($_SERVER["argv"]) > 2 ? $_SERVER["argv"][2] : null; - print new Unit_Test($modules, $filter); + $filter = count($_SERVER["argv"]) > 2 ? $_SERVER["argv"][2] : null; + print new Unit_Test($modules, $filter); + } catch (Exception $e) { + print "Exception: {$e->getMessage()}\n"; + print $e->getTraceAsString() . "\n"; + } } } -- cgit v1.2.3 From 20a2d9f9a8bc0f69b3ebef846a88869870e4e0c4 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Thu, 28 May 2009 20:59:23 -0700 Subject: Reset the cascading file path properly before reinstalling. --- modules/gallery_unit_test/controllers/gallery_unit_test.php | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'modules') diff --git a/modules/gallery_unit_test/controllers/gallery_unit_test.php b/modules/gallery_unit_test/controllers/gallery_unit_test.php index d0760332..56220a19 100644 --- a/modules/gallery_unit_test/controllers/gallery_unit_test.php +++ b/modules/gallery_unit_test/controllers/gallery_unit_test.php @@ -95,10 +95,14 @@ class Gallery_Unit_Test_Controller extends Controller { module::$var_cache = array(); $db->clear_cache(); + // Rest the cascading class path + Kohana::config_set("core", Kohana::config_load("core")); + // Install all modules // Force gallery and user to be installed first to resolve dependencies. gallery_installer::install(true); module::load_modules(); + module::install("user"); module::activate("user"); $modules = array(); -- cgit v1.2.3 From d088a41747af4f0da93d8a3ba926d557f157b507 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Thu, 28 May 2009 21:00:06 -0700 Subject: Load the gallery module in load_modules(), but put it at the end of the module list (to match its location in the cascading filesystem) --- modules/gallery/helpers/module.php | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'modules') diff --git a/modules/gallery/helpers/module.php b/modules/gallery/helpers/module.php index d684033b..8abfa36d 100644 --- a/modules/gallery/helpers/module.php +++ b/modules/gallery/helpers/module.php @@ -204,14 +204,20 @@ class module_Core { self::$modules = array(); self::$active = array(); $kohana_modules = array(); - foreach (ORM::factory("module")->where("name <>", "gallery")->find_all() as $module) { + foreach (ORM::factory("module")->find_all() as $module) { self::$modules[$module->name] = $module; - if ($module->active) { + if (!$module->active) { + continue; + } + + if ($module->name == "gallery") { + $gallery = $module; + } else { self::$active[] = $module; + $kohana_modules[] = MODPATH . $module->name; } - $kohana_modules[] = MODPATH . $module->name; } - + self::$active[] = $gallery; // put gallery last in the module list to match core.modules Kohana::config_set( "core.modules", array_merge($kohana_modules, Kohana::config("core.modules"))); } -- cgit v1.2.3 From 73f348b29efea0100b24b31f637c77ceca44911c Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Thu, 28 May 2009 21:07:47 -0700 Subject: Protect get() against missing records. --- modules/exif/helpers/exif.php | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'modules') diff --git a/modules/exif/helpers/exif.php b/modules/exif/helpers/exif.php index c488bbd4..970be5ac 100644 --- a/modules/exif/helpers/exif.php +++ b/modules/exif/helpers/exif.php @@ -88,6 +88,10 @@ class exif_Core { $record = ORM::factory("exif_record") ->where("item_id", $item->id) ->find(); + if (!$record->loaded) { + return array(); + } + $definitions = self::_keys(); $keys = unserialize($record->data); foreach ($keys as $key => $value) { -- cgit v1.2.3 From c4c70c537d1d72ad5e476190c069270450fa7048 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Thu, 28 May 2009 21:13:49 -0700 Subject: Tweak path slightly --- modules/exif/tests/Exif_Test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'modules') diff --git a/modules/exif/tests/Exif_Test.php b/modules/exif/tests/Exif_Test.php index aa76d036..312ed535 100644 --- a/modules/exif/tests/Exif_Test.php +++ b/modules/exif/tests/Exif_Test.php @@ -22,7 +22,7 @@ class Exif_Test extends Unit_Test_Case { $rand = rand(); $root = ORM::factory("item", 1); $photo = photo::create( - $root, DOCROOT . "modules/exif/tests/data/image.jpg", "$rand.jpg", $rand, $rand); + $root, MODPATH . "exif/tests/data/image.jpg", "$rand.jpg", $rand, $rand); $expected = array( array("caption" => "Camera Maker", "value" => "Pentax Corporation"), -- cgit v1.2.3 From 356bac0db0dca5d2b8102b31b6c6b9509f595c29 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Thu, 28 May 2009 21:18:46 -0700 Subject: Restore calls to module::load_modules() after install/activate/deactivate/uninstall events. --- modules/gallery/helpers/module.php | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'modules') diff --git a/modules/gallery/helpers/module.php b/modules/gallery/helpers/module.php index 8abfa36d..2fd5be6c 100644 --- a/modules/gallery/helpers/module.php +++ b/modules/gallery/helpers/module.php @@ -114,6 +114,7 @@ class module_Core { if (method_exists($installer_class, "install")) { call_user_func_array(array($installer_class, "install"), array()); } + module::load_modules(); // Now the module is installed but inactive, so don't leave it in the active path array_shift($kohana_modules); @@ -144,6 +145,7 @@ class module_Core { $module->active = true; $module->save(); } + module::load_modules(); graphics::activate_rules($module_name); log::success( @@ -167,6 +169,7 @@ class module_Core { $module->active = false; $module->save(); } + module::load_modules(); graphics::deactivate_rules($module_name); log::success( @@ -189,6 +192,7 @@ class module_Core { if ($module->loaded) { $module->delete(); } + module::load_modules(); // We could delete the module vars here too, but it's nice to leave them around // in case the module gets reinstalled. -- cgit v1.2.3