Skip to content

Commit

Permalink
Merge pull request #52 from Oksydan/falconize-migration
Browse files Browse the repository at this point in the history
Falconize migration
  • Loading branch information
Oksydan authored Feb 4, 2024
2 parents 8074207 + bbfd968 commit e8bac10
Show file tree
Hide file tree
Showing 21 changed files with 1,708 additions and 1,572 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
}
},
"require": {
"php": ">=7.4.0"
"php": ">=7.4.0",
"oksydan/falconize": "^1.0"
},
"config": {
"preferred-install": "dist",
Expand Down
2,583 changes: 1,506 additions & 1,077 deletions composer.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion config/admin/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ services:
Oksydan\IsImageslider\:
resource: '../../src/*'
exclude:
- '../../src/{Controller}'
- '../../src/{Controller,Falconize}'
- '../../src/index.php'
- '../../src/*/index.php'
- '../../src/**/index.php'
Expand Down
5 changes: 5 additions & 0 deletions config/configuration.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
imports:
- { resource: './database/image_slider.yml' }
- { resource: './database/image_slider_lang.yml' }
- { resource: './database/image_slider_shop.yml' }
- { resource: './hooks/register.yml' }
26 changes: 26 additions & 0 deletions config/database/image_slider.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
database_tables:
image_slider:
columns:
- name: id_slide
type: integer
length: 11
notnull: true
autoincrement: true
- name: active
type: boolean
notnull: true
- name: position
type: integer
length: 11
notnull: true
- name: display_from
type: datetime
notnull: false
default: null
- name: display_to
type: datetime
notnull: false
default: null
primary:
- id_slide

47 changes: 47 additions & 0 deletions config/database/image_slider_lang.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
database_tables:
image_slider_lang:
columns:
- name: id_slide
type: integer
length: 11
notnull: true
- name: id_lang
type: integer
length: 11
notnull: true
- name: title
type: string
length: 255
notnull: true
- name: legend
type: string
length: 255
notnull: true
- name: image
type: string
length: 255
notnull: true
- name: image_mobile
type: string
length: 255
notnull: true
- name: url
type: string
length: 255
notnull: true
- name: description
type: text
notnull: true
primary:
- id_slide
- id_lang

constraint_keys:
- name: is_imageslider_constraint_lang
foreign_table: lang
update: NO ACTION
delete: CASCADE
local_columns:
- id_lang
foreign_columns:
- id_lang
24 changes: 24 additions & 0 deletions config/database/image_slider_shop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
database_tables:
image_slider_shop:
columns:
- name: id_slide
type: integer
length: 11
notnull: true
- name: id_shop
type: integer
length: 11
notnull: true
primary:
- id_slide
- id_shop

constraint_keys:
- name: is_imageslider_constraint_shop
foreign_table: shop
update: NO ACTION
delete: CASCADE
local_columns:
- id_shop
foreign_columns:
- id_shop
1 change: 1 addition & 0 deletions config/front/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ services:
- '../../src/index.php'
- '../../src/*/index.php'
- '../../src/**/index.php'
- '../../src/Falconize/*'

Oksydan\IsImageslider\Hook\:
resource: '../../src/Hook/*'
Expand Down
4 changes: 4 additions & 0 deletions config/hooks/register.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
hooks:
register:
- name: displayHome
- name: displayHeader
58 changes: 25 additions & 33 deletions is_imageslider.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,22 @@
if (file_exists(__DIR__ . '/vendor/autoload.php')) {
require_once __DIR__ . '/vendor/autoload.php';
} else {
throw new \Exception('You must run "composer install --no-dev" command in module directory');
throw new Exception('You must run "composer install --no-dev" command in module directory');
}

use Oksydan\Falconize\Falconize;
use Oksydan\Falconize\PrestaShop\Module\PrestaShopModuleInterface;
use Oksydan\IsImageslider\Falconize\FalconizeConfiguration;
use Oksydan\IsImageslider\Hook\HookInterface;
use Oksydan\IsImageslider\Hook\WidgetCapability;
use Oksydan\IsImageslider\Installer\ImageSliderInstaller;
use PrestaShop\PrestaShop\Adapter\SymfonyContainer;
use PrestaShop\PrestaShop\Core\Module\WidgetInterface;
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;

class Is_imageslider extends Module implements WidgetInterface
class Is_imageslider extends Module implements WidgetInterface, PrestaShopModuleInterface
{
public $multistoreCompatibility = self::MULTISTORE_COMPATIBILITY_YES;
protected ?Falconize $falconize;

public function __construct()
{
Expand All @@ -33,7 +36,7 @@ public function __construct()
* https://www.waynet.pl/
*/
$this->author = 'Igor Stępień';
$this->version = '2.3.2';
$this->version = '3.0.0';
$this->need_instance = 0;

$this->bootstrap = true;
Expand All @@ -44,6 +47,21 @@ public function __construct()
$this->ps_versions_compliancy = ['min' => '8.0.0', 'max' => _PS_VERSION_];
}

public function getFalconize()
{
if (!isset($this->falconize)) {
$falconizeConfiguration = new FalconizeConfiguration(
$this,
SymfonyContainer::getInstance()->get('doctrine.dbal.default_connection'),
_DB_PREFIX_,
_PS_VERSION_
);
$this->falconize = new Falconize($falconizeConfiguration);
}

return $this->falconize;
}

public function isUsingNewTranslationSystem(): bool
{
return true;
Expand All @@ -56,22 +74,20 @@ public function install(): bool
{
return
parent::install()
&& $this->registerHook('displayHeader')
&& $this->registerHook('displayHome')
&& $this->getInstaller()->createTables();
&& $this->getFalconize()->install();
}

/**
* @return bool
*/
public function uninstall(): bool
{
return $this->getInstaller()->dropTables() && parent::uninstall();
return $this->getFalconize()->uninstall() && parent::uninstall();
}

public function getContent(): void
{
\Tools::redirectAdmin(SymfonyContainer::getInstance()->get('router')->generate('is_imageslider_controller'));
Tools::redirectAdmin(SymfonyContainer::getInstance()->get('router')->generate('is_imageslider_controller'));
}

/**
Expand All @@ -90,30 +106,6 @@ public function getService($serviceName)
}
}

/**
* @return ImageSliderInstaller
*/
private function getInstaller(): ImageSliderInstaller
{
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 */
public function __call($methodName, array $arguments)
{
Expand Down
57 changes: 57 additions & 0 deletions src/Falconize/FalconizeConfiguration.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

declare(strict_types=1);

namespace Oksydan\IsImageslider\Falconize;

use Doctrine\DBAL\Connection;
use Oksydan\Falconize\FalconizeConfigurationInterface;
use Oksydan\Falconize\PrestaShop\Module\PrestaShopModuleInterface;

final class FalconizeConfiguration implements FalconizeConfigurationInterface
{
protected PrestaShopModuleInterface $module;

protected Connection $connection;

protected string $databasePrefix;

protected string $prestashopVersion;

public function __construct(
PrestaShopModuleInterface $module,
Connection $connection,
string $databasePrefix,
string $prestashopVersion
) {
$this->module = $module;
$this->connection = $connection;
$this->databasePrefix = $databasePrefix;
$this->prestashopVersion = $prestashopVersion;
}

public function getConnection(): Connection
{
return $this->connection;
}

public function getModule(): PrestaShopModuleInterface
{
return $this->module;
}

public function getConfigurationFile(): \SplFileInfo
{
return new \SplFileInfo(__DIR__ . '/../../config/configuration.yml');
}

public function getDatabasePrefix(): string
{
return $this->databasePrefix;
}

public function getPrestashopVersion(): string
{
return $this->prestashopVersion;
}
}
76 changes: 0 additions & 76 deletions src/Installer/ActionDatabaseAbstract.php

This file was deleted.

Loading

0 comments on commit e8bac10

Please sign in to comment.