/**
  * The actual ChangesSink.
  * For max. the $timeout value this method should block and if no changes
  * are available return an empty array.
  * If changes are available a list of folderids is expected.
  *
  * @param int           $timeout        max. amount of seconds to block
  *
  * @access public
  * @return array
  */
 public function ChangesSink($timeout = 30)
 {
     $notifications = array();
     $sinkresult = @mapi_sink_timedwait($this->changesSink, $timeout * 1000);
     foreach ($sinkresult as $sinknotif) {
         // check if something in the monitored folders changed
         if (isset($sinknotif['parentid']) && array_key_exists($sinknotif['parentid'], $this->changesSinkFolders)) {
             $notifications[] = $this->changesSinkFolders[$sinknotif['parentid']];
         }
         // deletes and moves
         if (isset($sinknotif['oldparentid']) && array_key_exists($sinknotif['oldparentid'], $this->changesSinkFolders)) {
             $notifications[] = $this->changesSinkFolders[$sinknotif['oldparentid']];
         }
     }
     return $notifications;
 }
Exemple #2
0
 /**
  * The actual ChangesSink.
  * For max. the $timeout value this method should block and if no changes
  * are available return an empty array.
  * If changes are available a list of folderids is expected.
  *
  * @param int           $timeout        max. amount of seconds to block
  *
  * @access public
  * @return array
  */
 public function ChangesSink($timeout = 30)
 {
     // clear the folder stats cache
     unset($this->folderStatCache);
     $notifications = array();
     $hierarchyNotifications = array();
     $sinkresult = @mapi_sink_timedwait($this->changesSink, $timeout * 1000);
     // reverse array so that the changes on folders are before changes on messages and
     // it's possible to filter such notifications
     $sinkresult = array_reverse($sinkresult, true);
     foreach ($sinkresult as $sinknotif) {
         // add a notification on a folder
         if ($sinknotif['objtype'] == MAPI_FOLDER) {
             $hierarchyNotifications[$sinknotif['entryid']] = IBackend::HIERARCHYNOTIFICATION;
         }
         // change on a message, remove hierarchy notification
         if (isset($sinknotif['parentid']) && $sinknotif['objtype'] == MAPI_MESSAGE && isset($notifications[$sinknotif['parentid']])) {
             unset($hierarchyNotifications[$sinknotif['parentid']]);
         }
         // TODO check if adding $sinknotif['objtype'] = MAPI_MESSAGE wouldn't break anything
         // check if something in the monitored folders changed
         if (isset($sinknotif['parentid']) && array_key_exists($sinknotif['parentid'], $this->changesSinkFolders)) {
             $notifications[] = $this->changesSinkFolders[$sinknotif['parentid']];
         }
         // deletes and moves
         if (isset($sinknotif['oldparentid']) && array_key_exists($sinknotif['oldparentid'], $this->changesSinkFolders)) {
             $notifications[] = $this->changesSinkFolders[$sinknotif['oldparentid']];
         }
     }
     // validate hierarchy notifications by comparing the hierarchy hashes (too many false positives otherwise)
     if (!empty($hierarchyNotifications)) {
         $hash = $this->getHierarchyHash();
         if ($hash !== $this->changesSinkHierarchyHash) {
             ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendKopano->ChangesSink() Hierarchy notification, pending validation. New hierarchyHash: %s", $hash));
             $notifications[] = IBackend::HIERARCHYNOTIFICATION;
             $this->changesSinkHierarchyHash = $hash;
         }
     }
     return $notifications;
 }