Merged in victorsl/processmaker/PM-404 (pull request #880)
PM-404 "En la actualizacion de un plugin no se actualiza el singleton" SOLVED
This commit is contained in:
@@ -49,6 +49,9 @@ pake_task('new-project', 'project_exists');
|
||||
pake_desc("build new plugin \n args: <name>");
|
||||
pake_task('new-plugin', 'project_exists');
|
||||
|
||||
pake_desc("Update the plugin attributes in all workspaces\n args: <plugin-name>");
|
||||
pake_task("update-plugin-attributes", "project_exists");
|
||||
|
||||
pake_desc("pack plugin in .tar file \n args: <plugin>");
|
||||
pake_task('pack-plugin', 'project_exists');
|
||||
|
||||
@@ -275,7 +278,7 @@ function convertPhpName($f) {
|
||||
function copyPluginFile($tplName, $fName, $class) {
|
||||
$pluginOutDirectory = PATH_OUTTRUNK . "plugins" . PATH_SEP . $class . PATH_SEP;
|
||||
$pluginFilename = $pluginOutDirectory . $fName;
|
||||
|
||||
|
||||
$fileTpl = PATH_GULLIVER_HOME . 'bin' . PATH_SEP . 'tasks' . PATH_SEP . 'templates' . PATH_SEP . $tplName . '.tpl';
|
||||
$content = file_get_contents($fileTpl);
|
||||
$iSize = file_put_contents($pluginFilename, $content);
|
||||
@@ -293,7 +296,7 @@ function savePluginFile($fName, $tplName, $class, $tableName, $fields = null, $u
|
||||
$template->assign('className', $class);
|
||||
$template->assign('tableName', $tableName);
|
||||
$template->assign('menuId', 'ID_' . strtoupper($class));
|
||||
|
||||
|
||||
if( is_array($fields) ) {
|
||||
foreach( $fields as $block => $data ) {
|
||||
$template->gotoBlock("_ROOT");
|
||||
@@ -704,7 +707,7 @@ function run_new_plugin($task, $args) {
|
||||
$fields["dashboard"][] = array(
|
||||
"className" => $pluginName
|
||||
);
|
||||
|
||||
|
||||
$fields["dashboardAttribute"] = "private \$dashletsUids;";
|
||||
$fields["dashboardAttributeValue"] = "
|
||||
\$this->dashletsUids = array(
|
||||
@@ -720,9 +723,9 @@ function run_new_plugin($task, $args) {
|
||||
$fields["dashboardSetup"] = "\$this->registerDashlets();";
|
||||
$fields["dashboardEnable"] = "\$this->dashletInsert();";
|
||||
$fields["dashboardDisable"] = "\$this->dashletDelete();";
|
||||
|
||||
|
||||
G::verifyPath($pluginHome . PATH_SEP . "views", true);
|
||||
|
||||
|
||||
savePluginFile($pluginName . PATH_SEP . "classes" . PATH_SEP . "class.dashlet". $pluginName . ".php", "pluginDashletClass.php", $pluginName, $pluginName);
|
||||
copyPluginFile("pluginDashlet.html", $pluginName . PATH_SEP . "views" . PATH_SEP . "dashlet". $pluginName . ".html", $pluginName, null, true);
|
||||
}
|
||||
@@ -2613,3 +2616,28 @@ function run_check_standard_code ( $task, $options) {
|
||||
pakeColor::colorize($val['dos'] ? 'dos' : ' ', 'INFO'), $val['file'] );
|
||||
}
|
||||
}
|
||||
|
||||
function run_update_plugin_attributes($task, $args)
|
||||
{
|
||||
try {
|
||||
G::LoadClass("plugin");
|
||||
|
||||
//Verify data
|
||||
if (!isset($args[0])) {
|
||||
throw new Exception("Error: You must specify the name of a plugin");
|
||||
}
|
||||
|
||||
//Set variables
|
||||
$pluginName = $args[0];
|
||||
|
||||
//Update plugin attributes
|
||||
$pmPluginRegistry = &PMPluginRegistry::getSingleton();
|
||||
|
||||
$pmPluginRegistry->updatePluginAttributesInAllWorkspaces($pluginName);
|
||||
|
||||
echo "Done!\n";
|
||||
} catch (Exception $e) {
|
||||
echo $e->getMessage() . "\n";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -260,7 +260,7 @@ class PMPluginRegistry
|
||||
//register the default directory, later we can have more
|
||||
$this->_aPluginDetails[$sNamespace]->enabled = true;
|
||||
if (class_exists($detail->sClassName)) {
|
||||
$oPlugin = new $detail->sClassName( $detail->sNamespace, $detail->sFilename );
|
||||
$oPlugin = new $detail->sClassName( $detail->sNamespace, $detail->sFilename );
|
||||
} else {
|
||||
$oPlugin = $detail;
|
||||
}
|
||||
@@ -1513,5 +1513,88 @@ class PMPluginRegistry
|
||||
{
|
||||
return $this->_aCronFiles;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the plugin attributes in all workspaces
|
||||
*
|
||||
* @param string $pluginName Plugin name
|
||||
*
|
||||
* return void
|
||||
*/
|
||||
public function updatePluginAttributesInAllWorkspaces($pluginName)
|
||||
{
|
||||
try {
|
||||
G::LoadClass("system");
|
||||
G::LoadClass("wsTools");
|
||||
|
||||
//Set variables
|
||||
$pluginFileName = $pluginName . ".php";
|
||||
|
||||
//Verify data
|
||||
if (!file_exists(PATH_PLUGINS . $pluginFileName)) {
|
||||
throw new Exception("Error: The plugin not exists");
|
||||
}
|
||||
|
||||
//Update plugin attributes
|
||||
require_once(PATH_PLUGINS . $pluginFileName);
|
||||
|
||||
$pmPluginRegistry = &PMPluginRegistry::getSingleton();
|
||||
|
||||
$pluginDetails = $pmPluginRegistry->getPluginDetails($pluginFileName);
|
||||
|
||||
if (isset($pluginDetails->aWorkspaces) && is_array($pluginDetails->aWorkspaces) && count($pluginDetails->aWorkspaces) > 0) {
|
||||
$arrayWorkspace = array();
|
||||
|
||||
foreach (System::listWorkspaces() as $value) {
|
||||
$workspaceTools = $value;
|
||||
|
||||
$arrayWorkspace[] = $workspaceTools->name;
|
||||
}
|
||||
|
||||
$arrayWorkspaceAux = array_diff($arrayWorkspace, $pluginDetails->aWorkspaces); //Workspaces to update
|
||||
$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 = PMPluginRegistry::loadSingleton($workspacePathDataSite . "plugin.singleton");
|
||||
|
||||
if (isset($pmPluginRegistry->_aPluginDetails[$pluginName])) {
|
||||
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 = PMPluginRegistry::loadSingleton($workspacePathDataSite . "plugin.singleton");
|
||||
|
||||
$pmPluginRegistry->disablePlugin($pluginName);
|
||||
|
||||
file_put_contents($workspacePathDataSite . "plugin.singleton", $pmPluginRegistry->serializeInstance());
|
||||
}
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user