function findDifferencesProcess() { $errors = array(); $this->syncLog->truncate(); // delete unfinished items for db file foreach (self::$compareTypes as $tableType) { $set = SyncSetFactory::create($tableType, SyncCompare::getDesktopConnectionParams($tableType, $this->desktopFilePath), $this->desktopFileId); if ($set) { $leftItems = $set->fetchLeftPool(); //desktop db $meta_done = false; $pk = 'id'; foreach ($leftItems as $ld) { $rItem = $actions = array(); try { $ldata = null; $rdata = null; if (!$meta_done) { $has_uuid = $ld->getTable()->has_uuid_col(); $meta_done = true; $pk = $ld->getTable()->PK(); } $userMessage = ''; if ($has_uuid && $ld->uuid) { $rItem = $set->fetchRightItemByUuid($ld->uuid); } if ($rItem) { //exact uuid match on item if ($set->isDirty($ld, $rItem)) { if ($set->isConflict($ld, $rItem)) { // true if conflict $userMessage = 'Update (with conflict)'; $actions[] = 'update-conflict'; $ldata = $ld->toArray(); $rdata = $rItem->toArray(); } else { $userMessage = 'Update'; $actions[] = 'update'; } } } else { //no exact uuid match on item, look for field level match $rItem = $set->fetchFieldMatch($ld); if ($rItem) { if ($set->usesAlias()) { $actions[] = 'add-alias'; } if ($set->isDirty($ld, $rItem)) { if ($set->isConflict($ld, $rItem)) { $userMessage = "Update (with conflict)"; $actions[] = 'update-conflict'; $ldata = $ld->toArray(); $rdata = $rItem->toArray(); } else { $userMessage = 'Update'; $actions[] = 'update'; } } } else { //no right match //do we insert deleted rows? no $has_soft_delete = $ld->getTable()->has_is_deleted_col(); if (!$has_soft_delete or $has_soft_delete && !$ld->is_deleted) { $actions[] = 'insert'; $rItem = new stdClass(); $rItem->uuid = null; $rItem->{$pk} = null; $userMessage = 'New item'; } } } if ((!$actions or $actions[0] != 'insert') && $rItem && $rItem->getTable()->has_is_deleted_col()) { if ($rItem->is_deleted && $ld->is_deleted || $ld->is_deleted && $set->isReferenced($rItem)) { //if they're both deleted then skip $actions = array(); //skip } else { if ($ld->is_deleted) { $actions = array('delete'); } } } //$this->syncLog->add($tableType, $ld->uuid, $rItem->uuid, null, null); // log no-action. for counts foreach ($actions as $action) { $this->syncLog->add($tableType, $ld->{$pk}, $rItem->{$pk}, $action, $userMessage, $ldata, $rdata); } } catch (Exception $e) { $this->syncLog->add(array($e->getMessage(), $tableType, $ld->{$pk}, $rItem->{$pk}, @$actions[0])); $errors[] = print_r($e->getMessage(), true); } } try { $deletables = $set->fetchHardDeletes(); if ($deletables) { foreach ($deletables as $d) { $pk = $d->getTable()->PK(); $this->syncLog->add($tableType, null, $d->{$pk}, 'delete'); } } } catch (Exception $e) { $this->syncLog->add($tableType, null, null, 'error'); $errors[] = print_r($e->getMessage(), true); } } $this->syncLog->addTableCompleteMessage($tableType); } return $errors; }