/** * @param \Facebook\GraphNodes\GraphEdge $edge * @return array * @throws \Exception */ protected function saveRemoteData(Facebook\GraphNodes\GraphEdge $edge) { $arrPosts = ApiHelper::toPosts($edge); try { Post::model()->batchInsert($arrPosts, ['continueOnError' => true]); } catch (\Exception $e) { if ($e->getCode() !== 11000) { throw $e; } } $posts = []; foreach ($arrPosts as $item) { $post = new Post(); foreach ($item as $attr => $value) { $post->setAttribute($attr, $value); } $posts[] = $post; } return $posts; }