From e1a580b42c2ed7c4593b29f5ecaa063f7b439ce8 Mon Sep 17 00:00:00 2001 From: Sam Mousa Date: Sat, 29 Mar 2014 16:55:48 +0100 Subject: [PATCH] Dev Fixed issue with dynamic plugin model not properly setting isNewRecord. Dev Added plugin support to ConsoleApplication Dev Added plugin cron command that fires cron event. --- application/commands/PluginCommand.php | 30 +++++++++ application/core/ConsoleApplication.php | 65 ++++++++++++++++++- .../libraries/PluginManager/LimesurveyApi.php | 14 ++++ .../libraries/PluginManager/PluginManager.php | 2 +- application/models/PluginDynamic.php | 4 +- 5 files changed, 111 insertions(+), 4 deletions(-) create mode 100644 application/commands/PluginCommand.php diff --git a/application/commands/PluginCommand.php b/application/commands/PluginCommand.php new file mode 100644 index 00000000000..bf6062ad7b5 --- /dev/null +++ b/application/commands/PluginCommand.php @@ -0,0 +1,30 @@ +getPluginManager(); + $event = new PluginEvent('cron'); + $event->set('interval', $interval); + $pm->dispatchEvent($event); + + + } + } + +?> \ No newline at end of file diff --git a/application/core/ConsoleApplication.php b/application/core/ConsoleApplication.php index 4f009ae7fbf..4ca049ff0d1 100644 --- a/application/core/ConsoleApplication.php +++ b/application/core/ConsoleApplication.php @@ -1,19 +1,55 @@ basePath. DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'email.php'); $this->config = array_merge($this->config, $email); + + // Now initialize the plugin manager + $this->initPluginManager(); + + } + + /** + * Get the Api object. + */ + public function getApi() + { + if (!isset($this->api)) + { + $this->api = new LimesurveyApi(); + } + return $this->api; } + /** * This function is implemented since em_core_manager incorrectly requires * it to create urls. @@ -48,6 +84,33 @@ public function getConfig($name = null) } } + /** + * Get the pluginManager + * + * @return PluginManager + */ + public function getPluginManager() + { + return $this->pluginManager; + } + + /** + * This method handles initialization of the plugin manager + * + * When you want to insert your own plugin manager, or experiment with different settings + * then this is where you should do that. + */ + public function initPluginManager() + { + Yii::import('application.libraries.PluginManager.*'); + Yii::import('application.libraries.PluginManager.Storage.*'); + Yii::import('application.libraries.PluginManager.Question.*'); + $this->pluginManager = new PluginManager($this->getApi()); + + // And load the active plugins + $this->pluginManager->loadPlugins(); + } + /** * Loads a helper * diff --git a/application/libraries/PluginManager/LimesurveyApi.php b/application/libraries/PluginManager/LimesurveyApi.php index 71e84983d13..79a9a66f835 100644 --- a/application/libraries/PluginManager/LimesurveyApi.php +++ b/application/libraries/PluginManager/LimesurveyApi.php @@ -55,6 +55,20 @@ public function createTable($plugin, $sTableName, $aColumns, $sOptions=null) return false; } + /** + * Builds and executes a SQL statement for dropping a DB table. + * @param mixed $plugin The plugin object, id or name. + * @param string $sTableName the name of the table to be created. The name will be properly quoted and prefixed by the method. + */ + public function dropTable($plugin, $sTableName) + { + if (null !== $sTableName = $this->getTableName($plugin, $sTableName)) + { + return App()->getDb()->createCommand()->dropTable($sTableName); + } + return false; + } + public function createUrl($route, array $params) { return App()->createAbsoluteUrl($route, $params); diff --git a/application/libraries/PluginManager/PluginManager.php b/application/libraries/PluginManager/PluginManager.php index 00cbf6a017a..66e757f280e 100644 --- a/application/libraries/PluginManager/PluginManager.php +++ b/application/libraries/PluginManager/PluginManager.php @@ -41,7 +41,7 @@ public function __construct($api) } $this->pluginDirs[] = 'webroot.plugins'; // User plugins - $this->pluginDirs[] = 'webroot.application.core.plugins'; // Core plugins + $this->pluginDirs[] = 'application.core.plugins'; // Core plugins } /** diff --git a/application/models/PluginDynamic.php b/application/models/PluginDynamic.php index 7233e4529e1..272b7698d8e 100644 --- a/application/models/PluginDynamic.php +++ b/application/models/PluginDynamic.php @@ -27,10 +27,10 @@ public function __construct($sTableName = null, $scenario = 'insert') } - protected function instantiate($attributes) + protected function instantiate($attributes = null) { $class=get_class($this); - $model=new $class($this->tableName()); + $model=new $class($this->tableName(), null); return $model; } /**