Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

12110: Missing cascade into attribute set deletion. #12167

Merged
merged 10 commits into from
Dec 7, 2017
Merged

12110: Missing cascade into attribute set deletion. #12167

merged 10 commits into from
Dec 7, 2017

Conversation

nmalevanec
Copy link
Contributor

@nmalevanec nmalevanec commented Nov 10, 2017

Description

Fix for: Missing cascade into attribute set deletion.

Fixed Issues (if relevant)

  1. Missing cascade into attribute set deletion #12110: Missing cascade into attribute set deletion

Manual testing scenarios

  1. Create a custom attributes set.
  2. Attach some products to this attributes set.
  3. Got to attributes set admin page.
  4. Delete your custom attributes set.
  5. Confirm you want to remove attached products also.
  6. Check, table url_rewrite should be cleaned from references to removed products.
  7. Check, that new product named like an old one from removed attribute set can be created via API or admin interface.

Contribution checklist

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • All automated tests passed successfully (all builds on Travis CI are green)

@magento-engcom-team magento-engcom-team added Reproduced on 2.1.x The issue has been reproduced on latest 2.1 release Reproduced on 2.2.x The issue has been reproduced on latest 2.2 release Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release labels Nov 10, 2017
@sidolov sidolov self-assigned this Nov 30, 2017
@sidolov sidolov added this to the November 2017 milestone Nov 30, 2017
@sidolov
Copy link
Contributor

sidolov commented Dec 1, 2017

Hi @nmalevanec, you in a right way, but problem deeper than an issue with URL rewrites. The main reason why URL rewrites still present in db is foreign key (relations between catalog_product_entity and eav_attribute_set tables). You fix problem with rewrites, but we still has problems with other product artifacts that should be deleted in before, after methods, plugins, observers etc.
Right way to fix this issue is remove foreign key from catalog_product_entity and introduce plugin, that will delete all products from attribute set programatically, in this case all product handlers will be called (for url rewrites - observer: \Magento\CatalogUrlRewrite\Observer\ProductProcessUrlRewriteRemovingObserver).

* See COPYING.txt for license details.
*/

namespace Magento\CatalogUrlRewrite\Plugin\Eav\AttributeSetRepository;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move plugin to Catalog module

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

/**
* Remove url rewrites for products with given attribute set.
*/
class RemoveProductUrlRewrite
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename plugin to RemoveProducts

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

*
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function aroundDelete(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use after plugin instead of around

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, may be I have missed something. But, if I'll use after plugin I won't have attribute set id in results, only bool true and instance of AttributeSetRepository. And I need attribute set id in order to filter product collection.

if (!empty($productIds)) {
$productIds = array_chunk($productIds, $this->chunkSize);
foreach ($productIds as $ids) {
$this->urlPersist->deleteByData(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove products from db

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

*
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function aroundDelete(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

@nmalevanec nmalevanec Dec 4, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I wrote above, in after plugin I do not have attribute set id for filtering product collection.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After plugins provide access to all method arguments.

public function afterDelete(
   AttributeSetRepositoryInterface $subject,
   $result,
   AttributeSetInterface $attributeSet
) {
  // use $attributeSet->getId()
  ...
  return $result;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed. Sorry, for not paying enough attention to devdocs before.

@sidolov
Copy link
Contributor

sidolov commented Dec 4, 2017

Hi @nmalevanec , consider to port this solution to 2.3 version
Thanks!

@sidolov
Copy link
Contributor

sidolov commented Dec 4, 2017

Fixed static test (suppress cyclomatic complexity for \Magento\Catalog\Setup\UpgradeSchema::upgrade)

@nmalevanec
Copy link
Contributor Author

@sidolov port on 2.3 - #12538

@magento-team magento-team merged commit c7fbbcc into magento:2.2-develop Dec 7, 2017
magento-team pushed a commit that referenced this pull request Dec 7, 2017
[EngCom] Public Pull Requests - 2.2-develop
 - MAGETWO-84981: Trying to get data from non existent products #12539
 - MAGETWO-84979: [Backport 2.2-develop] Fix swagger-ui on instances of Magento running on a non-standard port #12541
 - MAGETWO-84903: Added namespace to product videos fotorama events #12469
 - MAGETWO-84862: [Backport 2.2-develop] #11409: Too many password reset requests even when disabled in settings #11435
 - MAGETWO-84856: Issue 12506: Fixup typo getDispretionPath -> getDispersionPath #12507
 - MAGETWO-84808: 12110: Missing cascade into attribute set deletion. #12167
 - MAGETWO-83503: [2.2] - Add command to view mview state and queue #12122
 - MAGETWO-80223: Fix syntax of expectException() calls #11099
@nmalevanec nmalevanec deleted the 12110 branch August 21, 2018 07:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Progress: accept Release Line: 2.2 Reproduced on 2.1.x The issue has been reproduced on latest 2.1 release Reproduced on 2.2.x The issue has been reproduced on latest 2.2 release Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants