diff --git a/src/bundle/Command/MigrateNamespacesCommand.php b/src/bundle/Command/MigrateNamespacesCommand.php index 866c3e96..4b7d9487 100644 --- a/src/bundle/Command/MigrateNamespacesCommand.php +++ b/src/bundle/Command/MigrateNamespacesCommand.php @@ -1,5 +1,11 @@ gateway = $gateway; } @@ -36,7 +42,7 @@ public function configure(): void null, InputOption::VALUE_REQUIRED, 'Internal option - only used for subprocesses', - ) + ) ->addOption( 'cursor-stop', null, @@ -51,11 +57,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int $this->cursorStop = $input->getOption('cursor-stop') !== null ? (int) $input->getOption('cursor-stop') : null; // Check that both --cursor-start and cursor-start are set, or neither - if ( ($this->cursorStart === null) xor ($this->cursorStop === null) ) { + if (($this->cursorStart === null) xor ($this->cursorStop === null)) { throw new RuntimeException('The options --cursor-start and -cursor-stop are only for internal use !'); } - parent::execute($input, $output); return self::SUCCESS; @@ -69,9 +74,9 @@ protected function getObjectCount(): int protected function iterate(): void { $limit = $this->getIterationCount(); - $cursor = [ + $cursor = [ 'start' => -1, - 'stop' => null + 'stop' => null, ]; $contentAttributeIDs = $this->gateway->getContentObjectAttributeIds($cursor['start'], $limit); @@ -89,7 +94,7 @@ protected function iterate(): void protected function completed(): void { - $this->output->writeln(PHP_EOL . "Completed"); + $this->output->writeln(PHP_EOL . 'Completed'); } protected function getNextCursor(array $contentAttributeIDs): ?int @@ -127,15 +132,15 @@ protected function isChildProcess(): bool protected function updateNamespacesInColumns(int $contentAttributeIdStart, int $contentAttributeIdStop): void { - $contentAttributes = $this->gateway->getContentObjectAttributes($contentAttributeIdStart,$contentAttributeIdStop); + $contentAttributes = $this->gateway->getContentObjectAttributes($contentAttributeIdStart, $contentAttributeIdStop); foreach ($contentAttributes as $contentAttribute) { $contentAttribute['data_text'] = str_replace('xmlns:ezxhtml="http://ez.no/xmlns/ezpublish/docbook/xhtml"', 'xmlns:ezxhtml="http://FOOBAR.co/xmlns/dxp/docbook/xhtml"', $contentAttribute['data_text']); - $contentAttribute['data_text'] = str_replace( 'xmlns:ezcustom="http://ez.no/xmlns/ezpublish/docbook/custom"', 'xmlns:ezcustom="http://FOOBAR.co/xmlns/dxp/docbook/custom"', $contentAttribute['data_text']); + $contentAttribute['data_text'] = str_replace('xmlns:ezcustom="http://ez.no/xmlns/ezpublish/docbook/custom"', 'xmlns:ezcustom="http://FOOBAR.co/xmlns/dxp/docbook/custom"', $contentAttribute['data_text']); if (!$this->isDryRun()) { $this->gateway->updateContentObjectAttribute($contentAttribute['data_text'], $contentAttribute['contentobject_id'], $contentAttribute['id'], $contentAttribute['version'], $contentAttribute['language_code']); } } } -} \ No newline at end of file +} diff --git a/src/bundle/Command/MultiprocessComand.php b/src/bundle/Command/MultiprocessComand.php index 46c4b96a..082ba24c 100644 --- a/src/bundle/Command/MultiprocessComand.php +++ b/src/bundle/Command/MultiprocessComand.php @@ -1,5 +1,11 @@ permissionResolver = $permissionResolver; $this->userService = $userService; $this->dryRun = false; @@ -70,7 +78,7 @@ public function configure(): void InputOption::VALUE_REQUIRED, 'Ibexa DXP username', 'admin' - ) + ) ->addOption( 'dry-run', null, @@ -91,12 +99,12 @@ public function configure(): void 1 ) ->addOption( - 'iteration-count', - null, - InputOption::VALUE_OPTIONAL, - 'Number of objects to process in a single iteration. Set to avoid using too much memory [default: 10000]', - 10000 - ); + 'iteration-count', + null, + InputOption::VALUE_OPTIONAL, + 'Number of objects to process in a single iteration. Set to avoid using too much memory [default: 10000]', + 10000 + ); } protected function execute(InputInterface $input, OutputInterface $output): int @@ -106,7 +114,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int $this->userService->loadUserByLogin($this->user) ); - $this->environment = (string) $input->getOption("env"); + $this->environment = (string) $input->getOption('env'); if ($input->getOption('dry-run')) { $this->dryRun = true; @@ -133,9 +141,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int $cursor = $this->constructCursorFromInputOptions(); $this->processData($cursor); } else { - $this->output->writeln("Processing " . $this->getObjectCount() . " items."); - $this->output->writeln("Using " . $this->getMaxProcesses() . " concurrent processes and processing " . $this->getIterationCount() . " items per iteration"); - + $this->output->writeln('Processing ' . $this->getObjectCount() . ' items.'); + $this->output->writeln('Using ' . $this->getMaxProcesses() . ' concurrent processes and processing ' . $this->getIterationCount() . ' items per iteration'); $this->startProgressBar(); @@ -148,11 +155,17 @@ protected function execute(InputInterface $input, OutputInterface $output): int } abstract protected function getObjectCount(): int; + abstract protected function processData(mixed $cursor); + abstract protected function constructCursorFromInputOptions(): mixed; + abstract protected function addChildProcessArguments(mixed $cursor): array; + abstract protected function isChildProcess(): bool; + abstract protected function iterate(): void; + abstract protected function completed(): void; public function isDryRun(): bool @@ -175,7 +188,6 @@ protected function doFork(): bool return $this->maxProcesses > 1; } - protected function waitForAvailableProcessSlot() { if (!$this->processSlotAvailable()) { @@ -233,7 +245,7 @@ protected function createChildProcess(mixed $cursor, int $itemCount) $phpBinaryFinder = new PhpExecutableFinder(); $phpBinaryPath = $phpBinaryFinder->find(); - $arguments =[ + $arguments = [ $phpBinaryPath, 'bin/console', $this->getName(), @@ -289,5 +301,4 @@ protected function finishProgressBar() $this->progressBar->finish(); } } - } diff --git a/src/lib/Persistence/Legacy/ContentModelGateway.php b/src/lib/Persistence/Legacy/ContentModelGateway.php index 240ba34d..7d07baca 100644 --- a/src/lib/Persistence/Legacy/ContentModelGateway.php +++ b/src/lib/Persistence/Legacy/ContentModelGateway.php @@ -1,13 +1,20 @@ setParameter(':data_type', self::FIELD_TYPE_IDENTIFIER); - $statement = $query->execute(); return (int) $statement->fetchOne(); @@ -138,5 +144,4 @@ public function updateContentObjectAttribute($xml, $contentId, $attributeId, $ve ->setParameter(':languagecode', $languageCode); $updateQuery->execute(); } - -} \ No newline at end of file +}