Пример #1
0
 /**
  * Wipes 'a' or all devices of a user.
  * If no user is set, the device is generally wiped.
  * If no device id is set, all devices of the user will be wiped.
  * Device id or user must be set!
  *
  * @param string    $requestedBy    user which requested this operation
  * @param string    $user           (opt)user of the device
  * @param string    $devid          (opt) device id which should be wiped
  *
  * @return boolean
  * @access public
  */
 public static function WipeDevice($requestedBy, $user, $devid = false)
 {
     if ($user === false && $devid === false) {
         return false;
     }
     if ($devid === false) {
         $devicesIds = ZPush::GetStateMachine()->GetAllDevices($user);
         ZLog::Write(LOGLEVEL_DEBUG, sprintf("ZPushAdmin::WipeDevice(): all '%d' devices for user '%s' found to be wiped", count($devicesIds), $user));
         foreach ($devicesIds as $deviceid) {
             if (!self::WipeDevice($requestedBy, $user, $deviceid)) {
                 ZLog::Write(LOGLEVEL_ERROR, sprintf("ZPushAdmin::WipeDevice(): wipe devices failed for device '%s' of user '%s'. Aborting.", $deviceid, $user));
                 return false;
             }
         }
     } else {
         if ($devid !== false && $user === false) {
             $users = self::ListUsers($devid);
             ZLog::Write(LOGLEVEL_DEBUG, sprintf("ZPushAdmin::WipeDevice(): device '%d' is used by '%d' users and will be wiped", $devid, count($users)));
             if (count($users) == 0) {
                 ZLog::Write(LOGLEVEL_ERROR, sprintf("ZPushAdmin::WipeDevice(): no user found on device '%s'. Aborting.", $devid));
             }
             return self::WipeDevice($requestedBy, $users[0], $devid);
         } else {
             // load device data
             $device = new ASDevice($devid, ASDevice::UNDEFINED, $user, ASDevice::UNDEFINED);
             try {
                 $device->SetData(ZPush::GetStateMachine()->GetState($devid, IStateMachine::DEVICEDATA), false);
             } catch (StateNotFoundException $e) {
                 ZLog::Write(LOGLEVEL_ERROR, sprintf("ZPushAdmin::WipeDevice(): device '%s' of user '%s' can not be found", $devid, $user));
                 return false;
             }
             // set wipe status
             if ($device->GetWipeStatus() == SYNC_PROVISION_RWSTATUS_WIPED) {
                 ZLog::Write(LOGLEVEL_INFO, sprintf("ZPushAdmin::WipeDevice(): device '%s' of user '%s' was alread sucessfully remote wiped on %s", $devid, $user, strftime("%Y-%m-%d %H:%M", $device->GetWipeActionOn())));
             } else {
                 $device->SetWipeStatus(SYNC_PROVISION_RWSTATUS_PENDING, $requestedBy);
             }
             // save device data
             try {
                 if ($device->IsNewDevice()) {
                     ZLog::Write(LOGLEVEL_ERROR, sprintf("ZPushAdmin::WipeDevice(): data of user '%s' not synchronized on device '%s'. Aborting.", $user, $devid));
                     return false;
                 }
                 ZPush::GetStateMachine()->SetState($device->GetData(), $devid, IStateMachine::DEVICEDATA);
                 ZLog::Write(LOGLEVEL_DEBUG, sprintf("ZPushAdmin::WipeDevice(): device '%s' of user '%s' marked to be wiped", $devid, $user));
             } catch (StateNotFoundException $e) {
                 ZLog::Write(LOGLEVEL_ERROR, sprintf("ZPushAdmin::WipeDevice(): state for device '%s' of user '%s' can not be saved", $devid, $user));
                 return false;
             }
         }
     }
     return true;
 }