diff --git a/.github/workflows/ci-linux.yml b/.github/workflows/ci-linux.yml index 4252b3b..24cb3d6 100644 --- a/.github/workflows/ci-linux.yml +++ b/.github/workflows/ci-linux.yml @@ -65,7 +65,7 @@ jobs: repository: galette/galette path: galette-core fetch-depth: 1 - ref: master + ref: develop - name: Checkout plugin uses: actions/checkout@v7 @@ -189,7 +189,7 @@ jobs: uses: galette/.github/actions/build-galette@main with: php-version: ${{ matrix.php-version }} - galette-ref: master + galette-ref: develop - name: Checkout plugin uses: actions/checkout@v7 @@ -276,7 +276,7 @@ jobs: uses: galette/.github/actions/build-galette@main with: php-version: '8.4' - galette-ref: master + galette-ref: develop - name: Checkout plugin uses: actions/checkout@v7 diff --git a/_define.php b/_define.php index 3455104..f73dec7 100644 --- a/_define.php +++ b/_define.php @@ -8,13 +8,14 @@ declare(strict_types=1); -/** @var \Galette\Core\Plugins $this */ -$this->register( +use Galette\Core\Plugins\PluginDefinition; + +return new PluginDefinition( name: 'Galette Auto', //Name desc: 'Plugin to manage Automobile clubs', //Short description author: 'Johan Cwiklinski', //Author version: '2.3.0', //Version - compver: '1.3.0', //Galette compatible version + compver: '1.4.0', //Galette compatible version route: 'auto', //routing name date: '2026-10-03', //Release date acls: [ //routes permissions diff --git a/lib/GaletteAuto/PluginGaletteAuto.php b/lib/GaletteAuto/PluginGaletteAuto.php index 1088ecb..c20d74c 100644 --- a/lib/GaletteAuto/PluginGaletteAuto.php +++ b/lib/GaletteAuto/PluginGaletteAuto.php @@ -15,6 +15,7 @@ use Galette\Core\Login; use Galette\Core\Plugins\DashboardProviderInterface; use Galette\Core\Plugins\InstallableInterface; +use Galette\Core\Plugins\InstallInitInterface; use Galette\Core\Plugins\MemberActionProviderInterface; use Galette\Core\Plugins\MenuProviderInterface; use Galette\Core\Plugins\PublicPagesProviderInterface; @@ -29,7 +30,7 @@ * @author Johan Cwiklinski */ -class PluginGaletteAuto extends GalettePlugin implements MenuProviderInterface, DashboardProviderInterface, MemberActionProviderInterface, InstallableInterface, PublicPagesProviderInterface +class PluginGaletteAuto extends GalettePlugin implements MenuProviderInterface, DashboardProviderInterface, MemberActionProviderInterface, InstallableInterface, InstallInitInterface, PublicPagesProviderInterface { #[Inject] private readonly Db $zdb; //@phpstan-ignore property.uninitializedReadonly,property.onlyRead (injected from DI) @@ -259,6 +260,35 @@ public function isInstalled(): bool ; } + /** + * Create default vehicle types, in the language of the user installing the plugin + * + * @param Db $zdb Database instance + */ + public function installInit(Db $zdb): void + { + $types = [ + _T('Car', 'auto') => [ + 'name' => VehicleType::REQUIRED, + 'registration' => VehicleType::REQUIRED, + ], + _T('Motorbike', 'auto') => [ + 'name' => VehicleType::REQUIRED, + 'registration' => VehicleType::REQUIRED, + 'body' => VehicleType::HIDDEN, + 'finition' => VehicleType::HIDDEN, + 'seats' => VehicleType::HIDDEN, + ], + ]; + + foreach ($types as $name => $fields) { + $type = new VehicleType($zdb); + $type->setValue((string)$name); + $type->setFields($fields); + $type->store(new: true); + } + } + /** * Version of tables installed before plugins versions were recorded * diff --git a/phpstan.neon b/phpstan.neon index d2d1bae..0e797a4 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -9,7 +9,6 @@ parameters: - _config.inc.php - ../../includes/sys_config/paths.inc.php - ../../config/config.inc.php.dist - - ../../includes/sys_config/galette_tcpdf_config.php scanDirectories: - ../../includes/ - ../../lib/ diff --git a/scripts/upgrade-to-1.2-mysql.sql b/scripts/sql/upgrade-to-1.2-mysql.sql similarity index 97% rename from scripts/upgrade-to-1.2-mysql.sql rename to scripts/sql/upgrade-to-1.2-mysql.sql index 9e91c35..bab7327 100644 --- a/scripts/upgrade-to-1.2-mysql.sql +++ b/scripts/sql/upgrade-to-1.2-mysql.sql @@ -26,6 +26,7 @@ CREATE TABLE galette_auto_types ( PRIMARY KEY (id_type) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci; +-- renamed in the language of the user upgrading, by the UpgradeTo12 update class INSERT INTO galette_auto_types (type) VALUES ('Car'); ALTER TABLE galette_auto_cars ADD id_type int unsigned DEFAULT NULL; diff --git a/scripts/upgrade-to-1.2-pgsql.sql b/scripts/sql/upgrade-to-1.2-pgsql.sql similarity index 97% rename from scripts/upgrade-to-1.2-pgsql.sql rename to scripts/sql/upgrade-to-1.2-pgsql.sql index 4d16a78..8860bd2 100644 --- a/scripts/upgrade-to-1.2-pgsql.sql +++ b/scripts/sql/upgrade-to-1.2-pgsql.sql @@ -26,6 +26,7 @@ CREATE TABLE galette_auto_types ( PRIMARY KEY (id_type) ); +-- renamed in the language of the user upgrading, by the UpgradeTo12 update class INSERT INTO galette_auto_types (type) VALUES ('Car'); ALTER TABLE galette_auto_cars ADD COLUMN id_type integer DEFAULT NULL; diff --git a/scripts/upgrade-to-1.2.php b/scripts/upgrade-to-1.2.php new file mode 100644 index 0000000..b1e6714 --- /dev/null +++ b/scripts/upgrade-to-1.2.php @@ -0,0 +1,53 @@ + + */ +class UpgradeTo12 extends AbstractUpdater +{ + protected ?string $db_version = '1.2'; + + /** + * Main constructor + */ + public function __construct() + { + parent::__construct(); + $this->setSqlScripts($this->db_version); + } + + /** + * Update instructions + */ + protected function update(): bool + { + return true; + } + + /** + * Name the type existing vehicles were given, once SQL script has run + */ + protected function postUpdate(): bool + { + $update = $this->zdb->update(AUTO_PREFIX . VehicleType::TABLE); + $update->set([VehicleType::FIELD => _T('Car', 'auto')]); + $update->where([VehicleType::FIELD => 'Car']); + $this->zdb->execute($update); + return true; + } +} diff --git a/tests/GaletteAuto/tests/units/PluginGaletteAuto.php b/tests/GaletteAuto/tests/units/PluginGaletteAuto.php index fad83c8..e1c7a9f 100644 --- a/tests/GaletteAuto/tests/units/PluginGaletteAuto.php +++ b/tests/GaletteAuto/tests/units/PluginGaletteAuto.php @@ -127,4 +127,25 @@ public function testLegacyDbVersion(): void $plugin = $this->container->get(\GaletteAuto\PluginGaletteAuto::class); $this->assertNull($plugin->getLegacyDbVersion()); } + + /** + * Default vehicle types are created on install + */ + public function testInstallInit(): void + { + $plugin = $this->container->get(\GaletteAuto\PluginGaletteAuto::class); + $plugin->installInit($this->zdb); + + $types = []; + foreach ($this->zdb->execute($this->zdb->select(AUTO_PREFIX . \GaletteAuto\VehicleType::TABLE)) as $row) { + $types[$row->type] = new \GaletteAuto\VehicleType($this->zdb, (int)$row->id_type); + } + $this->assertSame(['Car', 'Motorbike'], array_keys($types)); + + $this->assertTrue($types['Car']->isRequired('registration')); + $this->assertFalse($types['Car']->isHidden('body')); + $this->assertTrue($types['Motorbike']->isRequired('registration')); + $this->assertTrue($types['Motorbike']->isHidden('body')); + $this->assertFalse($types['Motorbike']->isHidden('transmission')); + } }