Exemple #1
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.'));
             }
         }
     }
 }
Exemple #2
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();
 }
Exemple #3
0
 public static function listingFor($conditions = array(), $limit = false)
 {
     $query = "\n\t\t\t\tSELECT\n\t\t\t\t\tTasks.*,\n\t\t\t\t\tSource.email as source_email,\n\t\t\t\t\tSourceProfile.avatar as source_avatar,\n\t\t\t\t\tDestination.email as destination_email,\n\t\t\t\t\tDestinationProfile.avatar as destination_avatar\n\t\t\t\tFROM\n\t\t\t\t\ttasks Tasks\n\t\t\t\t\tLEFT JOIN users Source\n\t\t\t\t\t       ON Source.id = Tasks.user_id\n\t\t\t\t\tLEFT JOIN users_profiles SourceProfile\n\t\t\t\t\t \t   ON SourceProfile.user_id = Source.id\n\t\t\t\t    LEFT JOIN users Destination\n\t\t\t\t\t       ON Destination.id = Tasks.user_affected_id\n\t\t\t\t\tLEFT JOIN users_profiles DestinationProfile\n\t\t\t\t\t \t   ON DestinationProfile.user_id = Destination.id\n\t\t\t\tWHERE";
     if (isset($conditions['type'])) {
         if (is_array($conditions['type'])) {
             $query .= "(";
             foreach ($conditions['type'] as $type) {
                 $query .= " Tasks.type = '" . $type . "' OR ";
             }
             $query = substr($query, 0, -4) . ") AND";
         } else {
             $query .= " Tasks.type = '" . $conditions['type'] . "' AND ";
         }
     }
     if (isset($conditions['status'])) {
         if (is_array($conditions['status'])) {
             $query .= "(";
             foreach ($conditions['status'] as $stat) {
                 $query .= " Tasks.status = '" . $stat . "' OR ";
             }
             $query = substr($query, 0, -4) . ") AND";
         } else {
             $query .= " Tasks.status = '" . $conditions['status'] . "' AND ";
         }
     }
     if (isset($conditions['viewed'])) {
         $query .= " Tasks.viewed = '" . $conditions['viewed'] . "' AND ";
     }
     if (isset($conditions['group_id'])) {
         $query .= "( Tasks.group_id = '" . $conditions['group_id'] . "'";
     } else {
         $query .= "( Tasks.user_id = " . $conditions['user_id'];
         if (isset($conditions['user_affected_id'])) {
             $query .= " OR Tasks.user_affected_id = " . $conditions['user_affected_id'];
         }
     }
     $query .= ")\n\t\t\t\tORDER BY Tasks.created_at DESC ";
     if ($limit) {
         $query .= ' LIMIT ' . $limit . ' ';
     }
     $tasks = static::execute($query)->toArray();
     if ($tasks) {
         foreach ($tasks as $key => $task) {
             $query = "\n\t\t\t\t\tSELECT\n\t\t\t\t\t\tServices.name,\n\t\t\t\t\t\tServices.image_css\n\t\t\t\t\tFROM\n\t\t\t\t\t\ttasks_services TasksServices\n\t\t\t\t\t\tLEFT JOIN services Services\n\t\t\t\t\t\t\t   ON Services.id = TasksServices.service_id\n\t\t\t\t\tWHERE\n\t\t\t\t\t\tTasksServices.task_id = " . $task['id'];
             $tasks[$key]['services'] = static::execute($query)->toArray();
             $query = "\n\t\t\t\t\tSELECT\n\t\t\t\t\t\tShares.*\n\t\t\t\t\tFROM\n\t\t\t\t\t\tshares Shares\n\t\t\t\t\tWHERE\n\t\t\t\t\t\tShares.task_id = " . $task['id'];
             $share = array();
             $share = SharesModel::execute($query)->toArray();
             if ($share) {
                 $share = current($share);
             }
             $tasks[$key]['share'] = $share;
         }
     }
     return $tasks;
 }
Exemple #4
0
 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);
     }
 }
Exemple #5
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');
 }