diff --git a/Command/BlogImportCommand.php b/Command/BlogImportCommand.php index eeae0c6..87c1e74 100644 --- a/Command/BlogImportCommand.php +++ b/Command/BlogImportCommand.php @@ -2,7 +2,6 @@ namespace Victoire\DevTools\VacuumBundle\Command; -use Buzz\Exception\RuntimeException; use Sensio\Bundle\GeneratorBundle\Command\Helper\QuestionHelper; use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; use Symfony\Component\Console\Input\InputInterface; @@ -258,11 +257,7 @@ private function validateView($id) private function validatePath($path) { if (!realpath($path)) { - throw new RuntimeException(sprintf('Wrong path the file "%s" can\'t be found', $path)); - } - - if (mime_content_type($path) != 'application/xml') { - throw new RuntimeException('Wrong file format. Format accepted "xml"'); + throw new \RuntimeException(sprintf('Wrong path the file "%s" can\'t be found', $path)); } return $path; diff --git a/Pipeline/WordPress/Stages/Article/VicArticleContentStages.php b/Pipeline/WordPress/Stages/Article/VicArticleContentStages.php index 983f436..a8798ba 100644 --- a/Pipeline/WordPress/Stages/Article/VicArticleContentStages.php +++ b/Pipeline/WordPress/Stages/Article/VicArticleContentStages.php @@ -80,6 +80,7 @@ public function __invoke(CommandPayloadInterface $payload) private function generateDOMDocument($content) { $document = new \DOMDocument(); + try { $document->loadHTML( mb_convert_encoding($content, 'HTML-ENTITIES', 'UTF-8'), @@ -104,6 +105,7 @@ private function handleImg(\DOMDocument $document, Article $article, $payload) if (null != $document->getElementsByTagName('img')) { $xpath = new \DOMXPath($document); $nodes = $xpath->query('//a//img'); + /** @var \DOMNode $node */ foreach ($nodes as $node) { $distantPath = $this->mediaFormater->cleanUrl($node->getAttribute('src')); @@ -116,6 +118,18 @@ private function handleImg(\DOMDocument $document, Article $article, $payload) $image = $this->mediaFormater->generateImageMedia($distantPath, $folder); $node->setAttribute('src', $image->getUrl()); + //managing wrapping a's + $parentNode = $node->parentNode; + if (XML_ELEMENT_NODE === $parentNode->nodeType && 'a' === $parentNode->nodeName) { + //$parentNode->attributes + $href = $parentNode->getAttribute('href'); + if ('png' === substr($href, strlen($href) - 3) || 'jpg' === substr($href, strlen($href) - 3)) { + $distantPath = $this->mediaFormater->cleanUrl($href); + $image = $this->mediaFormater->generateImageMedia($distantPath, $folder); + + $parentNode->setAttribute('href', $image->getUrl()); + } + } } } diff --git a/Pipeline/WordPress/Stages/Author/AuthorDataExtractorStages.php b/Pipeline/WordPress/Stages/Author/AuthorDataExtractorStages.php index dd4551f..83ffe28 100644 --- a/Pipeline/WordPress/Stages/Author/AuthorDataExtractorStages.php +++ b/Pipeline/WordPress/Stages/Author/AuthorDataExtractorStages.php @@ -4,6 +4,7 @@ use Doctrine\ORM\EntityManager; use Symfony\Component\Console\Helper\Table; +use Victoire\Bundle\UserBundle\Entity\User; use Victoire\DevTools\VacuumBundle\Entity\WordPress\Author; use Victoire\DevTools\VacuumBundle\Payload\CommandPayloadInterface; use Victoire\DevTools\VacuumBundle\Pipeline\PersisterStageInterface; @@ -52,8 +53,8 @@ public function __invoke(CommandPayloadInterface $payload) foreach ($channel->author as $wpAuthor) { $email = $xmlDataFormater->formatString('author_email', $wpAuthor); - $authorByUsername = $this->entityManager->getRepository('AppBundle:User\User')->findOneBy(['username' => $email]); - $authorByEmail = $this->entityManager->getRepository('AppBundle:User\User')->findOneBy(['email' => $email]); + $authorByUsername = $this->entityManager->getRepository(User::class)->findOneBy(['username' => $email]); + $authorByEmail = $this->entityManager->getRepository(User::class)->findOneBy(['email' => $email]); if (empty($authorByUsername) && empty($authorByEmail)) { $row = [ diff --git a/Pipeline/WordPress/Stages/SEO/VicSEOGenerator.php b/Pipeline/WordPress/Stages/SEO/VicSEOGenerator.php index b90b460..e1ae157 100644 --- a/Pipeline/WordPress/Stages/SEO/VicSEOGenerator.php +++ b/Pipeline/WordPress/Stages/SEO/VicSEOGenerator.php @@ -81,7 +81,7 @@ public function __invoke(CommandPayloadInterface $payload) */ private function generateNewSEOPage(CommandPayloadInterface $payload, $wpArticle, XmlDataFormater $xmlDataFormater, $article) { - if (count($wpArticle->postmeta > 2)) { + if ((is_array($wpArticle->postmeta) || $wpArticle->postmeta instanceof Countable) && count($wpArticle->postmeta) > 2) { $seo = new PageSeo(); $seo->setDefaultLocale($payload->getNewVicBlog()->getDefaultLocale()); foreach ($wpArticle->postmeta as $meta) {