Commit 8d2ad6e6 authored by Michele Lunardi's avatar Michele Lunardi

ZP-1372 Folder re-sync is triggered on deletions ratio threshold. Released...

ZP-1372 Folder re-sync is triggered on deletions ratio threshold. Released under the Affero GNU General Public License (AGPL) version 3.
parent 4c334595
......@@ -43,6 +43,7 @@ class PHPWrapper {
private $contentparameters;
private $folderid;
private $prefix;
private $devid;
/**
......@@ -62,6 +63,7 @@ class PHPWrapper {
$this->mapiprovider = new MAPIProvider($session, $this->store);
$this->folderid = $folderid;
$this->prefix = '';
$this->devid = '';
if ($folderid) {
$folderidHex = bin2hex($folderid);
......@@ -69,6 +71,7 @@ class PHPWrapper {
if ($folderid != $folderidHex) {
$this->prefix = $folderid . ':';
}
$this->devid = ZPush::GetDeviceManager()->devid;
}
}
......@@ -165,11 +168,43 @@ class PHPWrapper {
* @access public
* @return
*/
public function ImportMessageDeletion($flags, $sourcekeys) {
public function ImportMessageDeletion($flags, $sourcekeys) {
$amount = count($sourcekeys);
if ($amount > 1000) {
if ((!defined('DELETION_COUNT_THR') || !defined('DELETION_RATIO_THR')) && $amount > 1000) {
throw new StatusException(sprintf("PHPWrapper->ImportMessageDeletion(): Received %d remove requests from ICS for folder '%s' (max. 1000 allowed). Triggering folder re-sync.", $amount, bin2hex($this->folderid)), SYNC_STATUS_INVALIDSYNCKEY, null, LOGLEVEL_ERROR);
}
// Analyse only if above DELETION_COUNT_THR threshold
else if ( defined('DELETION_COUNT_THR') && defined('DELETION_RATIO_THR') && $amount > DELETION_COUNT_THR) {
// Convert an PR_SOURCE_KEY to an PR_ENTRYID, for example to be able to open a folder if you only have a PR_SOURCE_KEY.
$entryid = mapi_msgstore_entryidfromsourcekey($this->store, $this->folderid);
if(!$entryid) {
ZLog::Write(LOGLEVEL_WARN, sprintf("PHPWrapper->ImportMessageDeletion(): Error, mapi_msgstore_entryidfromsourcekey failed for folder '%s' Stop Analysis and revert to normal delete. Error %s", bin2hex($this->folderid), mapi_last_hresult()));
}else{
// opens current folder
$wi_mfolder = mapi_msgstore_openentry($this->store, $entryid);
if(!$wi_mfolder) {
ZLog::Write(LOGLEVEL_WARN, sprintf("PHPWrapper->ImportMessageDeletion(): Error, mapi_msgstore_openentry failed for folder '%s' Stop Analysis and revert to normal delete. Error %s", bin2hex($this->folderid), mapi_last_hresult()));
}else{
// retrieve folder properties
$wi_mfolderProps = mapi_getprops($wi_mfolder, array(PR_CONTENT_COUNT));
if(!isset($wi_mfolderProps[PR_CONTENT_COUNT])) {
ZLog::Write(LOGLEVEL_WARN, sprintf("PHPWrapper->ImportMessageDeletion(): Error, mapi_getprops failed for folder '%s' Stop Analysis and revert to normal delete. Error %s", bin2hex($this->folderid), mapi_last_hresult()));
}else{
//get count of remaining folder elements
$wi_mfolderElementsCount = $wi_mfolderProps[PR_CONTENT_COUNT];
//get ratio between deleted element count and remaining elements count
$ratio = $amount / $wi_mfolderElementsCount;
if($ratio > DELETION_RATIO_THR || $ratio == 0){
throw new StatusException(sprintf("PHPWrapper->ImportMessageDeletion(): Received %d remove requests from ICS for devId='%s' folder='%s' folderCount='%d' ratio='%0.2f' threshold='%0.2f' . Triggering folder re-sync.", $amount, $this->devid, bin2hex($this->folderid), $wi_mfolderElementsCount, $ratio, DELETION_RATIO_THR), SYNC_STATUS_INVALIDSYNCKEY, null, LOGLEVEL_ERROR);
}else{
ZLog::Write(LOGLEVEL_DEBUG, sprintf("PHPWrapper->ImportMessageDeletion(): Received %d remove requests from ICS for devId='%s' folder='%s' folderCount='%d' ratio='%0.2f' threshold='%0.2f' . Not Triggering folder re-sync. ", $amount, $this->devid, bin2hex($this->folderid), $wi_mfolderElementsCount, $ratio, DELETION_RATIO_THR));
}
}
}
}
}
else {
ZLog::Write(LOGLEVEL_DEBUG, sprintf("PHPWrapper->ImportMessageDeletion(): Received %d remove requests from ICS", $amount));
}
......
......@@ -289,6 +289,21 @@ class ZPush {
if (defined('USE_X_FORWARDED_FOR_HEADER')) {
ZLog::Write(LOGLEVEL_INFO, "The configuration parameter 'USE_X_FORWARDED_FOR_HEADER' was deprecated in favor of 'USE_CUSTOM_REMOTE_IP_HEADER'. Please update your configuration.");
}
//check folder re-sync triggering settings
if(defined('DELETION_COUNT_THR') && !defined('DELETION_RATIO_THR')){
throw new FatalMisconfigurationException("Only DELETION_COUNT_THR defined. Please define DELETION_RATIO_THR.");
}
else if(!defined('DELETION_COUNT_THR') && defined('DELETION_RATIO_THR')){
throw new FatalMisconfigurationException("Only DELETION_RATIO_THR defined. Please define DELETION_COUNT_THR.");
}
if ( (defined('DELETION_COUNT_THR')) && (!is_int(DELETION_COUNT_THR) || DELETION_COUNT_THR < 1)){
throw new FatalMisconfigurationException("The DELETION_COUNT_THR value must be a number higher than 0.");
}
if ( (defined('DELETION_RATIO_THR')) && (!is_numeric(DELETION_RATIO_THR) || DELETION_RATIO_THR <= 0)){
throw new FatalMisconfigurationException("The DELETION_RATIO_THR value must be a number higher than 0.");
}
return true;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment