ModifyTable.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\Setup\Declaration\Schema\Operations;
  7. use Magento\Framework\Setup\Declaration\Schema\Db\DbSchemaWriterInterface;
  8. use Magento\Framework\Setup\Declaration\Schema\Db\DefinitionAggregator;
  9. use Magento\Framework\Setup\Declaration\Schema\Dto\Column;
  10. use Magento\Framework\Setup\Declaration\Schema\Dto\Table;
  11. use Magento\Framework\Setup\Declaration\Schema\ElementHistory;
  12. use Magento\Framework\Setup\Declaration\Schema\OperationInterface;
  13. /**
  14. * Modify table operation.
  15. *
  16. * Used to change table options.
  17. */
  18. class ModifyTable implements OperationInterface
  19. {
  20. /**
  21. * Operation name.
  22. */
  23. const OPERATION_NAME = 'modify_table';
  24. /**
  25. * @var DbSchemaWriterInterface
  26. */
  27. private $dbSchemaWriter;
  28. /**
  29. * @param DbSchemaWriterInterface $dbSchemaWriter
  30. */
  31. public function __construct(DbSchemaWriterInterface $dbSchemaWriter)
  32. {
  33. $this->dbSchemaWriter = $dbSchemaWriter;
  34. }
  35. /**
  36. * {@inheritdoc}
  37. */
  38. public function getOperationName()
  39. {
  40. return self::OPERATION_NAME;
  41. }
  42. /**
  43. * {@inheritdoc}
  44. */
  45. public function isOperationDestructive()
  46. {
  47. return false;
  48. }
  49. /**
  50. * {@inheritdoc}
  51. */
  52. public function doOperation(ElementHistory $elementHistory)
  53. {
  54. /** @var Table $table */
  55. $table = $elementHistory->getNew();
  56. /** @var Table $oldTable */
  57. $oldTable = $elementHistory->getOld();
  58. $oldOptions = $oldTable->getDiffSensitiveParams();
  59. $statements = [];
  60. foreach ($table->getDiffSensitiveParams() as $optionName => $optionValue) {
  61. if ($oldOptions[$optionName] !== $optionValue) {
  62. $statements[] = $this->dbSchemaWriter->modifyTableOption(
  63. $table->getName(),
  64. $table->getResource(),
  65. $optionName,
  66. $optionValue
  67. );
  68. }
  69. }
  70. return $statements;
  71. }
  72. }