Skip to content

Commit

Permalink
fix(installer): prepare the ps entity manager before starting
Browse files Browse the repository at this point in the history
  • Loading branch information
EdieLemoine committed Sep 26, 2023
1 parent c54d103 commit 016c9ee
Showing 1 changed file with 48 additions and 1 deletion.
49 changes: 48 additions & 1 deletion src/Pdk/Installer/Service/PsInstallerService.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,20 @@
use Carrier;
use Context;
use Db;
use Doctrine\Common\Annotations\AnnotationReader;
use Doctrine\Common\Annotations\DocParser;
use Doctrine\Common\Annotations\PsrCachedReader;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Mapping\Driver\AnnotationDriver;
use Doctrine\Persistence\Mapping\Driver\MappingDriverChain;
use Language;
use Module;
use MyParcelNL\Pdk\App\Account\Contract\PdkAccountRepositoryInterface;
use MyParcelNL\Pdk\App\Installer\Service\InstallerService;
use MyParcelNL\Pdk\Facade\Pdk;
use MyParcelNL\PrestaShop\Facade\MyParcelModule;
use MyParcelNL\PrestaShop\Pdk\Installer\Exception\InstallationException;
use Symfony\Component\Cache\Adapter\ArrayAdapter;
use Tab;

final class PsInstallerService extends InstallerService
Expand All @@ -24,14 +31,16 @@ final class PsInstallerService extends InstallerService
private $module;

/**
* @param ...$args
* @param mixed ...$args
*
* @return void
* @throws \Doctrine\Common\Annotations\AnnotationException
* @throws \MyParcelNL\PrestaShop\Pdk\Installer\Exception\InstallationException
*/
public function install(...$args): void
{
$this->setModule($args);
$this->prepareEntityManager();
parent::install($args);
}

Expand All @@ -54,11 +63,13 @@ public function setModule(array $args): void
* @param mixed ...$args
*
* @return void
* @throws \Doctrine\Common\Annotations\AnnotationException
* @throws \MyParcelNL\PrestaShop\Pdk\Installer\Exception\InstallationException
*/
public function uninstall(...$args): void
{
$this->setModule($args);
$this->prepareEntityManager();
parent::uninstall($args);
}

Expand Down Expand Up @@ -120,6 +131,16 @@ protected function migrateUp(string $version): void
MyParcelModule::registerHooks();
}

/**
* @param null|string $version
*
* @return void
*/
protected function updateInstalledVersion(?string $version): void
{
// do nothing
}

private function installDatabase(): void
{
foreach (Pdk::get('databaseMigrationClasses') as $migration) {
Expand Down Expand Up @@ -152,6 +173,32 @@ private function installTabs(): void
}
}

/**
* @return void
* @throws \Doctrine\Common\Annotations\AnnotationException
*/
private function prepareEntityManager(): void
{
$appInfo = Pdk::getAppInfo();

/** @var EntityManagerInterface $entityManager */
$entityManager = Pdk::get('ps.entityManager');

$driverChain = $entityManager
->getConfiguration()
->getMetadataDriverImpl();

$docParser = new DocParser();
$reader = new AnnotationReader($docParser);
$reader = new PsrCachedReader($reader, new ArrayAdapter());

$driver = new AnnotationDriver($reader, ["{$appInfo->path}src/Entity"]);

if ($driverChain instanceof MappingDriverChain) {
$driverChain->addDriver($driver, 'MyParcelNL\PrestaShop\Entity');
}
}

/**
* @return void
* @throws \MyParcelNL\PrestaShop\Pdk\Installer\Exception\InstallationException
Expand Down

0 comments on commit 016c9ee

Please sign in to comment.