up observations

This commit is contained in:
Ronald Quenta
2017-07-26 16:15:32 -04:00
committed by Ronald Quenta
parent c979a43d36
commit 2825cb6868
16 changed files with 177 additions and 167 deletions

2
composer.lock generated
View File

@@ -322,7 +322,7 @@
],
"authors": [
{
"name": "Jean-Marc Trémeaux",
"name": "Jean-Marc Tr??meaux",
"homepage": "http://naku.dohcrew.com/",
"role": "Developer"
},

View File

0
tests/bootstrap.php Normal file
View File

View File

@@ -0,0 +1,121 @@
<?php
namespace Tests\ProcessMaker\Plugins;
use ProcessMaker\Plugins\Interfaces\PluginDetail;
use ProcessMaker\Plugins\Interfaces\Plugins;
use ProcessMaker\Plugins\PluginsRegistry;
use Tests\WorkflowTestCase;
class PluginsRegistryTest extends WorkflowTestCase
{
/**
* @var PluginsRegistry $oPluginRegistry
*/
protected $oPluginRegistry;
/**
* This is called before each test method.
* Initialize and create required objects in DB
*/
public function setUp()
{
// We should call our Parent setUp before we do anything else in setUp method
parent::setUp();
$this->oPluginRegistry = new PluginsRegistry();
$this->oPluginRegistry->setupPlugins();
}
/**
* @test
*/
public function getPlugins()
{
$this->assertObjectHasAttribute('Plugins', $this->oPluginRegistry, 'Plugins attribute does not exist');
$this->assertEquals([], $this->oPluginRegistry->getPlugins(), 'The Plugins attribute is not an array');
}
/**
* @test
*/
public function setPlugins()
{
$this->assertObjectHasAttribute('Plugins', $this->oPluginRegistry, 'Plugins attribute does not exist');
$this->oPluginRegistry->setPlugins([]);
$this->assertEquals([], $this->oPluginRegistry->getPlugins(), 'The Plugins attribute is not an array');
}
/**
* @test
*/
public function loadSingleton()
{
$oPluginRegistry = PluginsRegistry::loadSingleton();
$this->assertObjectHasAttribute('Plugins', $oPluginRegistry, 'Plugins attribute does not exist');
$this->assertInstanceOf(Plugins::class, $oPluginRegistry, '');
}
/**
* @test
*/
public function registerPlugin()
{
$oPluginRegistry = PluginsRegistry::loadSingleton();
$pluginFile = 'enterprise.php';
//add the plugin php file
require_once(PATH_CORE . "methods" . PATH_SEP . "enterprise" . PATH_SEP . "enterprise.php");
//register mulitenant in the plugin registry singleton, because details are read from this instance
$oPluginRegistry->registerPlugin("enterprise", $pluginFile);
$this->assertObjectHasAttribute('_aPluginDetails', $oPluginRegistry, 'Plugins attribute does not exist');
$this->assertInstanceOf(PluginDetail::class, $oPluginRegistry->_aPluginDetails['enterprise'], '');
}
/**
* @test
*/
public function getPluginDetails()
{
$oPluginRegistry = PluginsRegistry::loadSingleton();
$pluginFile = 'enterprise.php';
//add the plugin php file
require_once(PATH_CORE . "methods" . PATH_SEP . "enterprise" . PATH_SEP . "enterprise.php");
//register mulitenant in the plugin registry singleton, because details are read from this instance
$details = $oPluginRegistry->getPluginDetails($pluginFile);
$this->assertEquals('enterprise', $details->sNamespace, 'Namespace attribute does not equals');
$this->assertObjectHasAttribute('sNamespace', $details, 'sNamespace attribute does not exist');
$this->assertInstanceOf(PluginDetail::class, $details, '');
}
/**
* @test
*/
public function enablePlugin()
{
$oPluginRegistry = PluginsRegistry::loadSingleton();
$pluginFile = 'enterprise.php';
//add the plugin php file
require_once(PATH_CORE . "methods" . PATH_SEP . "enterprise" . PATH_SEP . "enterprise.php");
//register mulitenant in the plugin registry singleton, because details are read from this instance
$details = $oPluginRegistry->getPluginDetails($pluginFile);
$this->assertEquals(false, $details->enabled, 'Not disable Plugin');
$result = $oPluginRegistry->enablePlugin($details->sNamespace);
$this->assertEquals(true, $result, 'Plugin is enable');
}
/**
* @test
*/
public function disablePlugin()
{
$oPluginRegistry = PluginsRegistry::loadSingleton();
$pluginFile = 'enterprise.php';
//add the plugin php file
require_once(PATH_CORE . "methods" . PATH_SEP . "enterprise" . PATH_SEP . "enterprise.php");
//register mulitenant in the plugin registry singleton, because details are read from this instance
$details = $oPluginRegistry->getPluginDetails($pluginFile);
$result = $oPluginRegistry->enablePlugin($details->sNamespace);
$this->assertEquals(true, $result, 'Plugin is enable');
$oPluginRegistry->disablePlugin($details->sNamespace);
$details = $oPluginRegistry->getPluginDetails($pluginFile);
$this->assertEquals(false, $details->enabled, 'Plugin is enable');
}
}

View File

@@ -303,14 +303,14 @@ CLI::taskArg('workspace', true, true);
CLI::taskOpt("lang", "Specify the language to migrate the content data. If not specified, then 'en' (English) will be used by default.\n Ex: -lfr (French) Ex: --lang=zh-CN (Mainland Chinese)", "l:","lang=");
CLI::taskRun("run_migrate_content");
CLI::taskName('migrate-plugin-information');
CLI::taskName('migrate-plugins-singleton-information');
CLI::taskDescription(<<<EOT
Migrating the content schema to match the latest version
  Specify the WORKSPACE to migrate from a existing workspace.
  Specify the WORKSPACE to migrate from an existing workspace.
If no workspace is specified, then the tables schema will be upgraded or
migrate on all available workspaces.
migrated to all available workspaces.
EOT
);
CLI::taskArg('workspace', true, true);
@@ -1096,22 +1096,21 @@ function run_migrate_indexing_acv($args, $opts) {
}
function run_migrate_plugin($args, $opts) {
G::LoadSystem('inputfilter');
$filter = new InputFilter();
$args = $filter->xssFilterHard($args);
$workspaces = get_workspaces_from_args($args);
$lang = array_key_exists("lang", $opts) ? $opts['lang'] : SYS_LANG;
$start = microtime(true);
CLI::logging("> Migrating and populating data...\n");
/** @var workspaceTools $workspace */
foreach ($workspaces as $workspace) {
if (!defined('SYS_SYS')) {
define('SYS_SYS', $workspace->name);
}
//Check if the command is executed by a specific workspace
if (count($workspaces) === 1) {
$workspace = array_shift($workspaces);
print_r('Regenerating Singleton in: ' . pakeColor::colorize($workspace->name, 'INFO') . "\n");
$workspace->migrateSingleton($workspace->name);
CLI::logging("-> Regenerating Singleton \n");
$workspace->migrateSingleton($workspace->name, $lang);
} else {
CLI::logging("> Migrating and populating data...\n");
$start = microtime(true);
/** @var workspaceTools $workspace */
foreach ($workspaces as $workspace) {
passthru('./processmaker migrate-plugins-singleton-information '.$workspace->name);
}
$stop = microtime(true);
CLI::logging("<*> Migrating and populating data Singleton took " . ($stop - $start) . " seconds.\n");
}
$stop = microtime(true);
CLI::logging("<*> Migrating and populating data Singleton took " . ($stop - $start) . " seconds.\n");
}
}

View File

@@ -203,10 +203,10 @@ class workspaceTools
CLI::logging("<*> Updating rows in Web Entry table for classic processes took " . ($stop - $start) . " seconds.\n");
$start = microtime(true);
CLI::logging("> Migrating and populating data...\n");
$this->migrateSingleton($workSpace, $lang);
CLI::logging("> Migrating and populating plugin singleton data...\n");
$this->migrateSingleton($workSpace);
$stop = microtime(true);
CLI::logging("<*> Migrating and populating data Singleton took " . ($stop - $start) . " seconds.\n");
CLI::logging("<*> Migrating and populating plugin singleton data took " . ($stop - $start) . " seconds.\n");
}
/**
@@ -3876,16 +3876,15 @@ class workspaceTools
/**
* @param $workspace
* @param mixed|string $lang
*/
public function migrateSingleton($workspace, $lang = SYS_LANG)
public function migrateSingleton($workspace)
{
if ((!class_exists('Memcache') || !class_exists('Memcached')) && !defined('MEMCACHED_ENABLED')) {
define('MEMCACHED_ENABLED', false);
}
$this->initPropel(true);
$conf = new Configuration();
if(!$bExist = $conf->exists('MIGRATED_PLUGIN', 'singleton')){
if (!$bExist = $conf->exists('MIGRATED_PLUGIN', 'singleton')) {
$pathSingleton = PATH_DATA . 'sites' . PATH_SEP . $workspace . PATH_SEP . 'plugin.singleton';
$oPluginRegistry = unserialize(file_get_contents($pathSingleton));
$pluginAdapter = new \ProcessMaker\Plugins\Adapters\PluginAdapter();

View File

@@ -385,7 +385,7 @@ class AddonsManager extends BaseAddonsManager
$_SESSION["__ENTERPRISE_INSTALL__"] = 1;
}
$oPluginRegistry = &PMPluginRegistry::getSingleton();
$oPluginRegistry = &ProcessMaker\Plugins\PluginsRegistry::loadSingleton();
$oPluginRegistry->installPluginArchive($filename, $this->getAddonName());
$this->setState();

View File

@@ -33,29 +33,29 @@ class PluginsRegistry extends BasePluginsRegistry
}
/**
* @param $PR_UID
* @param $prUid
* @return array
* @throws Exception
*/
public static function load($PR_UID)
public static function load($prUid)
{
$oPluginsRegistry = PluginsRegistryPeer::retrieveByPK($PR_UID);
$oPluginsRegistry = PluginsRegistryPeer::retrieveByPK($prUid);
if ($oPluginsRegistry) {
/** @var array $aFields */
$aFields = $oPluginsRegistry->toArray(BasePeer::TYPE_FIELDNAME);
return $aFields;
} else {
throw new Exception("User with $PR_UID does not exist!");
throw new Exception("Plugin with $prUid does not exist!");
}
}
/**
* @param $PR_UID
* @param $prUid
* @return mixed|bool
*/
public static function exists($PR_UID)
public static function exists($prUid)
{
$oPluginsRegistry = PluginsRegistryPeer::retrieveByPk($PR_UID);
$oPluginsRegistry = PluginsRegistryPeer::retrieveByPk($prUid);
if ($oPluginsRegistry) {
return true;
} else {
@@ -64,17 +64,17 @@ class PluginsRegistry extends BasePluginsRegistry
}
/**
* @param $PR_UID
* @param $prUid
* @param array $pluginData
* @return mixed|array|bool
*/
public static function loadOrCreateIfNotExists($PR_UID, $pluginData = array())
public static function loadOrCreateIfNotExists($prUid, $pluginData = array())
{
if (!self::exists($PR_UID)) {
$pluginData['PR_UID'] = $PR_UID;
if (!self::exists($prUid)) {
$pluginData['PR_UID'] = $prUid;
self::create($pluginData);
} else {
$fields = self::load($PR_UID);
$fields = self::load($prUid);
$pluginData = array_merge($fields, $pluginData);
}
return $pluginData;
@@ -135,36 +135,4 @@ class PluginsRegistry extends BasePluginsRegistry
throw ($oError);
}
}
public static function enable($pr_uid)
{
$oConnection = Propel::getConnection(PluginsRegistryPeer::DATABASE_NAME);
try {
$oPluginsRegistry = PluginsRegistryPeer::retrieveByPK($pr_uid);
if ($oPluginsRegistry) {
$aData['PLUGIN_ENABLE'] = true;
$oPluginsRegistry->fromArray($aData, BasePeer::TYPE_FIELDNAME);
if ($oPluginsRegistry->validate()) {
$oConnection->begin();
$iResult = $oPluginsRegistry->save();
$oConnection->commit();
return $iResult;
} else {
$sMessage = '';
$aValidationFailures = $oPluginsRegistry->getValidationFailures();
/** @var ValidationFailed $oValidationFailure */
foreach ($aValidationFailures as $oValidationFailure) {
$sMessage .= $oValidationFailure->getMessage() . '<br />';
}
throw (new Exception('The registry cannot be updated!<br />' . $sMessage));
}
} else {
throw (new Exception('This row doesn\'t exist!'));
}
} catch (Exception $oError) {
$oConnection->rollback();
throw ($oError);
}
}
}

View File

@@ -79,39 +79,14 @@ try {
BasePeer::doUpdate($oCriteriaSelect, $oCriteriaUpdate, $cnn);
///////
//$licenseManager = &pmLicenseManager::getSingleton();
//plugin.singleton //are all the plugins that are enabled in the SYS_SYS
$pluginRegistry = &PMPluginRegistry::getSingleton();
$arrayAddon = array();
//ee //all plugins enterprise installed in /processmaker/workflow/engine/plugins (no matter if they are enabled/disabled)
if (file_exists(PATH_DATA_SITE . "ee")) {
$arrayAddon = unserialize(trim(file_get_contents(PATH_DATA_SITE . "ee")));
}
foreach ($arrayAddon as $addon) {
$sFileName = substr($addon["sFilename"], 0, strpos($addon["sFilename"], "-"));
if (file_exists(PATH_PLUGINS . $sFileName . ".php")) {
$addonDetails = $pluginRegistry->getPluginDetails($sFileName . ".php");
$enabled = 0;
if ($addonDetails) {
$enabled = ($addonDetails->enabled)? 1 : 0;
}
if ($enabled == 1 && !in_array($sFileName, $licenseManager->features)) {
require_once (PATH_PLUGINS . $sFileName . ".php");
$pluginRegistry->disablePlugin($sFileName);
}
//are all the plugins that are enabled in the workspace
$pluginRegistry =& ProcessMaker\Plugins\PluginsRegistry::loadSingleton();
foreach ($pluginRegistry->_aPluginDetails as $plugin) {
if ($plugin->enabled && !in_array($plugin->sNamespace, $licenseManager->features)) {
$pluginRegistry->disablePlugin($plugin->sNamespace);
$pluginRegistry->pluginAdapter->savePlugin($plugin->sNamespace, $pluginRegistry);
}
}
file_put_contents(PATH_DATA_SITE . "plugin.singleton", $pluginRegistry->serializeInstance());
}
}
break;
@@ -207,10 +182,6 @@ try {
break;
}
//$logContents = file_get_contents("$log.log", false, NULL, 0, 10);
//if (!empty($logContents))
// break;
$retries += 1;
if ($retries > $max_retries) {
@@ -219,11 +190,6 @@ try {
}
}
//if ($failed) {
// //$addon->clearState(); //clearState no found
// $result["success"] = false;
//}
$result["status"] = "OK";
} catch (Exception $e) {
$result["message"] = $e->getMessage();
@@ -355,4 +321,3 @@ try {
))
);
}

View File

@@ -36,6 +36,15 @@ if ($aux['extension'] != 'dat') {
BasePeer::doUpdate($oCriteriaSelect, $oCriteriaUpdate, $cnn);
//are all the plugins that are enabled in the workspace
$pluginRegistry =& ProcessMaker\Plugins\PluginsRegistry::loadSingleton();
foreach ($pluginRegistry->_aPluginDetails as $plugin) {
if ($plugin->enabled && !in_array($plugin->sNamespace, $licenseManager->features)) {
$pluginRegistry->disablePlugin($plugin->sNamespace);
$pluginRegistry->pluginAdapter->savePlugin($plugin->sNamespace, $pluginRegistry);
}
}
G::SendTemporalMessage('ID_NLIC', 'info');
} else {
G::SendTemporalMessage('ID_WARNING_ENTERPRISE_LICENSE_MSG', 'warning');

View File

@@ -1,10 +1,4 @@
<?php
/**
* Created by PhpStorm.
* User: dev-ronald
* Date: 7/20/17
* Time: 9:49 AM
*/
namespace ProcessMaker\Plugins\Interfaces;

View File

@@ -75,9 +75,6 @@ class PluginsRegistry extends Plugins
{
if (self::$instance == null) {
self::$instance = new PluginsRegistry();
if (!is_object(self::$instance) || get_class(self::$instance) != "ProcessMaker\Plugins\PluginsRegistry") {
throw new \Exception("Can't load main PluginRegistry object.");
}
}
return self::$instance;
}
@@ -133,10 +130,6 @@ class PluginsRegistry extends Plugins
$detail->bPrivate = $plugin->bPrivate;
}
//if (isset($this->_aPluginDetails[$sNamespace])){
// $detail->enabled = $this->_aPluginDetails[$sNamespace]->enabled;
//}
$this->_aPluginDetails[$sNamespace] = $detail;
}
@@ -191,7 +184,6 @@ class PluginsRegistry extends Plugins
$pluginSrcDir = PATH_PLUGINS . $currentPlugin->sNamespace . PATH_SEP . 'src';
if (is_dir($pluginSrcDir)) {
//Bootstrap::registerDir($detail->sNamespace.'/src', $pluginSrcDir);
$loader = ClassLoader::getInstance();
$loader->add($pluginSrcDir);
}
@@ -217,10 +209,8 @@ class PluginsRegistry extends Plugins
public function disablePlugin($sNamespace, $eventPlugin = 1)
{
if ($currentPlugin = $this->_aPluginDetails[$sNamespace]) {
//unset($currentPlugin->_aPluginDetails[$sNamespace]);
$currentPlugin->enabled = false;
if ($eventPlugin == 1) {
//$currentPlugin->_aPlugins[$currentPlugin->sNamespace] = $currentPlugin;
// If plugin class exists check if disable method exist,
// otherwise use default plugin details
if (class_exists($currentPlugin->sClassName)) {
@@ -276,7 +266,6 @@ class PluginsRegistry extends Plugins
$namePlugin = array();
foreach ($files as $f) {
if (preg_match("/^([\w\.]*).ini$/", $f["filename"], $matches)) {
//if (preg_match( "/^(.*pluginConfig)\.ini$/", $f["filename"], $matches )) {
$plugins[] = $matches[1];
}
if (preg_match("/^.*($pluginName)\.php$/", $f["filename"], $matches)) {
@@ -288,29 +277,25 @@ class PluginsRegistry extends Plugins
throw new \Exception("Multiple plugins in one archive are not supported currently");
}
//if (isset($pluginName) && !in_array($pluginName, $plugins)) {
if (isset($pluginName) && !in_array($pluginName, $namePlugin)) {
throw new \Exception("Plugin '$pluginName' not found in archive");
}
//$pluginName = $plugins[0];
$pluginFile = "$pluginName.php";
$res = $tar->extract(PATH_PLUGINS);
if (!file_exists(PATH_PLUGINS . $pluginFile)) {
throw (new \Exception("File \"$pluginFile\" doesn't exist"));
}
// $filter = new \InputFilter();
$path = PATH_PLUGINS . $pluginFile;
// $path = $filter->validateInput($path, 'path');
require_once($path);
/** @var PluginDetail $details */
$details = $this->getPluginDetails($pluginFile);
$this->installPlugin($details->sNamespace);
// $this->setupPlugins();
$this->enablePlugin($details->sNamespace);
$this->pluginAdapter->savePlugin($details->sNamespace, $this);
}
public function uninstallPlugin($sNamespace)
@@ -375,6 +360,7 @@ class PluginsRegistry extends Plugins
foreach ($arrayPlugin as $index => $value) {
if (isset($attributes["_aPluginDetails"][$value])) {
$pluginRegistry->disablePlugin($value, 0);
$pluginRegistry->pluginAdapter->savePlugin($value, $pluginRegistry);
}
}
@@ -748,12 +734,6 @@ class PluginsRegistry extends Plugins
public function getReports()
{
return $this->_aReports;
// $report = array();
// foreach ($this->_aReports as $row => $detail) {
// $sClassName = str_replace('plugin', 'class', $this->_aPluginDetails[$detail]->sClassName);
// $report[] = $sClassName;
// }
// return $report;
}
/**
@@ -764,12 +744,6 @@ class PluginsRegistry extends Plugins
public function getPmFunctions()
{
return $this->_aPmFunctions;
// $pmf = array();
// foreach ($this->_aPmFunctions as $row => $detail) {
// $sClassName = str_replace('plugin', 'class', $this->_aPluginDetails[$detail]->sClassName);
// $pmf[] = $sClassName;
// }
// return $pmf;
}
/**
@@ -973,10 +947,7 @@ class PluginsRegistry extends Plugins
{
try {
require_once(PATH_CORE . "methods" . PATH_SEP . "enterprise" . PATH_SEP . "enterprise.php");
// require_once("class.serverConfiguration.php");
$iPlugins = 0;
// $oServerConf =& \serverConf::getSingleton();
// $oServerConf->addPlugin(SYS_SYS, $this->_aPluginDetails);
foreach ($this->_aPluginDetails as $namespace => $detail) {
if (isset($detail->enabled) && $detail->enabled) {
if (!empty($detail->sFilename) && file_exists($detail->sFilename)) {
@@ -1029,7 +1000,6 @@ class PluginsRegistry extends Plugins
$classFile = PATH_PLUGINS . $pluginFolder . PATH_SEP . 'class.' . $pluginFolder . '.php';
if (file_exists($classFile)) {
$sClassName = substr_replace($className, "class", -6, 6);
//$sClassName = str_replace ( 'plugin', 'class', $className );
if (!class_exists($sClassName)) {
require_once $classFile;
}
@@ -1083,18 +1053,6 @@ class PluginsRegistry extends Plugins
*/
public function eevalidate()
{
// $fileL = PATH_DATA_SITE . 'license.dat';
// $fileS = PATH_DATA . 'license.dat';
// if ((file_exists($fileL)) || (file_exists($fileS))) {
// //Found a License
// if (class_exists('pmLicenseManager')) {
// $sSerializedFile = PATH_DATA_SITE . 'lmn.singleton';
// $pmLicenseManagerO = &\pmLicenseManager::getSingleton();
// if (file_exists($sSerializedFile)) {
// $pmLicenseManagerO->unSerializeInstance(file_get_contents($sSerializedFile));
// }
// }
// }
}
/**

View File

@@ -680,15 +680,10 @@ if (defined( 'DEBUG_SQL_LOG' ) && DEBUG_SQL_LOG) {
//here we are loading all plugins registered
//the singleton has a list of enabled plugins
$sSerializedFile = PATH_DATA_SITE . 'plugin.singleton';
$oPluginRegistry = &ProcessMaker\Plugins\PluginsRegistry::loadSingleton();
$attributes = $oPluginRegistry->getAttributes();
Bootstrap::LoadTranslationPlugins( defined( 'SYS_LANG' ) ? SYS_LANG : "en" , $attributes);
// Setup plugins
$avoidChangedWorkspaceValidation = false;
$oPluginRegistry->setupPlugins(); //get and setup enabled plugins
//Set Time Zone
/*----------------------------------********---------------------------------*/
$_SESSION['__SYSTEM_UTC_TIME_ZONE__'] = (int)($config['system_utc_time_zone']) == 1;
@@ -740,7 +735,9 @@ if (SYS_LANG != 'en' && ! is_file( PATH_LANGUAGECONT . 'translation.' . SYS_LANG
Bootstrap::LoadTranslationObject(SYS_LANG);
}
// Setup plugins
$oPluginRegistry->setupPlugins(); //get and setup enabled plugins
$avoidChangedWorkspaceValidation = false;
// Load custom Classes and Model from Plugins.
Bootstrap::LoadAllPluginModelClasses();