Skip to content

Commit

Permalink
Counting fieldattributes that was or was not changed by ibexa:migrate…
Browse files Browse the repository at this point in the history
…:richtext-namespaces script
  • Loading branch information
vidarl committed Feb 17, 2023
1 parent a38f00f commit 5ce46b3
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 6 deletions.
24 changes: 20 additions & 4 deletions src/bundle/Command/AbstractMultiProcessComand.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,22 @@ abstract protected function iterate(): void;
*/
abstract protected function completed(): void;

/**
* Anything written to standard output from the subprocess might be processed here
* Typically, you may print that on the console.
*
* @param string $output
*/
abstract protected function processIncrementalOutput(string $output): void;

/**
* Anything written to standard error from the subprocess might be processed here
* Typically, you may print that on the console.
*
* @param string $output
*/
abstract protected function processIncrementalErrorOutput(string $output): void;

public function isDryRun(): bool
{
return $this->dryRun;
Expand Down Expand Up @@ -255,8 +271,8 @@ private function waitForChild(): void
$itemCount = $p['itemCount'];

if (!$process->isRunning()) {
$this->output->write($process->getIncrementalOutput());
$this->output->write($process->getIncrementalErrorOutput());
$this->processIncrementalOutput($process->getIncrementalOutput());
$this->processIncrementalErrorOutput($process->getIncrementalErrorOutput());
$childEnded = true;
$exitStatus = $process->getExitCode();
if ($exitStatus !== 0) {
Expand All @@ -266,8 +282,8 @@ private function waitForChild(): void
$this->advanceProgressBar($itemCount);
break;
}
$this->output->write($process->getIncrementalOutput());
$this->output->write($process->getIncrementalErrorOutput());
$this->processIncrementalOutput($process->getIncrementalOutput());
$this->processIncrementalErrorOutput($process->getIncrementalErrorOutput());
}
if (!$childEnded) {
sleep(1);
Expand Down
42 changes: 40 additions & 2 deletions src/bundle/Command/MigrateNamespacesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,18 @@ final class MigrateNamespacesCommand extends AbstractMultiProcessComand

private ?int $objectCount;

private int $convertDone;

private int $convertSkipped;

public function __construct(
PermissionResolver $permissionResolver,
UserService $userService,
Gateway $gateway
) {
$this->objectCount = null;
$this->convertDone = 0;
$this->convertSkipped = 0;
parent::__construct(null, $permissionResolver, $userService);
$this->gateway = $gateway;
}
Expand Down Expand Up @@ -105,6 +111,8 @@ protected function iterate(): void
protected function completed(): void
{
$this->output->writeln(PHP_EOL . 'Completed');
$this->output->writeln("Converted $this->convertDone field attributes(s)");
$this->output->writeln("Skipped $this->convertSkipped field attributes(s) which already had correct namespaces");
}

protected function getNextCursor(array $contentAttributeIDs): ?int
Expand All @@ -117,6 +125,10 @@ protected function getNextCursor(array $contentAttributeIDs): ?int
protected function processData($cursor)
{
$this->updateNamespacesInColumns($cursor['start'], $cursor['stop']);
if ($this->isChildProcess()) {
$this->output->writeln("Converted:$this->convertDone");
$this->output->writeln("Skipped:$this->convertSkipped");
}
}

protected function constructCursorFromInputOptions(): mixed
Expand All @@ -140,6 +152,27 @@ protected function isChildProcess(): bool
return $this->cursorStart !== null || $this->cursorStop !== null;
}

protected function processIncrementalOutput(string $output)
{
if ($output !== '') {
$lines = explode(PHP_EOL, $output);
foreach ($lines as $line) {
if (strpos($line, 'Converted:') === 0) {
$this->convertDone += (int) substr($line, strpos($line, ':') + 1);
} elseif (strpos($line, 'Skipped:') === 0) {
$this->convertSkipped += (int) substr($line, strpos($line, ':') + 1);
} elseif ($line !== '') {
$this->output->writeln($line);
}
}
}
}

protected function processIncrementalErrorOutput(string $output)
{
$this->output->write($output);
}

public static function migrateNamespaces(string $xmlText)
{
$xmlText = str_replace('xmlns:ezxhtml="http://ez.no/xmlns/ezpublish/docbook/xhtml"', 'xmlns:ezxhtml="http://ibexa.co/xmlns/dxp/docbook/xhtml"', $xmlText);
Expand All @@ -160,8 +193,13 @@ protected function updateNamespacesInColumns(int $contentAttributeIdStart, int $
//$orgString = $contentAttribute['data_text'];
$newXml = self::migrateNamespaces($contentAttribute['data_text']);

if (!$this->isDryRun() && ($newXml !== $contentAttribute['data_text'])) {
$this->gateway->updateContentObjectAttribute($newXml, $contentAttribute['contentobject_id'], $contentAttribute['id'], $contentAttribute['version'], $contentAttribute['language_code']);
if ($newXml !== $contentAttribute['data_text']) {
++$this->convertDone;
if (!$this->isDryRun()) {
$this->gateway->updateContentObjectAttribute($newXml, $contentAttribute['contentobject_id'], $contentAttribute['id'], $contentAttribute['version'], $contentAttribute['language_code']);
}
} else {
++$this->convertSkipped;
}
}
}
Expand Down

0 comments on commit 5ce46b3

Please sign in to comment.