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.')); } } } }
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(); }
public static function clean($source, $destination, $syncTaskId = 0, $ignoreUpdate = false) { $share = SharesModel::first(array('task_id' => $syncTaskId)); if ($share) { $share = $share->toArray(); $data = json_decode($share['data'], true); static::_clean($source, $source, $syncTaskId, $data); } }
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'); }