Skip to content

Commit

Permalink
CS fix
Browse files Browse the repository at this point in the history
  • Loading branch information
vidarl committed Jan 30, 2023
1 parent e140fa2 commit a023267
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 36 deletions.
31 changes: 18 additions & 13 deletions src/bundle/Command/MigrateNamespacesCommand.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
<?php

/**
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);

namespace Ibexa\Bundle\FieldTypeRichText\Command;

use Ibexa\Contracts\Core\Repository\PermissionResolver;
Expand All @@ -10,20 +16,20 @@
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;


final class MigrateNamespacesCommand extends MultiprocessComand
{
private Gateway $gateway;

private ?int $cursorStart;

private ?int $cursorStop;

public function __construct(
PermissionResolver $permissionResolver,
UserService $userService,
Gateway $gateway,
)
{
parent::__construct("ibexa:migrate:richtext-namespaces", $permissionResolver, $userService);
) {
parent::__construct('ibexa:migrate:richtext-namespaces', $permissionResolver, $userService);
$this->gateway = $gateway;
}

Expand All @@ -36,7 +42,7 @@ public function configure(): void
null,
InputOption::VALUE_REQUIRED,
'Internal option - only used for subprocesses',
)
)
->addOption(
'cursor-stop',
null,
Expand All @@ -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;
Expand All @@ -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);
Expand All @@ -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
Expand Down Expand Up @@ -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']);
}
}
}
}
}
47 changes: 29 additions & 18 deletions src/bundle/Command/MultiprocessComand.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
<?php

/**
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);

namespace Ibexa\Bundle\FieldTypeRichText\Command;

use Ibexa\Contracts\Core\Repository\PermissionResolver;
Expand All @@ -10,7 +16,6 @@
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\Process\PhpExecutableFinder;
use Symfony\Component\Process\Process;

Expand All @@ -33,27 +38,30 @@ abstract class MultiprocessComand extends Command
protected $progressBar;

protected OutputInterface $output;

private bool $dryRun;

private int $maxProcesses;

/**
* @var Process[]
* @var \Symfony\Component\Process\Process[]
*/
private $processes;

/**
* @var string
*/
private mixed $user;

private int $iterationCount;

private string $environment;

public function __construct(
string $name = null,
PermissionResolver $permissionResolver,
UserService $userService,
)
{
) {
$this->permissionResolver = $permissionResolver;
$this->userService = $userService;
$this->dryRun = false;
Expand All @@ -70,7 +78,7 @@ public function configure(): void
InputOption::VALUE_REQUIRED,
'Ibexa DXP username',
'admin'
)
)
->addOption(
'dry-run',
null,
Expand All @@ -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
Expand All @@ -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;
Expand All @@ -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();

Expand All @@ -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
Expand All @@ -175,7 +188,6 @@ protected function doFork(): bool
return $this->maxProcesses > 1;
}


protected function waitForAvailableProcessSlot()
{
if (!$this->processSlotAvailable()) {
Expand Down Expand Up @@ -233,7 +245,7 @@ protected function createChildProcess(mixed $cursor, int $itemCount)
$phpBinaryFinder = new PhpExecutableFinder();
$phpBinaryPath = $phpBinaryFinder->find();

$arguments =[
$arguments = [
$phpBinaryPath,
'bin/console',
$this->getName(),
Expand Down Expand Up @@ -289,5 +301,4 @@ protected function finishProgressBar()
$this->progressBar->finish();
}
}

}
15 changes: 10 additions & 5 deletions src/lib/Persistence/Legacy/ContentModelGateway.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
<?php

/**
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);

namespace Ibexa\FieldTypeRichText\Persistence\Legacy;

use Doctrine\DBAL\Connection;

class ContentModelGateway
{
const DB_TABLE_CONTENTOBJECT_ATTRIBUTE = 'ezcontentobject_attribute';
const FIELD_TYPE_IDENTIFIER = 'ezrichtext';
public const DB_TABLE_CONTENTOBJECT_ATTRIBUTE = 'ezcontentobject_attribute';
public const FIELD_TYPE_IDENTIFIER = 'ezrichtext';

/**
* @var \Doctrine\DBAL\Connection
*/
Expand All @@ -31,7 +38,6 @@ public function countRichtextAttributes(): int
)
->setParameter(':data_type', self::FIELD_TYPE_IDENTIFIER);


$statement = $query->execute();

return (int) $statement->fetchOne();
Expand Down Expand Up @@ -138,5 +144,4 @@ public function updateContentObjectAttribute($xml, $contentId, $attributeId, $ve
->setParameter(':languagecode', $languageCode);
$updateQuery->execute();
}

}
}

0 comments on commit a023267

Please sign in to comment.