From ec86b2e894f4edd483f91a8d8c8c00da0e3da9f0 Mon Sep 17 00:00:00 2001 From: Julien Dubuisson Duplessis Date: Wed, 17 Apr 2019 12:30:58 +0200 Subject: [PATCH 1/6] fix exception namespace --- Command/BlogImportCommand.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Command/BlogImportCommand.php b/Command/BlogImportCommand.php index eeae0c6..64771ca 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,11 @@ 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)); + 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('Wrong file format. Format accepted "xml"'); } return $path; From 90c349a0effaf800406b32df2740f3b5f8c9a3b7 Mon Sep 17 00:00:00 2001 From: Julien Dubuisson Duplessis Date: Wed, 17 Apr 2019 12:33:55 +0200 Subject: [PATCH 2/6] handle image links when vacuuming images, handle the wrapping link if it is an image --- .../Stages/Article/VicArticleContentStages.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/Pipeline/WordPress/Stages/Article/VicArticleContentStages.php b/Pipeline/WordPress/Stages/Article/VicArticleContentStages.php index 983f436..5702298 100644 --- a/Pipeline/WordPress/Stages/Article/VicArticleContentStages.php +++ b/Pipeline/WordPress/Stages/Article/VicArticleContentStages.php @@ -104,6 +104,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 +117,19 @@ 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()); + } + } } } From 2a80be8318eeb30b12d4cb209557e56852d19363 Mon Sep 17 00:00:00 2001 From: Julien Dubuisson Duplessis Date: Wed, 17 Apr 2019 12:35:42 +0200 Subject: [PATCH 3/6] rely on existing User class for author import --- .../WordPress/Stages/Author/AuthorDataExtractorStages.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) 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 = [ From 59483f58dacdcbf0e7304f253cebfed9ff0d083f Mon Sep 17 00:00:00 2001 From: Julien Dubuisson Duplessis Date: Wed, 17 Apr 2019 12:37:08 +0200 Subject: [PATCH 4/6] check that postmeta is countable --- Pipeline/WordPress/Stages/SEO/VicSEOGenerator.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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) { From 2c0b33ba10fa79e3b191d0f3ce012e70d903b611 Mon Sep 17 00:00:00 2001 From: Julien Dubuisson Duplessis Date: Wed, 17 Apr 2019 12:39:25 +0200 Subject: [PATCH 5/6] remove application/xml check it is too strict when using files generated by WordPress --- Command/BlogImportCommand.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/Command/BlogImportCommand.php b/Command/BlogImportCommand.php index 64771ca..87c1e74 100644 --- a/Command/BlogImportCommand.php +++ b/Command/BlogImportCommand.php @@ -260,10 +260,6 @@ private function validatePath($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"'); - } - return $path; } From 9337319cb6ba9b26893bacf218bdf66c1b98d8f5 Mon Sep 17 00:00:00 2001 From: Julien Dubuisson Duplessis Date: Wed, 17 Apr 2019 12:45:59 +0200 Subject: [PATCH 6/6] fixes code style --- Pipeline/WordPress/Stages/Article/VicArticleContentStages.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Pipeline/WordPress/Stages/Article/VicArticleContentStages.php b/Pipeline/WordPress/Stages/Article/VicArticleContentStages.php index 5702298..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'), @@ -117,13 +118,12 @@ 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) ) { + if ('png' === substr($href, strlen($href) - 3) || 'jpg' === substr($href, strlen($href) - 3)) { $distantPath = $this->mediaFormater->cleanUrl($href); $image = $this->mediaFormater->generateImageMedia($distantPath, $folder);