DropTable.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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\Table;
  10. use Magento\Framework\Setup\Declaration\Schema\ElementHistory;
  11. use Magento\Framework\Setup\Declaration\Schema\OperationInterface;
  12. /**
  13. * Drop table operation.
  14. */
  15. class DropTable implements OperationInterface
  16. {
  17. /**
  18. * Operation name.
  19. */
  20. const OPERATION_NAME = 'drop_table';
  21. /**
  22. * @var DefinitionAggregator
  23. */
  24. private $definitionAggregator;
  25. /**
  26. * @var DbSchemaWriterInterface
  27. */
  28. private $dbSchemaWriter;
  29. /**
  30. * Constructor.
  31. *
  32. * @param DefinitionAggregator $definitionAggregator
  33. * @param DbSchemaWriterInterface $dbSchemaWriter
  34. */
  35. public function __construct(
  36. DefinitionAggregator $definitionAggregator,
  37. DbSchemaWriterInterface $dbSchemaWriter
  38. ) {
  39. $this->definitionAggregator = $definitionAggregator;
  40. $this->dbSchemaWriter = $dbSchemaWriter;
  41. }
  42. /**
  43. * {@inheritdoc}
  44. */
  45. public function isOperationDestructive()
  46. {
  47. return true;
  48. }
  49. /**
  50. * {@inheritdoc}
  51. */
  52. public function getOperationName()
  53. {
  54. return self::OPERATION_NAME;
  55. }
  56. /**
  57. * {@inheritdoc}
  58. */
  59. public function doOperation(ElementHistory $tableHistory)
  60. {
  61. /**
  62. * @var Table $table
  63. */
  64. $table = $tableHistory->getOld();
  65. return [$this->dbSchemaWriter->dropTable($table->getName(), $table->getResource())];
  66. }
  67. }