function doUpdatesProcess()
 {
     $errors = array();
     // do the queued items by table order
     foreach (self::$compareTypes as $tableType) {
         $set = SyncSetFactory::create($tableType, SyncCompare::getDesktopConnectionParams($tableType, $this->desktopFilePath), $this->desktopFileId);
         $list = $this->syncLog->pendingList($tableType);
         foreach ($list as $logData) {
             try {
                 if (!$logData->is_skipped and !$logData->timestamp_completed) {
                     switch ($logData->action) {
                         case 'insert':
                         case 'update':
                         case 'update-conflict':
                             //verify any referenced items that we're not inserting already exist
                             $set->verifyFKs($logData->left_id, $this->syncLog);
                             break;
                     }
                 }
                 //$this->syncLog->markDone($logData->id);
             } catch (Exception $e) {
                 $this->syncLog->add(array($e->getMessage(), $tableType, $logData->left_id, '?', $logData));
                 $errors[] = print_r($e, true);
             }
         }
     }
     if ($errors) {
         return $errors;
     }
     // do the queued items by table order
     foreach (self::$compareTypes as $tableType) {
         $set = SyncSetFactory::create($tableType, SyncCompare::getDesktopConnectionParams($tableType, $this->desktopFilePath), $this->desktopFileId);
         $list = $this->syncLog->pendingList($tableType);
         foreach ($list as $logData) {
             try {
                 if (!$logData->is_skipped and !$logData->timestamp_completed) {
                     switch ($logData->action) {
                         case 'insert':
                             $set->insertMember($logData->left_id);
                             break;
                         case 'update':
                         case 'update-conflict':
                             $set->updateMember($logData->left_id, $logData->right_id);
                             break;
                         case 'delete':
                             $set->deleteMember($logData->right_id);
                             break;
                         case 'add-alias':
                             $set->addAliasMember($logData->left_id, $logData->right_id);
                             break;
                     }
                 }
                 $this->syncLog->markDone($logData->id);
             } catch (Exception $e) {
                 $errors[] = print_r($e, true);
             }
         }
     }
     // mark job as done
     $time = $this->syncFile->now_expr();
     $this->syncFile->update(array('timestamp_completed' => $time), '(id="' . $this->desktopFileId . '")');
     return $errors;
 }
function test($filename)
{
    $db = SyncCompare::getDesktopConnectionParams('_app', Globals::$BASE_PATH . 'app/controllers/sync/test_dbs/' . $filename);
    $_app = new ITechTable($db);
    $_app = $_app->fetchAll()->current();
    $previous_files = new SyncFile();
    $previous = $previous_files->getAdapter()->query("SELECT * FROM syncfile WHERE application_id = '" . $_app->app_id . "' AND timestamp_completed IS NOT NULL ORDER BY timestamp_completed DESC LIMIT 1");
    $previous_timestamp = $_app->init_timestamp;
    //first time
    if ($previous) {
        $previous = $previous->fetchAll();
        if ($previous) {
            $previous_timestamp = $previous[0]['timestamp_completed'];
        }
    }
    $save = array('filename' => $filename, 'filepath' => Globals::$BASE_PATH . 'app/controllers/sync/test_dbs/', 'application_id' => $_app->app_id, 'application_version' => $_app->app_id, 'timestamp_last_sync' => $previous_timestamp);
    // dest info
    $syncFile = new SyncFile();
    $fid = $syncFile->insert($save);
    try {
        $syncCompare = new SyncCompare($fid);
        echo "sanity check\n";
        $msg = $syncCompare->sanityCheck();
        if (!$msg) {
            echo "find diffs\n";
            $has_errors = $syncCompare->findDifferencesProcess();
            $syncLog = new SyncLog($fid);
            $totals = $syncLog->pendingTotals();
            foreach ($totals as $tot) {
                echo $tot['item_type'] . '::' . $tot['action'] . '::' . $tot['cnt'] . "\n";
            }
            $pendingList = $syncLog->pendingList();
            //var_dump($pendingList);
            //insert
            var_dump($syncCompare->doUpdatesProcess());
            echo "verifying \n";
            //look for inserted values
            foreach ($pendingList as $p) {
                if ($p->action == 'insert') {
                    $set = SyncSetFactory::create($p->item_type, $db, $fid);
                    if ($p->left_id) {
                        $lo = $set->fetchLeftItemById($p->left_id);
                        if ($p->item_type != 'trainer') {
                            $ro = $set->fetchFieldMatch($lo);
                        } else {
                            $ro = $set->fetchRightItemByUuid($lo->uuid);
                        }
                        if (!$ro) {
                            echo $p->item_type . ' not found: ' . $p->left_id . "\n";
                        }
                    }
                }
            }
        } else {
            $has_errors = $msg;
        }
    } catch (Exception $e) {
        $has_errors = $e->getMessage();
    }
    try {
        if (!$msg) {
            echo "find diffs\n";
            //$has_errors = $syncCompare->findDifferencesProcess();
        } else {
            $has_errors = $msg;
        }
    } catch (Exception $e) {
        $has_errors = $e->getMessage();
    }
    var_dump($has_errors);
}