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
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php

declare(strict_types=1);

namespace Tweakwise\Magento2Tweakwise\Setup\Patch\Schema;

use Magento\Framework\Setup\Patch\SchemaPatchInterface;
use Magento\Framework\Setup\SchemaSetupInterface;

class CleanupLegacyIndexesTweakwiseAttributeSlugTable implements SchemaPatchInterface
{
/**
* @param SchemaSetupInterface $schemaSetup
*/
public function __construct(private readonly SchemaSetupInterface $schemaSetup)
{
}

/**
* Drop legacy indexes that were created before declarative schema took over.
* The declarative schema creates its own indexes with canonical names;
* the old ones are left behind because they were not registered in db_schema_whitelist.json.
*
* @return $this
*/
public function apply(): self
{
$setup = $this->schemaSetup;
$setup->startSetup();

$connection = $setup->getConnection();
$tableName = $setup->getTable('tweakwise_attribute_slug');

$existingIndexes = array_column(
$connection->fetchAll('SHOW INDEX FROM ' . $connection->quoteIdentifier($tableName)),
'Key_name'
);

foreach (['ATTRIBUTE', 'STORE_SLUG'] as $indexName) {
if (!in_array($indexName, $existingIndexes, true)) {
continue;
}

$connection->dropIndex($tableName, $indexName);
}

$setup->endSetup();

return $this;
}

/**
* @return class-string[]
*/
public static function getDependencies(): array
{
return [
AddAttributeCodeToTweakwiseAttributeSlugTable::class,
];
}

/**
* @return string[]
*/
public function getAliases(): array
{
return [];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php

declare(strict_types=1);

namespace Tweakwise\Magento2Tweakwise\Setup\Patch\Schema;

use Magento\Framework\Setup\Patch\SchemaPatchInterface;
use Magento\Framework\Setup\SchemaSetupInterface;

class SetSlugColumnCollationTweakwiseAttributeSlugTable implements SchemaPatchInterface
{
/**
* @param SchemaSetupInterface $schemaSetup
*/
public function __construct(private readonly SchemaSetupInterface $schemaSetup)
{
}

/**
* Change the slug column to utf8mb4_bin collation so that accent-distinct slugs
* (e.g. "e" vs "é" after transliteration) are treated as unique by the DB index.
* utf8mb4_bin is chosen over utf8mb4_0900_as_cs for compatibility with MariaDB.
* Slugs are always lowercased ASCII after transliteration, so binary comparison
* is safe and equivalent to accent+case-sensitive for this data.
*
* @return $this
*/
public function apply(): self
{
$setup = $this->schemaSetup;
$setup->startSetup();

$connection = $setup->getConnection();
$tableName = $connection->quoteIdentifier($setup->getTable('tweakwise_attribute_slug'));

// phpcs:disable Magento2.SQL.RawQuery.FoundRawSql -- modifyColumn() has no per-column collation support; ALTER TABLE is the only option
$connection->query(
'ALTER TABLE ' . $tableName
. ' MODIFY COLUMN `slug` VARCHAR(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL'
. " COMMENT 'URL Slug'"
);
// phpcs:enable Magento2.SQL.RawQuery.FoundRawSql

$setup->endSetup();

return $this;
}

/**
* @return class-string[]
*/
public static function getDependencies(): array
{
return [
CleanupLegacyIndexesTweakwiseAttributeSlugTable::class,
];
}

/**
* @return string[]
*/
public function getAliases(): array
{
return [];
}
}
Loading