Recurring.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Bundle\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. $listTables = [
  45. 'catalog_product_bundle_price_index' => 'entity_id',
  46. 'catalog_product_bundle_selection' => 'product_id',
  47. ];
  48. foreach ($listTables as $tableName => $columnName) {
  49. $this->addExternalForeignKeys($installer, $tableName, $columnName);
  50. }
  51. $installer->endSetup();
  52. }
  53. /**
  54. * Add external foreign keys
  55. *
  56. * @param SchemaSetupInterface $installer
  57. * @param string $tableName
  58. * @param string $columnName
  59. * @return void
  60. * @throws \Exception
  61. */
  62. protected function addExternalForeignKeys(SchemaSetupInterface $installer, $tableName, $columnName)
  63. {
  64. $metadata = $this->metadataPool->getMetadata(ProductInterface::class);
  65. $this->externalFKSetup->install(
  66. $installer,
  67. $metadata->getEntityTable(),
  68. $metadata->getIdentifierField(),
  69. $tableName,
  70. $columnName
  71. );
  72. }
  73. }