Esempio n. 1
0
 public static function start()
 {
     // Create task
     $task = TasksModel::create();
     $task->user_id = $_SESSION['current']['username']['id'];
     $task->user_affected_id = $_SESSION['current']['username']['id'];
     $task->group_id = $_SESSION['current']['username']['group'];
     $task->type = TasksModel::TYPE_BACKUP;
     $task->title = 'Backup Data';
     $task->created_at = date(DATE_TIME);
     $task->estimate = 10 * 60;
     $task->status = TasksModel::STATUS_PROGRESS;
     $task->save();
     // Add services
     if ($_POST['services']) {
         foreach ($_POST['services'] as $serviceId) {
             $serviceId = (int) $serviceId;
             $taskService = TasksServicesModel::create(array('task_id' => $task->id, 'service_id' => $serviceId))->save();
         }
         $task->contains = json_encode(ServicesActionsModel::getActions($_POST['services']));
         $task->save();
     }
     \Util::notice(array('type' => 'success', 'text' => 'The backup process has started. Check the list below to review it\'s status.'));
     $task = new PushTask('/queue/backup/' . $task->id);
     $task->add();
 }
Esempio n. 2
0
 public static function save()
 {
     if (isset($_POST) && isset($_POST['error']) || !isset($_POST['access_token'])) {
         if (isset($_POST['error']) && $_POST['error'] != 'immediate_failed') {
             \Util::notice(array('type' => 'danger', 'text' => 'Sorry, operation failed with the following error: ' . $_POST['error']));
         } else {
             echo json_encode(array('error' => 'immediate_failed'));
         }
     } else {
         $share = SharesModel::first(array('link' => $_POST['task']));
         if ($share) {
             $share = $share->toArray();
             $data = json_decode($share['data'], true);
             if (strtotime($share['created_at']) + $share['expires'] > time()) {
                 $task = TasksModel::first($share['task_id'])->toArray();
                 $service = ServicesModel::first($share['service_id'])->toArray();
                 $source = UsersModel::profile($task['user_id']);
                 $destination['username']['id'] = uniqid();
                 $destination['credentials'] = $_POST;
                 call_user_func_array(array('app\\libraries\\' . $service['library'], 'backup'), array($destination, 0, $task['id']));
                 call_user_func_array(array('app\\libraries\\' . $service['library'], 'migrate'), array($source, $destination, $task['id'], false, $data));
                 \Util::notice(array('type' => 'success', 'text' => 'The data is being imported. Please check your account in a couple of minutes.'));
             } else {
                 \Util::notice(array('type' => 'danger', 'text' => 'The requested link has expired.'));
             }
         }
     }
 }
Esempio n. 3
0
 public static function revert($source, $destination, $syncTaskId = 0, $ignoreUpdate = false)
 {
     $task = TasksModel::first($syncTaskId)->toArray();
     if ($task) {
         $taskType = $task['type'];
         switch ($taskType) {
             case TasksModel::TYPE_MIGRATE:
                 static::_clean($destination, $source, $syncTaskId);
                 static::_cleanDB($syncTaskId);
                 break;
             case TasksModel::TYPE_SYNC:
                 static::_clean($source, $destination, $syncTaskId);
                 static::_clean($destination, $source, $syncTaskId);
                 static::_cleanDB($syncTaskId);
                 break;
             case TasksModel::TYPE_MOVE:
                 static::_transfer($source, $source, $syncTaskId, 'ignoreUpdate');
                 static::_clean($destination, $source, $syncTaskId);
                 static::_cleanDB($syncTaskId);
                 break;
             case TasksModel::TYPE_CLEAN:
                 $share = SharesModel::first(array('task_id' => $syncTaskId));
                 if ($share) {
                     $share = $share->toArray();
                     $data = json_decode($share['data'], true);
                     static::_transfer($source, $source, $syncTaskId, 'ignoreUpdate', $data);
                 }
                 break;
         }
     }
     return array();
 }
Esempio n. 4
0
 public static function notifications()
 {
     $count = 0;
     if (isset($_SESSION['current'])) {
         $count = count(TasksModel::listingFor(array('user_id' => $_SESSION['current']['username']['id'], 'user_affected_id' => $_SESSION['current']['username']['id'], 'status' => array(TasksModel::STATUS_FINISHED, TasksModel::STATUS_REVERTED), 'viewed' => '0')));
     }
     echo $count;
 }
Esempio n. 5
0
 public static function details($accountKey = false)
 {
     if ($accountKey) {
         $account = $_SESSION['usernames'][$accountKey];
     } else {
         $account = $_SESSION['current'];
     }
     $templateData = array('template' => 'accounts/details', 'title' => 'Migrate - Account details', 'bodyId' => 'accounts-details', 'styles' => array('accounts.css'), 'scripts' => array('accounts.js'), 'account' => $account, 'services' => ServicesModel::withPermissions(), 'selectedServices' => UsersServicesModel::all(array('user_id' => $account['username']['id']))->column('service_id'), 'tasks' => TasksModel::listingFor(array('user_id' => $account['username']['id'], 'user_affected_id' => $account['username']['id'])), 'intro' => (bool) IntroModel::first(array('page' => 'profile', 'group' => $_SESSION['current']['username']['group'])));
     if (!$templateData['intro']) {
         IntroModel::create(array('page' => 'profile', 'group' => $_SESSION['current']['username']['group']))->save();
     }
     \Render::layout('template', $templateData);
 }
Esempio n. 6
0
 /**
  * Dashboard index page
  */
 public static function index($finish = false)
 {
     if ($finish) {
         \Auth::showWizard('finish');
     } else {
         if (\Auth::showWizard()) {
             \Router::redirect('accounts/permissions');
         }
     }
     $templateData = array('template' => 'dashboard/content', 'title' => 'Migrate - Dashboard', 'bodyId' => 'dashboard', 'styles' => array('dashboard.css'), 'scripts' => array(), 'queue' => TasksModel::listingFor(array('user_id' => $_SESSION['current']['username']['id'], 'user_affected_id' => $_SESSION['current']['username']['id']), 4), 'services' => ServicesModel::forUser(array('id' => $_SESSION['current']['username']['id'], 'limit' => 4)), 'usernames' => $_SESSION['usernames'], 'intro' => (bool) IntroModel::first(array('page' => 'dashboard', 'group' => $_SESSION['current']['username']['group'])));
     if (!$templateData['intro']) {
         IntroModel::create(array('page' => 'dashboard', 'group' => $_SESSION['current']['username']['group']))->save();
     }
     \Render::layout('template', $templateData);
 }
Esempio n. 7
0
 public static function detail()
 {
     $taskId = (int) $_POST['id'];
     $task = TasksModel::details($taskId);
     if ($task['services']) {
         foreach ($task['services'] as $service) {
             if ($service['id'] == $_POST['type']) {
                 $_service = $service;
             }
         }
     }
     // Migrated Data
     $migratedData = array();
     $share = SharesModel::first(array('task_id' => $task['id']));
     if ($share) {
         $share = $share->toArray();
         $migratedData = json_decode($share['data'], true);
         $service = ServicesModel::first($share['service_id'])->toArray();
         $backups = call_user_func_array(array('app\\libraries\\' . $service['library'], 'shared'), array($task));
     }
     echo \Render::view('clean/details/' . strtolower($_service['name']), array('task' => $task, 'service' => $_service, 'migratedData' => $migratedData, 'data' => $backups), 'return');
 }
Esempio n. 8
0
 public static function add($taskId = 0, $revert = false)
 {
     $taskId = (int) $taskId;
     if ($taskId) {
         $start = microtime(true);
         $task = TasksModel::details($taskId);
         // Settings
         $settings = array('initialStatus' => TasksModel::STATUS_SCHEDULED, 'startStatus' => TasksModel::STATUS_PROGRESS, 'finishStatus' => TasksModel::STATUS_FINISHED, 'source' => true, 'sourceBackup' => true, 'destination' => true, 'destinationBackup' => true, 'action' => true, 'actionType' => TasksModel::TYPE_BACKUP);
         if ($task && $task['services']) {
             switch ($task['type']) {
                 case TasksModel::TYPE_BACKUP:
                     $settings['destination'] = false;
                     $settings['action'] = false;
                     break;
                 case TasksModel::TYPE_MIGRATE:
                 case TasksModel::TYPE_SYNC:
                 case TasksModel::TYPE_MOVE:
                     $settings['actionType'] = $task['type'];
                     if ($revert) {
                         $settings['initialStatus'] = TasksModel::STATUS_FINISHED;
                         $settings['startStatus'] = TasksModel::STATUS_REVERTING;
                         $settings['finishStatus'] = TasksModel::STATUS_REVERTED;
                         $settings['sourceBackup'] = false;
                         $settings['destinationBackup'] = false;
                         $settings['actionType'] = TasksModel::TYPE_REVERT;
                     }
                     break;
                 case TasksModel::TYPE_SHARE:
                     $settings['destination'] = false;
                     $settings['action'] = false;
                     break;
                 case TasksModel::TYPE_CLEAN:
                     $settings['destination'] = false;
                     $settings['actionType'] = TasksModel::TYPE_CLEAN;
                     if ($revert) {
                         $settings['initialStatus'] = TasksModel::STATUS_FINISHED;
                         $settings['startStatus'] = TasksModel::STATUS_REVERTING;
                         $settings['finishStatus'] = TasksModel::STATUS_REVERTED;
                         $settings['sourceBackup'] = false;
                         $settings['destinationBackup'] = false;
                         $settings['actionType'] = TasksModel::TYPE_REVERT;
                     }
                     break;
             }
             if ($task['status'] == $settings['initialStatus']) {
                 // Start the task
                 $dbTask = TasksModel::first($taskId);
                 $dbTask->started_at = date(DATE_TIME);
                 $dbTask->status = $settings['startStatus'];
                 $dbTask->save();
                 $source = array();
                 if ($settings['source']) {
                     $source = UsersModel::profile($task['user_id']);
                     $source['credentials'] = \Auth::oAuthRefreshToken($source, 'updateSession', 'force');
                 }
                 $destination = array();
                 if ($settings['destination']) {
                     $destination = UsersModel::profile($task['user_affected_id']);
                     $destination['credentials'] = \Auth::oAuthRefreshToken($destination, 'updateSession', 'force');
                 }
                 // Call services
                 foreach ($task['services'] as $service) {
                     $stats = array();
                     // Save source data
                     if ($settings['source'] && $settings['sourceBackup']) {
                         $stats = call_user_func_array(array('app\\libraries\\' . $service['library'], 'backup'), array($source, 0, $taskId));
                     }
                     // Save destination data
                     if ($settings['destination'] && $settings['destinationBackup']) {
                         $stats = call_user_func_array(array('app\\libraries\\' . $service['library'], 'backup'), array($destination, 0, $taskId));
                     }
                     // Copy source to destination
                     if ($settings['action'] && $settings['actionType']) {
                         $stats = call_user_func_array(array('app\\libraries\\' . $service['library'], $settings['actionType']), array($source, $destination, $taskId, false));
                     }
                     // Update task service
                     $taskService = TasksServicesModel::first(array('task_id' => $task['id'], 'service_id' => $service['id']));
                     if ($settings['actionType'] != TasksModel::TYPE_REVERT) {
                         $taskService->stats = json_encode($stats);
                         $taskService->save();
                     }
                 }
                 // Finish Task
                 $dbTask->finished_at = date(DATE_TIME, time());
                 $dbTask->duration = microtime(true) - $start;
                 $dbTask->status = $settings['finishStatus'];
                 $dbTask->save();
             }
         }
     }
 }
Esempio n. 9
0
 public static function start()
 {
     // Create task
     $task = TasksModel::create();
     $task->user_id = $_SESSION['wizard']['source']['username']['id'];
     $task->user_affected_id = $_SESSION['wizard']['destination']['username']['id'];
     $task->group_id = $_SESSION['current']['username']['group'];
     $task->type = \Util::action(false, $_SESSION['wizard']['action']);
     $task->title = ucfirst(\Util::action()) . ' Data';
     $task->created_at = date(DATE_TIME);
     $task->estimate = 10 * 60;
     $task->save();
     // Add services
     if ($_SESSION['wizard']['services']) {
         foreach ($_SESSION['wizard']['services'] as $serviceId => $service) {
             $serviceId = (int) $serviceId;
             TasksServicesModel::create(array('task_id' => $task->id, 'service_id' => $serviceId))->save();
         }
         $task->contains = json_encode(ServicesActionsModel::getActions($_POST['services']));
         $task->save();
     }
     // Reset wizard
     unset($_SESSION['wizard']);
     $task = new PushTask('/queue/add/' . $task->id);
     $task->add();
     // Notification
     \Util::notice(array('type' => 'success', 'text' => 'Your ' . \Util::action('termination') . ' process has started. Check the list below to see it\'s status.'));
 }