Merged in bugfix/PMCORE-3010 (pull request #7926)
PMCORE-3010 Approved-by: Julio Cesar Laura Avendaño
This commit is contained in:
committed by
Julio Cesar Laura Avendaño
commit
0dde1a5619
@@ -0,0 +1,109 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\unit\workflow\engine\src\ProcessMaker\Report;
|
||||||
|
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
use Exception;
|
||||||
|
use ProcessMaker\Model\Application;
|
||||||
|
use ProcessMaker\Model\Delegation;
|
||||||
|
use ProcessMaker\Model\Process;
|
||||||
|
use ProcessMaker\Report\Reporting;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
class ReportingTest extends TestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Field object reporting.
|
||||||
|
* @var object
|
||||||
|
*/
|
||||||
|
public $reporting;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method setUp.
|
||||||
|
*/
|
||||||
|
public function setUp()
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
$this->reporting = new Reporting();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method tearDown.
|
||||||
|
*/
|
||||||
|
public function tearDown()
|
||||||
|
{
|
||||||
|
parent::tearDown();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This tests the method fillReportByUser().
|
||||||
|
* @test
|
||||||
|
* @covers \ProcessMaker\Report\Reporting::fillReportByUser()
|
||||||
|
*/
|
||||||
|
public function it_should_test_method_fillReportByUser()
|
||||||
|
{
|
||||||
|
$dateInit = date("YYYY-MM-DD");
|
||||||
|
$dateFinish = date("YYYY-MM-DD");
|
||||||
|
|
||||||
|
factory(Delegation::class)->create([
|
||||||
|
'DEL_DELEGATE_DATE' => $dateInit
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->reporting->setPathToAppCacheFiles(PATH_METHODS . 'setup' . PATH_SEP . 'setupSchemas' . PATH_SEP);
|
||||||
|
$this->reporting->fillReportByUser($dateInit, $dateFinish);
|
||||||
|
|
||||||
|
$result = DB::table("USR_REPORTING")->get();
|
||||||
|
$this->assertInstanceOf('Illuminate\Support\Collection', $result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This tests the method fillReportByUser() waiting for an exception.
|
||||||
|
* @test
|
||||||
|
* @covers \ProcessMaker\Report\Reporting::fillReportByUser()
|
||||||
|
*/
|
||||||
|
public function it_should_test_method_fillReportByUser_waiting_for_an_exception()
|
||||||
|
{
|
||||||
|
//assertion Exception
|
||||||
|
$this->expectException(Exception::class);
|
||||||
|
|
||||||
|
$dateInit = date("YYYY-MM-DD");
|
||||||
|
$dateFinish = date("YYYY-MM-DD");
|
||||||
|
$this->reporting->fillReportByUser($dateInit, $dateFinish);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This tests the method fillReportByProcess().
|
||||||
|
* @test
|
||||||
|
* @covers \ProcessMaker\Report\Reporting::fillReportByProcess()
|
||||||
|
*/
|
||||||
|
public function it_should_test_method_fillReportByProcess()
|
||||||
|
{
|
||||||
|
$dateInit = date("YYYY-MM-DD");
|
||||||
|
$dateFinish = date("YYYY-MM-DD");
|
||||||
|
|
||||||
|
factory(Delegation::class)->create([
|
||||||
|
'DEL_DELEGATE_DATE' => $dateInit
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->reporting->setPathToAppCacheFiles(PATH_METHODS . 'setup' . PATH_SEP . 'setupSchemas' . PATH_SEP);
|
||||||
|
$this->reporting->fillReportByProcess($dateInit, $dateFinish);
|
||||||
|
|
||||||
|
$result = DB::table("PRO_REPORTING")->get();
|
||||||
|
$this->assertInstanceOf('Illuminate\Support\Collection', $result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This tests the method fillReportByProcess() waiting for an exception.
|
||||||
|
* @test
|
||||||
|
* @covers \ProcessMaker\Report\Reporting::fillReportByProcess()
|
||||||
|
*/
|
||||||
|
public function it_should_test_method_fillReportByProcess_waiting_for_an_exception()
|
||||||
|
{
|
||||||
|
//assertion Exception
|
||||||
|
$this->expectException(Exception::class);
|
||||||
|
|
||||||
|
$dateInit = date("YYYY-MM-DD");
|
||||||
|
$dateFinish = date("YYYY-MM-DD");
|
||||||
|
$this->reporting->fillReportByProcess($dateInit, $dateFinish);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -45,7 +45,10 @@ SELECT
|
|||||||
0,
|
0,
|
||||||
NULL
|
NULL
|
||||||
FROM
|
FROM
|
||||||
APP_CACHE_VIEW AS ACV
|
APPLICATION
|
||||||
|
INNER JOIN APP_DELEGATION AS ACV ON
|
||||||
|
APPLICATION.APP_NUMBER=ACV.APP_NUMBER AND
|
||||||
|
APPLICATION.PRO_UID=ACV.PRO_UID
|
||||||
WHERE
|
WHERE
|
||||||
(ACV.DEL_DELEGATE_DATE BETWEEN CAST(@INIT_DATE AS DATETIME) AND CAST(@FINISH_DATE AS DATETIME))
|
(ACV.DEL_DELEGATE_DATE BETWEEN CAST(@INIT_DATE AS DATETIME) AND CAST(@FINISH_DATE AS DATETIME))
|
||||||
AND ACV.DEL_DELEGATE_DATE IS NOT NULL
|
AND ACV.DEL_DELEGATE_DATE IS NOT NULL
|
||||||
|
|||||||
76
workflow/engine/src/ProcessMaker/Report/Reporting.php
Normal file
76
workflow/engine/src/ProcessMaker/Report/Reporting.php
Normal file
@@ -0,0 +1,76 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace ProcessMaker\Report;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
|
class Reporting
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Field pathToAppCacheFiles.
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $pathToAppCacheFiles;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set pathToAppCacheFiles property.
|
||||||
|
* @param string $path
|
||||||
|
*/
|
||||||
|
public function setPathToAppCacheFiles(string $path)
|
||||||
|
{
|
||||||
|
$this->pathToAppCacheFiles = $path;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This populates the USR_REPORTING table.
|
||||||
|
* @param string $dateInit
|
||||||
|
* @param string $dateFinish
|
||||||
|
* @return void
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public function fillReportByUser(string $dateInit, string $dateFinish): void
|
||||||
|
{
|
||||||
|
$filenameSql = $this->pathToAppCacheFiles . "triggerFillReportByUser.sql";
|
||||||
|
|
||||||
|
if (!file_exists($filenameSql)) {
|
||||||
|
throw new Exception("File {$filenameSql} doesn't exist");
|
||||||
|
}
|
||||||
|
|
||||||
|
DB::statement("TRUNCATE TABLE USR_REPORTING");
|
||||||
|
|
||||||
|
$sql = explode(';', file_get_contents($filenameSql));
|
||||||
|
|
||||||
|
foreach ($sql as $key => $val) {
|
||||||
|
$val = str_replace('{init_date}', $dateInit, $val);
|
||||||
|
$val = str_replace('{finish_date}', $dateFinish, $val);
|
||||||
|
DB::statement($val);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This populates the PRO_REPORTING table
|
||||||
|
* @param string $dateInit
|
||||||
|
* @param string $dateFinish
|
||||||
|
* @return void
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public function fillReportByProcess(string $dateInit, string $dateFinish): void
|
||||||
|
{
|
||||||
|
$filenameSql = $this->pathToAppCacheFiles . "triggerFillReportByProcess.sql";
|
||||||
|
|
||||||
|
if (!file_exists($filenameSql)) {
|
||||||
|
throw new Exception("File {$filenameSql} doesn't exist");
|
||||||
|
}
|
||||||
|
|
||||||
|
DB::statement("TRUNCATE TABLE PRO_REPORTING");
|
||||||
|
|
||||||
|
$sql = explode(';', file_get_contents($filenameSql));
|
||||||
|
|
||||||
|
foreach ($sql as $key => $val) {
|
||||||
|
$val = str_replace('{init_date}', $dateInit, $val);
|
||||||
|
$val = str_replace('{finish_date}', $dateFinish, $val);
|
||||||
|
DB::statement($val);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,7 +5,6 @@ namespace ProcessMaker\TaskScheduler;
|
|||||||
use Application;
|
use Application;
|
||||||
use AppAssignSelfServiceValueGroupPeer;
|
use AppAssignSelfServiceValueGroupPeer;
|
||||||
use AppAssignSelfServiceValuePeer;
|
use AppAssignSelfServiceValuePeer;
|
||||||
use AppCacheView;
|
|
||||||
use AppDelegation;
|
use AppDelegation;
|
||||||
use App\Jobs\TaskScheduler;
|
use App\Jobs\TaskScheduler;
|
||||||
use Bootstrap;
|
use Bootstrap;
|
||||||
@@ -26,6 +25,7 @@ use ProcessMaker\BusinessModel\TimerEvent;
|
|||||||
use ProcessMaker\BusinessModel\WebEntry;
|
use ProcessMaker\BusinessModel\WebEntry;
|
||||||
use ProcessMaker\Core\JobsManager;
|
use ProcessMaker\Core\JobsManager;
|
||||||
use ProcessMaker\Plugins\PluginRegistry;
|
use ProcessMaker\Plugins\PluginRegistry;
|
||||||
|
use ProcessMaker\Report\Reporting;
|
||||||
use Propel;
|
use Propel;
|
||||||
use ResultSet;
|
use ResultSet;
|
||||||
use SpoolRun;
|
use SpoolRun;
|
||||||
@@ -493,11 +493,11 @@ class Task
|
|||||||
|
|
||||||
$dateFinish = ($dateFinish != null) ? $dateFinish : date("Y-m-d H:i:s");
|
$dateFinish = ($dateFinish != null) ? $dateFinish : date("Y-m-d H:i:s");
|
||||||
|
|
||||||
$appCacheView = new AppCacheView();
|
$reporting = new Reporting();
|
||||||
$appCacheView->setPathToAppCacheFiles(PATH_METHODS . 'setup' . PATH_SEP . 'setupSchemas' . PATH_SEP);
|
$reporting->setPathToAppCacheFiles(PATH_METHODS . 'setup' . PATH_SEP . 'setupSchemas' . PATH_SEP);
|
||||||
$this->setExecutionMessage("Calculating data to fill the 'User Reporting'...");
|
$this->setExecutionMessage("Calculating data to fill the 'User Reporting'...");
|
||||||
$appCacheView->fillReportByUser($dateInit, $dateFinish);
|
$reporting->fillReportByUser($dateInit, $dateFinish);
|
||||||
setExecutionResultMessage("DONE");
|
$this->setExecutionResultMessage("DONE");
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
$this->setExecutionResultMessage("WITH ERRORS", "error");
|
$this->setExecutionResultMessage("WITH ERRORS", "error");
|
||||||
if ($this->asynchronous === false) {
|
if ($this->asynchronous === false) {
|
||||||
@@ -537,11 +537,11 @@ class Task
|
|||||||
try {
|
try {
|
||||||
|
|
||||||
$dateFinish = ($dateFinish != null) ? $dateFinish : date("Y-m-d H:i:s");
|
$dateFinish = ($dateFinish != null) ? $dateFinish : date("Y-m-d H:i:s");
|
||||||
$appcv = new AppCacheView();
|
|
||||||
$appcv->setPathToAppCacheFiles(PATH_METHODS . 'setup' . PATH_SEP . 'setupSchemas' . PATH_SEP);
|
|
||||||
|
|
||||||
|
$reporting = new Reporting();
|
||||||
|
$reporting->setPathToAppCacheFiles(PATH_METHODS . 'setup' . PATH_SEP . 'setupSchemas' . PATH_SEP);
|
||||||
$this->setExecutionMessage("Calculating data to fill the 'Process Reporting'...");
|
$this->setExecutionMessage("Calculating data to fill the 'Process Reporting'...");
|
||||||
$appcv->fillReportByProcess($dateInit, $dateFinish);
|
$reporting->fillReportByProcess($dateInit, $dateFinish);
|
||||||
$this->setExecutionResultMessage("DONE");
|
$this->setExecutionResultMessage("DONE");
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
$this->setExecutionResultMessage("WITH ERRORS", "error");
|
$this->setExecutionResultMessage("WITH ERRORS", "error");
|
||||||
|
|||||||
Reference in New Issue
Block a user