/** * 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'); }
/** * 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'); } }
/** * 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); } $db = new SaveFeedsToTable(); $request = []; $limit = 5; $total = $limit * 6; for ($i = 1; $i <= $total; $i++) { if ($i % $limit == 0) { $offset = $i - $limit; $feeds_id = $db->getIdOfLastFeeds('feeds', $offset, $limit); $action = []; foreach ($feeds_id as $id) { $action[] = ['action' => 'comments', 'from' => $id->id]; } $results = $send->sendRequest($action); if (count($results) > 0 && is_array($results)) { $count = 0; foreach ($results as $result) { if (count($result) > 0 && is_array($result)) { foreach ($result 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, 'parent_feed_id' => $feeds_id[$count]->id, 'name' => $feed->from->name]); } } } $count++; } } } } $this->info('Actualizacion de comentarios correcta'); }