Recurring.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\CatalogUrlRewrite\Setup;
  7. use Magento\Catalog\Api\Data\CategoryInterface;
  8. use Magento\Catalog\Api\Data\ProductInterface;
  9. use Magento\CatalogUrlRewrite\Model\ResourceModel\Category\Product as ResourceProduct;
  10. use Magento\Framework\EntityManager\MetadataPool;
  11. use Magento\Framework\Setup\ExternalFKSetup;
  12. use Magento\Framework\Setup\InstallSchemaInterface;
  13. use Magento\Framework\Setup\ModuleContextInterface;
  14. use Magento\Framework\Setup\SchemaSetupInterface;
  15. /**
  16. * CatalogUrlRewrite recurring setup
  17. */
  18. class Recurring implements InstallSchemaInterface
  19. {
  20. /**
  21. * @var MetadataPool
  22. */
  23. protected $metadataPool;
  24. /**
  25. * @var ExternalFKSetup
  26. */
  27. protected $externalFKSetup;
  28. /**
  29. * @param MetadataPool $metadataPool
  30. * @param ExternalFKSetup $externalFKSetup
  31. */
  32. public function __construct(
  33. MetadataPool $metadataPool,
  34. ExternalFKSetup $externalFKSetup
  35. ) {
  36. $this->metadataPool = $metadataPool;
  37. $this->externalFKSetup = $externalFKSetup;
  38. }
  39. /**
  40. * {@inheritdoc}
  41. */
  42. public function install(SchemaSetupInterface $setup, ModuleContextInterface $context)
  43. {
  44. $installer = $setup;
  45. $installer->startSetup();
  46. $metadata = $this->metadataPool->getMetadata(CategoryInterface::class);
  47. $this->externalFKSetup->install(
  48. $installer,
  49. $metadata->getEntityTable(),
  50. $metadata->getIdentifierField(),
  51. ResourceProduct::TABLE_NAME,
  52. 'category_id'
  53. );
  54. $metadata = $this->metadataPool->getMetadata(ProductInterface::class);
  55. $this->externalFKSetup->install(
  56. $installer,
  57. $metadata->getEntityTable(),
  58. $metadata->getIdentifierField(),
  59. 'catalog_url_rewrite_product_category',
  60. 'product_id'
  61. );
  62. $installer->endSetup();
  63. }
  64. }