Merged in bugfix/HOR-3663 (pull request #5933)
HOR-3663 Approved-by: Julio Cesar Laura Avendaño <contact@julio-laura.com>
This commit is contained in:
@@ -129,6 +129,21 @@ class PluginRegistry
|
||||
$this->_aPluginDetails[$Namespace] = $detail;
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregister the plugin in the class
|
||||
* @param string $namespace Name Plugin
|
||||
* @return PluginDetail
|
||||
*/
|
||||
public function unregisterPlugin($namespace)
|
||||
{
|
||||
$detail = null;
|
||||
if (isset($this->_aPluginDetails[$namespace])) {
|
||||
$detail = $this->_aPluginDetails[$namespace];
|
||||
unset($this->_aPluginDetails[$namespace]);
|
||||
}
|
||||
return $detail;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get setup Plugins
|
||||
* @return int
|
||||
@@ -1371,85 +1386,32 @@ class PluginRegistry
|
||||
|
||||
/**
|
||||
* Update the plugin attributes in all workspaces
|
||||
* @param string $Namespace Name of Plugin
|
||||
* @param string $workspace Name workspace
|
||||
* @param string $namespace Name of Plugin
|
||||
* @throws Exception
|
||||
*/
|
||||
public function updatePluginAttributesInAllWorkspaces($Namespace)
|
||||
public function updatePluginAttributesInAllWorkspaces($workspace, $namespace)
|
||||
{
|
||||
try {
|
||||
G::LoadClass("wsTools");
|
||||
|
||||
//Set variables
|
||||
$pluginFileName = $Namespace . ".php";
|
||||
$pluginFileName = $namespace . ".php";
|
||||
|
||||
//Verify data
|
||||
if (!file_exists(PATH_PLUGINS . $pluginFileName)) {
|
||||
throw new Exception("Error: The plugin not exists");
|
||||
}
|
||||
|
||||
//Update plugin attributes
|
||||
//remove old data plugin
|
||||
$pmPluginRegistry = PluginRegistry::loadSingleton();
|
||||
$pluginDetails = $pmPluginRegistry->unregisterPlugin($namespace);
|
||||
|
||||
//Load plugin attributes
|
||||
require_once(PATH_PLUGINS . $pluginFileName);
|
||||
|
||||
$pmPluginRegistry = PluginRegistry::loadSingleton();
|
||||
|
||||
$pluginDetails = $pmPluginRegistry->getPluginDetails($pluginFileName);
|
||||
|
||||
if (is_array($pluginDetails->getWorkspaces()) &&
|
||||
count($pluginDetails->getWorkspaces()) > 0
|
||||
) {
|
||||
$arrayWorkspace = array();
|
||||
|
||||
foreach (PmSystem::listWorkspaces() as $value) {
|
||||
$workspaceTools = $value;
|
||||
|
||||
$arrayWorkspace[] = $workspaceTools->name;
|
||||
}
|
||||
//Workspaces to update
|
||||
$arrayWorkspaceAux = array_diff($arrayWorkspace, $pluginDetails->getWorkspaces());
|
||||
$strWorkspaceNoWritable = "";
|
||||
|
||||
$arrayWorkspace = array();
|
||||
|
||||
foreach ($arrayWorkspaceAux as $value) {
|
||||
$workspace = $value;
|
||||
|
||||
$workspacePathDataSite = PATH_DATA . "sites" . PATH_SEP . $workspace . PATH_SEP;
|
||||
|
||||
if (file_exists($workspacePathDataSite . "plugin.singleton")) {
|
||||
$pmPluginRegistry = PluginRegistry::loadSingleton();
|
||||
|
||||
if (isset($pmPluginRegistry->_aPluginDetails[$Namespace])) {
|
||||
if (!is_writable($workspacePathDataSite . "plugin.singleton")) {
|
||||
$strWorkspaceNoWritable .= (($strWorkspaceNoWritable != "") ? ", " : "") . $workspace;
|
||||
}
|
||||
|
||||
$arrayWorkspace[] = $workspace;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Verify data
|
||||
if ($strWorkspaceNoWritable != "") {
|
||||
throw new Exception(
|
||||
'Error: The workspaces ' .
|
||||
$strWorkspaceNoWritable .
|
||||
' has problems of permissions of write in file "plugin.singleton", solve this problem'
|
||||
);
|
||||
}
|
||||
|
||||
//Update plugin attributes
|
||||
foreach ($arrayWorkspace as $value) {
|
||||
$workspace = $value;
|
||||
|
||||
$workspacePathDataSite = PATH_DATA . "sites" . PATH_SEP . $workspace . PATH_SEP;
|
||||
|
||||
$pmPluginRegistry = PluginRegistry::loadSingleton();
|
||||
|
||||
$pmPluginRegistry->disablePlugin($Namespace);
|
||||
|
||||
$pmPluginRegistry->savePlugin($Namespace);
|
||||
}
|
||||
if (is_array($pluginDetails->getWorkspaces()) && !in_array($workspace, $pluginDetails->getWorkspaces())) {
|
||||
$pmPluginRegistry->disablePlugin($namespace);
|
||||
}
|
||||
$pmPluginRegistry->savePlugin($namespace);
|
||||
} catch (Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
|
||||
122
workflow/engine/src/ProcessMaker/Util/Cnn.php
Normal file
122
workflow/engine/src/ProcessMaker/Util/Cnn.php
Normal file
@@ -0,0 +1,122 @@
|
||||
<?php
|
||||
|
||||
namespace ProcessMaker\Util;
|
||||
|
||||
use Propel;
|
||||
|
||||
/**
|
||||
* Class Cnn
|
||||
* @package ProcessMaker\Util
|
||||
*/
|
||||
class Cnn
|
||||
{
|
||||
private $dbFile;
|
||||
private $workspace;
|
||||
|
||||
/**
|
||||
* Establishes connection for the workspace
|
||||
* @param string $workspace Name workspace
|
||||
*/
|
||||
public static function connect($workspace)
|
||||
{
|
||||
$cnn = new static();
|
||||
$cnn->workspace = $workspace;
|
||||
Propel::initConfiguration($cnn->buildParams());
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the parameters required to connect to each workspace database
|
||||
* @return array
|
||||
*/
|
||||
public function buildParams()
|
||||
{
|
||||
if ($this->readFileDBWorkspace()) {
|
||||
return $this->prepareDataSources();
|
||||
}
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads the workspace db.php file
|
||||
* @return bool
|
||||
*/
|
||||
private function readFileDBWorkspace()
|
||||
{
|
||||
if (file_exists(PATH_DB . $this->workspace . PATH_SEP . 'db.php')) {
|
||||
$this->dbFile = file_get_contents(PATH_DB . $this->workspace . PATH_SEP . 'db.php');
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepares data resources
|
||||
* @return array
|
||||
*/
|
||||
private function prepareDataSources()
|
||||
{
|
||||
$phpCode = preg_replace(
|
||||
'/define\s*\(\s*[\x22\x27](.*)[\x22\x27]\s*,\s*(\x22.*\x22|\x27.*\x27)\s*\)\s*;/i',
|
||||
'$$1 = $2;',
|
||||
$this->dbFile
|
||||
);
|
||||
$phpCode = str_replace(['<?php', '<?', '?>'], '', $phpCode);
|
||||
|
||||
eval($phpCode);
|
||||
|
||||
$dataSources = [];
|
||||
$dataSources['datasources'] = array(
|
||||
'workflow' => array(
|
||||
'connection' => $this->buildDsnString(
|
||||
$DB_ADAPTER,
|
||||
$DB_HOST,
|
||||
$DB_NAME,
|
||||
$DB_USER,
|
||||
urlencode($DB_PASS)
|
||||
),
|
||||
'adapter' => "mysql"
|
||||
),
|
||||
'rbac' => array(
|
||||
'connection' => $this->buildDsnString(
|
||||
$DB_ADAPTER,
|
||||
$DB_RBAC_HOST,
|
||||
$DB_RBAC_NAME,
|
||||
$DB_RBAC_USER,
|
||||
urlencode($DB_RBAC_PASS)
|
||||
),
|
||||
'adapter' => "mysql"
|
||||
),
|
||||
'report' => array(
|
||||
'connection' => $this->buildDsnString(
|
||||
$DB_ADAPTER,
|
||||
$DB_REPORT_HOST,
|
||||
$DB_REPORT_NAME,
|
||||
$DB_REPORT_USER,
|
||||
urlencode($DB_REPORT_PASS)
|
||||
),
|
||||
'adapter' => "mysql"
|
||||
)
|
||||
);
|
||||
return $dataSources;
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the DSN string to be used by PROPEL
|
||||
* @param string $adapter
|
||||
* @param string $host
|
||||
* @param string $name
|
||||
* @param string $user
|
||||
* @param string $pass
|
||||
* @return string
|
||||
*/
|
||||
private function buildDsnString($adapter, $host, $name, $user, $pass)
|
||||
{
|
||||
$dns = $adapter . "://" . $user . ":" . $pass . "@" . $host . "/" . $name;
|
||||
switch ($adapter) {
|
||||
case 'mysql':
|
||||
$dns .= '?encoding=utf8';
|
||||
break;
|
||||
}
|
||||
return $dns;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user