Skip to content

Commit

Permalink
Merge pull request #2034 from dpfaffenbauer/issues/remove-db-and-clas…
Browse files Browse the repository at this point in the history
…s-migrate

[DB] Remove Migrate and ClassUpdate rename and fix psalm issues
  • Loading branch information
dpfaffenbauer authored Jul 4, 2022
2 parents e1f089a + 841131e commit 56743c7
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 562 deletions.
11 changes: 6 additions & 5 deletions src/CoreShop/Bundle/ResourceBundle/Installer/SqlInstaller.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,17 @@

namespace CoreShop\Bundle\ResourceBundle\Installer;

use Pimcore\Db;
use Doctrine\DBAL\Connection;
use Symfony\Component\Console\Helper\ProgressBar;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\HttpKernel\KernelInterface;

final class SqlInstaller implements ResourceInstallerInterface
{
public function __construct(private KernelInterface $kernel)
public function __construct(
private KernelInterface $kernel,
private Connection $connection
)
{
}

Expand All @@ -41,14 +44,12 @@ public function installResources(OutputInterface $output, string $applicationNam
$progress->setProgressCharacter('<comment>░</comment>');
$progress->setFormat(' %current%/%max% [%bar%] %percent:3s%% %message%');

$db = Db::get();

$progress->start(count($sqlFilesToExecute));

foreach ($sqlFilesToExecute as $sqlFile) {
$progress->setMessage(sprintf('<info>Execute SQL File %s</info>', $sqlFile));

$db->executeQuery(file_get_contents($this->kernel->locateResource($sqlFile)));
$this->connection->executeQuery(file_get_contents($this->kernel->locateResource($sqlFile)));

$progress->advance();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ services:
CoreShop\Bundle\ResourceBundle\Installer\SqlInstaller:
arguments:
- '@kernel'
- '@doctrine.dbal.default_connection'
tags:
- { name: coreshop.resource.installer, type: sql, priority: 400}

Expand Down

This file was deleted.

34 changes: 10 additions & 24 deletions src/CoreShop/Component/Pimcore/DataObject/ClassUpdate.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,10 @@
use CoreShop\Component\Pimcore\Exception\ClassDefinitionNotFoundException;
use Pimcore\Model\DataObject;

class ClassUpdate extends AbstractDefinitionUpdate implements ClassUpdateRenameInterface
class ClassUpdate extends AbstractDefinitionUpdate
{
private DataObject\ClassDefinition $classDefinition;

private array $fieldsToRename = [];

public function __construct(string $className)
{
parent::__construct();
Expand All @@ -34,30 +32,18 @@ public function __construct(string $className)
}

$this->fieldDefinitions = $this->classDefinition->getFieldDefinitions();
$this->jsonDefinition = json_decode(DataObject\ClassDefinition\Service::generateClassDefinitionJson($this->classDefinition), true);
$this->jsonDefinition = json_decode(
DataObject\ClassDefinition\Service::generateClassDefinitionJson($this->classDefinition),
true
);
}

public function save(): bool
{
foreach ($this->fieldsToRename as $from => $to) {
$renamer = new ClassDefinitionFieldReNamer($this->classDefinition, $from, $to);
$renamer->rename();
}

return null !== DataObject\ClassDefinition\Service::importClassDefinitionFromJson($this->classDefinition, json_encode($this->jsonDefinition), true);
}

public function renameField(string $fieldName, string $newFieldName): void
{
$this->findField(
$fieldName,
false,
function (array &$foundField, int $index, array &$parent) use ($fieldName, $newFieldName) {
$this->fieldsToRename[$fieldName] = [
'newName' => $newFieldName,
'definition' => $foundField,
];
}
);
return null !== DataObject\ClassDefinition\Service::importClassDefinitionFromJson(
$this->classDefinition,
json_encode($this->jsonDefinition),
true
);
}
}

This file was deleted.

Loading

0 comments on commit 56743c7

Please sign in to comment.