Ejemplo n.º 1
0
 public static function backup($user, $taskId = 0, $syncTaskId = 0, $ignoreUpdate = false)
 {
     // Stats
     $stats = array('lists' => 0, 'tasks' => 0);
     // Lists
     $lists = \Rest::get(static::$endpoints['lists'], array('maxResults' => static::$limit), $user);
     if ($lists && $lists['items']) {
         foreach ($lists['items'] as $list) {
             // Save List
             $backup = BackupsModel::create();
             $backup->user_id = $user['username']['id'];
             $backup->task_id = $taskId;
             $backup->sync_task_id = $syncTaskId;
             $backup->entity_id = $list['id'];
             $backup->entity_type = static::$kind['list'];
             $backup->entity_title = $list['title'];
             $backup->entity_picture = \Render::image('no-photo.png');
             $backup->entity = json_encode($list);
             $backup->created = date(DATE_TIME);
             $backup->save();
             $stats['lists']++;
             // Save tasks
             $newTasks = array();
             do {
                 $payload = array('maxResults' => static::$limit, 'showCompleted' => 'true', 'showHidden' => 'true');
                 if (isset($tasks['nextPageToken'])) {
                     $payload['pageToken'] = $tasks['nextPageToken'];
                 }
                 $tasks = \Rest::get(sprintf(static::$endpoints['tasks'], $backup->entity_id), $payload, $user);
                 if (isset($tasks['result']['error'])) {
                     d($tasks);
                 }
                 if (isset($tasks['items'])) {
                     foreach ($tasks['items'] as $task) {
                         $formatedData = array('user_id' => $user['username']['id'], 'task_id' => $taskId, 'sync_task_id' => $syncTaskId, 'parent_id' => $backup->id, 'entity_id' => $task['id'], 'entity_type' => static::$kind['task'], 'entity_parent' => $backup->entity_id, 'entity_title' => $task['title'], 'entity_picture' => \Render::image('no-photo.png'), 'entity_new_id' => '', 'entity' => json_encode($task), 'created' => date(DATE_TIME));
                         $newTasks[] = $formatedData;
                         $stats['tasks']++;
                     }
                 }
             } while (isset($tasks['nextPageToken']) && $tasks['nextPageToken']);
             if ($newTasks) {
                 BackupsModel::insertBatch($newTasks);
             }
         }
     }
     return $stats;
 }
Ejemplo n.º 2
0
 public static function backup($user, $taskId = 0, $syncTaskId = 0)
 {
     // Stats
     $stats = array('links' => 0);
     // Lists
     $lists = \Rest::get(static::$endpoints['links'], array(), $user);
     if ($lists && $lists['items']) {
         foreach ($lists['items'] as $list) {
             // Save List
             $backup = BackupsModel::create();
             $backup->user_id = $user['username']['id'];
             $backup->task_id = $taskId;
             $backup->sync_task_id = $syncTaskId;
             $backup->entity_id = $list['id'];
             $backup->entity_type = static::$kind['link'];
             $backup->entity = json_encode($list);
             $backup->created = date(DATE_TIME);
             $backup->save();
             $stats['links']++;
         }
     }
     return $stats;
 }
Ejemplo n.º 3
0
 public static function backup($user, $taskId = 0, $syncTaskId = 0, $ignoreUpdate = false)
 {
     // Stats
     $stats = array('contacts' => 0);
     $contactsFeed = \Rest::get(static::$endpoints['contacts'], array(), $user);
     if (isset($contactsFeed->entry)) {
         foreach ($contactsFeed->entry as $entry) {
             $contact = array();
             $contact['id'] = @basename($entry->id);
             $contact['name'] = (string) $entry->title;
             $data = $entry->children('http://schemas.google.com/g/2005');
             // Email Address
             if ($data->email) {
                 foreach ($data->email as $entity) {
                     $attributes = (array) $entity->attributes();
                     $contact['emails'][] = $attributes['@attributes'];
                 }
             }
             // Instant messaging
             if ($data->im) {
                 foreach ($data->im as $entity) {
                     $attributes = (array) $entity->attributes();
                     $contact['im'][] = $attributes['@attributes'];
                 }
             }
             // Phone numbers
             if ($data->phoneNumber) {
                 foreach ($data->phoneNumber as $entity) {
                     $attributes = (array) $entity->attributes();
                     $attributes = $attributes['@attributes'];
                     $attributes['number'] = (string) $entity;
                     $contact['phoneNumbers'][] = $attributes;
                 }
             }
             // Postal addresses
             if ($data->postalAddress) {
                 foreach ($data->postalAddress as $entity) {
                     $attributes = (array) $entity->attributes();
                     $attributes = $attributes['@attributes'];
                     $attributes['address'] = (string) $entity;
                     $contact['postalAddress'][] = $attributes;
                 }
             }
             // Save Contact
             if ($contact) {
                 $backup = BackupsModel::create();
                 $backup->user_id = $user['username']['id'];
                 $backup->task_id = $taskId;
                 $backup->sync_task_id = $syncTaskId;
                 $backup->entity_id = $contact['id'];
                 $backup->entity_type = static::$kind['contact'];
                 $backup->entity_title = $contact['name'];
                 $backup->entity_picture = \Render::image('no-photo.jpg');
                 $backup->entity = json_encode($contact);
                 $backup->created = date(DATE_TIME);
                 $backup->save();
             }
             $stats['contacts']++;
         }
     }
     return $stats;
 }