2015-02-13 16:19:01 -04:00
< ? php
/**
* Description of ActionsByEmailFeature
*
*/
2015-03-03 17:54:30 -04:00
if ( ! class_exists ( 'enterprisePlugin' )) {
return ;
}
// Load dependences
G :: LoadClass ( 'feature' );
class ActionsByEmailFeature extends PMFeature
2015-02-13 16:19:01 -04:00
{
2015-03-04 17:56:32 -04:00
protected $triggers ;
protected $classInstance ;
2015-03-03 17:54:30 -04:00
public function __construct ( $namespace , $filename = null )
{
$result = parent :: __construct ( $namespace , $filename );
$this -> sFriendlyName = 'Actions By Email' ;
$this -> sDescription = 'Actions by Email using variables as multiple choice actions delivered by email' ;
$this -> sFeatureFolder = 'ActionsByEmail' ;
2015-03-04 17:56:32 -04:00
$this -> classInstance = array ( 'filename' => 'class.actionsByEmail.php' , 'classname' => 'actionsByEmailClass' );
2015-03-03 17:54:30 -04:00
$this -> sSetupPage = '' ;
$this -> iVersion = self :: getFeatureVersion ( $namespace );
$this -> aWorkspaces = null ;
$this -> aDependences = array ( array ( 'sClassName' => 'enterprise' ), array ( 'sClassName' => 'pmLicenseManager' ));
2015-03-04 17:56:32 -04:00
$this -> triggers = array ();
// $this->bPrivate = parent::registerEE($this->sFeatureFolder, $this->iVersion);
2015-03-03 17:54:30 -04:00
return $result ;
}
2015-02-13 16:19:01 -04:00
public function setup ()
{
2015-03-03 17:54:30 -04:00
try {
if ( ! defined ( 'PM_CREATE_NEW_DELEGATION' )) {
throw new Exception ( 'It might be using a version of ProcessMaker which is not totally compatible with this plugin, the minimun required version is 2.0.37' );
}
$this -> registerTrigger ( PM_CREATE_NEW_DELEGATION , 'sendActionsByEmail' );
} catch ( Exception $error ) {
}
2015-02-13 16:19:01 -04:00
}
2015-03-03 17:54:30 -04:00
2015-03-04 17:56:32 -04:00
public function executeTriggers ( $triggerId , $data )
{
$method = $this -> triggers [ $triggerId ];
require_once PATH_FEATURES . $this -> sFeatureFolder . DS . $this -> classInstance [ 'filename' ];
$actionsByEmail = new $this -> classInstance [ 'classname' ]();
$actionsByEmail -> $method ( $data );
}
public function registerTrigger ( $triggerId , $method )
{
$this -> triggers [ $triggerId ] = $method ;
}
2015-02-13 16:19:01 -04:00
public function install ()
{
2015-03-03 17:54:30 -04:00
$this -> checkTables ();
2015-02-13 16:19:01 -04:00
}
2015-03-03 17:54:30 -04:00
2015-02-13 16:19:01 -04:00
public function enable ()
{
2015-03-03 17:54:30 -04:00
$this -> checkTables ();
2015-02-13 16:19:01 -04:00
}
2015-03-03 17:54:30 -04:00
2015-02-13 16:19:01 -04:00
public function disable ()
{
2015-03-03 17:54:30 -04:00
// Nothing to do for now
}
/**
* This method get the version of this plugin , when the plugin is packaged in the tar . gz
* the file " version " in the plugin folder has this information for development purposes ,
* we calculate the version using git commands , because the repository is in GIT
*
* @ param String $namespace The namespace of the plugin
* @ return String $version
*/
private static function getFeatureVersion ( $namespace )
{
return " 2.0.20 " ;
}
public function checkTables ()
{
$con = Propel :: getConnection ( 'workflow' );
$stmt = $con -> createStatement ();
// setting the path of the sql schema files
$filenameSql = PATH_PLUGINS . 'actionsByEmail/data/schema.sql' ;
// checking the existence of the schema file
if ( ! file_exists ( $filenameSql )) {
throw new Exception ( " File data/schema.sql doesn't exists " );
}
// exploding the sql query in an array
$sql = explode ( ';' , file_get_contents ( $filenameSql ));
$stmt -> executeQuery ( 'SET FOREIGN_KEY_CHECKS = 0;' );
// executing each query stored in the array
foreach ( $sql as $sentence ) {
if ( trim ( $sentence ) != '' ) {
$stmt -> executeQuery ( $sentence );
}
}
2015-02-13 16:19:01 -04:00
}
}