Recurring.php 1.8 KB

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