UpgradeSchema.php 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php
  2. /**
  3. * Refer to LICENSE.txt distributed with the Temando Shipping module for notice of license
  4. */
  5. namespace Temando\Shipping\Setup;
  6. use Magento\Framework\Setup\ModuleContextInterface;
  7. use Magento\Framework\Setup\SchemaSetupInterface;
  8. use Magento\Framework\Setup\UpgradeSchemaInterface;
  9. /**
  10. * Init module schema
  11. *
  12. * @package Temando\Shipping\Setup
  13. * @author Christoph Aßmann <christoph.assmann@netresearch.de>
  14. * @author Benjamin Heuer <benjamin.heuer@netresearch.de>
  15. * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
  16. * @link http://www.temando.com/
  17. */
  18. class UpgradeSchema implements UpgradeSchemaInterface
  19. {
  20. /**
  21. * @var SetupSchema
  22. */
  23. private $installer;
  24. /**
  25. * @var RmaSetupSchema
  26. */
  27. private $rmaInstaller;
  28. /**
  29. * UpgradeSchema constructor.
  30. *
  31. * @param SetupSchema $installer
  32. * @param RmaSetupSchema $rmaInstaller
  33. */
  34. public function __construct(SetupSchema $installer, RmaSetupSchema $rmaInstaller)
  35. {
  36. $this->installer = $installer;
  37. $this->rmaInstaller = $rmaInstaller;
  38. }
  39. /**
  40. * @param SchemaSetupInterface $setup
  41. * @param ModuleContextInterface $context
  42. *
  43. * @return void
  44. * @throws \Zend_Db_Exception
  45. */
  46. public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $context)
  47. {
  48. // beware, this is the version we are upgrading from, not to!
  49. $moduleVersion = $context->getVersion();
  50. if (version_compare($moduleVersion, '0.1.0', '<')) {
  51. $this->installer->createOrderTable($setup);
  52. $this->installer->createShipmentTable($setup);
  53. }
  54. if (version_compare($moduleVersion, '0.2.6', '<')) {
  55. $this->installer->setShipmentOriginLocationNullable($setup);
  56. }
  57. if (version_compare($moduleVersion, '0.3.1', '<')) {
  58. $this->installer->createAddressTable($setup);
  59. }
  60. if (version_compare($moduleVersion, '1.1.0', '<')) {
  61. $this->rmaInstaller->createRmaShipmentTable($setup);
  62. }
  63. if (version_compare($moduleVersion, '1.2.0', '<')) {
  64. $this->rmaInstaller->addReturnShipmentIdColumn($setup);
  65. $this->installer->createCollectionPointSearchTable($setup);
  66. $this->installer->createQuoteCollectionPointTable($setup);
  67. $this->installer->createOrderCollectionPointTable($setup);
  68. }
  69. if (version_compare($moduleVersion, '1.2.1', '<')) {
  70. $this->installer->addCollectionPointSearchPendingColumn($setup);
  71. }
  72. if (version_compare($moduleVersion, '1.4.0', '<')) {
  73. $this->installer->createPickupLocationSearchTable($setup);
  74. $this->installer->createQuotePickupLocationTable($setup);
  75. $this->installer->createOrderPickupLocationTable($setup);
  76. }
  77. if (version_compare($moduleVersion, '1.5.0', '<')) {
  78. $this->installer->addDeliveryLocationDistanceColumn($setup);
  79. }
  80. }
  81. }