Skip to content

Commit

Permalink
Let "ezxmltext:convert-to-richtext --content-object .." output non-va…
Browse files Browse the repository at this point in the history
…lidating Docbook xml on imports
  • Loading branch information
vidarl committed Oct 18, 2018
1 parent cb178a2 commit 167c9c7
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions bundle/Command/ImportXmlCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ class ImportXmlCommand extends ContainerAwareCommand
*/
private $output;

/**
* @var string|null
*/
private $contentObjectId;

public function __construct(Gateway $gateway, RichTextConverter $converter)
{
parent::__construct();
Expand Down Expand Up @@ -98,7 +103,7 @@ protected function execute(InputInterface $input, OutputInterface $output)

$this->output = $output;

$contentObjectId = $input->getOption('content-object');
$this->contentObjectId = $input->getOption('content-object');

if ($input->getOption('export-dir')) {
$this->exportDir = $input->getOption('export-dir');
Expand All @@ -118,10 +123,10 @@ protected function execute(InputInterface $input, OutputInterface $output)
}
$this->converter->setImageContentTypes($imageContentTypeIds);

$this->importDumps($dryRun, $contentObjectId);
$this->importDumps($dryRun);
}

protected function importDumps($dryRun, $contentObjectId = null)
protected function importDumps($dryRun)
{
foreach (new \DirectoryIterator($this->exportDir) as $dirItem) {
if ($dirItem->isFile() && $dirItem->getExtension() === 'xml') {
Expand All @@ -143,7 +148,7 @@ protected function importDumps($dryRun, $contentObjectId = null)
$language = $fileNameArray[4];
$filename = $this->exportDir . DIRECTORY_SEPARATOR . $dirItem->getFilename();

if ($contentObjectId !== null && $contentObjectId !== $objectId) {
if ($this->contentObjectId !== null && $this->contentObjectId !== $objectId) {
continue;
}

Expand All @@ -155,7 +160,9 @@ protected function importDumps($dryRun, $contentObjectId = null)

protected function validateConversion(DOMDocument $xmlDoc, $filename, $attributeId)
{
$this->converter->convert($xmlDoc, true, true, $attributeId);
$docBookDoc = new DOMDocument();
$docBookDoc->loadXML($this->converter->convert($xmlDoc, true, true, $attributeId));
$docBookDoc->formatOutput = true;
// Looks like XSLT processor is setting formatOutput to true
$xmlDoc->formatOutput = false;
$errors = $this->converter->getErrors();
Expand All @@ -178,6 +185,11 @@ protected function validateConversion(DOMDocument $xmlDoc, $filename, $attribute
}
}
}

if ($this->contentObjectId !== null) {
$this->output->writeln('Docbook result:');
$this->output->writeln($docBookDoc->saveXML());
}
} else {
$result = true;
}
Expand Down

0 comments on commit 167c9c7

Please sign in to comment.