This commit is contained in:
Julio Cesar Laura Avendaño
2019-04-11 17:19:56 -04:00
parent 47dcbbe9b5
commit 2877d0ba7b
2 changed files with 51 additions and 12 deletions

View File

@@ -318,6 +318,7 @@ function processWorkspace()
executeScheduledCases(); executeScheduledCases();
executeUpdateAppTitle(); executeUpdateAppTitle();
executeCaseSelfService(); executeCaseSelfService();
cleanSelfServiceTables();
executePlugins(); executePlugins();
/*----------------------------------********---------------------------------*/ /*----------------------------------********---------------------------------*/
fillReportByUser(); fillReportByUser();
@@ -1047,3 +1048,46 @@ function sendNotifications()
saveLog("ExecuteSendNotifications", "error", "Error when sending notifications " . $e->getMessage()); saveLog("ExecuteSendNotifications", "error", "Error when sending notifications " . $e->getMessage());
} }
} }
/**
* Clean unused records in tables related to the Self-Service Value Based feature
*
* @see processWorkspace()
*
* @link https://wiki.processmaker.com/3.2/Executing_cron.php#Syntax_of_cron.php_Options
*/
function cleanSelfServiceTables()
{
try {
global $argvx;
// Check if the action can be executed
if ($argvx !== "" && strpos($argvx, "clean-self-service-tables") === false) {
return false;
}
// Start message
setExecutionMessage("Clean unused records for Self-Service Value Based feature");
// Get Propel connection
$cnn = Propel::getConnection(AppAssignSelfServiceValueGroupPeer::DATABASE_NAME);
// Delete related rows and missing relations, criteria don't execute delete with joins
$cnn->begin();
$stmt = $cnn->createStatement();
$stmt->executeQuery("DELETE " . AppAssignSelfServiceValueGroupPeer::TABLE_NAME . "
FROM " . AppAssignSelfServiceValueGroupPeer::TABLE_NAME . "
LEFT JOIN " . AppAssignSelfServiceValuePeer::TABLE_NAME . "
ON (" . AppAssignSelfServiceValueGroupPeer::ID . " = " . AppAssignSelfServiceValuePeer::ID . ")
WHERE " . AppAssignSelfServiceValuePeer::ID . " IS NULL");
$cnn->commit();
// Success message
setExecutionResultMessage("DONE");
} catch (Exception $e) {
$cnn->rollback();
setExecutionResultMessage("WITH ERRORS", "error");
eprintln(" '-" . $e->getMessage(), "red");
saveLog("ExecuteCleanSelfServiceTables", "error", "Error when try to clean self-service tables " . $e->getMessage());
}
}

View File

@@ -64,6 +64,12 @@ class AppAssignSelfServiceValue extends BaseAppAssignSelfServiceValue
* *
* @return void * @return void
* @throws Exception * @throws Exception
*
* @see \Cases->removeCase()
* @see \Cases->setCatchUser()
* @see \Cases->updateCase()
*
* @link https://wiki.processmaker.com/3.2/Tasks#Self_Service_Value_Based_Assignment
*/ */
public function remove($applicationUid, $delIndex = 0) public function remove($applicationUid, $delIndex = 0)
{ {
@@ -76,18 +82,7 @@ class AppAssignSelfServiceValue extends BaseAppAssignSelfServiceValue
$criteria->add(AppAssignSelfServiceValuePeer::DEL_INDEX, $delIndex, Criteria::EQUAL); $criteria->add(AppAssignSelfServiceValuePeer::DEL_INDEX, $delIndex, Criteria::EQUAL);
} }
$result = AppAssignSelfServiceValuePeer::doDelete($criteria); AppAssignSelfServiceValuePeer::doDelete($criteria);
// Delete related rows and missing relations, criteria don't execute delete with joins
$cnn = Propel::getConnection(AppAssignSelfServiceValueGroupPeer::DATABASE_NAME);
$cnn->begin();
$stmt = $cnn->createStatement();
$rs = $stmt->executeQuery("DELETE " . AppAssignSelfServiceValueGroupPeer::TABLE_NAME . "
FROM " . AppAssignSelfServiceValueGroupPeer::TABLE_NAME . "
LEFT JOIN " . AppAssignSelfServiceValuePeer::TABLE_NAME . "
ON (" . AppAssignSelfServiceValueGroupPeer::ID . " = " . AppAssignSelfServiceValuePeer::ID . ")
WHERE " . AppAssignSelfServiceValuePeer::ID . " IS NULL");
$cnn->commit();
} catch (Exception $e) { } catch (Exception $e) {
throw $e; throw $e;
} }