Skip to content

Commit

Permalink
Merge pull request #16 from fredden/clean-data-in-wrong-tables
Browse files Browse the repository at this point in the history
Remove data from 'wrong' table
  • Loading branch information
sprankhub authored Jul 25, 2022
2 parents 19047da + 6a1abb1 commit a67181f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function __construct(
protected function configure()
{
$description
= 'Remove catalog_eav_attribute and attribute values which are missing parent entry in eav_attribute';
= 'Remove orphaned attribute values - those which are missing a parent entry (with the corresponding backend_type) in eav_attribute';
$this
->setName('eav:clean:attributes-and-values-without-parent')
->setDescription($description)
Expand Down Expand Up @@ -76,13 +76,13 @@ public function execute(InputInterface $input, OutputInterface $output)
$eavTable = $this->resourceConnection->getTableName('eav_attribute');
$entityValueTable = $this->resourceConnection->getTableName($code . '_entity_' . $type);
$query = "SELECT * FROM $entityValueTable WHERE `attribute_id` NOT IN(SELECT attribute_id"
. " FROM `$eavTable` WHERE entity_type_id = " . $entityType->getEntityTypeId() . ")";
. " FROM `$eavTable` WHERE entity_type_id = " . $entityType->getEntityTypeId() . " AND backend_type = '$type')";
$results = $db->fetchAll($query);
$output->writeln("Clean up " . count($results) . " rows in $entityValueTable");

if (!$isDryRun && count($results) > 0) {
$db->query("DELETE FROM $entityValueTable WHERE `attribute_id` NOT IN(SELECT attribute_id"
. " FROM `$eavTable` WHERE entity_type_id = " . $entityType->getEntityTypeId() . ")");
. " FROM `$eavTable` WHERE entity_type_id = " . $entityType->getEntityTypeId() . " AND backend_type = '$type')");
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Run `bin/magento` in the Magento 2 root and look for the `eav:` commands.
* `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.
* `eav:attributes:remove-unused` Remove attributes with no values set in products and attributes that are not present in any attribute sets.
* `eav:media:remove-unused` Remove unused product images.
* `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`.

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


### Contributors
- Nikita Zhavoronkova
- Anastasiia Sukhorukova
Expand Down

0 comments on commit a67181f

Please sign in to comment.