Asynchrounous gmail relabeling
fixing enterprise marks database schema mod delete commented code revert unitended change
This commit is contained in:
@@ -340,6 +340,7 @@ function processWorkspace()
|
||||
fillReportByUser();
|
||||
fillReportByProcess();
|
||||
synchronizeDrive();
|
||||
synchronizeGmailLabels();
|
||||
/*----------------------------------********---------------------------------*/
|
||||
} catch (Exception $oError) {
|
||||
saveLog("main", "error", "Error processing workspace : " . $oError->getMessage() . "\n");
|
||||
@@ -982,5 +983,26 @@ function synchronizeDrive ()
|
||||
}
|
||||
}
|
||||
|
||||
/*----------------------------------********---------------------------------*/
|
||||
function synchronizeGmailLabels()
|
||||
{
|
||||
try
|
||||
{
|
||||
global $argvx;
|
||||
|
||||
if (strpos($argvx, "synchronize-gmail-labels") === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
setExecutionMessage("Synchronize labels in Gmail");
|
||||
G::LoadClass('labelsGmail');
|
||||
$labGmail = new labelsGmail();
|
||||
$labGmail->processPendingRelabelingInQueue();
|
||||
setExecutionResultMessage("DONE");
|
||||
|
||||
} catch (Exception $e) {
|
||||
setExecutionResultMessage("WITH ERRORS", "error");
|
||||
eprintln(" '-" . $e->getMessage(), "red");
|
||||
saveLog("synchronizeGmailLabels", "error", "Error when synchronizing Gmail labels: " . $e->getMessage());
|
||||
}
|
||||
}
|
||||
/*----------------------------------********---------------------------------*/
|
||||
|
||||
@@ -12,6 +12,7 @@ class labelsGmail
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
print G::LoadTranslation("ID_PMGMAIL_GENERAL_ERROR") . $e->getMessage();
|
||||
throw ($e);
|
||||
}
|
||||
return $labels;
|
||||
}
|
||||
@@ -34,6 +35,7 @@ class labelsGmail
|
||||
$message = $service->users_messages->modify($userId, $messageId, $mods);
|
||||
} catch (Exception $e) {
|
||||
print G::LoadTranslation("ID_PMGMAIL_GENERAL_ERROR") . $e->getMessage();
|
||||
throw ($e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,6 +65,7 @@ class labelsGmail
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
print G::LoadTranslation("ID_PMGMAIL_GENERAL_ERROR") . $e->getMessage();
|
||||
throw ($e);
|
||||
}
|
||||
} while ($pageToken);
|
||||
|
||||
@@ -286,31 +289,68 @@ class labelsGmail
|
||||
return $count . ' labels successfully deleted.';
|
||||
}
|
||||
|
||||
public function addRelabelingToQueue($caseId, $index, $actualLastIndex, $unassigned=false)
|
||||
{
|
||||
$labelingQueue = new GmailRelabeling();
|
||||
$labelingQueue->setAppUid($caseId);
|
||||
$labelingQueue->setDelIndex($index);
|
||||
$labelingQueue->setCurrentLastIndex($actualLastIndex);
|
||||
$labelingQueue->setUnassigned(($unassigned === true) ? 1 : 0);
|
||||
$labelingQueue->setStatus('pending');
|
||||
$labelingQueue->save();
|
||||
}
|
||||
|
||||
public function processPendingRelabelingInQueue()
|
||||
{
|
||||
$c = new \Criteria( 'workflow' );
|
||||
$c->add( \GmailRelabelingPeer::STATUS, 'pending' );
|
||||
$list = \GmailRelabelingPeer::doSelect($c);
|
||||
foreach($list as $task) {
|
||||
try {
|
||||
$oResponse = $this->setLabels($task->getAppUid(),
|
||||
$task->getDelIndex(),
|
||||
$task->getCurrentLastIndex(),
|
||||
($task->getUnassigned() === 1) ? true : false
|
||||
);
|
||||
$task->setStatus('completed');
|
||||
}
|
||||
catch(exception $e){
|
||||
$task->setMsgError($e->getMessage());
|
||||
$task->setStatus('pending');
|
||||
}
|
||||
$task->save();
|
||||
}
|
||||
}
|
||||
|
||||
private function getLabelsIds($service) {
|
||||
$result = array();
|
||||
$listlabels = $this->listLabels($service);
|
||||
foreach ($listlabels as $label) {
|
||||
$labId = $label->getId();
|
||||
$labName = $label->getName();
|
||||
switch($labName){
|
||||
case "* Inbox":
|
||||
$result['Inbox'] = $labId;
|
||||
break;
|
||||
case "* Participated":
|
||||
$result['Participated'] = $labId;
|
||||
break;
|
||||
case "* Unassigned":
|
||||
$result['Unassigned'] = $labId;
|
||||
break;
|
||||
case "* Draft":
|
||||
$result['Draft'] = $labId;
|
||||
break;
|
||||
case "* Paused":
|
||||
$result['Paused'] = $labId;
|
||||
break;
|
||||
try {
|
||||
$listlabels = $this->listLabels($service);
|
||||
foreach ($listlabels as $label) {
|
||||
$labId = $label->getId();
|
||||
$labName = $label->getName();
|
||||
switch($labName){
|
||||
case "* Inbox":
|
||||
$result['Inbox'] = $labId;
|
||||
break;
|
||||
case "* Participated":
|
||||
$result['Participated'] = $labId;
|
||||
break;
|
||||
case "* Unassigned":
|
||||
$result['Unassigned'] = $labId;
|
||||
break;
|
||||
case "* Draft":
|
||||
$result['Draft'] = $labId;
|
||||
break;
|
||||
case "* Paused":
|
||||
$result['Paused'] = $labId;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch(Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
19
workflow/engine/classes/model/GmailRelabeling.php
Normal file
19
workflow/engine/classes/model/GmailRelabeling.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
require_once 'classes/model/om/BaseGmailRelabeling.php';
|
||||
|
||||
|
||||
/**
|
||||
* Skeleton subclass for representing a row from the 'GMAIL_RELABELING' table.
|
||||
*
|
||||
*
|
||||
*
|
||||
* You should add additional methods to this class to meet the
|
||||
* application requirements. This class will only be generated as
|
||||
* long as it does not already exist in the output directory.
|
||||
*
|
||||
* @package classes.model
|
||||
*/
|
||||
class GmailRelabeling extends BaseGmailRelabeling {
|
||||
|
||||
} // GmailRelabeling
|
||||
23
workflow/engine/classes/model/GmailRelabelingPeer.php
Normal file
23
workflow/engine/classes/model/GmailRelabelingPeer.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
// include base peer class
|
||||
require_once 'classes/model/om/BaseGmailRelabelingPeer.php';
|
||||
|
||||
// include object class
|
||||
include_once 'classes/model/GmailRelabeling.php';
|
||||
|
||||
|
||||
/**
|
||||
* Skeleton subclass for performing query and update operations on the 'GMAIL_RELABELING' table.
|
||||
*
|
||||
*
|
||||
*
|
||||
* You should add additional methods to this class to meet the
|
||||
* application requirements. This class will only be generated as
|
||||
* long as it does not already exist in the output directory.
|
||||
*
|
||||
* @package classes.model
|
||||
*/
|
||||
class GmailRelabelingPeer extends BaseGmailRelabelingPeer {
|
||||
|
||||
} // GmailRelabelingPeer
|
||||
@@ -0,0 +1,82 @@
|
||||
<?php
|
||||
|
||||
require_once 'propel/map/MapBuilder.php';
|
||||
include_once 'creole/CreoleTypes.php';
|
||||
|
||||
|
||||
/**
|
||||
* This class adds structure of 'GMAIL_RELABELING' table to 'workflow' DatabaseMap object.
|
||||
*
|
||||
*
|
||||
*
|
||||
* These statically-built map classes are used by Propel to do runtime db structure discovery.
|
||||
* For example, the createSelectSql() method checks the type of a given column used in an
|
||||
* ORDER BY clause to know whether it needs to apply SQL to make the ORDER BY case-insensitive
|
||||
* (i.e. if it's a text column type).
|
||||
*
|
||||
* @package workflow.classes.model.map
|
||||
*/
|
||||
class GmailRelabelingMapBuilder
|
||||
{
|
||||
|
||||
/**
|
||||
* The (dot-path) name of this class
|
||||
*/
|
||||
const CLASS_NAME = 'classes.model.map.GmailRelabelingMapBuilder';
|
||||
|
||||
/**
|
||||
* The database map.
|
||||
*/
|
||||
private $dbMap;
|
||||
|
||||
/**
|
||||
* Tells us if this DatabaseMapBuilder is built so that we
|
||||
* don't have to re-build it every time.
|
||||
*
|
||||
* @return boolean true if this DatabaseMapBuilder is built, false otherwise.
|
||||
*/
|
||||
public function isBuilt()
|
||||
{
|
||||
return ($this->dbMap !== null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the databasemap this map builder built.
|
||||
*
|
||||
* @return the databasemap
|
||||
*/
|
||||
public function getDatabaseMap()
|
||||
{
|
||||
return $this->dbMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* The doBuild() method builds the DatabaseMap
|
||||
*
|
||||
* @return void
|
||||
* @throws PropelException
|
||||
*/
|
||||
public function doBuild()
|
||||
{
|
||||
$this->dbMap = Propel::getDatabaseMap('workflow');
|
||||
|
||||
$tMap = $this->dbMap->addTable('GMAIL_RELABELING');
|
||||
$tMap->setPhpName('GmailRelabeling');
|
||||
|
||||
$tMap->setUseIdGenerator(false);
|
||||
|
||||
$tMap->addPrimaryKey('APP_UID', 'AppUid', 'string', CreoleTypes::VARCHAR, true, 32);
|
||||
|
||||
$tMap->addPrimaryKey('DEL_INDEX', 'DelIndex', 'int', CreoleTypes::INTEGER, true, null);
|
||||
|
||||
$tMap->addColumn('CURRENT_LAST_INDEX', 'CurrentLastIndex', 'int', CreoleTypes::INTEGER, true, null);
|
||||
|
||||
$tMap->addColumn('UNASSIGNED', 'Unassigned', 'int', CreoleTypes::INTEGER, true, null);
|
||||
|
||||
$tMap->addColumn('STATUS', 'Status', 'string', CreoleTypes::VARCHAR, true, 32);
|
||||
|
||||
$tMap->addColumn('MSG_ERROR', 'MsgError', 'string', CreoleTypes::LONGVARCHAR, false, null);
|
||||
|
||||
} // doBuild()
|
||||
|
||||
} // GmailRelabelingMapBuilder
|
||||
812
workflow/engine/classes/model/om/BaseGmailRelabeling.php
Normal file
812
workflow/engine/classes/model/om/BaseGmailRelabeling.php
Normal file
File diff suppressed because it is too large
Load Diff
582
workflow/engine/classes/model/om/BaseGmailRelabelingPeer.php
Normal file
582
workflow/engine/classes/model/om/BaseGmailRelabelingPeer.php
Normal file
File diff suppressed because it is too large
Load Diff
@@ -5246,4 +5246,29 @@
|
||||
</vendor>
|
||||
</index>
|
||||
</table>
|
||||
|
||||
<table name="GMAIL_RELABELING">
|
||||
<vendor type="mysql">
|
||||
<parameter name="Name" value="GMAIL_RELABELING"/>
|
||||
<parameter name="Engine" value="InnoDB" />
|
||||
<parameter name="Version" value="10" />
|
||||
<parameter name="Row_format" value="Dynamic" />
|
||||
<parameter name="Data_free" value="0" />
|
||||
<parameter name="Auto_increment" value="" />
|
||||
<parameter name="Check_time" value="" />
|
||||
<parameter name="Collation" value="utf8_general_ci" />
|
||||
<parameter name="Checksum" value="" />
|
||||
<parameter name="Create_options" value="" />
|
||||
<parameter name="Comment" value="Task for label relabaling"/>
|
||||
</vendor>
|
||||
<column name="APP_UID" type="VARCHAR" size="32" required="true" primaryKey="true" default=""/>
|
||||
<column name="DEL_INDEX" type="INTEGER" required="true" primaryKey="true" default="0"/>
|
||||
<column name="CURRENT_LAST_INDEX" type="INTEGER" required="true" default="0"/>
|
||||
<column name="UNASSIGNED" type="INTEGER" required="true" default="0"/>
|
||||
<column name="STATUS" type="VARCHAR" size="32" required="true" default="pending"/>
|
||||
<column name="MSG_ERROR" type="LONGVARCHAR"/>
|
||||
<index name="indexStatus">
|
||||
<index-column name="STATUS"/>
|
||||
</index>
|
||||
</table>
|
||||
</database>
|
||||
|
||||
@@ -2930,3 +2930,23 @@ CREATE TABLE `NOTIFICATION_DEVICE`
|
||||
)ENGINE=InnoDB DEFAULT CHARSET='utf8' COMMENT='Definitions Notification device.';
|
||||
# This restores the fkey checks, after having unset them earlier
|
||||
# SET FOREIGN_KEY_CHECKS = 1;
|
||||
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
#-- GMAIL_RELABELING
|
||||
#-----------------------------------------------------------------------------
|
||||
|
||||
CREATE TABLE `GMAIL_RELABELING` (
|
||||
`APP_UID` VARCHAR(32) NOT NULL DEFAULT '',
|
||||
`DEL_INDEX` INT(11) NOT NULL DEFAULT '0',
|
||||
`CURRENT_LAST_INDEX` INT(11) NOT NULL DEFAULT '0',
|
||||
`UNASSIGNED` INT(11) NOT NULL DEFAULT '0',
|
||||
`STATUS` VARCHAR(32) NOT NULL DEFAULT 'pending',
|
||||
`MSG_ERROR` TEXT NULL,
|
||||
PRIMARY KEY (`APP_UID`, `DEL_INDEX`),
|
||||
KEY `indexStatus` (`STATUS`)
|
||||
)ENGINE=InnoDB DEFAULT CHARSET='utf8' COMMENT='Task to synchronize Gmail Labels';
|
||||
# This restores the fkey checks, after having unset them earlier
|
||||
# SET FOREIGN_KEY_CHECKS = 1;
|
||||
|
||||
|
||||
@@ -71,8 +71,7 @@ if ($aDelegation['USR_UID'] == "") {
|
||||
if(array_key_exists('gmail',$_SESSION) && $_SESSION['gmail'] == 1){
|
||||
require_once (PATH_HOME . "engine" . PATH_SEP . "classes" . PATH_SEP . "class.labelsGmail.php");
|
||||
$labGmail = new labelsGmail();
|
||||
$oResponse = $labGmail->setLabels($sAppUid, $iDelIndex, -1, true);
|
||||
|
||||
$labGmail->addRelabelingToQueue($sAppUid, $iDelIndex, -1, true);
|
||||
die( '<script type="text/javascript">
|
||||
parent.document.getElementById("iframePM").setAttribute("src", "'.$_SESSION["server"].'cases/cases_Open?APP_UID=' . $_SESSION["APPLICATION"] . '&DEL_INDEX=' . $_SESSION["INDEX"] . '&action=unassigned");
|
||||
</script>' );
|
||||
|
||||
@@ -32,7 +32,7 @@ foreach ($appDelPrev as $app){
|
||||
|
||||
require_once (PATH_HOME . "engine" . PATH_SEP . "classes" . PATH_SEP . "class.labelsGmail.php");
|
||||
$oLabels = new labelsGmail();
|
||||
$oResponse = $oLabels->setLabels($caseId, $actualIndex, $actualLastIndex, false);
|
||||
$oLabels->addRelabelingToQueue($caseId, $actualIndex, $actualLastIndex, false);
|
||||
|
||||
G::LoadClass( "AppDocumentDrive" );
|
||||
$drive = new AppDocumentDrive();
|
||||
|
||||
Reference in New Issue
Block a user