diff options
Diffstat (limited to 'modules')
-rw-r--r-- | modules/exif/helpers/exif.php | 4 | ||||
-rw-r--r-- | modules/exif/tests/Exif_Test.php | 2 | ||||
-rw-r--r-- | modules/gallery/helpers/module.php | 42 | ||||
-rw-r--r-- | modules/gallery_unit_test/controllers/gallery_unit_test.php | 79 |
4 files changed, 72 insertions, 55 deletions
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) { 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"), diff --git a/modules/gallery/helpers/module.php b/modules/gallery/helpers/module.php index ad46b2ff..2fd5be6c 100644 --- a/modules/gallery/helpers/module.php +++ b/modules/gallery/helpers/module.php @@ -107,16 +107,17 @@ 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"; 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_pop($kohana_modules); + array_shift($kohana_modules); Kohana::config_set("core.modules", $kohana_modules); log::success( @@ -131,7 +132,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"; @@ -144,16 +145,17 @@ class module_Core { $module->active = true; $module->save(); } + module::load_modules(); - 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 <module>_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 <module>_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) { @@ -167,8 +169,8 @@ class module_Core { $module->active = false; $module->save(); } + module::load_modules(); - self::load_modules(); graphics::deactivate_rules($module_name); log::success( "module", t("Deactivated module %module_name", array("module_name" => $module_name))); @@ -190,11 +192,11 @@ 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. - self::load_modules(); log::success( "module", t("Uninstalled module %module_name", array("module_name" => $module_name))); } @@ -203,23 +205,25 @@ 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")->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; - // @todo: force 'gallery' to be at the end } - - Kohana::config_set("core.modules", $kohana_modules); + 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"))); } /** diff --git a/modules/gallery_unit_test/controllers/gallery_unit_test.php b/modules/gallery_unit_test/controllers/gallery_unit_test.php index c1457b12..56220a19 100644 --- a/modules/gallery_unit_test/controllers/gallery_unit_test.php +++ b/modules/gallery_unit_test/controllers/gallery_unit_test.php @@ -69,48 +69,57 @@ 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(); + // 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(); - 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"; + } } } |