]> gitweb.fluxo.info Git - lorea/elgg.git/commitdiff
Refs #3362. Plugins don't check deps upon boot. Made package and manifest private...
authorbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>
Wed, 27 Apr 2011 02:37:16 +0000 (02:37 +0000)
committerbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>
Wed, 27 Apr 2011 02:37:16 +0000 (02:37 +0000)
git-svn-id: http://code.elgg.org/elgg/trunk@9030 36083f99-b078-4883-b0ff-0f9b5a30f544

21 files changed:
actions/admin/plugins/activate.php
actions/admin/plugins/activate_all.php
actions/admin/plugins/deactivate.php
actions/admin/plugins/deactivate_all.php
actions/admin/plugins/set_priority.php
actions/admin/plugins/simple_update_states.php
actions/plugins/settings/save.php
actions/plugins/usersettings/save.php
engine/classes/ElggPlugin.php
engine/classes/ElggPluginPackage.php
engine/lib/admin.php
engine/lib/deprecated-1.8.php
engine/lib/plugins.php
install/ElggInstaller.php
views/default/admin/plugin_settings.php
views/default/admin/plugins/advanced.php
views/default/core/settings/tools.php
views/default/forms/admin/plugins/simple_update_states.php
views/default/object/plugin/advanced.php
views/default/object/plugin/elements/dependencies.php
views/default/object/plugin/simple.php

index 0d930b27f606c8b1bcc6aecb5dacffb6418fa4dd..e04ee6298420a8d56fd4eb4ac525c9c891fbd049 100644 (file)
@@ -29,7 +29,7 @@ foreach ($plugin_guids as $guid) {
        if ($plugin->activate()) {
                $activated_guids[] = $guid;
        } else {
-               register_error(elgg_echo('admin:plugins:activate:no', array($plugin->manifest->getName())));
+               register_error(elgg_echo('admin:plugins:activate:no', array($plugin->getManifest()->getName())));
        }
 }
 
index 25802ce2ee2b4b7edd8b7e9014121ce1d46eaa15..0f03528775d448e6882a46dc59bef45ec663185c 100644 (file)
@@ -13,9 +13,9 @@ $plugins = elgg_get_plugins('inactive');
 
 foreach ($plugins as $plugin) {
        if ($plugin->activate()) {
-               //system_message(elgg_echo('admin:plugins:activate:yes', array($plugin->manifest->getName())));
+               //system_message(elgg_echo('admin:plugins:activate:yes', array($plugin->getManifest()->getName())));
        } else {
-               register_error(elgg_echo('admin:plugins:activate:no', array($plugin->manifest->getName())));
+               register_error(elgg_echo('admin:plugins:activate:no', array($plugin->getManifest()->getName())));
        }
 }
 
index 74c78e0fcdeef20dfbffe39f253e824bfeb9db7d..9ec620e1319bd92e89156ddc4ed3d25340fa50e2 100644 (file)
@@ -26,9 +26,9 @@ foreach ($plugin_guids as $guid) {
        }
 
        if ($plugin->deactivate()) {
-               //system_message(elgg_echo('admin:plugins:deactivate:yes', array($plugin->manifest->getName())));
+               //system_message(elgg_echo('admin:plugins:deactivate:yes', array($plugin->getManifest()->getName())));
        } else {
-               register_error(elgg_echo('admin:plugins:deactivate:no', array($plugin->manifest->getName())));
+               register_error(elgg_echo('admin:plugins:deactivate:no', array($plugin->getManifest()->getName())));
        }
 }
 
index f1bea0a2c70374b349c5865d448198eb1d9b9fdf..446cad8c089f965382071776c6054b05e053b59d 100644 (file)
@@ -13,9 +13,9 @@ $plugins = elgg_get_plugins('active');
 
 foreach ($plugins as $plugin) {
        if ($plugin->deactivate()) {
-               //system_message(elgg_echo('admin:plugins:deactivate:yes', array($plugin->manifest->getName())));
+               //system_message(elgg_echo('admin:plugins:deactivate:yes', array($plugin->getManifest()->getName())));
        } else {
-               register_error(elgg_echo('admin:plugins:deactivate:no', array($plugin->manifest->getName())));
+               register_error(elgg_echo('admin:plugins:deactivate:no', array($plugin->getManifest()->getName())));
        }
 }
 
index fd7857e49175b55971477e44db6cd0d57cebf46b..702aae91b09c25a1f7952c19ee16c135200cd08d 100644 (file)
@@ -25,9 +25,9 @@ if (!($plugin instanceof ElggPlugin)) {
 }
 
 if ($plugin->setPriority($priority)) {
-       //system_message(elgg_echo('admin:plugins:set_priority:yes', array($plugin->manifest->getName())));
+       //system_message(elgg_echo('admin:plugins:set_priority:yes', array($plugin->getManifest()->getName())));
 } else {
-       register_error(elgg_echo('admin:plugins:set_priority:no', array($plugin->manifest->getName())));
+       register_error(elgg_echo('admin:plugins:set_priority:no', array($plugin->getManifest()->getName())));
 }
 
 // don't regenerate the simplecache because the plugin won't be
index 662a5c3dd87c724e8c25c304418147be22d96f38..7601013a796b9c535239fe7796221bcca4b852d0 100644 (file)
@@ -22,7 +22,7 @@ $success = TRUE;
 
 foreach ($installed_plugins as $plugin) {
        // this is only for simple plugins.
-       if ($plugin->manifest->getAdminInterface() != 'simple') {
+       if ($plugin->getManifest()->getAdminInterface() != 'simple') {
                continue;
        }
 
index f3c865b9f7bc831db62ce5a703ff9ee0cdb3b693..3b5694039fcb36c53d8270adc9fc390d731c40f6 100644 (file)
@@ -21,7 +21,7 @@ if (!($plugin instanceof ElggPlugin)) {
        forward(REFERER);
 }
 
-$plugin_name = $plugin->manifest->getName();
+$plugin_name = $plugin->getManifest()->getName();
 
 $result = false;
 
index 9c1657388ba6ab978fa6bc1ba679f95448f441b1..c6214f68dedcd7ba0b3fc4df00a54fe37ce96ef6 100644 (file)
@@ -29,7 +29,7 @@ if (!($user instanceof ElggUser)) {
        forward(REFERER);
 }
 
-$plugin_name = $plugin->manifest->getName();
+$plugin_name = $plugin->getManifest()->getName();
 
 // make sure we're admin or the user
 if (!$user->canEdit()) {
index 20a8673dea2d7e6834bb4fd9f6ef5211b91540c0..eb911455aab8ee7cc09948f1e1bb6cd901adad22 100644 (file)
@@ -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;
+       }
 }
index 4daab381efbd6afde9486f2c2ad3b7d51bff9d38..bad99362f7f569c04457189544d4863fce585f53 100644 (file)
@@ -334,13 +334,13 @@ class ElggPluginPackage {
 
                // first, check if any active plugin conflicts with us.
                foreach ($enabled_plugins as $plugin) {
-                       $temp_conflicts = $plugin->manifest->getConflicts();
+                       $temp_conflicts = $plugin->getManifest()->getConflicts();
                        foreach ($temp_conflicts as $conflict) {
                                if ($conflict['type'] == 'plugin' && $conflict['name'] == $this_id) {
                                        $result = $this->checkDepPlugin($conflict, $enabled_plugins, false);
 
                                        // rewrite the conflict to show the originating plugin
-                                       $conflict['name'] = $plugin->manifest->getName();
+                                       $conflict['name'] = $plugin->getManifest()->getName();
 
                                        if (!$full_report && !$result['status']) {
                                                return $result['status'];
index 06418c44fe03f0ee76d62080459901f630888543..61f64c8b3174cdf5cd0b9e6e2ba1e0f4651da253 100644 (file)
@@ -329,7 +329,7 @@ function elgg_admin_add_plugin_settings_menu() {
                        elgg_register_menu_item('page', array(
                                'name' => $plugin_id,
                                'href' => "admin/plugin_settings/$plugin_id",
-                               'text' => $plugin->manifest->getName(),
+                               'text' => $plugin->getManifest()->getName(),
                                'parent_name' => 'settings',
                                'context' => 'admin',
                                'section' => 'configure',
@@ -541,7 +541,7 @@ function admin_markdown_page_handler($pages) {
                return true;
        }
 
-       $title = $plugin->manifest->getName() . ": $filename";
+       $title = $plugin->getManifest()->getName() . ": $filename";
        $text = Markdown($file_contents);
 
        $body = elgg_view_layout('admin', array(
index bb52881cd1f50e2b8a311f07af8e5c67146b5b9f..595b12aea335f0d544be28890a4a71b4e2cd1177 100644 (file)
@@ -1667,7 +1667,7 @@ function get_installed_plugins($status = 'all') {
                if ($include) {
                        $installed_plugins[$plugin->getID()] = array(
                                'active' => $plugin->isActive(),
-                               'manifest' => $plugin->manifest->getManifest()
+                               'manifest' => $plugin->getManifest()->getManifest()
                        );
                }
        }
index 0947b7a8e326191bac46874bb7c359c176ea0b1c..5aed3065af9ade8b123760abdbc38447a664e16f 100644 (file)
@@ -266,9 +266,9 @@ function elgg_is_active_plugin($plugin_id, $site_guid = null) {
 /**
  * Loads all active plugins in the order specified in the tool admin panel.
  *
- * @note This is called on every page load and includes additional checking that plugins
- * are fit to be loaded.  If a plugin is active and problematic, it will be disabled
- * and a visible error emitted.
+ * @note This is called on every page load. If a plugin is active and problematic, it
+ * will be disabled and a visible error emitted. This does not check the deps system because
+ * that was too slow.
  *
  * @return bool
  */
@@ -307,17 +307,6 @@ function elgg_load_plugins() {
        $plugins = elgg_get_plugins('active');
        if ($plugins) {
                foreach ($plugins as $plugin) {
-                       // check if plugin can be started and try to start it.
-                       // if anything is bad, disable it and emit a message.
-                       if (!$plugin->isValid()) {
-                               $plugin->deactivate();
-                               $msg = elgg_echo('PluginException:MisconfiguredPlugin', array($plugin->getID(), $plugin->guid));
-                               register_error($msg);
-                               $return = false;
-
-                               continue;
-                       }
-
                        try {
                                $plugin->start($start_flags);
                        } catch (Exception $e) {
@@ -345,11 +334,10 @@ function elgg_load_plugins() {
  * Returns an ordered list of plugins
  *
  * @param string $status      The status of the plugins. active, inactive, or all.
- * @param bool   $include_bad Include physically deleted and invalid plugins?
  * @param mixed  $site_guid   Optional site guid
  * @return array
  */
-function elgg_get_plugins($status = 'active', $include_bad = false, $site_guid = NULL) {
+function elgg_get_plugins($status = 'active', $site_guid = null) {
        $db_prefix = get_config('dbprefix');
        $priority = elgg_namespace_plugin_private_setting('internal', 'priority');
 
@@ -388,22 +376,9 @@ function elgg_get_plugins($status = 'active', $include_bad = false, $site_guid =
                        break;
        }
 
-       if ($include_bad) {
-               $old_ia = elgg_set_ignore_access(true);
-       }
-
+       $old_ia = elgg_set_ignore_access(true);
        $plugins = elgg_get_entities_from_relationship($options);
-
-       if ($include_bad) {
-               elgg_set_ignore_access($old_ia);
-       } else {
-               // remove bad plugins
-               foreach ($plugins as $i => $plugin) {
-                       if (!$plugin->isValid()) {
-                               unset ($plugins[$i]);
-                       }
-               }
-       }
+       elgg_set_ignore_access($old_ia);
 
        return $plugins;
 }
@@ -573,7 +548,7 @@ function elgg_get_plugins_provides($type = null, $name = null) {
                $provides = array();
 
                foreach ($active_plugins as $plugin) {
-                       if ($plugin_provides = $plugin->manifest->getProvides()) {
+                       if ($plugin_provides = $plugin->getManifest()->getProvides()) {
                                foreach ($plugin_provides as $provided) {
                                        $provides[$provided['type']][$provided['name']] = array(
                                                'version' => $provided['version'],
index 1bf4808ef109d2d0cd9dc0f227f8a890968707a3..62d3f65670023486526bc3745598366f72dd191d 100644 (file)
@@ -1344,8 +1344,8 @@ class ElggInstaller {
                elgg_generate_plugin_entities();
                $plugins = elgg_get_plugins('any');
                foreach ($plugins as $plugin) {
-                       if ($plugin->manifest) {
-                               if ($plugin->manifest->getActivateOnInstall()) {
+                       if ($plugin->getManifest()) {
+                               if ($plugin->getManifest()->getActivateOnInstall()) {
                                        $plugin->activate();
                                }
                        }
index 7473768c0d9fd7fc104f2c1d6cbf47621d0c50aa..c75492270c5370a2449c1eee07be45e31029bb0a 100644 (file)
@@ -17,7 +17,7 @@ $vars['entity'] = $plugin;
 $settings = false;
 
 if (elgg_view_exists("settings/$plugin_id/edit") || elgg_view_exists("plugins/$plugin_id/settings")) {
-       $title = $plugin->manifest->getName();
+       $title = $plugin->getManifest()->getName();
 
        $params = array('id' => "$plugin_id-settings");
        $body = elgg_view_form("plugins/settings/save", $params, $vars);
index 02e9ae58b77e9ed12fd106db824d6b14305ceffa..550154fcd9ae5bdcf735ce86f3635774f692a03f 100644 (file)
@@ -22,7 +22,7 @@ foreach ($installed_plugins as $id => $plugin) {
                continue;
        }
 
-       $plugin_categories = $plugin->manifest->getCategories();
+       $plugin_categories = $plugin->getManifest()->getCategories();
 
        // handle plugins that don't declare categories
        // unset them here because this is the list we foreach
index ff02c91834d6e9ceee91a483b06bf48b707540de..87c98902fd8b0ee468b39b73be4fdd8b53aa04d3 100644 (file)
@@ -29,7 +29,7 @@ foreach ($installed_plugins as $plugin) {
                if (elgg_view_exists("usersettings/$plugin_id/edit") 
                        || elgg_view_exists("plugins/$plugin_id/usersettings")) {
        
-                       $title = $plugin->manifest->getName();
+                       $title = $plugin->getManifest()->getName();
                        $body = elgg_view_form('plugins/usersettings/save', array(), array('entity' => $plugin));
                        echo elgg_view_module('info', $title, $body);
                }
index 12b2cd6166da50422284748794994a424c30e2cf..cc1c1a7102ff162de4e81f1a0306500452b08df8 100644 (file)
@@ -16,9 +16,9 @@ foreach ($installed_plugins as $plugin) {
        if (!$plugin->isValid()) {
                continue;
        }
-       $interface = $plugin->manifest->getAdminInterface();
+       $interface = $plugin->getManifest()->getAdminInterface();
        if ($interface == 'simple') {
-               $plugin_list[$plugin->manifest->getName()] = $plugin;
+               $plugin_list[$plugin->getManifest()->getName()] = $plugin;
        }
 }
 
index a346d4ff1d888e863cd0b86324de0f49c7b72836..4c8bc8c17a6c0241923572a97ced6a789e061c9e 100644 (file)
@@ -13,7 +13,7 @@ $plugin = $vars['entity'];
 $priority = $plugin->getPriority();
 $active = $plugin->isActive();
 
-$name = $plugin->manifest->getName();
+$name = $plugin->getManifest()->getName();
 $can_activate = $plugin->canActivate();
 $max_priority = elgg_get_max_plugin_priority();
 $actions_base = '/action/admin/plugins/';
@@ -123,7 +123,7 @@ if ($categories) {
 }
 
 $screenshots_html = '';
-$screenshots = $plugin->manifest->getScreenshots();
+$screenshots = $plugin->getManifest()->getScreenshots();
 if ($screenshots) {
        $base_url = elgg_get_plugins_path() . $plugin->getID() . '/';
        foreach ($screenshots as $screenshot) {
@@ -138,17 +138,17 @@ if ($screenshots) {
 }
 
 // metadata
-$description = elgg_view('output/longtext', array('value' => $plugin->manifest->getDescription()));
+$description = elgg_view('output/longtext', array('value' => $plugin->getManifest()->getDescription()));
 $author = '<span>' . elgg_echo('admin:plugins:label:author') . '</span>: '
-                       . elgg_view('output/text', array('value' => $plugin->manifest->getAuthor()));
-$version = htmlspecialchars($plugin->manifest->getVersion());
+                       . elgg_view('output/text', array('value' => $plugin->getManifest()->getAuthor()));
+$version = htmlspecialchars($plugin->getManifest()->getVersion());
 $website = elgg_view('output/url', array(
-       'href' => $plugin->manifest->getWebsite(),
-       'text' => $plugin->manifest->getWebsite()
+       'href' => $plugin->getManifest()->getWebsite(),
+       'text' => $plugin->getManifest()->getWebsite()
 ));
 
-$copyright = elgg_view('output/text', array('value' => $plugin->manifest->getCopyright()));
-$license = elgg_view('output/text', array('value' => $plugin->manifest->getLicense()));
+$copyright = elgg_view('output/text', array('value' => $plugin->getManifest()->getCopyright()));
+$license = elgg_view('output/text', array('value' => $plugin->getManifest()->getLicense()));
 
 // show links to text files
 $files = $plugin->getAvailableTextFiles();
@@ -189,11 +189,11 @@ if (elgg_view_exists($settings_view)) {
 }
 ?>
                        <div class="elgg-head">
-                               <h3><?php echo $plugin->manifest->getName(). " $version $settings_link"; ?></h3>
+                               <h3><?php echo $plugin->getManifest()->getName(). " $version $settings_link"; ?></h3>
                        </div>
                        <?php
-                       if ($plugin->manifest->getApiVersion() < 1.8) {
-                               $reqs = $plugin->manifest->getRequires();
+                       if ($plugin->getManifest()->getApiVersion() < 1.8) {
+                               $reqs = $plugin->getManifest()->getRequires();
                                if (!$reqs) {
                                        $message = elgg_echo('admin:plugins:warning:elgg_version_unknown');
                                        echo "<p class=\"elgg-state-error\">$message</p>";
index 11a441a4aa17e32837fd28fc5cf52a001305ebd2..b5cdaf8b6f255acd6ac744a02b877999e51a0a88 100644 (file)
@@ -9,7 +9,7 @@
  */
 
 $plugin = elgg_extract('plugin', $vars, false);
-$deps = $plugin->package->checkDependencies(true);
+$deps = $plugin->getPackage()->checkDependencies(true);
 
 $columns = array('type', 'name', 'expected_value', 'local_value', 'comment');
 
index d57d819341789d5e2b053cd122d465a1d164b520..5f5b08f1004fa5d7f4b7456e5e07eb322281d931 100644 (file)
@@ -5,11 +5,11 @@ $plugin_guid = $plugin->guid;
 $plugin_id = $plugin->getID();
 $active = $plugin->isActive();
 $can_activate = $plugin->canActivate();
-$name = $plugin->manifest->getName();
-$author = $plugin->manifest->getAuthor();
-$version = $plugin->manifest->getVersion();
-$website = $plugin->manifest->getWebsite();
-$description = $plugin->manifest->getDescription();
+$name = $plugin->getManifest()->getName();
+$author = $plugin->getManifest()->getAuthor();
+$version = $plugin->getManifest()->getVersion();
+$website = $plugin->getManifest()->getWebsite();
+$description = $plugin->getManifest()->getDescription();
 
 if ($active) {
        $active_class = 'elgg-state-active';