Merged in danteloayza/processmaker/GI-159 (pull request #3322)

revert GI-159
This commit is contained in:
Dante Loayza
2015-12-07 09:46:19 -04:00
3 changed files with 35 additions and 139 deletions

View File

@@ -72,7 +72,7 @@ class labelsGmail
function setLabels($caseId, $index, $actualLastIndex, $unassigned=false){ function setLabels($caseId, $index, $actualLastIndex, $unassigned=false){
//First getting the actual thread data //First getting the actual thread data
$Pmgmail = new \ProcessMaker\BusinessModel\Pmgmail(); $Pmgmail = new \ProcessMaker\BusinessModel\Pmgmail();
$appData = $Pmgmail->getAppData($caseId, $index); $appData = $Pmgmail->getDraftApp($caseId, $index);
foreach ($appData as $application){ foreach ($appData as $application){
$appNumber = $application['APP_NUMBER']; $appNumber = $application['APP_NUMBER'];

View File

@@ -2,8 +2,6 @@
namespace ProcessMaker\BusinessModel; namespace ProcessMaker\BusinessModel;
use \G; use \G;
use Symfony\Component\Config\Definition\Exception\Exception;
/** /**
* @copyright Colosa - Bolivia * @copyright Colosa - Bolivia
*/ */
@@ -34,144 +32,38 @@ class Pmgmail {
} }
/** /**
* Get Application data by appUid. Searches just in list_inbox, list_paused, list_unassigned * Get Application data by appUid
* because those are the only places from which an email to update user gmail trays will
* be sent.
* the reason to seach in thos 3 tables is because We prefer to make 3 queries in
* 3 tables with few rows than using app_cache_view that has
* a lot more.
* *
* @param string $appUid Unique id of the app * @param string $app_uid Unique id of the app
* @param string $index * @param string $index
* *
* return row in list_inbox, list_paused or list_unassigned, if nothing is * return row app_cache_view
* found a null value is returned
* *
*/ */
public function getAppData($appUid, $index=1) public function getDraftApp($app_uid, $index=1)
{ {
if (empty($appUid)) {
throw new Exception('Null or undefined appUids are not accepted.');
}
//the current version of Propel does not support union queries, so
//3 queries are sent. The first time that a row that conforms to the
//seach criteria is found, the function terminates and returns this row.
$rowInbox = $this->getAppDataFromListInbox($appUid, $index);
if (count($rowInbox) > 0) {
return $rowInbox;
}
$rowUnassigned = $this->getAppDataFromListUnassigned($appUid, $index);
if (count($rowUnassigned) > 0) {
return $rowUnassigned;
}
$rowPaused = $this->getAppDataFromListPaused($appUid, $index);
if (count($rowPaused) > 0) {
return $rowPaused;
}
return null;
}
/**
* Get Application data in a del index searchin in the list_inbox table
*
* @param string $appUid Unique id of the app
* @param string $index
*
* return row
*
*/
private function getAppDataFromListInbox($appUid, $index) {
$c = new \Criteria( 'workflow' ); $c = new \Criteria( 'workflow' );
$c->clearSelectColumns(); $c->clearSelectColumns();
$c->addSelectColumn( \ListInboxPeer::APP_NUMBER ); $c->addSelectColumn( \AppCacheViewPeer::APP_NUMBER );
$c->addSelectColumn( \ListInboxPeer::APP_STATUS ); $c->addSelectColumn( \AppCacheViewPeer::APP_STATUS );
$c->addSelectColumn( \ListInboxPeer::DEL_INDEX ); $c->addSelectColumn( \AppCacheViewPeer::DEL_INDEX );
$c->addSelectColumn( \ListInboxPeer::DEL_DELEGATE_DATE ); $c->addSelectColumn( \AppCacheViewPeer::APP_DEL_PREVIOUS_USER );
$c->addSelectColumn( \ListInboxPeer::USR_UID ); $c->addSelectColumn( \AppCacheViewPeer::DEL_DELEGATE_DATE );
$c->addSelectColumn( \ListInboxPeer::PRO_UID ); $c->addSelectColumn( \AppCacheViewPeer::USR_UID );
$c->addSelectColumn( \ListInboxPeer::APP_PRO_TITLE ); $c->addSelectColumn( \AppCacheViewPeer::PRO_UID );
$c->addSelectColumn( \ListInboxPeer::APP_TAS_TITLE ); $c->addSelectColumn( \AppCacheViewPeer::APP_PRO_TITLE );
$c->addSelectColumn( \ListInboxPeer::TAS_UID ); $c->addSelectColumn( \AppCacheViewPeer::APP_TAS_TITLE );
$c->add( \ListInboxPeer::APP_UID, $appUid ); $c->addSelectColumn( \AppCacheViewPeer::DEL_THREAD_STATUS );
$c->add( \ListInboxPeer::DEL_INDEX, $index ); $c->addSelectColumn( \AppCacheViewPeer::TAS_UID );
$c->addSelectColumn( \AppCacheViewPeer::DEL_LAST_INDEX );
$rs = \ListInboxPeer::doSelectRS( $c ); $c->add( \AppCacheViewPeer::APP_UID, $app_uid );
$c->add( \AppCacheViewPeer::DEL_INDEX, $index );
$rs = \AppCacheViewPeer::doSelectRS( $c );
$rs->setFetchmode( \ResultSet::FETCHMODE_ASSOC ); $rs->setFetchmode( \ResultSet::FETCHMODE_ASSOC );
return $this->resultSetToArray($rs);
}
/**
* Get Application data in a del index searchin in the list_inbox table
*
* @param string $appUid Unique id of the app
* @param string $index
*
* return row
*
*/
private function getAppDataFromListPaused($appUid, $index) {
$c = new \Criteria( 'workflow' );
$c->clearSelectColumns();
$c->addSelectColumn( \ListPausedPeer::APP_NUMBER );
$c->addSelectColumn("'PAUSED' APP_STATUS");
$c->addSelectColumn( \ListPausedPeer::DEL_INDEX );
$c->addSelectColumn( \ListPausedPeer::DEL_DELEGATE_DATE );
$c->addSelectColumn( \ListPausedPeer::USR_UID );
$c->addSelectColumn( \ListPausedPeer::PRO_UID );
$c->addSelectColumn( \ListPausedPeer::APP_PRO_TITLE );
$c->addSelectColumn( \ListPausedPeer::APP_TAS_TITLE );
$c->addSelectColumn( \ListPausedPeer::TAS_UID );
$c->add( \ListPausedPeer::APP_UID, $appUid );
$c->add( \ListPausedPeer::DEL_INDEX, $index );
$rs = \ListPausedPeer::doSelectRS( $c );
$rs->setFetchmode( \ResultSet::FETCHMODE_ASSOC );
return $this->resultSetToArray($rs);
}
/**
* Get Application data in a del index searchin in the list_inbox table
*
* @param string $appUid Unique id of the app
* @param string $index
*
* return row
*
*/
private function getAppDataFromListUnassigned($appUid, $index) {
$c = new \Criteria( 'workflow' );
$c->clearSelectColumns();
$c->addSelectColumn( \ListUnassignedPeer::APP_NUMBER );
$c->addSelectColumn("'UNASSIGNED' APP_STATUS");
$c->addSelectColumn( \ListUnassignedPeer::DEL_INDEX );
$c->addSelectColumn( \ListUnassignedPeer::DEL_DELEGATE_DATE );
$c->addSelectColumn("'' USR_UID");
$c->addSelectColumn( \ListUnassignedPeer::PRO_UID );
$c->addSelectColumn( \ListUnassignedPeer::APP_PRO_TITLE );
$c->addSelectColumn( \ListUnassignedPeer::APP_TAS_TITLE );
$c->addSelectColumn( \ListUnassignedPeer::TAS_UID );
$c->add( \ListUnassignedPeer::APP_UID, $appUid );
$c->add( \ListUnassignedPeer::DEL_INDEX, $index );
$rs = \ListUnassignedPeer::doSelectRS( $c );
$rs->setFetchmode( \ResultSet::FETCHMODE_ASSOC );
return $this->resultSetToArray($rs);
}
/**
* Returns an array create from a resultset
*
* @param string $rs result set from which the array will be created
*
* return row array
*
*/
private function resultSetToArray($rs) {
$rows = Array (); $rows = Array ();
while ($rs->next()) { while ($rs->next()) {
$rows[] = $rs->getRow(); $rows[] = $rs->getRow();
@@ -179,7 +71,6 @@ class Pmgmail {
return $rows; return $rows;
} }
/** /**
* Send email using appUid and mail * Send email using appUid and mail
* *
@@ -212,18 +103,21 @@ class Pmgmail {
$dataFormToShowString .= " " . $field . " " . $value; $dataFormToShowString .= " " . $field . " " . $value;
} }
} }
$appData = $this->getAppData($app_uid, $index); $appData = $this->getDraftApp($app_uid, $index);
foreach ($appData as $application){ foreach ($appData as $application){
$appNumber = $application['APP_NUMBER']; $appNumber = $application['APP_NUMBER'];
$appStatus = $application['APP_STATUS']; $appStatus = $application['APP_STATUS'];
$index = $application['DEL_INDEX']; $index = $application['DEL_INDEX'];
$prvUsr = $application['APP_DEL_PREVIOUS_USER'];
$delegateDate = $application['DEL_DELEGATE_DATE']; $delegateDate = $application['DEL_DELEGATE_DATE'];
$nextUsr = $application['USR_UID']; $nextUsr = $application['USR_UID'];
$proUid = $application['PRO_UID']; $proUid = $application['PRO_UID'];
$proName = $application['APP_PRO_TITLE']; $proName = $application['APP_PRO_TITLE'];
$tasName = $application['APP_TAS_TITLE']; $tasName = $application['APP_TAS_TITLE'];
$threadStatus = $application['DEL_THREAD_STATUS'];
$tasUid = $application['TAS_UID']; $tasUid = $application['TAS_UID'];
$lastIndex = $application['DEL_LAST_INDEX'];
if($appStatus == "DRAFT"){ if($appStatus == "DRAFT"){
$labelID = "PMDRFT"; $labelID = "PMDRFT";
@@ -267,6 +161,7 @@ class Pmgmail {
fwrite($file, '-**- Task Name: @#taskName<br/>'); fwrite($file, '-**- Task Name: @#taskName<br/>');
fwrite($file, '-**- Index: @#index<br/>'); fwrite($file, '-**- Index: @#index<br/>');
fwrite($file, '-**- Action: @#action<br/>'); fwrite($file, '-**- Action: @#action<br/>');
fwrite($file, '-**- Previous User: @#prevUser<br/>');
fwrite($file, '-**- Delegate Date: @#delDate<br/>'); fwrite($file, '-**- Delegate Date: @#delDate<br/>');
fwrite($file, '-**- Process Id: @#proUid<br/>'); fwrite($file, '-**- Process Id: @#proUid<br/>');
fwrite($file, '-**- Type: @#type<br/>'); fwrite($file, '-**- Type: @#type<br/>');
@@ -284,6 +179,7 @@ class Pmgmail {
'taskName' => $tasName, 'taskName' => $tasName,
'index' => $index, 'index' => $index,
'action' => $appStatus, 'action' => $appStatus,
'prevUser' => $prvUsr,
'delDate' => $delegateDate, 'delDate' => $delegateDate,
'proUid' => $proUid, 'proUid' => $proUid,
'type' => $labelID, 'type' => $labelID,

View File

@@ -46,7 +46,7 @@ class GmailIntegration extends Api
{ {
try { try {
$Pmgmail = new \ProcessMaker\BusinessModel\Pmgmail(); $Pmgmail = new \ProcessMaker\BusinessModel\Pmgmail();
$response = $Pmgmail->getAppData($app_uid); $response = $Pmgmail->getDraftApp($app_uid);
return $response; return $response;
} catch (\Exception $e) { } catch (\Exception $e) {
throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage())); throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage()));