Back to index

d-push  2.0
Static Public Member Functions
ZPushAdmin Class Reference

List of all members.

Static Public Member Functions

static ListDevices ($user=false)
 //TODO resync of a foldertype for all users (e.g.
static ListUsers ($devid)
 List users of a device known to Z-Push.
static GetDeviceDetails ($devid, $user)
 Returns details of a device like synctimes, policy and wipe status, synched folders etc.
static WipeDevice ($requestedBy, $user, $devid=false)
 Wipes 'a' or all devices of a user.
static RemoveDevice ($user=false, $devid=false)
 Removes device details from the z-push directory.
static ResyncFolder ($user, $devid, $folderid)
 Marks a folder of a device of a user for re-synchronization.
static ResyncDevice ($user, $devid=false)
 Marks a all folders synchronized to a device for re-synchronization If no user is set all user which are synchronized for a device are marked for re-synchronization.
static ClearLoopDetectionData ($user=false, $devid=false)
 Clears loop detection data.
static GetLoopDetectionData ($user, $devid)
 Returns loop detection data of a user & device.

Detailed Description

Definition at line 44 of file zpushadmin.php.


Member Function Documentation

static ZPushAdmin::ClearLoopDetectionData ( user = false,
devid = false 
) [static]

Clears loop detection data.

Parameters:
string$user(opt) user which data should be removed - user may not be specified without device id
string$devid(opt) device id which data to be removed
Returns:
boolean public

Definition at line 396 of file zpushadmin.php.

                                                                                 {
        $loopdetection = new LoopDetection();
        return $loopdetection->ClearData($user, $devid);
    }
static ZPushAdmin::GetDeviceDetails ( devid,
user 
) [static]

Returns details of a device like synctimes, policy and wipe status, synched folders etc.

Parameters:
string$deviddevice id
string$useruser to be looked up
Returns:
ASDevice object public

Definition at line 94 of file zpushadmin.php.

                                                           {

        try {
            $device = new ASDevice($devid, ASDevice::UNDEFINED, $user, ASDevice::UNDEFINED);
            $device->SetData(ZPush::GetStateMachine()->GetState($devid, IStateMachine::DEVICEDATA), false);
            $device->StripData();

            try {
                $lastsync = SyncCollections::GetLastSyncTimeOfDevice($device);
                if ($lastsync)
                    $device->SetLastSyncTime($lastsync);
            }
            catch (StateInvalidException $sive) {
                ZLog::Write(LOGLEVEL_WARN, sprintf("ZPushAdmin::GetDeviceDetails(): device '%s' of user '%s' has invalid states. Please sync to solve this issue.", $devid, $user));
                $device->SetDeviceError("Invalid states. Please force synchronization!");
            }

            return $device;
        }
        catch (StateNotFoundException $e) {
            ZLog::Write(LOGLEVEL_ERROR, sprintf("ZPushAdmin::GetDeviceDetails(): device '%s' of user '%s' can not be found", $devid, $user));
            return false;
        }
    }

Here is the call graph for this function:

Here is the caller graph for this function:

static ZPushAdmin::GetLoopDetectionData ( user,
devid 
) [static]

Returns loop detection data of a user & device.

Parameters:
string$user
string$devid
Returns:
array/boolean returns false if data is not available public

Definition at line 410 of file zpushadmin.php.

                                                               {
        $loopdetection = new LoopDetection();
        return $loopdetection->GetCachedData($user, $devid);
    }
static ZPushAdmin::ListDevices ( user = false) [static]

//TODO resync of a foldertype for all users (e.g.

Appointment) List devices known to Z-Push. If no user is given, all devices are listed

Parameters:
string$userdevices of that user, if false all devices of all users
Returns:
array public

Definition at line 58 of file zpushadmin.php.

                                                      {
        return ZPush::GetStateMachine()->GetAllDevices($user);
    }

Here is the call graph for this function:

Here is the caller graph for this function:

static ZPushAdmin::ListUsers ( devid) [static]

List users of a device known to Z-Push.

Parameters:
string$devidusers of that device
Returns:
array public

Definition at line 70 of file zpushadmin.php.

                                             {
        try {
            $devState = ZPush::GetStateMachine()->GetState($devid, IStateMachine::DEVICEDATA);

            if ($devState instanceof StateObject && isset($devState->devices) && is_array($devState->devices))
                return array_keys($devState->devices);
            else
                return array();
        }
        catch (StateNotFoundException $stnf) {
            return array();
        }
    }

Here is the call graph for this function:

Here is the caller graph for this function:

static ZPushAdmin::RemoveDevice ( user = false,
devid = false 
) [static]

Removes device details from the z-push directory.

If device id is not set, all devices of a user are removed. If the user is not set, the details of the device (independently if used by several users) is removed. Device id or user must be set!

Parameters:
string$user(opt) user of the device
string$devid(opt) device id which should be wiped
Returns:
boolean public

Definition at line 205 of file zpushadmin.php.

                                                                       {
        if ($user === false && $devid === false)
            return false;

        // remove all devices for user
        if ($devid === false && $user !== false) {
            $devicesIds = ZPush::GetStateMachine()->GetAllDevices($user);
            ZLog::Write(LOGLEVEL_DEBUG, sprintf("ZPushAdmin::RemoveDevice(): all '%d' devices for user '%s' found to be removed", count($devicesIds), $user));
            foreach ($devicesIds as $deviceid) {
                if (!self::RemoveDevice($user, $deviceid)) {
                    ZLog::Write(LOGLEVEL_ERROR, sprintf("ZPushAdmin::RemoveDevice(): removing devices failed for device '%s' of user '%s'. Aborting", $deviceid, $user));
                    return false;
                }
            }
        }
        // remove a device completely (for connected users to this device)
        else if ($devid !== false && $user === false) {
            $users = self::ListUsers($devid);
            ZLog::Write(LOGLEVEL_DEBUG, sprintf("ZPushAdmin::RemoveDevice(): device '%d' is used by '%d' users and will be removed", $devid, count($users)));
            foreach ($users as $aUser) {
                if (!self::RemoveDevice($aUser, $devid)) {
                    ZLog::Write(LOGLEVEL_ERROR, sprintf("ZPushAdmin::RemoveDevice(): removing user '%s' from device '%s' failed. Aborting", $aUser, $devid));
                    return false;
                }
            }
        }

        // user and deviceid set
        else {
            // load device data
            $device = new ASDevice($devid, ASDevice::UNDEFINED, $user, ASDevice::UNDEFINED);
            $devices = array();
            try {
                $devicedata = ZPush::GetStateMachine()->GetState($devid, IStateMachine::DEVICEDATA);
                $device->SetData($devicedata, false);
                $devices = $devicedata->devices;
            }
            catch (StateNotFoundException $e) {
                ZLog::Write(LOGLEVEL_ERROR, sprintf("ZPushAdmin::RemoveDevice(): device '%s' of user '%s' can not be found", $devid, $user));
                return false;
            }

            // remove all related states
            foreach ($device->GetAllFolderIds() as $folderid)
                StateManager::UnLinkState($device, $folderid);

            // remove hierarchcache
            StateManager::UnLinkState($device, false);

            // remove backend storage permanent data
            ZPush::GetStateMachine()->CleanStates($device->GetDeviceId(), IStateMachine::BACKENDSTORAGE, false, 99999999999);

            // remove devicedata and unlink user from device
            unset($devices[$user]);
            if (isset($devicedata->devices))
                $devicedata->devices = $devices;
            ZPush::GetStateMachine()->UnLinkUserDevice($user, $devid);

            // no more users linked for device - remove device data
            if (count($devices) == 0)
                ZPush::GetStateMachine()->CleanStates($devid, IStateMachine::DEVICEDATA, false);

            // save data if something left
            else
                ZPush::GetStateMachine()->SetState($devicedata, $devid, IStateMachine::DEVICEDATA);

            ZLog::Write(LOGLEVEL_DEBUG, sprintf("ZPushAdmin::RemoveDevice(): data of device '%s' of user '%s' removed", $devid, $user));
        }
        return true;
    }

Here is the call graph for this function:

Here is the caller graph for this function:

static ZPushAdmin::ResyncDevice ( user,
devid = false 
) [static]

Marks a all folders synchronized to a device for re-synchronization If no user is set all user which are synchronized for a device are marked for re-synchronization.

If no device id is set all devices of that user are marked for re-synchronization. If no user and no device are set then ALL DEVICES are marked for resynchronization (use with care!).

Parameters:
string$user(opt) user of the device
string$devid(opt)device id which should be wiped
Returns:
boolean public

Definition at line 323 of file zpushadmin.php.

                                                               {

        // search for target devices
        if ($devid === false) {
            $devicesIds = ZPush::GetStateMachine()->GetAllDevices($user);
            ZLog::Write(LOGLEVEL_DEBUG, sprintf("ZPushAdmin::ResyncDevice(): all '%d' devices for user '%s' found to be re-synchronized", count($devicesIds), $user));
            foreach ($devicesIds as $deviceid) {
                if (!self::ResyncDevice($user, $deviceid)) {
                    ZLog::Write(LOGLEVEL_ERROR, sprintf("ZPushAdmin::ResyncDevice(): wipe devices failed for device '%s' of user '%s'. Aborting", $deviceid, $user));
                    return false;
                }
            }
        }
        else {
            // get devicedata
            try {
                $devicedata = ZPush::GetStateMachine()->GetState($devid, IStateMachine::DEVICEDATA);
            }
            catch (StateNotFoundException $e) {
                ZLog::Write(LOGLEVEL_ERROR, sprintf("ZPushAdmin::ResyncDevice(): state for device '%s' can not be found", $devid));
                return false;

            }

            // loop through all users which currently use this device
            if ($user === false && $devicedata instanceof StateObject && isset($devicedata->devices) &&
                is_array($devicedata->devices) && count($devicedata->devices) > 1) {
                foreach (array_keys($devicedata) as $aUser) {
                    if (!self::ResyncDevice($aUser, $devid)) {
                        ZLog::Write(LOGLEVEL_ERROR, sprintf("ZPushAdmin::ResyncDevice(): re-synchronization failed for device '%s' of user '%s'. Aborting", $devid, $aUser));
                        return false;
                    }
                }
            }

            // load device data
            $device = new ASDevice($devid, ASDevice::UNDEFINED, $user, ASDevice::UNDEFINED);
            try {
                $device->SetData($devicedata, false);

                if ($device->IsNewDevice()) {
                    ZLog::Write(LOGLEVEL_ERROR, sprintf("ZPushAdmin::ResyncDevice(): data of user '%s' not synchronized on device '%s'. Aborting.",$user, $devid));
                    return false;
                }

                // delete all uuids
                foreach ($device->GetAllFolderIds() as $folderid)
                    StateManager::UnLinkState($device, $folderid);

                // remove hierarchcache
                StateManager::UnLinkState($device, false);

                ZPush::GetStateMachine()->SetState($device->GetData(), $devid, IStateMachine::DEVICEDATA);

                ZLog::Write(LOGLEVEL_DEBUG, sprintf("ZPushAdmin::ResyncDevice(): all folders synchronized to device '%s' of user '%s' marked to be re-synchronized.", $devid, $user));
            }
            catch (StateNotFoundException $e) {
                ZLog::Write(LOGLEVEL_ERROR, sprintf("ZPushAdmin::ResyncDevice(): state for device '%s' of user '%s' can not be found or saved", $devid, $user));
                return false;
            }
        }
        return true;
    }

Here is the call graph for this function:

Here is the caller graph for this function:

static ZPushAdmin::ResyncFolder ( user,
devid,
folderid 
) [static]

Marks a folder of a device of a user for re-synchronization.

Parameters:
string$useruser of the device
string$deviddevice id which should be wiped
string$folderidif not set, hierarchy state is linked
Returns:
boolean public

Definition at line 287 of file zpushadmin.php.

                                                                  {
        // load device data
        $device = new ASDevice($devid, ASDevice::UNDEFINED, $user, ASDevice::UNDEFINED);
        try {
            $device->SetData(ZPush::GetStateMachine()->GetState($devid, IStateMachine::DEVICEDATA), false);

            if ($device->IsNewDevice()) {
                ZLog::Write(LOGLEVEL_ERROR, sprintf("ZPushAdmin::ResyncFolder(): data of user '%s' not synchronized on device '%s'. Aborting.",$user, $devid));
                return false;
            }

            // remove folder state
            StateManager::UnLinkState($device, $folderid);

            ZPush::GetStateMachine()->SetState($device->GetData(), $devid, IStateMachine::DEVICEDATA);
            ZLog::Write(LOGLEVEL_DEBUG, sprintf("ZPushAdmin::ResyncFolder(): folder '%s' on device '%s' of user '%s' marked to be re-synchronized.", $devid, $user));
        }
        catch (StateNotFoundException $e) {
            ZLog::Write(LOGLEVEL_ERROR, sprintf("ZPushAdmin::ResyncFolder(): state for device '%s' of user '%s' can not be found or saved", $devid, $user));
            return false;
        }
    }

Here is the call graph for this function:

static ZPushAdmin::WipeDevice ( requestedBy,
user,
devid = false 
) [static]

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!

Parameters:
string$requestedByuser which requested this operation
string$user(opt)user of the device
string$devid(opt) device id which should be wiped
Returns:
boolean public

Definition at line 132 of file zpushadmin.php.

                                                                           {
        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;
                }
            }
        }

        // wipe a device completely (for connected users to this device)
        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;
    }

Here is the call graph for this function:

Here is the caller graph for this function:


The documentation for this class was generated from the following file: