Skip to content

Commit a67181f

Browse files
authored
Merge pull request #16 from fredden/clean-data-in-wrong-tables
Remove data from 'wrong' table
2 parents 19047da + 6a1abb1 commit a67181f

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

Console/Command/CleanUpAttributesAndValuesWithoutParentCommand.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public function __construct(
3838
protected function configure()
3939
{
4040
$description
41-
= 'Remove catalog_eav_attribute and attribute values which are missing parent entry in eav_attribute';
41+
= 'Remove orphaned attribute values - those which are missing a parent entry (with the corresponding backend_type) in eav_attribute';
4242
$this
4343
->setName('eav:clean:attributes-and-values-without-parent')
4444
->setDescription($description)
@@ -76,13 +76,13 @@ public function execute(InputInterface $input, OutputInterface $output)
7676
$eavTable = $this->resourceConnection->getTableName('eav_attribute');
7777
$entityValueTable = $this->resourceConnection->getTableName($code . '_entity_' . $type);
7878
$query = "SELECT * FROM $entityValueTable WHERE `attribute_id` NOT IN(SELECT attribute_id"
79-
. " FROM `$eavTable` WHERE entity_type_id = " . $entityType->getEntityTypeId() . ")";
79+
. " FROM `$eavTable` WHERE entity_type_id = " . $entityType->getEntityTypeId() . " AND backend_type = '$type')";
8080
$results = $db->fetchAll($query);
8181
$output->writeln("Clean up " . count($results) . " rows in $entityValueTable");
8282

8383
if (!$isDryRun && count($results) > 0) {
8484
$db->query("DELETE FROM $entityValueTable WHERE `attribute_id` NOT IN(SELECT attribute_id"
85-
. " FROM `$eavTable` WHERE entity_type_id = " . $entityType->getEntityTypeId() . ")");
85+
. " FROM `$eavTable` WHERE entity_type_id = " . $entityType->getEntityTypeId() . " AND backend_type = '$type')");
8686
}
8787
}
8888
}

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Run `bin/magento` in the Magento 2 root and look for the `eav:` commands.
1212
* `eav:attributes:restore-use-default-value` Check if product attribute admin value and storeview value are the same, so "use default" doesn't work anymore. Delete the storeview values.
1313
* `eav:attributes:remove-unused` Remove attributes with no values set in products and attributes that are not present in any attribute sets.
1414
* `eav:media:remove-unused` Remove unused product images.
15+
* `eav:clean:attributes-and-values-without-parent` Remove orphaned attribute values - those which are missing a parent entry (with the corresponding `backend_type`) in `eav_attribute`.
1516

1617
## Dry run
1718
Use `--dry-run` to check result without modifying data.
@@ -23,7 +24,6 @@ Installation with composer:
2324
composer require magento-hackathon/module-eavcleaner-m2
2425
```
2526

26-
2727
### Contributors
2828
- Nikita Zhavoronkova
2929
- Anastasiia Sukhorukova

0 commit comments

Comments
 (0)