Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/ci-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions _define.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 31 additions & 1 deletion lib/GaletteAuto/PluginGaletteAuto.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -29,7 +30,7 @@
* @author Johan Cwiklinski <johan@x-tnd.be>
*/

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)
Expand Down Expand Up @@ -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
*
Expand Down
1 change: 0 additions & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
53 changes: 53 additions & 0 deletions scripts/upgrade-to-1.2.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

/**
* This file is part of Galette Auto plugin (https://galette.eu).
* SPDX-FileCopyrightText: Copyright © 2009-2026 The Galette Team
* SPDX-License-Identifier: GPL-3.0-or-later
*/

declare(strict_types=1);

namespace GaletteAuto\Updates;

use Galette\Updater\AbstractUpdater;
use GaletteAuto\VehicleType;

/**
* Galette Auto 1.2 upgrade script: vehicle types
*
* @author Johan Cwiklinski <johan@x-tnd.be>
*/
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;
}
}
21 changes: 21 additions & 0 deletions tests/GaletteAuto/tests/units/PluginGaletteAuto.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
}
}
Loading