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 _clean($destination, $source, $syncTaskId = 0, $whitelist = array()) { $service = ServicesModel::first(array('library' => 'Tasks'))->toArray(); $task = TasksServicesModel::first(array('task_id' => $syncTaskId, 'service_id' => $service['id']))->toArray(); $task['stats'] = json_decode($task['stats'], true); // lists $lists = BackupsModel::all(array('user_id' => $source['username']['id'], 'sync_task_id' => $syncTaskId, 'entity_type' => static::$kind['list']))->toArray(); if ($lists && ($task['stats']['lists'] || $destination['username']['id'] == $source['username']['id'])) { foreach ($lists as $list) { // $whitelist - shared or clean data if ($whitelist) { if (isset($whitelist['lists']) && in_array($list['entity_id'], $whitelist['lists'])) { \Rest::delete('https://www.googleapis.com/tasks/v1/users/@me/lists/' . $list['entity_id'], array(), $destination); } } else { if ($destination['username']['id'] == $source['username']['id']) { \Rest::delete('https://www.googleapis.com/tasks/v1/users/@me/lists/' . $list['entity_id'], array(), $destination); } else { if ($list['entity_new_id']) { \Rest::delete('https://www.googleapis.com/tasks/v1/users/@me/lists/' . $list['entity_new_id'], array(), $destination); } } } } } }
public static function _clean($destination, $source, $syncTaskId = 0, $whitelist = array()) { $service = ServicesModel::first(array('library' => 'Calendar'))->toArray(); $task = TasksServicesModel::first(array('task_id' => $syncTaskId, 'service_id' => $service['id']))->toArray(); $task['stats'] = json_decode($task['stats'], true); // Calendars $calendars = CalendarsModel::all(array('user_id' => $source['username']['id'], 'sync_task_id' => $syncTaskId))->toArray(); // Events $toDeleteEvents = array(); $migratedEvents = MigratedDataModel::all(array('source_id' => $source['username']['id'], 'sync_task_id' => $syncTaskId, 'kind' => static::$kind['event'])); if ($migratedEvents) { $migratedEvents = $migratedEvents->toArray(); if ($migratedEvents) { $destinationCalendars = CalendarsModel::all(array('user_id' => $destination['username']['id'], 'sync_task_id' => $syncTaskId)); if ($destinationCalendars) { $destinationCalendars = $destinationCalendars->toArray(); if ($destinationCalendars) { foreach ($destinationCalendars as $calendar) { // get events $newEvents = array(); do { $payload = array('maxResults' => static::$limit); if (isset($events['nextPageToken'])) { $payload['pageToken'] = $events['nextPageToken']; } $events = \Rest::get(sprintf(static::$endpoints['events'], $calendar['calendar_id']), $payload, $destination); if (isset($events['result']['error'])) { d(static::$endpoints['events']); } if (isset($events['items'])) { foreach ($events['items'] as $event) { if (isset($event['summary'])) { $newEvents[static::identifier($event, $calendar)] = $event['id']; } } } } while (isset($events['nextPageToken']) && $events['nextPageToken']); // Mark events foreach ($migratedEvents as $event) { if (isset($newEvents[$event['unique']])) { $toDeleteEvents[] = array('eventId' => $newEvents[$event['unique']], 'calendarId' => $calendar['calendar_id']); } } } } } } } switch (true) { # Share / Clean ############################################################################ case !empty($whitelist): // Calendars if ($calendars) { foreach ($calendars as $calendar) { if (isset($whitelist['calendars']) && in_array($calendar['calendar_id'], $whitelist['calendars'])) { \Rest::delete('https://www.googleapis.com/calendar/v3/calendars/' . $calendar['calendar_id'], array(), $destination); } } } break; # Move ############################################################################ # Move ############################################################################ case $destination['username']['id'] == $source['username']['id']: // Calendars if ($calendars) { foreach ($calendars as $calendar) { \Rest::delete('https://www.googleapis.com/calendar/v3/calendars/' . $calendar['calendar_id'], array(), $destination); } } # Migrate / Sync ############################################################################ # Migrate / Sync ############################################################################ default: // Calendars if ($calendars && $task['stats']['calendars']) { foreach ($calendars as $calendar) { if ($calendar['calendar_new_id']) { \Rest::delete('https://www.googleapis.com/calendar/v3/calendars/' . $calendar['calendar_new_id'], array(), $destination); } } } // Events if ($toDeleteEvents && $task['stats']['events']) { foreach ($toDeleteEvents as $event) { \Rest::delete('https://www.googleapis.com/calendar/v3/calendars/' . $event['calendarId'] . '/events/' . $event['eventId'], array(), $destination); } } break; } }
public static function data() { $service = ServicesModel::first($_SESSION['clean']['service'])->toArray(); if (!isset($_SESSION['clean']['data']) || empty($_SESSION['clean']['data'])) { \Auth::oAuthRefreshToken($_SESSION['current'], 'updateSession', 'force'); $_SESSION['clean']['data'] = call_user_func_array(array('app\\libraries\\' . $service['library'], 'share'), array($_SESSION['current'])); } $data = $_SESSION['clean']['data']; echo \Render::view('clean/data', array('data' => $data, 'selectedData' => $_SESSION['clean']['selectedData']), 'return'); }
public static function _clean($destination, $source, $syncTaskId = 0, $whitelist = array()) { $service = ServicesModel::first(array('library' => 'Youtube'))->toArray(); $task = TasksServicesModel::first(array('task_id' => $syncTaskId, 'service_id' => $service['id']))->toArray(); $task['stats'] = json_decode($task['stats'], true); // Playlists $playlists = PlaylistsModel::all(array('user_id' => $source['username']['id'], 'sync_task_id' => $syncTaskId))->toArray(); // Videos $videos = array(); $migratedVideos = MigratedDataModel::all(array('source_id' => $source['username']['id'], 'sync_task_id' => $syncTaskId, 'kind' => static::$kind['video'])); if ($migratedVideos) { $migratedVideos = $migratedVideos->toArray(); if ($migratedVideos) { $destinationPlaylists = PlaylistsModel::all(array('user_id' => $destination['username']['id'], 'sync_task_id' => $syncTaskId)); if ($destinationPlaylists) { $destinationPlaylists = $destinationPlaylists->toArray(); if ($destinationPlaylists) { foreach ($destinationPlaylists as $playlist) { foreach ($migratedVideos as $video) { $payload = array('part' => static::$part['playlistItems']['minimal'], 'playlistId' => $playlist['youtube_playlist_id'], 'videoId' => $video['identifier']); $vids = array(); $vids = \Rest::get(static::$endpoints['playlistItems'], $payload, $destination); if (isset($vids['result']['error'])) { d($vids); } if ($vids && $vids['items']) { foreach ($vids['items'] as $vid) { $videos[] = $vid['id']; } } } } } } } } // Subscriptions $newSubscriptions = array(); $oldSubscriptions = MigratedDataModel::all(array('destination_id' => $destination['username']['id'], 'sync_task_id' => $syncTaskId))->column('identifier'); do { $payload = array('part' => static::$part['subscriptions']['minimal'], 'mine' => 'true', 'maxResults' => static::$limit); if (isset($subscriptions['nextPageToken'])) { $payload['pageToken'] = $subscriptions['nextPageToken']; } $subscriptions = \Rest::get(static::$endpoints['subscriptions'], $payload, $destination); if (isset($subscriptions['result']['error'])) { d($subscriptions); } if ($subscriptions['items']) { foreach ($subscriptions['items'] as $sub) { $newSubscriptions[] = $sub; } } } while (isset($subscriptions['nextPageToken']) && $subscriptions['nextPageToken']); switch (true) { # Share / Clean ############################################################################ case !empty($whitelist): // Playlist if ($playlists) { foreach ($playlists as $playlist) { if (isset($whitelist['playlists']) && in_array($playlist['youtube_playlist_id'], $whitelist['playlists'])) { \Rest::delete(static::$endpoints['playlists'], array('id' => $playlist['youtube_playlist_id']), $destination); } } } // Subscriptions if ($newSubscriptions) { foreach ($newSubscriptions as $sub) { if (isset($whitelist['subscriptions']) && in_array($sub['snippet']['resourceId']['channelId'], $whitelist['subscriptions'])) { \Rest::delete(static::$endpoints['subscriptions'], array('id' => $sub['id']), $destination); } } } break; # Move ############################################################################ # Move ############################################################################ case $destination['username']['id'] == $source['username']['id']: // Playlist if ($playlists) { foreach ($playlists as $playlist) { \Rest::delete(static::$endpoints['playlists'], array('id' => $playlist['youtube_playlist_id']), $destination); } } // Subscriptions if ($newSubscriptions) { foreach ($newSubscriptions as $sub) { \Rest::delete(static::$endpoints['subscriptions'], array('id' => $sub['id']), $destination); } } break; # Migrate / Sync ############################################################################ # Migrate / Sync ############################################################################ default: // Playlist if ($playlists && $task['stats']['playlists']) { foreach ($playlists as $playlist) { if ($playlist['new_youtube_id']) { \Rest::delete(static::$endpoints['playlists'], array('id' => $playlist['new_youtube_id']), $destination); } } } // Videos if ($videos && $task['stats']['videos']) { foreach ($videos as $videoId) { \Rest::delete(static::$endpoints['playlistItems'], array('id' => $videoId), $destination); } } // Subscriptions if ($newSubscriptions) { foreach ($newSubscriptions as $sub) { if (in_array($sub['snippet']['resourceId']['channelId'], $oldSubscriptions) && $task['stats']['subscriptions']) { \Rest::delete(static::$endpoints['subscriptions'], array('id' => $sub['id']), $destination); } } } break; } }
public static function selectService() { $id = (int) $_POST['id']; if ($_POST['action'] == 'select') { $_SESSION['wizard']['services'][$id] = ServicesModel::first($id)->toArray(); } else { if (isset($_SESSION['wizard']['services'][$id])) { unset($_SESSION['wizard']['services'][$id]); } } }