PMCORE-2302 Add in the upgrade process a script to update the table SCHEDULER in order to add the new option +async
This commit is contained in:
committed by
Julio Cesar Laura Avendaño
parent
c434e13467
commit
56b2a4f6dd
52
tests/unit/workflow/engine/classes/WorkflowToolsTest.php
Normal file
52
tests/unit/workflow/engine/classes/WorkflowToolsTest.php
Normal file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\unit\workflow\engine\classes;
|
||||
|
||||
use Tests\TestCase;
|
||||
use WorkspaceTools;
|
||||
|
||||
class WorkflowToolsTest extends TestCase
|
||||
{
|
||||
private $workspaceTools;
|
||||
|
||||
/**
|
||||
* Method set up.
|
||||
*/
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->workspaceTools = new WorkspaceTools('workflow');
|
||||
}
|
||||
|
||||
/**
|
||||
* Method tear down.
|
||||
*/
|
||||
public function tearDown()
|
||||
{
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
/**
|
||||
* This test the addAsyncOptionToSchedulerCommands method.
|
||||
* @test
|
||||
* @covers \WorkspaceTools::addAsyncOptionToSchedulerCommands()
|
||||
*/
|
||||
public function it_should_test_addAsyncOptionToSchedulerCommands_method()
|
||||
{
|
||||
//to do: a valid workspace is required.
|
||||
if (!defined('HASH_INSTALLATION') || !defined('SYSTEM_HASH')) {
|
||||
$message = "A workspace installation is required where the values HASH_INSTALLATION,"
|
||||
. "SYSTEM_HASH, db.php exist and are correct.";
|
||||
$this->markTestIncomplete($message);
|
||||
}
|
||||
ob_start();
|
||||
$this->workspaceTools->addAsyncOptionToSchedulerCommands(false);
|
||||
$string = ob_get_clean();
|
||||
$this->assertRegExp("/This was previously updated/", $string);
|
||||
|
||||
ob_start();
|
||||
$this->workspaceTools->addAsyncOptionToSchedulerCommands(true);
|
||||
$string = ob_get_clean();
|
||||
$this->assertRegExp("/Adding \+async option/", $string);
|
||||
}
|
||||
}
|
||||
@@ -428,6 +428,17 @@ EOT
|
||||
CLI::taskArg('fontFileName', false);
|
||||
CLI::taskRun('documents_remove_font');
|
||||
|
||||
/**
|
||||
* Add +async option to scheduler commands in table SCHEDULER.
|
||||
*/
|
||||
CLI::taskName('add-async-option-to-scheduler-commands');
|
||||
CLI::taskDescription(<<<EOT
|
||||
Add +async option to scheduler commands in table SCHEDULER.
|
||||
EOT
|
||||
);
|
||||
CLI::taskArg('workspace');
|
||||
CLI::taskRun('add_async_option_to_scheduler_commands');
|
||||
|
||||
/**
|
||||
* Function run_info
|
||||
*
|
||||
@@ -1606,3 +1617,26 @@ function documents_remove_font($args)
|
||||
CLI::logging($e->getMessage() . PHP_EOL . PHP_EOL);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add +async option to scheduler commands in table SCHEDULER.
|
||||
* @param array $args
|
||||
* @param string $opts
|
||||
*/
|
||||
function add_async_option_to_scheduler_commands($args, $opts)
|
||||
{
|
||||
if (count($args) === 1) {
|
||||
Bootstrap::setConstantsRelatedWs($args[0]);
|
||||
$workspaceTools = new WorkspaceTools($args[0]);
|
||||
|
||||
CLI::logging("> Adding +async option to scheduler commands...\n");
|
||||
$start = microtime(true);
|
||||
$workspaceTools->addAsyncOptionToSchedulerCommands(true);
|
||||
CLI::logging("<*> Adding +async option to scheduler commands took " . (microtime(true) - $start) . " seconds.\n");
|
||||
} else {
|
||||
$workspaces = get_workspaces_from_args($args);
|
||||
foreach ($workspaces as $workspace) {
|
||||
passthru(PHP_BINARY . ' processmaker add-async-option-to-scheduler-commands ' . $workspace->name);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -364,6 +364,11 @@ class WorkspaceTools
|
||||
$start = microtime(true);
|
||||
$this->updateTriggers(true, $lang);
|
||||
CLI::logging("* End updating MySQL triggers...(" . (microtime(true) - $start) . " seconds)\n");
|
||||
|
||||
CLI::logging("* Start adding +async option to scheduler commands...\n");
|
||||
$start = microtime(true);
|
||||
$this->addAsyncOptionToSchedulerCommands(true);
|
||||
CLI::logging("* End adding +async option to scheduler commands...(Completed on " . (microtime(true) - $start) . " seconds)\n");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2206,6 +2211,11 @@ class WorkspaceTools
|
||||
$start = microtime(true);
|
||||
$workspace->updateTriggers(true, $lang);
|
||||
CLI::logging("* End updating MySQL triggers...(" . (microtime(true) - $start) . " seconds)\n");
|
||||
|
||||
CLI::logging("* Start adding +async option to scheduler commands...\n");
|
||||
$start = microtime(true);
|
||||
$this->addAsyncOptionToSchedulerCommands(false);
|
||||
CLI::logging("* End adding +async option to scheduler commands...(Completed on " . (microtime(true) - $start) . " seconds)\n");
|
||||
}
|
||||
|
||||
CLI::logging("> Start To Verify License Enterprise...\n");
|
||||
@@ -5040,4 +5050,37 @@ class WorkspaceTools
|
||||
$database = $this->getDatabase($rbac);
|
||||
$database->executeQuery($query, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add +async option to scheduler commands in table SCHEDULER.
|
||||
* @param boolean $force
|
||||
*/
|
||||
public function addAsyncOptionToSchedulerCommands($force = false)
|
||||
{
|
||||
//read update status
|
||||
$this->initPropel(true);
|
||||
$conf = new Configurations();
|
||||
$exist = $conf->exists('ADDED_ASYNC_OPTION_TO_SCHEDULER', 'scheduler');
|
||||
if ($exist === true && $force === false) {
|
||||
$config = (object) $conf->load('ADDED_ASYNC_OPTION_TO_SCHEDULER', 'scheduler');
|
||||
if ($config->updated) {
|
||||
CLI::logging("-> This was previously updated.\n");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
//update process
|
||||
$updateQuery = ""
|
||||
. "UPDATE {$this->dbName}.SCHEDULER SET body = REPLACE(body, '+force\"', '+force +async\"') "
|
||||
. "WHERE body NOT LIKE '%+async%'"
|
||||
. "";
|
||||
$con = Propel::getConnection("workflow");
|
||||
$stmt = $con->createStatement();
|
||||
$stmt->executeQuery($updateQuery);
|
||||
CLI::logging("-> Adding +async option to scheduler commands in table {$this->dbName}.SCHEDULER\n");
|
||||
|
||||
//save update status
|
||||
$conf->aConfig = ['updated' => true];
|
||||
$conf->saveConfig('ADDED_ASYNC_OPTION_TO_SCHEDULER', 'scheduler');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user