Back to index

d-push  2.0
Public Member Functions | Public Attributes | Protected Attributes | Private Attributes
ChangesMemoryWrapper Class Reference
Inheritance diagram for ChangesMemoryWrapper:
Inheritance graph
[legend]
Collaboration diagram for ChangesMemoryWrapper:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 ChangesMemoryWrapper ()
 Constructor.
 Config ($state, $flags=0)
 Only used to load additional folder sync information for hierarchy changes.
 GetState ()
 Implement interfaces which are never used.
 LoadConflicts ($contentparameters, $state)
 
Methods for to import contents
 ConfigContentParameters ($contentparameters)
 Configures additional parameters used for content synchronization.
 ImportMessageReadFlag ($id, $flags)
 Imports a change in 'read' flag This can never conflict.
 ImportMessageMove ($id, $newfolder)
 Imports a move of a message.
 SetDestinationImporter (&$importer)
 
IImportChanges & destination importer
 ImportMessageChange ($id, $message)
 Imports a message change, which is imported into memory.
 ImportMessageDeletion ($id)
 Imports a message deletion, which is imported into memory.
 IsChanged ($id)
 Checks if a message id is flagged as changed.
 IsDeleted ($id)
 Checks if a message id is flagged as deleted.
 ImportFolderChange ($folder)
 Imports a folder change.
 ImportFolderDeletion ($id, $parent=false)
 Imports a folder deletion.
 InitializeExporter (&$importer)
 
IExportChanges & destination importer
 GetChangeCount ()
 Returns the amount of changes to be exported.
 Synchronize ()
 Synchronizes a change.
 __wakeup ()
 Initializes a few instance variables called after unserialization.
 HierarchyCache ()
 Constructor of the HierarchyCache.
 IsStateChanged ()
 Indicates if the cache was changed.
 CopyOldState ()
 Copy current CacheById to memory.
 GetFolder ($serverid, $oldState=false)
 Returns the SyncFolder object for a folder id If $oldstate is set, then the data from the previous state is returned.
 AddFolder ($folder)
 Adds a folder to the HierarchyCache.
 DelFolder ($serverid)
 Removes a folder to the HierarchyCache.
 ImportFolders ($folders)
 Imports a folder array to the HierarchyCache.
 ExportFolders ($oldstate=false)
 Exports all folders from the HierarchyCache.
 GetDeletedFolders ()
 Returns all folder objects which were deleted in this operation.
 GetStat ()
 Returns some statistics about the HierarchyCache.
 __sleep ()
 Returns objects which should be persistent called before serialization.

Public Attributes

const CHANGE = 1
const DELETION = 2

Protected Attributes

 $cacheById

Private Attributes

 $changes
 $step
 $destinationImporter
 $exportImporter

Detailed Description

Definition at line 45 of file changesmemorywrapper.php.


Member Function Documentation

HierarchyCache::__sleep ( ) [inherited]

Returns objects which should be persistent called before serialization.

public

Returns:
array

Definition at line 210 of file hierarchycache.php.

                              {
        return array("cacheById");
    }

Initializes a few instance variables called after unserialization.

public

Returns:
array

Definition at line 335 of file changesmemorywrapper.php.

                               {
        $this->changes = array();
        $this->step = 0;
    }
HierarchyCache::AddFolder ( folder) [inherited]

Adds a folder to the HierarchyCache.

Parameters:
SyncObject$folderpublic
Returns:
boolean

Definition at line 111 of file hierarchycache.php.

                                       {
        ZLog::Write(LOGLEVEL_DEBUG, "HierarchyCache: AddFolder() serverid: {$folder->serverid} displayname: {$folder->displayname}");

        // on update the $folder does most of the times not contain a type
        // we copy the value in this case to the new $folder object
        if (isset($this->cacheById[$folder->serverid]) && (!isset($folder->type) || $folder->type == false) && isset($this->cacheById[$folder->serverid]->type)) {
            $folder->type = $this->cacheById[$folder->serverid]->type;
            ZLog::Write(LOGLEVEL_DEBUG, sprintf("HierarchyCache: AddFolder() is an update: used type '%s' from old object", $folder->type));
        }

        // add/update
        $this->cacheById[$folder->serverid] = $folder;
        $this->changed = true;

        return true;
    }

Here is the call graph for this function:

Here is the caller graph for this function:

Constructor.

public

Returns:

Definition at line 60 of file changesmemorywrapper.php.

                                           {
        $this->changes = array();
        $this->step = 0;
        parent::HierarchyCache();
    }

Here is the call graph for this function:

ChangesMemoryWrapper::Config ( state,
flags = 0 
)

Only used to load additional folder sync information for hierarchy changes.

Parameters:
array$statecurrent state of additional hierarchy folders

public

Returns:
boolean

Implements IChanges.

Definition at line 74 of file changesmemorywrapper.php.

                                               {
        // we should never forward this changes to a backend
        if (!isset($this->destinationImporter)) {
            foreach($state as $addKey => $addFolder) {
                ZLog::Write(LOGLEVEL_DEBUG, sprintf("ChangesMemoryWrapper->Config(AdditionalFolders) : process folder '%s'", $addFolder->displayname));
                if (isset($addFolder->NoBackendFolder) && $addFolder->NoBackendFolder == true) {
                    $hasRights = ZPush::GetBackend()->Setup($addFolder->Store, true, $addFolder->serverid);
                    // delete the folder on the device
                    if (! $hasRights) {
                        // delete the folder only if it was an additional folder before, else ignore it
                        $synchedfolder = $this->GetFolder($addFolder->serverid);
                        if (isset($synchedfolder->NoBackendFolder) && $synchedfolder->NoBackendFolder == true)
                            $this->ImportFolderDeletion($addFolder->serverid, $addFolder->parentid);
                        continue;
                    }
                }
                // add folder to the device - if folder is already on the device, nothing will happen
                $this->ImportFolderChange($addFolder);
            }

            // look for folders which are currently on the device if there are now not to be synched anymore
            $alreadyDeleted = $this->GetDeletedFolders();
            foreach ($this->ExportFolders(true) as $sid => $folder) {
                // we are only looking at additional folders
                if (isset($folder->NoBackendFolder)) {
                    // look if this folder is still in the list of additional folders and was not already deleted (e.g. missing permissions)
                    if (!array_key_exists($sid, $state) && !array_key_exists($sid, $alreadyDeleted)) {
                        ZLog::Write(LOGLEVEL_INFO, sprintf("ChangesMemoryWrapper->Config(AdditionalFolders) : previously synchronized folder '%s' is not to be synched anymore. Sending delete to mobile.", $folder->displayname));
                        $this->ImportFolderDeletion($folder->serverid, $folder->parentid);
                    }
                }
            }
        }
        return true;
    }

Here is the call graph for this function:

Configures additional parameters used for content synchronization.

Parameters:
ContentParameters$contentparameterspublic
Returns:
boolean
Exceptions:
StatusException

Implements IExportChanges.

Definition at line 116 of file changesmemorywrapper.php.

{ return true; }

Copy current CacheById to memory.

public

Returns:
boolean

Definition at line 78 of file hierarchycache.php.

                                   {
        $this->cacheByIdOld = $this->cacheById;
        return true;
    }
HierarchyCache::DelFolder ( serverid) [inherited]

Removes a folder to the HierarchyCache.

Parameters:
string$serveridid of folder to be removed

public

Returns:
boolean

Definition at line 136 of file hierarchycache.php.

                                         {
        $ftype = $this->GetFolder($serverid);

        ZLog::Write(LOGLEVEL_DEBUG, sprintf("HierarchyCache: DelFolder() serverid: '%s' - type: '%s'", $serverid, $ftype->type));
        unset($this->cacheById[$serverid]);
        $this->changed = true;
        return true;
    }

Here is the call graph for this function:

Here is the caller graph for this function:

HierarchyCache::ExportFolders ( oldstate = false) [inherited]

Exports all folders from the HierarchyCache.

Parameters:
boolean$oldstate(optional) by default false

public

Returns:
array

Definition at line 175 of file hierarchycache.php.

                                                     {
        if ($oldstate === false)
            return $this->cacheById;
        else
            return $this->cacheByIdOld;
    }

Here is the caller graph for this function:

Returns the amount of changes to be exported.

public

Returns:
int

Implements IExportChanges.

Definition at line 294 of file changesmemorywrapper.php.

                                     {
        return count($this->changes);
    }

Returns all folder objects which were deleted in this operation.

public

Returns:
array with SyncFolder objects

Definition at line 188 of file hierarchycache.php.

                                        {
        // diffing the OldCacheById with CacheById we know if folders were deleted
        return array_diff_key($this->cacheByIdOld, $this->cacheById);
    }

Here is the caller graph for this function:

HierarchyCache::GetFolder ( serverid,
oldState = false 
) [inherited]

Returns the SyncFolder object for a folder id If $oldstate is set, then the data from the previous state is returned.

Parameters:
string$serverid
boolean$oldstate(optional) by default false

public

Returns:
SyncObject/boolean false if not found

Definition at line 93 of file hierarchycache.php.

                                                            {
        if (!$oldState && array_key_exists($serverid, $this->cacheById)) {
            return $this->cacheById[$serverid];
        }
        else if ($oldState && array_key_exists($serverid, $this->cacheByIdOld)) {
            return $this->cacheByIdOld[$serverid];
        }
        return false;
    }

Here is the caller graph for this function:

HierarchyCache::GetStat ( ) [inherited]

Returns some statistics about the HierarchyCache.

public

Returns:
string

Definition at line 199 of file hierarchycache.php.

                              {
        return sprintf("HierarchyCache is %s - Cached objects: %d", ((isset($this->cacheById))?"up":"down"), ((isset($this->cacheById))?count($this->cacheById):"0"));
    }

Implement interfaces which are never used.

Implements IChanges.

Definition at line 114 of file changesmemorywrapper.php.

{ return false;}

Constructor of the HierarchyCache.

public

Returns:

Definition at line 56 of file hierarchycache.php.

                                     {
        $this->cacheById = array();
        $this->cacheByIdOld = $this->cacheById;
        $this->changed = true;
    }

Here is the caller graph for this function:

Imports a folder change.

Parameters:
SyncFolder$folderfolder to be changed

public

Returns:
boolean

Implements IImportChanges.

Definition at line 195 of file changesmemorywrapper.php.

                                                {
        // if the destinationImporter is set, then this folder should be processed by another importer
        // instead of being loaded in memory.
        if (isset($this->destinationImporter)) {
            $ret = $this->destinationImporter->ImportFolderChange($folder);

            // if the operation was sucessfull, update the HierarchyCache
            if ($ret) {
                // for folder creation, the serverid is not set and has to be updated before
                if (!isset($folder->serverid) || $folder->serverid == "")
                    $folder->serverid = $ret;

                $this->AddFolder($folder);
            }
            return $ret;
        }
        // load into memory
        else {
            if (isset($folder->serverid)) {
                // The Zarafa HierarchyExporter exports all kinds of changes for folders (e.g. update no. of unread messages in a folder).
                // These changes are not relevant for the mobiles, as something changes but the relevant displayname and parentid
                // stay the same. These changes will be dropped and are not sent!
                $cacheFolder = $this->GetFolder($folder->serverid);
                if ($folder->equals($this->GetFolder($folder->serverid))) {
                    ZLog::Write(LOGLEVEL_DEBUG, sprintf("Change for folder '%s' will not be sent as modification is not relevant.", $folder->displayname));
                    return false;
                }

                // load this change into memory
                $this->changes[] = array(self::CHANGE, $folder);

                // HierarchyCache: already add/update the folder so changes are not sent twice (if exported twice)
                $this->AddFolder($folder);
                return true;
            }
            return false;
        }
    }

Here is the call graph for this function:

Here is the caller graph for this function:

ChangesMemoryWrapper::ImportFolderDeletion ( id,
parent = false 
)

Imports a folder deletion.

Parameters:
string$id
string$parent(opt) the parent id of the folders

public

Returns:
boolean

Implements IImportChanges.

Definition at line 243 of file changesmemorywrapper.php.

                                                               {
        // if the forwarder is set, then this folder should be processed by another importer
        // instead of being loaded in mem.
        if (isset($this->destinationImporter)) {
            $ret = $this->destinationImporter->ImportFolderDeletion($id, $parent);

            // if the operation was sucessfull, update the HierarchyCache
            if ($ret)
                $this->DelFolder($id);

            return $ret;
        }
        else {
            // if this folder is not in the cache, the change does not need to be streamed to the mobile
            if ($this->GetFolder($id)) {

                // load this change into memory
                $this->changes[] = array(self::DELETION, $id, $parent);

                // HierarchyCache: delete the folder so changes are not sent twice (if exported twice)
                $this->DelFolder($id);
                return true;
            }
        }
    }

Here is the call graph for this function:

Here is the caller graph for this function:

HierarchyCache::ImportFolders ( folders) [inherited]

Imports a folder array to the HierarchyCache.

Parameters:
array$foldersfolders to the HierarchyCache

public

Returns:
boolean

Definition at line 153 of file hierarchycache.php.

                                            {
        if (!is_array($folders))
            return false;

        $this->cacheById = array();

        foreach ($folders as $folder) {
            if (!isset($folder->type))
                continue;
            $this->AddFolder($folder);
        }
        return true;
    }

Here is the call graph for this function:

ChangesMemoryWrapper::ImportMessageChange ( id,
message 
)

Imports a message change, which is imported into memory.

Parameters:
string$idid of message which is changed
SyncObject$messagemessage to be changed

public

Returns:
boolean

Implements IImportChanges.

Definition at line 145 of file changesmemorywrapper.php.

                                                       {
        $this->changes[] = array(self::CHANGE, $id);
        return true;
    }

Imports a message deletion, which is imported into memory.

Parameters:
string$idid of message which is deleted

public

Returns:
boolean

Implements IImportChanges.

Definition at line 158 of file changesmemorywrapper.php.

                                               {
        $this->changes[] = array(self::DELETION, $id);
        return true;
    }
ChangesMemoryWrapper::ImportMessageMove ( id,
newfolder 
)

Imports a move of a message.

This occurs when a user moves an item to another folder

Parameters:
string$id
string$newfolderdestination folder

public

Returns:
boolean
Exceptions:
StatusException

Implements IImportChanges.

Definition at line 118 of file changesmemorywrapper.php.

{ return true; }

Imports a change in 'read' flag This can never conflict.

Parameters:
string$id
int$flagspublic
Returns:
boolean
Exceptions:
StatusException

Implements IImportChanges.

Definition at line 117 of file changesmemorywrapper.php.

{ return true; }


IExportChanges & destination importer

Initializes the Exporter where changes are synchronized to

Parameters:
IImportChanges$importerpublic
Returns:
boolean

Implements IExportChanges.

Definition at line 282 of file changesmemorywrapper.php.

                                                   {
        $this->exportImporter = $importer;
        $this->step = 0;
        return true;
    }

Checks if a message id is flagged as changed.

Parameters:
string$idmessage id

public

Returns:
boolean

Definition at line 171 of file changesmemorywrapper.php.

                                   {
        return (array_search(array(self::CHANGE, $id), $this->changes) === false) ? false:true;
    }

Checks if a message id is flagged as deleted.

Parameters:
string$idmessage id

public

Returns:
boolean

Definition at line 183 of file changesmemorywrapper.php.

                                   {
       return (array_search(array(self::DELETION, $id), $this->changes) === false) ? false:true;
    }

Indicates if the cache was changed.

public

Returns:
boolean

Definition at line 68 of file hierarchycache.php.

                                     {
        return $this->changed;
    }
ChangesMemoryWrapper::LoadConflicts ( contentparameters,
state 
)


Methods for to import contents

Loads objects which are expected to be exported with the state Before importing/saving the actual message from the mobile, a conflict detection should be done

Parameters:
ContentParameters$contentparameters
string$statepublic
Returns:
boolean
Exceptions:
StatusException

Implements IImportChanges.

Definition at line 115 of file changesmemorywrapper.php.

{ return true; }


IImportChanges & destination importer

Sets an importer where incoming changes should be sent to

Parameters:
IImportChanges$importermessage to be changed

public

Returns:
boolean

Definition at line 132 of file changesmemorywrapper.php.

                                                       {
        $this->destinationImporter = $importer;
    }

Synchronizes a change.

Only HierarchyChanges will be Synchronized()

public

Returns:
array

Implements IExportChanges.

Definition at line 304 of file changesmemorywrapper.php.

                                  {
        if($this->step < count($this->changes) && isset($this->exportImporter)) {

            $change = $this->changes[$this->step];

            if ($change[0] == self::CHANGE) {
                if (! $this->GetFolder($change[1]->serverid, true))
                    $change[1]->flags = SYNC_NEWMESSAGE;

                $this->exportImporter->ImportFolderChange($change[1]);
            }
            // deletion
            else {
                $this->exportImporter->ImportFolderDeletion($change[1], $change[2]);
            }
            $this->step++;

            // return progress array
            return array("steps" => count($this->changes), "progress" => $this->step);
        }
        else
            return false;
    }

Here is the call graph for this function:


Member Data Documentation

HierarchyCache::$cacheById [protected, inherited]

Definition at line 47 of file hierarchycache.php.

Definition at line 49 of file changesmemorywrapper.php.

Definition at line 51 of file changesmemorywrapper.php.

Definition at line 52 of file changesmemorywrapper.php.

Definition at line 50 of file changesmemorywrapper.php.

Definition at line 46 of file changesmemorywrapper.php.

Definition at line 47 of file changesmemorywrapper.php.


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