Ejemplo n.º 1
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $send = new SendToFacebook('facebook.txt');
     if (!$send->getConectionParameters()) {
         $this->error('Parámetros de conexión incorrectos');
         exit(1);
     }
     $from = $send->getUser();
     $action = ['action' => 'feed', 'from' => $from];
     $result = $send->sendRequest([$action]);
     $db = new SaveFeedsToTable();
     foreach ($result[0] as $feed) {
         // Comprobar si el usuario existe
         if (!$db->verifyIfExists('fb_users', $feed->from->id)) {
             $db->insertData('fb_users', ['id' => $feed->from->id, 'name' => $feed->from->name]);
         }
         // Comprobar si el feed existe
         if (!$db->verifyIfExists('feeds', $feed->id)) {
             $created_at = Carbon::parse($feed->created_time);
             $created_at->setTimezone('America/Bogota');
             if (property_exists($feed, 'message')) {
                 $message = $feed->message;
             } else {
                 $message = NULL;
             }
             if (property_exists($feed, 'story')) {
                 $story = $feed->story;
             } else {
                 $story = NULL;
             }
             $db->insertData('feeds', ['id' => $feed->id, 'created_at' => $created_at->format('Y-m-d H:i:s'), 'message' => $message, 'story' => $story, 'fb_user_id' => $feed->from->id, 'name' => $feed->from->name]);
         }
     }
     $this->info('Actualizacion de feeds correcta');
 }
Ejemplo n.º 2
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $send = new SendToFacebook('facebook.txt');
     if (!$send->getConectionParameters()) {
         $this->error('Parámetros de conexión incorrectos');
         exit(1);
     }
     $from = $send->getUser();
     $feeds = $this->_feed->whereNotNull('answer_text')->whereNotNull('taken_by')->where('answered', '=', 0)->get();
     $actions = [];
     if (count($feeds) > 0) {
         foreach ($feeds as $feed) {
             if ($feed->parent_feed_id == NULL) {
                 $id = $feed->id;
             } else {
                 $id = $feed->parent_feed_id;
             }
             $actions[] = ['action' => 'send', 'from' => $id, 'message' => $feed->answer_text];
             $date = Carbon::now('America/Bogota');
             $feed->answered = 1;
             $feed->answer_date = $date->format('Y-m-d H:i:s');
             $feed->save();
         }
         $result = $send->sendRequest($actions);
         $this->info('Los comentarios se enviaron correctamente');
     } else {
         $this->info('No se encontraron comentarios para enviar');
     }
 }