/**
  * Execute the migration.
  *
  * @access public
  * @return true
  */
 public function DoMigration()
 {
     print "StateMigratorFileToDB->DoMigration(): Starting migration routine." . PHP_EOL;
     $starttime = time();
     $deviceCount = 0;
     $stateCount = 0;
     try {
         // Fix hierarchy folder data before starting the migration
         ZPushAdmin::FixStatesHierarchyFolderData();
         $this->fsm = new FileStateMachine();
         if (!$this->fsm instanceof FileStateMachine) {
             throw new FatalNotImplementedException("This conversion script is only able to convert states from the FileStateMachine");
         }
         // get all state information for all devices
         $alldevices = $this->fsm->GetAllDevices(false);
         foreach ($alldevices as $devid) {
             $deviceCount++;
             $lowerDevid = strtolower($devid);
             $allStates = $this->fsm->GetAllStatesForDevice($lowerDevid);
             printf("Processing device: %s with %s states\t", str_pad($devid, 35), str_pad(count($allStates), 4, ' ', STR_PAD_LEFT));
             $migrated = 0;
             foreach ($allStates as $stateInfo) {
                 ZLog::Write(LOGLEVEL_DEBUG, sprintf("StateMigratorFileToDB->DoMigration(): Migrating state type:'%s' uuid:'%s' counter:'%s'", Utils::PrintAsString($stateInfo['type']), Utils::PrintAsString($stateInfo['uuid']), Utils::PrintAsString($stateInfo['counter'])));
                 $state = $this->fsm->GetState($lowerDevid, $stateInfo['type'], $stateInfo['uuid'], (int) $stateInfo['counter'], false);
                 $this->dbsm->SetState($state, $lowerDevid, $stateInfo['type'], empty($stateInfo['uuid']) ? NULL : $stateInfo['uuid'], (int) $stateInfo['counter']);
                 $migrated++;
             }
             // link devices to users
             $devState = $this->fsm->GetState($lowerDevid, IStateMachine::DEVICEDATA);
             foreach ($devState->devices as $user => $dev) {
                 $this->dbsm->LinkUserDevice($user, $dev->deviceid);
             }
             print " completed migration of {$migrated} states" . PHP_EOL;
             $stateCount += $migrated;
         }
     } catch (ZPushException $ex) {
         print PHP_EOL . "Something went wrong during the migration. The script will now exit." . PHP_EOL;
         die(get_class($ex) . ": " . $ex->getMessage() . PHP_EOL);
     }
     $timeSpent = gmdate("H:i:s", time() - $starttime);
     printf(PHP_EOL . "StateMigratorFileToDB->DoMigration(): Migration completed successfuly. Migrated %d devices with %d states in %s." . PHP_EOL . PHP_EOL, $deviceCount, $stateCount, $timeSpent);
 }
Beispiel #2
0
 /**
  * Fixes the states for potential issues
  *
  * @return
  * @access private
  */
 private static function CommandFixStates()
 {
     echo "Validating and fixing states (this can take some time):\n";
     echo "\tChecking username casings: ";
     if ($stat = ZPushAdmin::FixStatesDifferentUsernameCases()) {
         printf("Processed: %d - Converted: %d - Removed: %d\n", $stat[0], $stat[1], $stat[2]);
     } else {
         echo ZLog::GetLastMessage(LOGLEVEL_ERROR) . "\n";
     }
     // fixes ZP-339
     echo "\tChecking available devicedata & user linking: ";
     if ($stat = ZPushAdmin::FixStatesDeviceToUserLinking()) {
         printf("Processed: %d - Fixed: %d\n", $stat[0], $stat[1]);
     } else {
         echo ZLog::GetLastMessage(LOGLEVEL_ERROR) . "\n";
     }
     echo "\tChecking for unreferenced (obsolete) state files: ";
     if (($stat = ZPushAdmin::FixStatesUserToStatesLinking()) !== false) {
         printf("Processed: %d - Deleted: %d\n", $stat[0], $stat[1]);
     } else {
         echo ZLog::GetLastMessage(LOGLEVEL_ERROR) . "\n";
     }
     echo "\tChecking for hierarchy folder data state: ";
     if (($stat = ZPushAdmin::FixStatesHierarchyFolderData()) !== false) {
         printf("Devices: %d - Processed: %d - Fixed: %d - Device+User without hierarchy: %d\n", $stat[0], $stat[1], $stat[2], $stat[3]);
     } else {
         echo ZLog::GetLastMessage(LOGLEVEL_ERROR) . "\n";
     }
     echo "\tChecking flags of shared folders: ";
     if (($stat = ZPushAdmin::FixStatesAdditionalFolderFlags()) !== false) {
         printf("Devices: %d - Devices with additional folders: %d - Fixed: %d\n", $stat[0], $stat[1], $stat[2]);
     } else {
         echo ZLog::GetLastMessage(LOGLEVEL_ERROR) . "\n";
     }
 }