Skip to content

Commit

Permalink
module installation DB fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Oksydan committed Nov 21, 2022
1 parent e773a07 commit de7f5d0
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
22 changes: 19 additions & 3 deletions is_imageslider.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ public function __construct()
public function install(): bool
{
return
$this->registerHook('displayHeader')
parent::install()
&& $this->registerHook('displayHeader')
&& $this->registerHook('displayHome')
&& parent::install()
&& $this->getInstaller()->createTables();
}

Expand Down Expand Up @@ -86,7 +86,23 @@ public function getService($serviceName)
*/
private function getInstaller(): ImageSliderInstaller
{
return $this->get('oksydan.is_imageslider.image_slider_installer');
try {
$installer = $this->getService('oksydan.is_imageslider.image_slider_installer');
} catch (Error $error){
$installer = null;
}

if (null === $installer) {
$installer = new Oksydan\IsImageslider\Installer\ImageSliderInstaller(
$this->getService('doctrine.dbal.default_connection'),
(new Oksydan\IsImageslider\Installer\DatabaseYamlParser(
(new Oksydan\IsImageslider\Installer\Provider\DatabaseYamlProvider($this)
))),
$this->context
);
}

return $installer;
}

/** @param string $methodName */
Expand Down
9 changes: 8 additions & 1 deletion src/Installer/ImageSliderInstaller.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Context;
use Doctrine\DBAL\Connection;
use PrestaShop\PrestaShop\Adapter\ContainerFinder;
use Oksydan\IsImageslider\Installer\ActionDatabaseCrateTable;

class ImageSliderInstaller
{
Expand Down Expand Up @@ -52,7 +53,13 @@ public function createTables(): bool
{
$databaseData = $this->databaseYaml->getParsedFileData();
$container = $this->getContainer();
$createTableAction = $container->get('oksydan.is_imageslider.installer.action_databse_create_table');

// THIS WAY INSTEAD OF SERVICE CALL COZ OF NOT AVAILABLE SERVICE DURING INSTALLATION
$createTableAction = new ActionDatabaseCrateTable(
$container->get('doctrine.dbal.default_connection'),
$container->getParameter('database_prefix')
);

$createTableAction
->setData($databaseData)
->buildQuery();
Expand Down

0 comments on commit de7f5d0

Please sign in to comment.