Commit 1557f58b authored by Sebastian Kummer's avatar Sebastian Kummer

Merge pull request #687 in ZP/z-push from...

Merge pull request #687 in ZP/z-push from feature/ZP-1372-folder-re-sync-is-triggered-on-deletions-ratio-threshold to develop

* commit '8f1414f0':
  ZP-1372 PHP doc fix - added a dot at the end of the sentence.
  ZP-1372 Created getter ZPush::GetDeviceManager()->GetDevid() , resumed SYNC_STATUS_INVALIDSYNCKEY for triggering a folder resync. Released under the Affero GNU General Public License (AGPL) version 3.
  ZP-1372 Removed logging deviceid. Code style changes.
  ZP-1372 Moved 'Not Triggering folder re-sync' message to INFO level. Released under the Affero GNU General Public License (AGPL) version 3.
  ZP-1372 Folder re-sync is triggered on deletions ratio threshold. Released under the Affero GNU General Public License (AGPL) version 3.
parents 401043cc 8f1414f0
......@@ -167,9 +167,46 @@ class PHPWrapper {
*/
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
elseif (defined('DELETION_COUNT_THR') && defined('DELETION_RATIO_THR') && $amount > DELETION_COUNT_THR) {
// Convert a 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 0x%08X", 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 0x%08X", 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 0x%08X", 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;
$devid = ZPush::GetDeviceManager()->GetDevid();
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, $devid, bin2hex($this->folderid), $wi_mfolderElementsCount, $ratio, DELETION_RATIO_THR), SYNC_STATUS_INVALIDSYNCKEY, null, LOGLEVEL_ERROR);
}
else {
ZLog::Write(LOGLEVEL_INFO, 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, $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));
}
......
......@@ -1278,4 +1278,14 @@ class DeviceManager {
}
return $folder;
}
/**
* Returns the device id.
*
* @access public
* @return string
*/
public function GetDevid() {
return $this->devid;
}
}
......@@ -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.");
}
elseif (!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