PMCORE-2188 Migrate to queue job - Cron File: cron.php - Activity: report_by_user
This commit is contained in:
committed by
Julio Cesar Laura Avendaño
parent
ebfd16fea1
commit
76f678ce80
@@ -308,4 +308,34 @@ class TaskTest extends TestCase
|
||||
Queue::assertPushed(TaskScheduler::class);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This test verify the fillReportByUser activity method for synchronous and asynchronous execution.
|
||||
* @test
|
||||
* @covers ProcessMaker\TaskScheduler\Task::runTask()
|
||||
* @covers ProcessMaker\TaskScheduler\Task::fillReportByUser()
|
||||
* @dataProvider asynchronousCases
|
||||
*/
|
||||
public function it_should_test_fillReportByUser_method($asynchronous)
|
||||
{
|
||||
$task = new Task($asynchronous, '');
|
||||
$dateInit = $this->faker->dateTime;
|
||||
$dateFinish = $this->faker->dateTime;
|
||||
|
||||
//assert synchronous for cron file
|
||||
if ($asynchronous === false) {
|
||||
ob_start();
|
||||
$task->fillReportByUser($dateInit, $dateFinish);
|
||||
$printing = ob_get_clean();
|
||||
$this->assertRegExp("/User Reporting/", $printing);
|
||||
}
|
||||
|
||||
//assert asynchronous for job process
|
||||
if ($asynchronous === true) {
|
||||
Queue::fake();
|
||||
Queue::assertNothingPushed();
|
||||
$task->fillReportByUser($dateInit, $dateFinish);
|
||||
Queue::assertPushed(TaskScheduler::class);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -317,7 +317,9 @@ try {
|
||||
$task->executePlugins();
|
||||
}
|
||||
/*----------------------------------********---------------------------------*/
|
||||
fillReportByUser();
|
||||
if (empty($argvx) || strpos($argvx, "report_by_user") !== false) {
|
||||
$task->fillReportByUser($dateInit, $dateFinish);
|
||||
}
|
||||
fillReportByProcess();
|
||||
synchronizeDrive();
|
||||
synchronizeGmailLabels();
|
||||
@@ -587,36 +589,6 @@ function setExecutionResultMessage($m, $t = '')
|
||||
}
|
||||
/*----------------------------------********---------------------------------*/
|
||||
|
||||
function fillReportByUser()
|
||||
{
|
||||
try {
|
||||
global $argvx;
|
||||
global $dateInit;
|
||||
global $dateFinish;
|
||||
|
||||
if (strpos($argvx, "report_by_user") === false) {
|
||||
return false;
|
||||
}
|
||||
if ($dateInit == null) {
|
||||
eprintln("You must enter the starting date.", "red");
|
||||
eprintln('Example: +init-date"YYYY-MM-DD HH:MM:SS" +finish-date"YYYY-MM-DD HH:MM:SS"', "red");
|
||||
return false;
|
||||
}
|
||||
|
||||
$dateFinish = ($dateFinish != null) ? $dateFinish : date("Y-m-d H:i:s");
|
||||
|
||||
$appcv = new AppCacheView();
|
||||
$appcv->setPathToAppCacheFiles(PATH_METHODS . 'setup' . PATH_SEP . 'setupSchemas' . PATH_SEP);
|
||||
setExecutionMessage("Calculating data to fill the 'User Reporting'...");
|
||||
$appcv->fillReportByUser($dateInit, $dateFinish);
|
||||
setExecutionResultMessage("DONE");
|
||||
} catch (Exception $e) {
|
||||
setExecutionResultMessage("WITH ERRORS", "error");
|
||||
eprintln(" '-" . $e->getMessage(), "red");
|
||||
saveLog("fillReportByUser", "error", "Error in fill report by user: " . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
function fillReportByProcess()
|
||||
{
|
||||
try {
|
||||
|
||||
@@ -5,6 +5,7 @@ namespace ProcessMaker\TaskScheduler;
|
||||
use Application;
|
||||
use AppAssignSelfServiceValueGroupPeer;
|
||||
use AppAssignSelfServiceValuePeer;
|
||||
use AppCacheView;
|
||||
use AppDelegation;
|
||||
use App\Jobs\TaskScheduler;
|
||||
use Bootstrap;
|
||||
@@ -392,4 +393,43 @@ class Task
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This fills the report by user.
|
||||
* @param datetime $dateInit
|
||||
* @param datetime $dateFinish
|
||||
*/
|
||||
public function fillReportByUser($dateInit, $dateFinish)
|
||||
{
|
||||
$job = function() use($dateInit, $dateFinish) {
|
||||
try {
|
||||
if ($dateInit == null) {
|
||||
if ($this->asynchronous === false) {
|
||||
eprintln("You must enter the starting date.", "red");
|
||||
eprintln('Example: +init-date"YYYY-MM-DD HH:MM:SS" +finish-date"YYYY-MM-DD HH:MM:SS"', "red");
|
||||
}
|
||||
if ($this->asynchronous === true) {
|
||||
$message = 'You must enter the starting date. Example: +init-date"YYYY-MM-DD HH:MM:SS" +finish-date"YYYY-MM-DD HH:MM:SS"';
|
||||
Log::channel('taskScheduler:taskScheduler')->info($message, Bootstrap::context($context));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
$dateFinish = ($dateFinish != null) ? $dateFinish : date("Y-m-d H:i:s");
|
||||
|
||||
$appCacheView = new AppCacheView();
|
||||
$appCacheView->setPathToAppCacheFiles(PATH_METHODS . 'setup' . PATH_SEP . 'setupSchemas' . PATH_SEP);
|
||||
$this->setExecutionMessage("Calculating data to fill the 'User Reporting'...");
|
||||
$appCacheView->fillReportByUser($dateInit, $dateFinish);
|
||||
setExecutionResultMessage("DONE");
|
||||
} catch (Exception $e) {
|
||||
$this->setExecutionResultMessage("WITH ERRORS", "error");
|
||||
if ($this->asynchronous === false) {
|
||||
eprintln(" '-" . $e->getMessage(), "red");
|
||||
}
|
||||
$this->saveLog("fillReportByUser", "error", "Error in fill report by user: " . $e->getMessage());
|
||||
}
|
||||
};
|
||||
$this->runTask($job);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user