diff options
author | Bharat Mediratta <bharat@menalto.com> | 2009-05-28 21:42:18 -0700 |
---|---|---|
committer | Bharat Mediratta <bharat@menalto.com> | 2009-05-28 21:42:18 -0700 |
commit | 0097803efc1c71711bf9ccf5015fe43e75f8f28d (patch) | |
tree | b48e0013b55601d4d856350a3213880a424911ea | |
parent | f56e095aeb6e5544360136a48373300f3cecb715 (diff) | |
parent | 356bac0db0dca5d2b8102b31b6c6b9509f595c29 (diff) |
Merge branch 'master' of git://github.com/gallery/gallery3
-rw-r--r-- | application/config/config.php | 2 | ||||
-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 | ||||
-rw-r--r-- | system/core/Kohana.php | 38 |
6 files changed, 91 insertions, 76 deletions
diff --git a/application/config/config.php b/application/config/config.php index 92886dbe..d6da2ad1 100644 --- a/application/config/config.php +++ b/application/config/config.php @@ -119,7 +119,7 @@ $config['extension_prefix'] = 'MY_'; */ $config['modules'] = array( MODPATH . 'forge', - MODPATH . 'gallery', + MODPATH . 'gallery', // gallery must be *last* in the order ); if (TEST_MODE) { 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"; + } } } diff --git a/system/core/Kohana.php b/system/core/Kohana.php index ac64b5b8..95e44d82 100644 --- a/system/core/Kohana.php +++ b/system/core/Kohana.php @@ -298,7 +298,8 @@ final class Kohana { { if ($process === TRUE) { - self::$include_paths = array(); + // Add APPPATH as the first path + self::$include_paths = array(APPPATH); foreach (self::$configuration['core']['modules'] as $path) { @@ -309,9 +310,6 @@ final class Kohana { } } - // Add APPPATH after all modules - self::$include_paths[] = APPPATH; - // Add SYSPATH as the last path self::$include_paths[] = SYSPATH; } @@ -813,14 +811,14 @@ final class Kohana { { // PHP errors have 5 args, always $PHP_ERROR = (func_num_args() === 5); - + // Test to see if errors should be displayed if ($PHP_ERROR AND (error_reporting() & $exception) === 0) return; - + // This is useful for hooks to determine if a page has an error self::$has_error = TRUE; - + // Error handling will use exactly 5 args, every time if ($PHP_ERROR) { @@ -837,11 +835,11 @@ final class Kohana { $line = $exception->getLine(); $template = ($exception instanceof Kohana_Exception) ? $exception->getTemplate() : 'kohana_error_page'; } - + if (is_numeric($code)) { $codes = self::lang('errors'); - + if ( ! empty($codes[$code])) { list($level, $error, $description) = $codes[$code]; @@ -860,22 +858,22 @@ final class Kohana { $error = $code; $description = ''; } - + // Remove the DOCROOT from the path, as a security precaution $file = str_replace('\\', '/', realpath($file)); $file = preg_replace('|^'.preg_quote(DOCROOT).'|', '', $file); - + if ($level <= self::$configuration['core']['log_threshold']) { // Log the error self::log('error', self::lang('core.uncaught_exception', $type, $message, $file, $line)); } - + if ($PHP_ERROR) { $description = self::lang('errors.'.E_RECOVERABLE_ERROR); $description = is_array($description) ? $description[2] : ''; - + if ( ! headers_sent()) { // Send the 500 header @@ -890,13 +888,13 @@ final class Kohana { $exception->sendHeaders(); } } - + while (ob_get_level() > self::$buffer_level) { // Close open buffers ob_end_clean(); } - + // Test if display_errors is on if (self::$configuration['core']['display_errors'] === TRUE) { @@ -904,11 +902,11 @@ final class Kohana { { // Remove the first entry of debug_backtrace(), it is the exception_handler call $trace = $PHP_ERROR ? array_slice(debug_backtrace(), 1) : $exception->getTrace(); - + // Beautify backtrace $trace = self::backtrace($trace); } - + // Load the error require self::find_file('views', empty($template) ? 'kohana_error_page' : $template); } @@ -917,17 +915,17 @@ final class Kohana { // Get the i18n messages $error = self::lang('core.generic_error'); $message = self::lang('core.errors_disabled', url::site(), url::site(Router::$current_uri)); - + // Load the errors_disabled view require self::find_file('views', 'kohana_error_disabled'); } - + if ( ! Event::has_run('system.shutdown')) { // Run the shutdown even to ensure a clean exit Event::run('system.shutdown'); } - + // Turn off error reporting error_reporting(0); exit; |