Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions Command/BlogImportCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
14 changes: 14 additions & 0 deletions Pipeline/WordPress/Stages/Article/VicArticleContentStages.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand All @@ -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'));

Expand All @@ -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());
}
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 = [
Expand Down
2 changes: 1 addition & 1 deletion Pipeline/WordPress/Stages/SEO/VicSEOGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down