Back to index

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

List of all members.

Public Member Functions

 ExportChangesDiff ($backend, $folderid)
 Constructor.
 ConfigContentParameters ($contentparameters)
 Configures additional parameters used for content synchronization.
 InitializeExporter (&$importer)
 Sets the importer the exporter will sent it's changes to and initializes the Exporter.
 GetChangeCount ()
 Returns the amount of changes to be exported.
 Synchronize ()
 Synchronizes a change.
 Config ($state, $flags=0)
 Initializes the state.
 GetState ()
 Returns state.

Static Public Member Functions

static RowCmp ($a, $b)
 
DiffState specific stuff

Protected Member Functions

 getDiffTo ($new)
 Differential mechanism Compares the current syncstate to the sent $new.
 updateState ($type, $change)
 Update the state to reflect changes.
 isConflict ($type, $folderid, $id)
 Returns TRUE if the given ID conflicts with the given operation.

Protected Attributes

 $syncstate
 $backend
 $flags

Private Attributes

 $importer
 $folderid
 $contentparameters
 $cutoffdate
 $changes
 $step

Detailed Description

Definition at line 45 of file exportchangesdiff.php.


Member Function Documentation

DiffState::Config ( state,
flags = 0 
) [inherited]

Initializes the state.

Parameters:
string$state
int$flagspublic
Returns:
boolean status flag
Exceptions:
StatusException

Implements IChanges.

Definition at line 66 of file diffstate.php.

                                               {
        if ($state == "")
            $state = array();

        if (!is_array($state))
            throw new StatusException("Invalid state", SYNC_FSSTATUS_CODEUNKNOWN);

        $this->syncstate = $state;
        $this->flags = $flags;
        return true;
    }

Configures additional parameters used for content synchronization.

Parameters:
ContentParameters$contentparameterspublic
Returns:
boolean
Exceptions:
StatusException

Implements IExportChanges.

Definition at line 76 of file exportchangesdiff.php.

                                                                {
        $this->contentparameters = $contentparameters;
        $this->cutoffdate = Utils::GetCutOffDate($contentparameters->GetFilterType());
    }

Here is the call graph for this function:

ExportChangesDiff::ExportChangesDiff ( backend,
folderid 
)

Constructor.

Parameters:
object$backend
string$folderidpublic
Exceptions:
StatusException

Definition at line 62 of file exportchangesdiff.php.

                                                           {
        $this->backend = $backend;
        $this->folderid = $folderid;
    }

Returns the amount of changes to be exported.

public

Returns:
int

Implements IExportChanges.

Definition at line 138 of file exportchangesdiff.php.

                                     {
        return count($this->changes);
    }
DiffState::getDiffTo ( new) [protected, inherited]

Differential mechanism Compares the current syncstate to the sent $new.

Parameters:
array$newprotected
Returns:
array

Definition at line 120 of file diffstate.php.

                                       {
        $changes = array();

        // Sort both arrays in the same way by ID
        usort($this->syncstate, array("DiffState", "RowCmp"));
        usort($new, array("DiffState", "RowCmp"));

        $inew = 0;
        $iold = 0;

        // Get changes by comparing our list of messages with
        // our previous state
        while(1) {
            $change = array();

            if($iold >= count($this->syncstate) || $inew >= count($new))
                break;

            if($this->syncstate[$iold]["id"] == $new[$inew]["id"]) {
                // Both messages are still available, compare flags and mod
                if(isset($this->syncstate[$iold]["flags"]) && isset($new[$inew]["flags"]) && $this->syncstate[$iold]["flags"] != $new[$inew]["flags"]) {
                    // Flags changed
                    $change["type"] = "flags";
                    $change["id"] = $new[$inew]["id"];
                    $change["flags"] = $new[$inew]["flags"];
                    $changes[] = $change;
                }

                if($this->syncstate[$iold]["mod"] != $new[$inew]["mod"]) {
                    $change["type"] = "change";
                    $change["id"] = $new[$inew]["id"];
                    $changes[] = $change;
                }

                $inew++;
                $iold++;
            } else {
                if($this->syncstate[$iold]["id"] > $new[$inew]["id"]) {
                    // Message in state seems to have disappeared (delete)
                    $change["type"] = "delete";
                    $change["id"] = $this->syncstate[$iold]["id"];
                    $changes[] = $change;
                    $iold++;
                } else {
                    // Message in new seems to be new (add)
                    $change["type"] = "change";
                    $change["flags"] = SYNC_NEWMESSAGE;
                    $change["id"] = $new[$inew]["id"];
                    $changes[] = $change;
                    $inew++;
                }
            }
        }

        while($iold < count($this->syncstate)) {
            // All data left in 'syncstate' have been deleted
            $change["type"] = "delete";
            $change["id"] = $this->syncstate[$iold]["id"];
            $changes[] = $change;
            $iold++;
        }

        while($inew < count($new)) {
            // All data left in new have been added
            $change["type"] = "change";
            $change["flags"] = SYNC_NEWMESSAGE;
            $change["id"] = $new[$inew]["id"];
            $changes[] = $change;
            $inew++;
        }

        return $changes;
    }

Here is the caller graph for this function:

DiffState::GetState ( ) [inherited]

Returns state.

public

Returns:
string
Exceptions:
StatusException

Implements IChanges.

Definition at line 85 of file diffstate.php.

                               {
        if (!isset($this->syncstate) || !is_array($this->syncstate))
            throw new StatusException("DiffState->GetState(): Error, state not available", SYNC_FSSTATUS_CODEUNKNOWN, null, LOGLEVEL_WARN);

        return $this->syncstate;
    }

Sets the importer the exporter will sent it's changes to and initializes the Exporter.

Parameters:
object&$importerImplementation of IImportChanges

public

Returns:
boolean
Exceptions:
StatusException

Implements IExportChanges.

Definition at line 91 of file exportchangesdiff.php.

                                                   {
        $this->changes = array();
        $this->step = 0;
        $this->importer = $importer;

        if($this->folderid) {
            // Get the changes since the last sync
            if(!isset($this->syncstate) || !$this->syncstate)
                $this->syncstate = array();

            ZLog::Write(LOGLEVEL_DEBUG,sprintf("ExportChangesDiff->InitializeExporter(): Initializing message diff engine. '%d' messages in state", count($this->syncstate)));

            //do nothing if it is a dummy folder
            if ($this->folderid != SYNC_FOLDER_TYPE_DUMMY) {
                // Get our lists - syncstate (old)  and msglist (new)
                $msglist = $this->backend->GetMessageList($this->folderid, $this->cutoffdate);
                // if the folder was deleted, no information is available anymore. A hierarchysync should be executed
                if($msglist === false)
                    throw new StatusException("ExportChangesDiff->InitializeExporter(): Error, no message list available from the backend", SYNC_STATUS_FOLDERHIERARCHYCHANGED, null, LOGLEVEL_INFO);

                $this->changes = $this->getDiffTo($msglist);
            }
        }
        else {
            ZLog::Write(LOGLEVEL_DEBUG, "Initializing folder diff engine");

            ZLog::Write(LOGLEVEL_DEBUG, "ExportChangesDiff->InitializeExporter(): Initializing folder diff engine");

            $folderlist = $this->backend->GetFolderList();
            if($folderlist === false)
                throw new StatusException("ExportChangesDiff->InitializeExporter(): error, no folders available from the backend", SYNC_FSSTATUS_CODEUNKNOWN, null, LOGLEVEL_WARN);

            if(!isset($this->syncstate) || !$this->syncstate)
                $this->syncstate = array();

            $this->changes = $this->getDiffTo($folderlist);
        }

        ZLog::Write(LOGLEVEL_INFO, sprintf("ExportChangesDiff->InitializeExporter(): Found '%d' changes", count($this->changes) ));
    }

Here is the call graph for this function:

DiffState::isConflict ( type,
folderid,
id 
) [protected, inherited]

Returns TRUE if the given ID conflicts with the given operation.

This is only true in the following situations:

  • Changed here and changed there
  • Changed here and deleted there
  • Deleted here and changed there Any other combination of operations can be done (e.g. change flags & move or move & delete)
Parameters:
string$typeof change
string$folderid
string$idprotected
Returns:

Definition at line 246 of file diffstate.php.

                                                         {
        $stat = $this->backend->StatMessage($folderid, $id);

        if(!$stat) {
            // Message is gone
            if($type == "change")
                return true; // deleted here, but changed there
            else
                return false; // all other remote changes still result in a delete (no conflict)
        }

        foreach($this->syncstate as $state) {
            if($state["id"] == $id) {
                $oldstat = $state;
                break;
            }
        }

        if(!isset($oldstat)) {
            // New message, can never conflict
            return false;
        }

        if($stat["mod"] != $oldstat["mod"]) {
            // Changed here
            if($type == "delete" || $type == "change")
                return true; // changed here, but deleted there -> conflict, or changed here and changed there -> conflict
            else
                return false; // changed here, and other remote changes (move or flags)
        }
    }

Here is the caller graph for this function:

static DiffState::RowCmp ( a,
b 
) [static, inherited]


DiffState specific stuff

Comparing function used for sorting of the differential engine

Parameters:
array$a
array$bpublic
Returns:
boolean

Definition at line 106 of file diffstate.php.

                                          {
        // TODO implement different comparing functions
        return $a["id"] < $b["id"] ? 1 : -1;
    }

Synchronizes a change.

public

Returns:
array

Implements IExportChanges.

Definition at line 148 of file exportchangesdiff.php.

                                  {
        $progress = array();

        // Get one of our stored changes and send it to the importer, store the new state if
        // it succeeds
        if($this->folderid == false) {
            if($this->step < count($this->changes)) {
                $change = $this->changes[$this->step];

                switch($change["type"]) {
                    case "change":
                        $folder = $this->backend->GetFolder($change["id"]);
                        $stat = $this->backend->StatFolder($change["id"]);

                        if(!$folder)
                            return;

                        if($this->flags & BACKEND_DISCARD_DATA || $this->importer->ImportFolderChange($folder))
                            $this->updateState("change", $stat);
                        break;
                    case "delete":
                        if($this->flags & BACKEND_DISCARD_DATA || $this->importer->ImportFolderDeletion($change["id"]))
                            $this->updateState("delete", $change);
                        break;
                }

                $this->step++;

                $progress = array();
                $progress["steps"] = count($this->changes);
                $progress["progress"] = $this->step;

                return $progress;
            } else {
                return false;
            }
        }
        else {
            if($this->step < count($this->changes)) {
                $change = $this->changes[$this->step];

                switch($change["type"]) {
                    case "change":
                        // Note: because 'parseMessage' and 'statMessage' are two seperate
                        // calls, we have a chance that the message has changed between both
                        // calls. This may cause our algorithm to 'double see' changes.

                        $stat = $this->backend->StatMessage($this->folderid, $change["id"]);
                        $message = $this->backend->GetMessage($this->folderid, $change["id"], $this->contentparameters);

                        // copy the flag to the message
                        $message->flags = (isset($change["flags"])) ? $change["flags"] : 0;

                        if($stat && $message) {
                            if($this->flags & BACKEND_DISCARD_DATA || $this->importer->ImportMessageChange($change["id"], $message) == true)
                                $this->updateState("change", $stat);
                        }
                        break;
                    case "delete":
                        if($this->flags & BACKEND_DISCARD_DATA || $this->importer->ImportMessageDeletion($change["id"]) == true)
                            $this->updateState("delete", $change);
                        break;
                    case "flags":
                        if($this->flags & BACKEND_DISCARD_DATA || $this->importer->ImportMessageReadFlag($change["id"], $change["flags"]) == true)
                            $this->updateState("flags", $change);
                        break;
                    case "move":
                        if($this->flags & BACKEND_DISCARD_DATA || $this->importer->ImportMessageMove($change["id"], $change["parent"]) == true)
                            $this->updateState("move", $change);
                        break;
                }

                $this->step++;

                $progress = array();
                $progress["steps"] = count($this->changes);
                $progress["progress"] = $this->step;

                return $progress;
            } else {
                return false;
            }
        }
    }

Here is the call graph for this function:

DiffState::updateState ( type,
change 
) [protected, inherited]

Update the state to reflect changes.

Parameters:
string$typeof change
array$changeprotected
Returns:

Definition at line 204 of file diffstate.php.

                                                   {
        // Change can be a change or an add
        if($type == "change") {
            for($i=0; $i < count($this->syncstate); $i++) {
                if($this->syncstate[$i]["id"] == $change["id"]) {
                    $this->syncstate[$i] = $change;
                    return;
                }
            }
            // Not found, add as new
            $this->syncstate[] = $change;
        } else {
            for($i=0; $i < count($this->syncstate); $i++) {
                // Search for the entry for this item
                if($this->syncstate[$i]["id"] == $change["id"]) {
                    if($type == "flags") {
                        // Update flags
                        $this->syncstate[$i]["flags"] = $change["flags"];
                    } else if($type == "delete") {
                        // Delete item
                        array_splice($this->syncstate, $i, 1);
                    }
                    return;
                }
            }
        }
    }

Here is the caller graph for this function:


Member Data Documentation

DiffState::$backend [protected, inherited]

Definition at line 53 of file diffstate.php.

Definition at line 50 of file exportchangesdiff.php.

Definition at line 48 of file exportchangesdiff.php.

Definition at line 49 of file exportchangesdiff.php.

DiffState::$flags [protected, inherited]

Definition at line 54 of file diffstate.php.

Definition at line 47 of file exportchangesdiff.php.

Definition at line 46 of file exportchangesdiff.php.

Definition at line 51 of file exportchangesdiff.php.

DiffState::$syncstate [protected, inherited]

Definition at line 52 of file diffstate.php.


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