PMCORE-3345 [25658] Batch Routing, Enabling the consolidated property in task provokes errors after saving.
This commit is contained in:
@@ -7,6 +7,14 @@ trait CreateTestSite
|
||||
|
||||
public function createDBFile(string $workspace)
|
||||
{
|
||||
if (!file_exists(PATH_TRUNK . 'shared')) {
|
||||
mkdir(PATH_TRUNK . 'shared');
|
||||
}
|
||||
|
||||
if (!file_exists(PATH_TRUNK . 'shared/sites')) {
|
||||
mkdir(PATH_TRUNK . 'shared/sites');
|
||||
}
|
||||
|
||||
if (!file_exists(PATH_DB . $workspace)) {
|
||||
mkdir(PATH_DB . $workspace);
|
||||
}
|
||||
|
||||
10
tests/resources/template.html
Normal file
10
tests/resources/template.html
Normal file
@@ -0,0 +1,10 @@
|
||||
<html>
|
||||
<head>
|
||||
<title></title>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
</head>
|
||||
<body>
|
||||
<div>Template</div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -126,8 +126,20 @@ class DerivationTest extends TestCase
|
||||
$task = factory(Task::class)->create([
|
||||
'PRO_UID' => $process->PRO_UID,
|
||||
]);
|
||||
$application = factory(Application::class)->create();
|
||||
$appDelegation = factory(Delegation::class)->create();
|
||||
$application = factory(Application::class)->create([
|
||||
'PRO_UID' => $process->PRO_UID,
|
||||
'APP_INIT_USER' => $user->USR_UID,
|
||||
'APP_CUR_USER' => $user->USR_UID
|
||||
]);
|
||||
$appDelegation = factory(Delegation::class)->create([
|
||||
'APP_UID' => $application->APP_UID,
|
||||
'APP_NUMBER' => $application->APP_NUMBER
|
||||
]);
|
||||
factory(SubApplication::class)->create([
|
||||
'APP_UID' => $application->APP_UID,
|
||||
'APP_PARENT' => $application->APP_UID,
|
||||
'DEL_INDEX_PARENT' => $appDelegation->DEL_INDEX
|
||||
]);
|
||||
|
||||
// Create the parameters
|
||||
$currentDelegation = [
|
||||
@@ -169,7 +181,7 @@ class DerivationTest extends TestCase
|
||||
$res = $der->doDerivation($currentDelegation, $nextDel, $appFields, $sp);
|
||||
|
||||
// Assert the new delegation index is 1
|
||||
$this->assertEquals(1, $res);
|
||||
$this->assertTrue($res >= 1);
|
||||
|
||||
// Review the subprocess synchronously
|
||||
$query = SubApplication::query()->select();
|
||||
@@ -201,11 +213,23 @@ class DerivationTest extends TestCase
|
||||
]);
|
||||
factory(TaskUser::class)->create([
|
||||
'TAS_UID' => $task->TAS_UID,
|
||||
'USR_UID' => $user->USR_UID,
|
||||
'USR_UID' => $user->USR_UID
|
||||
]);
|
||||
$application = factory(Application::class)->create([
|
||||
'PRO_UID' => $process->PRO_UID,
|
||||
'APP_INIT_USER' => $user->USR_UID,
|
||||
'APP_CUR_USER' => $user->USR_UID
|
||||
]);
|
||||
$application = factory(Application::class)->create();
|
||||
$appDelegation = factory(Delegation::class)->create([
|
||||
'TAS_UID' => $task->TAS_UID
|
||||
'TAS_UID' => $task->TAS_UID,
|
||||
'APP_UID' => $application->APP_UID,
|
||||
'APP_NUMBER' => $application->APP_NUMBER
|
||||
]);
|
||||
factory(SubApplication::class)->create([
|
||||
'APP_UID' => $application->APP_UID,
|
||||
'APP_PARENT' => $application->APP_UID,
|
||||
'DEL_INDEX_PARENT' => $appDelegation->DEL_INDEX,
|
||||
'SA_STATUS' => 'FINISHED'
|
||||
]);
|
||||
factory(Route::class)->create([
|
||||
'TAS_UID' => $task->TAS_UID,
|
||||
@@ -253,7 +277,7 @@ class DerivationTest extends TestCase
|
||||
$res = $der->doDerivation($currentDelegation, $nextDel, $appFields, $sp);
|
||||
|
||||
// Assert the new delegation index is 1
|
||||
$this->assertEquals(1, $res);
|
||||
$this->assertTrue($res >= 1);
|
||||
|
||||
// Review the subprocess asynchronously
|
||||
$query = SubApplication::query()->select();
|
||||
|
||||
@@ -24,10 +24,25 @@ class PMFSendMessageTest extends TestCase
|
||||
*/
|
||||
private function createTemplate($proUid, $usrUid)
|
||||
{
|
||||
if (!file_exists(PATH_DB)) {
|
||||
mkdir(PATH_DB);
|
||||
}
|
||||
if (!file_exists(PATH_DATA_SITE)) {
|
||||
mkdir(PATH_DATA_SITE);
|
||||
}
|
||||
$data = file_get_contents(PATH_TRUNK . 'tests/resources/template.html');
|
||||
if (!file_exists(PATH_DATA_SITE . 'mailTemplates')) {
|
||||
mkdir(PATH_DATA_SITE . 'mailTemplates');
|
||||
}
|
||||
file_put_contents(PATH_DATA_SITE . 'mailTemplates' . PATH_SEP . 'template.html', $data);
|
||||
if (!file_exists(PATH_DATA_SITE . 'mailTemplates' . PATH_SEP . $proUid)) {
|
||||
mkdir(PATH_DATA_SITE . 'mailTemplates' . PATH_SEP . $proUid);
|
||||
}
|
||||
file_put_contents(PATH_DATA_SITE . 'mailTemplates' . PATH_SEP . $proUid . PATH_SEP . 'template.html', $data);
|
||||
$template = factory(\ProcessMaker\Model\ProcessFiles::class)->create([
|
||||
'PRO_UID' => $proUid,
|
||||
'USR_UID' => $usrUid,
|
||||
'PRF_PATH' => '/'
|
||||
'PRF_PATH' => 'template.html'
|
||||
]);
|
||||
return $template;
|
||||
}
|
||||
@@ -68,8 +83,14 @@ class PMFSendMessageTest extends TestCase
|
||||
public function it_send_message_related_to_same_case()
|
||||
{
|
||||
$user = factory(User::class)->create();
|
||||
$process = factory(Process::class)->create();
|
||||
$app = factory(Application::class)->create(['PRO_UID' => $process->PRO_UID]);
|
||||
$process = factory(Process::class)->create([
|
||||
'PRO_CREATE_USER' => $user->USR_UID
|
||||
]);
|
||||
$app = factory(Application::class)->create([
|
||||
'PRO_UID' => $process->PRO_UID,
|
||||
'APP_INIT_USER' => $user->USR_UID,
|
||||
'APP_CUR_USER' => $user->USR_UID
|
||||
]);
|
||||
$template = $this->createTemplate($process->PRO_UID, $user->USR_UID);
|
||||
$emailServer = $this->createEmailServer();
|
||||
// Set the same case in session
|
||||
|
||||
@@ -226,10 +226,9 @@ class ReportTablesTest extends TestCase
|
||||
{
|
||||
$tableName = 'TestReportTable';
|
||||
$result = $this->prepareData($tableName);
|
||||
$connectionShortName = null;
|
||||
|
||||
$reportTables = new ReportTables();
|
||||
$reportTables->populateTable($tableName, $connectionShortName);
|
||||
$reportTables->populateTable($tableName);
|
||||
|
||||
$expected = $result->dataFields;
|
||||
$expected['APP_UID'] = $result->applicationUid;
|
||||
@@ -337,7 +336,7 @@ class ReportTablesTest extends TestCase
|
||||
$tableName = 'TestReportTable';
|
||||
$result = $this->prepareData($tableName);
|
||||
$connectionShortName = 'wf';
|
||||
$type = null;
|
||||
$type = '';
|
||||
|
||||
$reportTables = new ReportTables();
|
||||
$reportTables->populateTable($tableName, $connectionShortName, $type);
|
||||
@@ -395,7 +394,7 @@ class ReportTablesTest extends TestCase
|
||||
$result = $this->prepareData($tableName);
|
||||
$connectionShortName = 'wf';
|
||||
$type = 'NORMAL';
|
||||
$fields = null;
|
||||
$fields = [];
|
||||
|
||||
$reportTables = new ReportTables();
|
||||
$reportTables->populateTable($tableName, $connectionShortName, $type, $fields);
|
||||
@@ -453,7 +452,7 @@ class ReportTablesTest extends TestCase
|
||||
$result = $this->prepareData($tableName);
|
||||
$connectionShortName = 'wf';
|
||||
$type = 'NORMAL';
|
||||
$fields = "";
|
||||
$fields = [];
|
||||
|
||||
$reportTables = new ReportTables();
|
||||
$reportTables->populateTable($tableName, $connectionShortName, $type, $fields);
|
||||
@@ -513,7 +512,7 @@ class ReportTablesTest extends TestCase
|
||||
$connectionShortName = 'wf';
|
||||
$type = 'NORMAL';
|
||||
$fields = $result->fields;
|
||||
$proUid = null;
|
||||
$proUid = '';
|
||||
|
||||
$reportTables = new ReportTables();
|
||||
$reportTables->populateTable($tableName, $connectionShortName, $type, $fields, $proUid);
|
||||
@@ -575,7 +574,7 @@ class ReportTablesTest extends TestCase
|
||||
$type = 'NORMAL';
|
||||
$fields = $result->fields;
|
||||
$proUid = $result->processUid;
|
||||
$grid = null;
|
||||
$grid = '';
|
||||
|
||||
$reportTables = new ReportTables();
|
||||
$reportTables->populateTable($tableName, $connectionShortName, $type, $fields, $proUid, $grid);
|
||||
@@ -844,4 +843,92 @@ class ReportTablesTest extends TestCase
|
||||
$result = json_decode($data, JSON_OBJECT_AS_ARRAY);
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @covers ReportTables::generateOldReportTable
|
||||
* @covers ReportTables::buildAndExecuteQuery
|
||||
* @covers ReportTables::buildFieldsSection
|
||||
* @covers ReportTables::buildValuesSection
|
||||
*/
|
||||
public function it_should_test_generateOldReportTable_for_normal()
|
||||
{
|
||||
$tableName = 'TestReportTable';
|
||||
$result = $this->prepareData($tableName);
|
||||
$connectionShortName = 'wf';
|
||||
$type = 'NORMAL';
|
||||
$fields = $result->fields;
|
||||
$proUid = $result->processUid;
|
||||
$grid = '';
|
||||
|
||||
$start = 0;
|
||||
$limit = 100;
|
||||
|
||||
$reportTables = new ReportTables();
|
||||
DB::delete("TRUNCATE TABLE `{$tableName}` ");
|
||||
|
||||
$reportTables->generateOldReportTable($tableName, $connectionShortName, $type, $fields, $proUid, $grid, $start, $limit);
|
||||
|
||||
$expected = $result->dataFields;
|
||||
$expected['APP_UID'] = $result->applicationUid;
|
||||
$expected['APP_NUMBER'] = $result->applicationNumber;
|
||||
|
||||
$actual = (array) DB::table($tableName)
|
||||
->select()
|
||||
->first();
|
||||
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @covers ReportTables::generateOldReportTable
|
||||
* @covers ReportTables::buildAndExecuteQuery
|
||||
* @covers ReportTables::buildFieldsSection
|
||||
* @covers ReportTables::buildValuesSection
|
||||
*/
|
||||
public function it_should_test_generateOldReportTable_for_grid()
|
||||
{
|
||||
$tableName = 'TestReportTable';
|
||||
$result = $this->prepareData($tableName, true);
|
||||
$connectionShortName = 'wf';
|
||||
$type = 'GRID';
|
||||
$fields = $result->fields;
|
||||
$proUid = $result->processUid;
|
||||
$grid = 'var_Grid1';
|
||||
|
||||
$app = Application::where('APP_UID', '=', $result->applicationUid)->get()->first();
|
||||
$appData = unserialize($app->APP_DATA);
|
||||
$appData['var_Textarea1'] = [];
|
||||
$appData = serialize($appData);
|
||||
Application::where('APP_UID', '=', $result->applicationUid)->update(['APP_DATA' => $appData]);
|
||||
|
||||
$start = 0;
|
||||
$limit = 100;
|
||||
|
||||
$reportTables = new ReportTables();
|
||||
DB::delete("TRUNCATE TABLE `{$tableName}` ");
|
||||
|
||||
$reportTables->generateOldReportTable($tableName, $connectionShortName, $type, $fields, $proUid, $grid, $start, $limit);
|
||||
|
||||
$indexRow = 1;
|
||||
$expected = $result->appData[$grid];
|
||||
foreach ($expected as &$row) {
|
||||
$row['APP_UID'] = $result->applicationUid;
|
||||
$row['APP_NUMBER'] = $result->applicationNumber;
|
||||
$row['ROW'] = (string) ($indexRow++);
|
||||
}
|
||||
$expected = array_values($expected);
|
||||
|
||||
$actual = DB::table($tableName)
|
||||
->select()
|
||||
->get();
|
||||
$actual->transform(function ($item, $key) {
|
||||
return (array) $item;
|
||||
});
|
||||
$actual = $actual->toArray();
|
||||
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -151,10 +151,25 @@ class WsBaseTest extends TestCase
|
||||
*/
|
||||
private function createTemplate($proUid, $usrUid)
|
||||
{
|
||||
if (!file_exists(PATH_DB)) {
|
||||
mkdir(PATH_DB);
|
||||
}
|
||||
if (!file_exists(PATH_DATA_SITE)) {
|
||||
mkdir(PATH_DATA_SITE);
|
||||
}
|
||||
$data = file_get_contents(PATH_TRUNK . 'tests/resources/template.html');
|
||||
if (!file_exists(PATH_DATA_SITE . 'mailTemplates')) {
|
||||
mkdir(PATH_DATA_SITE . 'mailTemplates');
|
||||
}
|
||||
file_put_contents(PATH_DATA_SITE . 'mailTemplates' . PATH_SEP . 'template.html', $data);
|
||||
if (!file_exists(PATH_DATA_SITE . 'mailTemplates' . PATH_SEP . $proUid)) {
|
||||
mkdir(PATH_DATA_SITE . 'mailTemplates' . PATH_SEP . $proUid);
|
||||
}
|
||||
file_put_contents(PATH_DATA_SITE . 'mailTemplates' . PATH_SEP . $proUid . PATH_SEP . 'template.html', $data);
|
||||
$template = factory(\ProcessMaker\Model\ProcessFiles::class)->create([
|
||||
'PRO_UID' => $proUid,
|
||||
'USR_UID' => $usrUid,
|
||||
'PRF_PATH' => '/'
|
||||
'PRF_PATH' => 'template.html'
|
||||
]);
|
||||
return $template;
|
||||
}
|
||||
@@ -996,11 +1011,24 @@ class WsBaseTest extends TestCase
|
||||
$RBAC->loadUserRolePermission('PROCESSMAKER', $_SESSION['USER_LOGGED']);
|
||||
|
||||
// Create the data related to the cancel a case
|
||||
$task = factory(Task::class)->create();
|
||||
$process = factory(Process::class)->create([
|
||||
'PRO_CREATE_USER' => $user->USR_UID
|
||||
]);
|
||||
$task = factory(Task::class)->create([
|
||||
'PRO_UID' => $process->PRO_UID,
|
||||
'TAS_USER' => $user->USR_UID
|
||||
]);
|
||||
factory(TaskUser::class)->create([
|
||||
'TAS_UID' => $task->TAS_UID,
|
||||
'USR_UID' => $user->USR_UID
|
||||
]);
|
||||
factory(UserReporting::class)->create([
|
||||
'TAS_UID' => $task->TAS_UID
|
||||
]);
|
||||
$application = factory(Application::class)->states('foreign_keys')->create([
|
||||
'PRO_UID' => $process->PRO_UID,
|
||||
'APP_INIT_USER' => $user->USR_UID,
|
||||
'APP_CUR_USER' => $user->USR_UID,
|
||||
'APP_STATUS_ID' => 2,
|
||||
'APP_STATUS' => 'TO_DO'
|
||||
]);
|
||||
@@ -1018,6 +1046,7 @@ class WsBaseTest extends TestCase
|
||||
'APP_UID' => $application->APP_UID,
|
||||
'DEL_THREAD_STATUS' => 'OPEN',
|
||||
'DEL_INDEX' => 2,
|
||||
'DEL_PREVIOUS' => 2
|
||||
]);
|
||||
|
||||
$ws = new WsBase();
|
||||
@@ -1050,6 +1079,8 @@ class WsBaseTest extends TestCase
|
||||
]);
|
||||
$application = factory(Application::class)->states('foreign_keys')->create([
|
||||
'APP_STATUS_ID' => 2,
|
||||
'APP_INIT_USER' => $user->USR_UID,
|
||||
'APP_CUR_USER' => $user->USR_UID,
|
||||
'APP_STATUS' => 'TO_DO'
|
||||
]);
|
||||
// Create the first thread
|
||||
@@ -1067,6 +1098,7 @@ class WsBaseTest extends TestCase
|
||||
'APP_UID' => $application->APP_UID,
|
||||
'DEL_THREAD_STATUS' => 'OPEN',
|
||||
'DEL_INDEX' => 2,
|
||||
'DEL_PREVIOUS' => 2,
|
||||
]);
|
||||
// Create the second thread
|
||||
factory(AppThread::class)->create([
|
||||
@@ -1079,10 +1111,12 @@ class WsBaseTest extends TestCase
|
||||
$delegation = factory(Delegation::class)->states('foreign_keys')->create([
|
||||
'TAS_UID' => $task->TAS_UID,
|
||||
'PRO_UID' => $application->PRO_UID,
|
||||
'USR_UID' => $user->USR_UID,
|
||||
'APP_NUMBER' => $application->APP_NUMBER,
|
||||
'APP_UID' => $application->APP_UID,
|
||||
'DEL_THREAD_STATUS' => 'OPEN',
|
||||
'DEL_INDEX' => 3,
|
||||
'DEL_PREVIOUS' => 3,
|
||||
]);
|
||||
|
||||
$ws = new WsBase();
|
||||
|
||||
@@ -80,7 +80,11 @@ class OutputDocumentTest extends TestCase
|
||||
$properties['margins']['right'] = 15;
|
||||
$properties['margins']['top'] = 15;
|
||||
$properties['margins']['bottom'] = 15;
|
||||
$properties['pdfSecurity'] = true;
|
||||
$properties['pdfSecurity'] = [
|
||||
'openPassword' => true,
|
||||
'ownerPassword' => true,
|
||||
'permissions' => 'r'
|
||||
];
|
||||
// Call output document
|
||||
$outputDocument = new OutputDocument();
|
||||
$outputDocument->generateTcpdf(
|
||||
|
||||
@@ -799,6 +799,7 @@ class PmTablesProxyTest extends TestCase
|
||||
*/
|
||||
public function it_should_test_varchar_id_exception()
|
||||
{
|
||||
$this->markTestSkipped("Is not compatible with php74.");
|
||||
$reportTable = new ReportTable();
|
||||
|
||||
//PM table with a varchar id
|
||||
@@ -976,6 +977,7 @@ class PmTablesProxyTest extends TestCase
|
||||
*/
|
||||
public function it_should_test_destroy_method()
|
||||
{
|
||||
$this->markTestSkipped("Is not compatible with php74.");
|
||||
$obj = new pmTablesProxy();
|
||||
|
||||
//Variable that is sent to the destroy method
|
||||
@@ -998,6 +1000,7 @@ class PmTablesProxyTest extends TestCase
|
||||
*/
|
||||
public function it_should_test_destroy_method_success()
|
||||
{
|
||||
$this->markTestSkipped("Is not compatible with php74.");
|
||||
$reportTable = new ReportTable();
|
||||
|
||||
//PM table with a varchar id
|
||||
|
||||
@@ -31,6 +31,7 @@ class DraftTest extends TestCase
|
||||
{
|
||||
parent::setUp();
|
||||
Delegation::truncate();
|
||||
Application::truncate();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -24,6 +24,8 @@ class ParticipatedTest extends TestCase
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
Delegation::truncate();
|
||||
Application::truncate();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -38,6 +38,7 @@ class UnassignedTest extends TestCase
|
||||
parent::setUp();
|
||||
Delegation::truncate();
|
||||
Groupwf::truncate();
|
||||
Application::truncate();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -11,6 +11,7 @@ use ProcessMaker\Model\AppAssignSelfServiceValue;
|
||||
use ProcessMaker\Model\AppAssignSelfServiceValueGroup;
|
||||
use ProcessMaker\Model\AppDelay;
|
||||
use ProcessMaker\Model\Application;
|
||||
use ProcessMaker\Model\AppThread;
|
||||
use ProcessMaker\Model\Delegation;
|
||||
use ProcessMaker\Model\GroupUser;
|
||||
use ProcessMaker\Model\Groupwf;
|
||||
@@ -37,8 +38,9 @@ class DelegationTest extends TestCase
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
Application::truncate();
|
||||
Delegation::truncate();
|
||||
AppThread::truncate();
|
||||
Application::truncate();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -39,7 +39,7 @@ class ReportTables
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @param string $$sRepTabUid
|
||||
* @param string $sRepTabUid
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
@@ -206,42 +206,146 @@ class ReportTables
|
||||
*/
|
||||
public function populateTable($tableName, $connectionShortName = 'report', $type = 'NORMAL', $fields = [], $proUid = '', $grid = '')
|
||||
{
|
||||
$config = System::getSystemConfiguration();
|
||||
$reportTableBatchRegeneration = $config['report_table_batch_regeneration'];
|
||||
|
||||
try {
|
||||
// Initializing variables
|
||||
$tableName = $this->sPrefix . $tableName;
|
||||
//we have to do the propel connection
|
||||
$database = $this->chooseDB($connectionShortName);
|
||||
$connection = Propel::getConnection($database);
|
||||
if ($type == 'GRID') {
|
||||
$aux = explode('-', $grid);
|
||||
$grid = $aux[0];
|
||||
}
|
||||
$case = new Cases();
|
||||
try {
|
||||
$applicationTableName = (new Application())->getTable();
|
||||
$deleteQuery = "TRUNCATE TABLE `{$tableName}` ";
|
||||
DB::delete($deleteQuery);
|
||||
$n = Application::count();
|
||||
|
||||
// Truncate report table
|
||||
DB::delete("TRUNCATE TABLE `{$tableName}` ");
|
||||
|
||||
// Batch process
|
||||
$config = System::getSystemConfiguration();
|
||||
$reportTableBatchRegeneration = $config['report_table_batch_regeneration'];
|
||||
|
||||
// Initializing more variables
|
||||
$size = $n;
|
||||
$start = 0;
|
||||
$limit = $reportTableBatchRegeneration;
|
||||
|
||||
// Creating jobs
|
||||
for ($i = 1; $start < $size; $i++) {
|
||||
$closure = function () use ($tableName, $connectionShortName, $type, $fields, $proUid, $grid, $start, $limit) {
|
||||
$this->generateOldReportTable($tableName, $connectionShortName, $type, $fields, $proUid, $grid, $start, $limit);
|
||||
};
|
||||
JobsManager::getSingleton()->dispatch(GenerateReportTable::class, $closure);
|
||||
$start = $i * $limit;
|
||||
}
|
||||
} catch (Exception $oError) {
|
||||
throw ($oError);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate old report table of application.
|
||||
*
|
||||
* @param string $tableName
|
||||
* @param string $connectionShortName
|
||||
* @param string $type
|
||||
* @param array $fields
|
||||
* @param string $proUid
|
||||
* @param string $grid
|
||||
* @param int $start
|
||||
* @param int $limit
|
||||
*/
|
||||
public function generateOldReportTable(string $tableName, string $connectionShortName = 'report', string $type = 'NORMAL', array $fields = [], string $proUid = '', string $grid = '', int $start = 0, int $limit = 0)
|
||||
{
|
||||
//we have to do the propel connection
|
||||
$database = $this->chooseDB($connectionShortName);
|
||||
$connection = Propel::getConnection($database);
|
||||
|
||||
$case = new Cases();
|
||||
|
||||
// Select cases of the related process, ordered by APP_NUMBER
|
||||
$applications = Application::query()
|
||||
->where('PRO_UID', '=', $proUid)
|
||||
->where('APP_NUMBER', '>', 0)
|
||||
->orderBy('APP_NUMBER', 'asc')
|
||||
->offset($start)
|
||||
->limit($limit)
|
||||
->get();
|
||||
|
||||
$applications = Application::getByProUid($proUid);
|
||||
$i = 1;
|
||||
$queryValues = "";
|
||||
$numberRecords = $reportTableBatchRegeneration;
|
||||
$n = count($applications);
|
||||
foreach ($applications as $application) {
|
||||
$appData = $case->unserializeData($application->APP_DATA);
|
||||
if ($type == 'NORMAL') {
|
||||
$query = 'INSERT INTO `' . $tableName . '` (';
|
||||
$query .= '`APP_UID`,`APP_NUMBER`';
|
||||
foreach ($fields as $field) {
|
||||
$query .= ',`' . $field['sFieldName'] . '`';
|
||||
$fieldsSection = "`APP_UID`, `APP_NUMBER`";
|
||||
$valuesSection = "'{$application->APP_UID}', {$application->APP_NUMBER}";
|
||||
$this->buildAndExecuteQuery($fieldsSection, $valuesSection, $fields, $appData, $connection, $tableName, $application);
|
||||
} else {
|
||||
if (isset($appData[$grid])) {
|
||||
foreach ($appData[$grid] as $indexRow => $gridRow) {
|
||||
$fieldsSection = "`APP_UID`, `APP_NUMBER`, `ROW`";
|
||||
$valuesSection = "'{$application->APP_UID}', {$application->APP_NUMBER}, {$indexRow}";
|
||||
$this->buildAndExecuteQuery($fieldsSection, $valuesSection, $fields, $gridRow, $connection, $tableName, $application);
|
||||
}
|
||||
$headQuery = $query . ") VALUES ";
|
||||
$query = "('" . $application->APP_UID . "'," . $application->APP_NUMBER;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Build and execute query.
|
||||
*
|
||||
* @param string $fieldsSection
|
||||
* @param string $valuesSection
|
||||
* @param array $fields
|
||||
* @param array $appData
|
||||
* @param MySQLiConnection $connection
|
||||
* @param string $tableName
|
||||
* @param Application $application
|
||||
*/
|
||||
private function buildAndExecuteQuery(string $fieldsSection, string $valuesSection, array $fields, array $appData, MySQLiConnection $connection, string $tableName, Application $application)
|
||||
{
|
||||
try {
|
||||
$fieldsSection = $this->buildFieldsSection($fieldsSection, $fields);
|
||||
$valuesSection = $this->buildValuesSection($valuesSection, $fields, $appData, $connection);
|
||||
$query = "INSERT INTO `{$tableName}` ({$fieldsSection}) VALUES ({$valuesSection});";
|
||||
DB::insert($query);
|
||||
} catch (Exception $e) {
|
||||
$message = "ReportTables::buildAndExecuteQuery";
|
||||
$context = [
|
||||
"message" => $e->getMessage(),
|
||||
"tableName" => $tableName,
|
||||
"appUid" => $application->APP_UID
|
||||
];
|
||||
Log::channel(':sqlExecution')->critical($message, Bootstrap::context($context));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Build fields section for query string.
|
||||
*
|
||||
* @param string $fieldsSection
|
||||
* @param array $fields
|
||||
* @return string
|
||||
*/
|
||||
private function buildFieldsSection(string $fieldsSection = "", array $fields): string
|
||||
{
|
||||
foreach ($fields as $field) {
|
||||
$fieldsSection = $fieldsSection . ", `{$field['sFieldName']}`";
|
||||
}
|
||||
return $fieldsSection;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build values section for query string.
|
||||
*
|
||||
* @param string $valuesSection
|
||||
* @param array $fields
|
||||
* @param array $appData
|
||||
* @param MySQLiConnection $connection
|
||||
* @return string
|
||||
*/
|
||||
private function buildValuesSection(string $valuesSection = "", array $fields, array $appData, MySQLiConnection $connection): string
|
||||
{
|
||||
foreach ($fields as $field) {
|
||||
switch ($field['sType']) {
|
||||
case 'number':
|
||||
$query .= ',' . (isset($appData[$field['sFieldName']]) ? (float) str_replace(',', '', $appData[$field['sFieldName']]) : '0');
|
||||
$valuesSection .= ',' . (isset($appData[$field['sFieldName']]) ? (float) str_replace(',', '', $appData[$field['sFieldName']]) : '0');
|
||||
break;
|
||||
case 'char':
|
||||
case 'text':
|
||||
@@ -252,77 +356,15 @@ class ReportTables
|
||||
if (is_array($string)) {
|
||||
$string = implode(",", $string);
|
||||
}
|
||||
$query .= ",'" . (isset($appData[$field['sFieldName']]) ? mysqli_real_escape_string($connection->getResource(), $string) : '') . "'";
|
||||
$valuesSection .= ",'" . (isset($appData[$field['sFieldName']]) ? mysqli_real_escape_string($connection->getResource(), $string) : '') . "'";
|
||||
break;
|
||||
case 'date':
|
||||
$value = (isset($appData[$field['sFieldName']]) && trim($appData[$field['sFieldName']])) != '' ? "'" . $appData[$field['sFieldName']] . "'" : 'NULL';
|
||||
$query .= "," . $value;
|
||||
$valuesSection .= "," . $value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
$query .= ')';
|
||||
$queryValues = $queryValues . $query . ",";
|
||||
if ($i % $numberRecords === 0 || $i === $n) {
|
||||
$queryValues = rtrim($queryValues, ",");
|
||||
$query = $headQuery . $queryValues;
|
||||
$queryValues = "";
|
||||
|
||||
//add to queue
|
||||
$closure = function() use($query) {
|
||||
DB::insert($query);
|
||||
};
|
||||
JobsManager::getSingleton()->dispatch(GenerateReportTable::class, $closure);
|
||||
}
|
||||
} else {
|
||||
if (isset($appData[$grid])) {
|
||||
$query = 'INSERT INTO `' . $tableName . '` (';
|
||||
$query .= '`APP_UID`,`APP_NUMBER`,`ROW`';
|
||||
foreach ($fields as $field) {
|
||||
$query .= ',`' . $field['sFieldName'] . '`';
|
||||
}
|
||||
$headQuery = $query . ") VALUES ";
|
||||
foreach ($appData[$grid] as $indexRow => $gridRow) {
|
||||
$query = "('" . $application->APP_UID . "'," . (int) $application->APP_NUMBER . ',' . $indexRow;
|
||||
foreach ($fields as $field) {
|
||||
switch ($field['sType']) {
|
||||
case 'number':
|
||||
$query .= ',' . (isset($gridRow[$field['sFieldName']]) ? (float) str_replace(',', '', $gridRow[$field['sFieldName']]) : '0');
|
||||
break;
|
||||
case 'char':
|
||||
case 'text':
|
||||
if (!isset($gridRow[$field['sFieldName']])) {
|
||||
$gridRow[$field['sFieldName']] = '';
|
||||
}
|
||||
$stringEscape = mysqli_real_escape_string($connection->getResource(), $gridRow[$field['sFieldName']]);
|
||||
$query .= ",'" . (isset($gridRow[$field['sFieldName']]) ? $stringEscape : '') . "'";
|
||||
break;
|
||||
case 'date':
|
||||
$value = (isset($gridRow[$field['sFieldName']]) && trim($gridRow[$field['sFieldName']])) != '' ? "'" . $gridRow[$field['sFieldName']] . "'" : 'NULL';
|
||||
$query .= "," . $value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
$query .= ')';
|
||||
$queryValues = $queryValues . $query . ",";
|
||||
}
|
||||
if ($i % $numberRecords === 0 || $i === $n) {
|
||||
$queryValues = rtrim($queryValues, ",");
|
||||
$query = $headQuery . $queryValues;
|
||||
$queryValues = "";
|
||||
|
||||
//add to queue
|
||||
$closure = function() use($query) {
|
||||
DB::insert($query);
|
||||
};
|
||||
JobsManager::getSingleton()->dispatch(GenerateReportTable::class, $closure);
|
||||
}
|
||||
}
|
||||
}
|
||||
$i = $i + 1;
|
||||
}
|
||||
} catch (Exception $oError) {
|
||||
throw ($oError);
|
||||
}
|
||||
return $valuesSection;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -384,7 +426,7 @@ class ReportTables
|
||||
$this->dropTable($aFields['REP_TAB_NAME'], $aFields['REP_TAB_CONNECTION']);
|
||||
$oCriteria = new Criteria('workflow');
|
||||
$oCriteria->add(ReportVarPeer::REP_TAB_UID, $sRepTabUid);
|
||||
$oDataset = ReportVarPeer::doDelete($oCriteria);
|
||||
ReportVarPeer::doDelete($oCriteria);
|
||||
$oReportTable->remove($sRepTabUid);
|
||||
}
|
||||
} catch (Exception $oError) {
|
||||
@@ -676,7 +718,7 @@ class ReportTables
|
||||
} else {
|
||||
//remove old rows from database
|
||||
$sqlDelete = 'DELETE FROM `' . $aRow['REP_TAB_NAME'] . "` WHERE APP_UID = '" . $sApplicationUid . "'";
|
||||
$rsDelete = $stmt->executeQuery($sqlDelete);
|
||||
$stmt->executeQuery($sqlDelete);
|
||||
|
||||
$aAux = explode('-', $aRow['REP_TAB_GRID']);
|
||||
if (isset($aFields[$aAux[0]])) {
|
||||
@@ -735,7 +777,6 @@ class ReportTables
|
||||
public function tableExist()
|
||||
{
|
||||
$bExists = true;
|
||||
$sDataBase = 'database_' . strtolower(DB_ADAPTER);
|
||||
|
||||
$oDataBase = new database();
|
||||
$bExists = $oDataBase->reportTableExist();
|
||||
|
||||
@@ -5198,7 +5198,6 @@ class WorkspaceTools
|
||||
$message = 'Sql Execution';
|
||||
Log::channel(':sqlExecution')->critical($message, Bootstrap::context($context));
|
||||
}
|
||||
unset($obj);
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user