From 056861ab9150c9c7c54ab5e86b90a4dd578187e6 Mon Sep 17 00:00:00 2001 From: Jonathan Danse Date: Thu, 25 Jun 2026 16:33:29 +0200 Subject: [PATCH 1/2] Add SQL request settings endpoint PUT /sql-request-settings (SaveSqlRequestSettingsCommand) sets the SQL manager export file encoding (utf-8 / iso-8859-1) and separator. A singleton resource. The integration test updates the settings and verifies them via Configuration. Co-Authored-By: Claude Opus 4.8 --- .../SqlRequestSettings/SqlRequestSettings.php | 56 ++++++++++++++++++ .../SqlRequestSettingsEndpointTest.php | 59 +++++++++++++++++++ 2 files changed, 115 insertions(+) create mode 100644 src/ApiPlatform/Resources/SqlRequestSettings/SqlRequestSettings.php create mode 100644 tests/Integration/ApiPlatform/SqlRequestSettingsEndpointTest.php diff --git a/src/ApiPlatform/Resources/SqlRequestSettings/SqlRequestSettings.php b/src/ApiPlatform/Resources/SqlRequestSettings/SqlRequestSettings.php new file mode 100644 index 000000000..c9bf0ed85 --- /dev/null +++ b/src/ApiPlatform/Resources/SqlRequestSettings/SqlRequestSettings.php @@ -0,0 +1,56 @@ + + * @copyright Since 2007 PrestaShop SA and Contributors + * @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0 + */ + +declare(strict_types=1); + +namespace PrestaShop\Module\APIResources\ApiPlatform\Resources\SqlRequestSettings; + +use ApiPlatform\Metadata\ApiResource; +use PrestaShop\PrestaShop\Core\Domain\SqlManagement\Command\SaveSqlRequestSettingsCommand; +use PrestaShop\PrestaShop\Core\Domain\SqlManagement\Exception\SqlRequestSettingsConstraintException; +use PrestaShopBundle\ApiPlatform\Metadata\CQRSUpdate; +use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\Validator\Constraints as Assert; + +#[ApiResource( + operations: [ + new CQRSUpdate( + uriTemplate: '/sql-request-settings', + read: false, + output: false, + CQRSCommand: SaveSqlRequestSettingsCommand::class, + scopes: ['sql_management_write'], + ), + ], + exceptionToStatus: [ + SqlRequestSettingsConstraintException::class => Response::HTTP_UNPROCESSABLE_ENTITY, + ], +)] +class SqlRequestSettings +{ + /** + * One of utf-8, iso-8859-1. + */ + #[Assert\NotBlank] + public string $fileEncoding; + + #[Assert\NotBlank] + public string $fileSeparator; +} diff --git a/tests/Integration/ApiPlatform/SqlRequestSettingsEndpointTest.php b/tests/Integration/ApiPlatform/SqlRequestSettingsEndpointTest.php new file mode 100644 index 000000000..ea441eeaa --- /dev/null +++ b/tests/Integration/ApiPlatform/SqlRequestSettingsEndpointTest.php @@ -0,0 +1,59 @@ + + * @copyright Since 2007 PrestaShop SA and Contributors + * @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0 + */ + +declare(strict_types=1); + +namespace PsApiResourcesTest\Integration\ApiPlatform; + +use Symfony\Component\HttpFoundation\Response; +use Tests\Resources\DatabaseDump; + +class SqlRequestSettingsEndpointTest extends ApiTestCase +{ + public static function setUpBeforeClass(): void + { + parent::setUpBeforeClass(); + self::createApiClient(['sql_management_write']); + } + + public static function tearDownAfterClass(): void + { + parent::tearDownAfterClass(); + DatabaseDump::restoreTables(['configuration']); + } + + public static function getProtectedEndpoints(): iterable + { + yield 'save sql request settings endpoint' => ['PUT', '/sql-request-settings']; + } + + public function testSaveSqlRequestSettings(): void + { + $this->updateItem( + '/sql-request-settings', + ['fileEncoding' => 'utf-8', 'fileSeparator' => ';'], + ['sql_management_write'], + Response::HTTP_NO_CONTENT + ); + + $this->assertSame('utf-8', \Configuration::get('PS_ENCODING_FILE_MANAGER_SQL')); + $this->assertSame(';', \Configuration::get('PS_SEPARATOR_FILE_MANAGER_SQL')); + } +} From c956b18bb76d608cb96c753256a5ff5db17d07c6 Mon Sep 17 00:00:00 2001 From: Jonathan Danse Date: Fri, 26 Jun 2026 09:51:51 +0200 Subject: [PATCH 2/2] Fix test: SQL encoding setting is stored as an int (utf-8 => 1) The handler maps the charset to an int (utf-8 => 1, iso-8859-1 => 2), so assert the integer value. Co-Authored-By: Claude Opus 4.8 --- .../Integration/ApiPlatform/SqlRequestSettingsEndpointTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Integration/ApiPlatform/SqlRequestSettingsEndpointTest.php b/tests/Integration/ApiPlatform/SqlRequestSettingsEndpointTest.php index ea441eeaa..2b1c4f334 100644 --- a/tests/Integration/ApiPlatform/SqlRequestSettingsEndpointTest.php +++ b/tests/Integration/ApiPlatform/SqlRequestSettingsEndpointTest.php @@ -53,7 +53,7 @@ public function testSaveSqlRequestSettings(): void Response::HTTP_NO_CONTENT ); - $this->assertSame('utf-8', \Configuration::get('PS_ENCODING_FILE_MANAGER_SQL')); + $this->assertSame(1, (int) \Configuration::get('PS_ENCODING_FILE_MANAGER_SQL')); $this->assertSame(';', \Configuration::get('PS_SEPARATOR_FILE_MANAGER_SQL')); } }