Skip to content

Commit

Permalink
Dev Fixed issue with dynamic plugin model not properly setting
Browse files Browse the repository at this point in the history
isNewRecord.
Dev Added plugin support to ConsoleApplication
Dev Added plugin cron command that fires cron event.
  • Loading branch information
SamMousa committed Mar 29, 2014
1 parent e722c87 commit e1a580b
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 4 deletions.
30 changes: 30 additions & 0 deletions application/commands/PluginCommand.php
@@ -0,0 +1,30 @@
<?php
/*
* LimeSurvey (tm)
* Copyright (C) 2011 The LimeSurvey Project Team / Carsten Schmitz
* All rights reserved.
* License: GNU/GPL License v2 or later, see LICENSE.php
* LimeSurvey is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
*
*/
class PluginCommand extends CConsoleCommand

This comment has been minimized.

Copy link
@Shnoulle

Shnoulle Apr 4, 2014

Collaborator

It's for manual : to use this plugn, user have to set a crontab himself with
application/commands/console.php plugin ?

Some CMS use ajax on each page to set some 'pseudo cron' : http://programmer.spip.net/How-cron-jobs-are-run

{
public $connection;

public function actionCron($interval)
{

$pm = Yii::app()->getPluginManager();
$event = new PluginEvent('cron');
$event->set('interval', $interval);
$pm->dispatchEvent($event);


}
}

?>
65 changes: 64 additions & 1 deletion application/core/ConsoleApplication.php
@@ -1,19 +1,55 @@
<?php


/**
* Load the globals helper as early as possible. Only earlier solution is to use
* index.php
*/
require_once(dirname(dirname(__FILE__)) . '/helpers/globals.php');

class ConsoleApplication extends CConsoleApplication
{

protected $config = array();

public $lang = null;

/**
*
* @var PluginManager
*/
protected $pluginManager;

/**
* @var LimesurveyApi
*/
protected $api;

public function __construct($config = null) {
parent::__construct($config);

// Set webroot alias.
Yii::setPathOfAlias('webroot', realpath(Yii::getPathOfAlias('application') . '/../'));
// Load email settings.
$email = require(Yii::app()->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.
Expand Down Expand Up @@ -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
*
Expand Down
14 changes: 14 additions & 0 deletions application/libraries/PluginManager/LimesurveyApi.php
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion application/libraries/PluginManager/PluginManager.php
Expand Up @@ -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
}

/**
Expand Down
4 changes: 2 additions & 2 deletions application/models/PluginDynamic.php
Expand Up @@ -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;
}
/**
Expand Down

1 comment on commit e1a580b

@Shnoulle
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.