コード例 #1
0
 /**
  * UnLinks all states from a folder id
  * Old states are removed assisting the StateMachine to get rid of old data.
  * The UUID is then removed from the device
  *
  * @param ASDevice  $device
  * @param string    $folderid
  * @param boolean   $removeFromDevice       indicates if the device should be
  *                                          notified that the state was removed
  * @param boolean   $retrieveUUIDFromDevice indicates if the UUID should be retrieved from
  *                                          device. If not true this parameter will be used as UUID.
  *
  * @access public
  * @return boolean
  */
 public static function UnLinkState(&$device, $folderid, $removeFromDevice = true, $retrieveUUIDFromDevice = true)
 {
     if ($retrieveUUIDFromDevice === true) {
         $savedUuid = $device->GetFolderUUID($folderid);
     } else {
         $savedUuid = $retrieveUUIDFromDevice;
     }
     if ($savedUuid) {
         ZLog::Write(LOGLEVEL_DEBUG, sprintf("StateManager::UnLinkState('%s'): saved state '%s' will be deleted.", $folderid, $savedUuid));
         ZPush::GetStateMachine()->CleanStates($device->GetDeviceId(), IStateMachine::DEFTYPE, $savedUuid, self::FIXEDHIERARCHYCOUNTER * 2);
         ZPush::GetStateMachine()->CleanStates($device->GetDeviceId(), IStateMachine::FOLDERDATA, $savedUuid);
         // CPO
         ZPush::GetStateMachine()->CleanStates($device->GetDeviceId(), IStateMachine::FAILSAVE, $savedUuid, self::FIXEDHIERARCHYCOUNTER * 2);
         ZPush::GetStateMachine()->CleanStates($device->GetDeviceId(), IStateMachine::BACKENDSTORAGE, $savedUuid, self::FIXEDHIERARCHYCOUNTER * 2);
         // remove all messages which could not be synched before
         $device->RemoveIgnoredMessage($folderid, false);
         if ($folderid === false && $savedUuid !== false) {
             ZPush::GetStateMachine()->CleanStates($device->GetDeviceId(), IStateMachine::HIERARCHY, $savedUuid, self::FIXEDHIERARCHYCOUNTER * 2);
         }
     }
     // delete this id from the uuid cache
     if ($removeFromDevice) {
         return $device->SetFolderUUID(false, $folderid);
     } else {
         return true;
     }
 }
コード例 #2
0
 /**
  * Fixes states of the user linking to the states
  * and removes all obsolete states
  *
  * @return boolean
  * @access public
  */
 public static function FixStatesUserToStatesLinking()
 {
     $processed = 0;
     $deleted = 0;
     $devices = ZPush::GetStateMachine()->GetAllDevices(false);
     ZLog::Write(LOGLEVEL_DEBUG, sprintf("ZPushAdmin::FixStatesUserToStatesLinking(): found %d devices", count($devices)));
     foreach ($devices as $devid) {
         try {
             // we work on device level
             $devicedata = ZPush::GetStateMachine()->GetState($devid, IStateMachine::DEVICEDATA);
             $knownUuids = array();
             // get all known UUIDs for this device
             foreach (self::ListUsers($devid) as $username) {
                 $device = new ASDevice($devid, ASDevice::UNDEFINED, $username, ASDevice::UNDEFINED);
                 $device->SetData($devicedata, false);
                 // get all known uuids of this device
                 $folders = $device->GetAllFolderIds();
                 // add a "false" folder id so the hierarchy UUID is retrieved
                 $folders[] = false;
                 foreach ($folders as $folderid) {
                     $uuid = $device->GetFolderUUID($folderid);
                     if ($uuid) {
                         $knownUuids[] = $uuid;
                     }
                 }
             }
         } catch (StateNotFoundException $e) {
         }
         // get all uuids for deviceid from statemachine
         $existingStates = ZPush::GetStateMachine()->GetAllStatesForDevice($devid);
         $processed = count($existingStates);
         ZLog::Write(LOGLEVEL_DEBUG, sprintf("ZPushAdmin::FixStatesUserToStatesLinking(): found %d valid uuids and %d states for device device '%s'", count($knownUuids), $processed, $devid));
         // remove states for all unknown uuids
         foreach ($existingStates as $obsoleteState) {
             if ($obsoleteState['type'] === IStateMachine::DEVICEDATA) {
                 continue;
             }
             if (!in_array($obsoleteState['uuid'], $knownUuids)) {
                 if (is_numeric($obsoleteState['counter'])) {
                     $obsoleteState['counter']++;
                 }
                 ZPush::GetStateMachine()->CleanStates($devid, $obsoleteState['type'], $obsoleteState['uuid'], $obsoleteState['counter']);
                 $deleted++;
             }
         }
     }
     return array($processed, $deleted);
 }