public function createCommentsTopic(WordPressAccess $wordPressAccess, PHPBoostAccess $PHPBoostAccess, stdClass $news) { // Récupération du statut des commentaires (ouvert/fermé) dans Wordpress $posts = $wordPressAccess->getAllPosts(); if (isset($posts[$news->rewrited_name])) { $commentsOpen = $posts[$news->rewrited_name]->comment_status != 'open'; } $count = $PHPBoostAccess->getSql()->prepare(' SELECT id_topic FROM ' . $PHPBoostAccess->getPrefix() . 'comments_topic WHERE module_id="news" AND id_in_module = :id '); $count->execute(array('id' => $news->id)); $nb = $count->rowCount(); if ($nb < 1) { $path = '/news/?url=/' . $news->category_id . '-' . $news->category_slug . '/' . $news->id . '-' . $news->rewrited_name . '/'; // Creation du comments topic $insert = $PHPBoostAccess->getSql()->prepare(' INSERT INTO ' . $PHPBoostAccess->getPrefix() . 'comments_topic(module_id, topic_identifier, id_in_module, is_locked, number_comments, path) VALUES (:module_id, :topic_identifier, :id_in_module, :is_locked, :number_comments, :path) '); $insert->execute(array('module_id' => 'news', 'topic_identifier' => 'default', 'id_in_module' => $news->id, 'is_locked' => $commentsOpen, 'number_comments' => 0, 'path' => $path)); return $PHPBoostAccess->getSql()->lastInsertId(); } else { $id_topic = $count->fetchObject()->id_topic; $update = $PHPBoostAccess->getSql()->prepare(' UPDATE ' . $PHPBoostAccess->getPrefix() . 'comments_topic SET is_locked = :is_locked WHERE id_topic = :id_topic '); $update->execute(array('is_locked' => $commentsOpen, 'id_topic' => $id_topic)); return $id_topic; } }
public function import(IOManager $io, WordPressAccess $wordPressAccess, PHPBoostAccess $phpBoostAccess) { // Récupération de tous les articles Wordpress $wpPost = $wordPressAccess->getAllPosts(); // Récupération de tous les articles PHPBoost existant $pboostPost = $phpBoostAccess->getAllPosts(); foreach ($wpPost as $post) { if (!array_key_exists($post->post_name, $pboostPost)) { // Si l'article n'existe pas, on le crée $this->addArticle($io, $phpBoostAccess, $post, $wordPressAccess); $io->writeln('Info: Article ' . $post->post_name . ' ajouté.'); } else { // Si l'article existe $io->writeln('Erreur: L\'article ' . $post->post_name . ' existe déjà.'); } } }