From 82593cd2bc056da73caa1b1e981c5a9ead0f1bf2 Mon Sep 17 00:00:00 2001 From: brettp Date: Wed, 27 Apr 2011 02:37:16 +0000 Subject: Refs #3362. Plugins don't check deps upon boot. Made package and manifest private properties of ElggPlugin and added ->getPackage() and ->getManifest(). git-svn-id: http://code.elgg.org/elgg/trunk@9030 36083f99-b078-4883-b0ff-0f9b5a30f544 --- engine/classes/ElggPlugin.php | 74 +++++++++++++++++++++++++++++-------------- 1 file changed, 51 insertions(+), 23 deletions(-) (limited to 'engine/classes/ElggPlugin.php') diff --git a/engine/classes/ElggPlugin.php b/engine/classes/ElggPlugin.php index 20a8673de..eb911455a 100644 --- a/engine/classes/ElggPlugin.php +++ b/engine/classes/ElggPlugin.php @@ -9,8 +9,8 @@ * @subpackage Plugins.Settings */ class ElggPlugin extends ElggObject { - public $package; - public $manifest; + private $package; + private $manifest; private $path; private $pluginID; @@ -76,18 +76,6 @@ class ElggPlugin extends ElggObject { // load the rest of the plugin parent::__construct($existing_guid); } - - // We have to let the entity load so we can manipulate it with the API. - // If the path is wrong or would cause an exception, catch it, - // disable the plugin, and emit an error. - try { - $this->package = new ElggPluginPackage($this->path, false); - $this->manifest = $this->package->getManifest(); - } catch (Exception $e) { - // we always have to allow the entity to load. - elgg_log("Failed to load $this->guid as a plugin. " . $e->getMessage(), 'WARNING'); - $this->errorMsg = $e->getmessage(); - } } /** @@ -152,7 +140,7 @@ class ElggPlugin extends ElggObject { * @return array */ public function getAvailableTextFiles() { - $filenames = $this->package->getTextFilenames(); + $filenames = $this->getPackage()->getTextFilenames(); $files = array(); foreach ($filenames as $filename) { @@ -562,13 +550,13 @@ class ElggPlugin extends ElggObject { return false; } - if (!$this->package instanceof ElggPluginPackage) { + if (!$this->getPackage() instanceof ElggPluginPackage) { $this->errorMsg = elgg_echo('ElggPlugin:NoPluginPackagePackage', array($this->getID(), $this->guid)); return false; } - if (!$this->package->isValid()) { - $this->errorMsg = $this->package->getError(); + if (!$this->getPackage()->isValid()) { + $this->errorMsg = $this->getPackage()->getError(); return false; } @@ -607,8 +595,8 @@ class ElggPlugin extends ElggObject { * @return bool */ public function canActivate($site_guid = null) { - if ($this->package) { - return $this->package->isValid() && $this->package->checkDependencies(); + if ($this->getPackage()) { + return $this->getPackage()->isValid() && $this->getPackage()->checkDependencies(); } return false; @@ -708,9 +696,9 @@ class ElggPlugin extends ElggObject { * @throws PluginException */ public function start($flags) { - if (!$this->canActivate()) { - return false; - } +// if (!$this->canActivate()) { +// return false; +// } // include start file if ($flags & ELGG_PLUGIN_INCLUDE_START) { @@ -958,4 +946,44 @@ class ElggPlugin extends ElggObject { public function getError() { return $this->errorMsg; } + + /** + * Returns this plugin's ElggPluginManifest object + * + * @return ElggPluginManifest + */ + public function getManifest() { + if ($this->manifest instanceof ElggPluginManifest) { + return $this->manifest; + } + + try { + $this->manifest = $this->getPackage()->getManifest(); + } catch (Exception $e) { + elgg_log("Failed to load manifest for plugin $this->guid. " . $e->getMessage(), 'WARNING'); + $this->errorMsg = $e->getmessage(); + } + + return $this->manifest; + } + + /** + * Returns this plugin's ElggPluginPackage object + * + * @return ElggPluginPackage + */ + public function getPackage() { + if ($this->package instanceof ElggPluginPackage) { + return $this->package; + } + + try { + $this->package = new ElggPluginPackage($this->path, false); + } catch (Exception $e) { + elgg_log("Failed to load package for $this->guid. " . $e->getMessage(), 'WARNING'); + $this->errorMsg = $e->getmessage(); + } + + return $this->package; + } } -- cgit v1.2.3 From 81d6884ecad771f4b4f2d8be7572d1a89deaab10 Mon Sep 17 00:00:00 2001 From: cash Date: Thu, 19 May 2011 11:21:53 +0000 Subject: Fixes #3462 empty classes directory is no longer treated as an error git-svn-id: http://code.elgg.org/elgg/trunk@9100 36083f99-b078-4883-b0ff-0f9b5a30f544 --- engine/classes/ElggPlugin.php | 7 +------ engine/lib/elgglib.php | 8 +------- languages/en.php | 1 - 3 files changed, 2 insertions(+), 14 deletions(-) (limited to 'engine/classes/ElggPlugin.php') diff --git a/engine/classes/ElggPlugin.php b/engine/classes/ElggPlugin.php index eb911455a..95a7362e2 100644 --- a/engine/classes/ElggPlugin.php +++ b/engine/classes/ElggPlugin.php @@ -839,12 +839,7 @@ class ElggPlugin extends ElggObject { return true; } - // but need to have working ones. - if (!elgg_register_classes($classes_path)) { - $msg = elgg_echo('ElggPlugin:Exception:CannotRegisterClasses', - array($this->getID(), $this->guid, $classes_path)); - throw new PluginException($msg); - } + elgg_register_classes($classes_path); return true; } diff --git a/engine/lib/elgglib.php b/engine/lib/elgglib.php index e67f8b627..170750849 100644 --- a/engine/lib/elgglib.php +++ b/engine/lib/elgglib.php @@ -33,21 +33,15 @@ function _elgg_autoload($class) { * * @param string $dir The dir to look in * - * @return true + * @return void * @since 1.8.0 */ function elgg_register_classes($dir) { $classes = elgg_get_file_list($dir, array(), array(), array('.php')); - if (!$classes) { - return false; - } - foreach ($classes as $class) { elgg_register_class(basename($class, '.php'), $class); } - - return true; } /** diff --git a/languages/en.php b/languages/en.php index ec39f64a9..768658c99 100644 --- a/languages/en.php +++ b/languages/en.php @@ -81,7 +81,6 @@ $english = array( 'ElggPlugin:Exception:CannotIncludeFile' => 'Cannot include %s for plugin %s (guid: %s) at %s. Check permissions!', 'ElggPlugin:Exception:CannotRegisterViews' => 'Cannot open views dir for plugin %s (guid: %s) at %s. Check permissions!', 'ElggPlugin:Exception:CannotRegisterLanguages' => 'Cannot register languages for plugin %s (guid: %s) at %s. Check permissions!', - 'ElggPlugin:Exception:CannotRegisterClasses' => 'Cannot register classes for plugin %s (guid: %s) at %s. Check permissions!', 'ElggPlugin:Exception:NoID' => 'No ID for plugin guid %s!', 'PluginException:ParserError' => 'Error parsing manifest with API version %s in plugin %s.', -- cgit v1.2.3