-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed custom_entity_attribute_set_id column migration
- Loading branch information
1 parent
1a7f290
commit 9b5ff3c
Showing
2 changed files
with
146 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Smile\CustomEntity\Setup\Patch\Data; | ||
|
||
use Magento\Framework\App\ResourceConnection; | ||
use Magento\Framework\Setup\Patch\DataPatchInterface; | ||
|
||
/** | ||
* Migrate custom_entity_attribute_set_id column data from `catalog_eav_attribute` to `eav_attribute` table. | ||
*/ | ||
class CustomEntityAttributeSetIdMigration implements DataPatchInterface | ||
{ | ||
/** | ||
* Attribute set id column name. | ||
*/ | ||
public const ATTRIBUTE_SET_ID_COLUMN = 'custom_entity_attribute_set_id'; | ||
|
||
/** | ||
* Resource connection. | ||
*/ | ||
protected ResourceConnection $resourceConnection; | ||
|
||
/** | ||
* Constructor. | ||
*/ | ||
public function __construct( | ||
ResourceConnection $resourceConnection | ||
) { | ||
$this->resourceConnection = $resourceConnection; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function apply() | ||
{ | ||
$connection = $this->resourceConnection->getConnection(); | ||
|
||
$catalogEavTable = $connection->getTableName('catalog_eav_attribute'); | ||
$eavTable = $connection->getTableName('eav_attribute'); | ||
|
||
if ( | ||
$connection->tableColumnExists($catalogEavTable, self::ATTRIBUTE_SET_ID_COLUMN) && | ||
$connection->tableColumnExists($eavTable, self::ATTRIBUTE_SET_ID_COLUMN) | ||
) { | ||
$select = $connection->select() | ||
->from(['cea' => 'catalog_eav_attribute'], [self::ATTRIBUTE_SET_ID_COLUMN]) | ||
->where('ea.attribute_id = cea.attribute_id'); | ||
|
||
$connection->query( | ||
$connection->updateFromSelect($select, ['ea' => 'eav_attribute']) | ||
); | ||
} | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public static function getDependencies() | ||
{ | ||
return []; | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function getAliases() | ||
{ | ||
return []; | ||
} | ||
} |
71 changes: 71 additions & 0 deletions
71
Setup/Patch/Schema/RemoveCatalogAttributeCustomEntitySetId.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Smile\CustomEntity\Setup\Patch\Schema; | ||
|
||
use Magento\Framework\App\ResourceConnection; | ||
use Magento\Framework\Setup\Patch\SchemaPatchInterface; | ||
use Smile\CustomEntity\Setup\Patch\Data\CustomEntityAttributeSetIdMigration; | ||
|
||
class RemoveCatalogAttributeCustomEntitySetId implements SchemaPatchInterface | ||
{ | ||
/** | ||
* Resource connection. | ||
*/ | ||
protected ResourceConnection $resourceConnection; | ||
|
||
/** | ||
* Constructor. | ||
*/ | ||
public function __construct( | ||
ResourceConnection $resourceConnection | ||
) { | ||
$this->resourceConnection = $resourceConnection; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function apply() | ||
{ | ||
$connection = $this->resourceConnection->getConnection(); | ||
|
||
$catalogEavTable = $connection->getTableName('catalog_eav_attribute'); | ||
$eavTable = $connection->getTableName('eav_attribute'); | ||
|
||
if ( | ||
$connection->tableColumnExists( | ||
$catalogEavTable, | ||
CustomEntityAttributeSetIdMigration::ATTRIBUTE_SET_ID_COLUMN | ||
) && | ||
$connection->tableColumnExists( | ||
$eavTable, | ||
CustomEntityAttributeSetIdMigration::ATTRIBUTE_SET_ID_COLUMN | ||
) | ||
) { | ||
$connection->dropColumn( | ||
$catalogEavTable, | ||
CustomEntityAttributeSetIdMigration::ATTRIBUTE_SET_ID_COLUMN | ||
); | ||
} | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public static function getDependencies() | ||
{ | ||
return [CustomEntityAttributeSetIdMigration::class]; | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function getAliases() | ||
{ | ||
return []; | ||
} | ||
} |