Skip to content

Commit

Permalink
Merge pull request magento#729 from magento-engcom/enhanced-declarati…
Browse files Browse the repository at this point in the history
…ve-schema-compatibility

Enhanced Declarative Schema Compatibility
  • Loading branch information
maghamed authored Mar 27, 2018
2 parents 73237b2 + c7d0d29 commit 8c8cfa1
Show file tree
Hide file tree
Showing 22 changed files with 266 additions and 344 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,17 @@
*/
declare(strict_types=1);

namespace Magento\InventoryCatalog\Setup;
namespace Magento\InventoryCatalog\Setup\Patch\Schema;

use Magento\Framework\Setup\InstallDataInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\Patch\SchemaPatchInterface;
use Magento\InventoryCatalog\Setup\Operation\AssignDefaultSourceToDefaultStock;
use Magento\InventoryCatalog\Setup\Operation\CreateDefaultSource;
use Magento\InventoryCatalog\Setup\Operation\CreateDefaultStock;
use Magento\InventoryCatalog\Setup\Operation\ReindexDefaultStock;
use Magento\InventoryCatalog\Setup\Operation\UpdateInventorySourceItem;

/**
* Install Default Source, Stock and link them together
* Patch schema with information about default stock
*/
class InstallData implements InstallDataInterface
class InitializeDefaultStock implements SchemaPatchInterface
{
/**
* @var CreateDefaultSource
Expand All @@ -36,47 +32,46 @@ class InstallData implements InstallDataInterface
*/
private $assignDefaultSourceToDefaultStock;

/**
* @var UpdateInventorySourceItem
*/
private $updateInventorySourceItem;

/**
* @var ReindexDefaultStock
*/
private $reindexDefaultStock;

/**
* @param CreateDefaultSource $createDefaultSource
* @param CreateDefaultStock $createDefaultStock
* @param AssignDefaultSourceToDefaultStock $assignDefaultSourceToDefaultStock
* @param UpdateInventorySourceItem $updateInventorySourceItem
* @param ReindexDefaultStock $reindexDefaultStock
*/
public function __construct(
CreateDefaultSource $createDefaultSource,
CreateDefaultStock $createDefaultStock,
AssignDefaultSourceToDefaultStock $assignDefaultSourceToDefaultStock,
UpdateInventorySourceItem $updateInventorySourceItem,
ReindexDefaultStock $reindexDefaultStock
AssignDefaultSourceToDefaultStock $assignDefaultSourceToDefaultStock
) {
$this->createDefaultSource = $createDefaultSource;
$this->createDefaultStock = $createDefaultStock;
$this->assignDefaultSourceToDefaultStock = $assignDefaultSourceToDefaultStock;
$this->updateInventorySourceItem = $updateInventorySourceItem;
$this->reindexDefaultStock = $reindexDefaultStock;
}

/**
* {@inheritdoc}
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
* @inheritDoc
*/
public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
public function apply()
{
$this->createDefaultSource->execute();
$this->createDefaultStock->execute();
$this->assignDefaultSourceToDefaultStock->execute();
$this->updateInventorySourceItem->execute($setup);
$this->reindexDefaultStock->execute();

return $this;
}

/**
* @inheritDoc
*/
public static function getDependencies()
{
return [];
}

/**
* @inheritDoc
*/
public function getAliases()
{
return [];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\InventoryCatalog\Setup\Patch\Schema;

use Magento\Framework\Setup\Patch\SchemaPatchInterface;
use Magento\InventoryCatalog\Setup\Operation\ReindexDefaultStock as Operation;

/**
* Patch Inventory Source Items with Inventory Stock Item Data
*/
class ReindexDefaultSource implements SchemaPatchInterface
{
/**
* @var Operation
*/
private $operation;

/**
* @param Operation $operation
*/
public function __construct(Operation $operation)
{
$this->operation = $operation;
}

/**
* @inheritDoc
*/
public function apply()
{
$this->operation->execute();

return $this;
}

/**
* @inheritDoc
*/
public static function getDependencies()
{
return [
UpdateInventorySourceItem::class
];
}

/**
* @inheritDoc
*/
public function getAliases()
{
return [];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\InventoryCatalog\Setup\Patch\Schema;

use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\Framework\Setup\Patch\SchemaPatchInterface;
use Magento\InventoryCatalog\Setup\Operation\UpdateInventorySourceItem as Operation;

/**
* Patch Inventory Source Items with Inventory Stock Item Data
*/
class UpdateInventorySourceItem implements SchemaPatchInterface
{
/**
* @var ModuleDataSetupInterface
*/
private $moduleDataSetup;

/**
* @var Operation
*/
private $operation;

/**
* @param ModuleDataSetupInterface $moduleDataSetup
* @param Operation $operation
*/
public function __construct(
ModuleDataSetupInterface $moduleDataSetup,
Operation $operation
) {
$this->moduleDataSetup = $moduleDataSetup;
$this->operation = $operation;
}

/**
* @inheritDoc
*/
public function apply()
{
$this->operation->execute($this->moduleDataSetup);

return $this;
}

/**
* @inheritDoc
*/
public static function getDependencies()
{
return [
InitializeDefaultStock::class,
];
}

/**
* @inheritDoc
*/
public function getAliases()
{
return [];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
use Magento\InventoryApi\Api\Data\SourceInterface;
use Magento\InventoryApi\Api\Data\SourceItemInterface;
use Magento\InventoryConfiguration\Model\GetAllowedProductTypesForSourceItemsInterface;
use Magento\InventoryLowQuantityNotification\Setup\Operation\CreateSourceConfigurationTable;
use Magento\InventoryLowQuantityNotificationApi\Api\Data\SourceItemConfigurationInterface;
use Psr\Log\LoggerInterface;

Expand Down Expand Up @@ -147,9 +146,7 @@ private function joinCatalogProduct()
*/
private function joinInventoryConfiguration()
{
$sourceItemConfigurationTable = $this->getTable(
CreateSourceConfigurationTable::TABLE_NAME_SOURCE_ITEM_CONFIGURATION
);
$sourceItemConfigurationTable = $this->getTable('inventory_low_stock_notification_configuration');

$this->getSelect()->joinInner(
['notification_configuration' => $sourceItemConfigurationTable],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
use Magento\Inventory\Model\ResourceModel\SourceItem;
use Magento\InventoryApi\Api\Data\SourceInterface;
use Magento\InventoryApi\Api\Data\SourceItemInterface;
use Magento\InventoryLowQuantityNotification\Setup\Operation\CreateSourceConfigurationTable;
use Magento\InventoryLowQuantityNotificationApi\Api\Data\SourceItemConfigurationInterface;

class ApplyBaseJoins
Expand All @@ -41,7 +40,7 @@ public function __construct(
*/
public function execute(Select $select)
{
$sourceItemConfigurationTable = CreateSourceConfigurationTable::TABLE_NAME_SOURCE_ITEM_CONFIGURATION;
$sourceItemConfigurationTable = 'inventory_low_stock_notification_configuration';
$configurationJoinCondition =
'source_item_config.' . SourceItemConfigurationInterface::SKU . ' = product.' . ProductInterface::SKU . ' '
. Select::SQL_AND
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
namespace Magento\InventoryLowQuantityNotification\Model\ResourceModel\SourceItemConfiguration;

use Magento\Framework\App\ResourceConnection;
use Magento\InventoryLowQuantityNotification\Setup\Operation\CreateSourceConfigurationTable;
use Magento\InventoryLowQuantityNotificationApi\Api\Data\SourceItemConfigurationInterface;

/**
Expand Down Expand Up @@ -39,7 +38,7 @@ public function execute(string $sourceCode, string $sku)
{
$connection = $this->resourceConnection->getConnection();
$sourceItemConfigurationTable = $this->resourceConnection
->getTableName(CreateSourceConfigurationTable::TABLE_NAME_SOURCE_ITEM_CONFIGURATION);
->getTableName('inventory_low_stock_notification_configuration');

$connection->delete($sourceItemConfigurationTable, [
SourceItemConfigurationInterface::SOURCE_CODE . ' = ?' => $sourceCode,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
namespace Magento\InventoryLowQuantityNotification\Model\ResourceModel\SourceItemConfiguration;

use Magento\Framework\App\ResourceConnection;
use Magento\InventoryLowQuantityNotification\Setup\Operation\CreateSourceConfigurationTable;
use Magento\InventoryLowQuantityNotificationApi\Api\Data\SourceItemConfigurationInterface;

/**
Expand Down Expand Up @@ -38,7 +37,7 @@ public function execute(string $sourceCode, string $sku)
{
$connection = $this->resourceConnection->getConnection();
$sourceItemConfigurationTable = $this->resourceConnection
->getTableName(CreateSourceConfigurationTable::TABLE_NAME_SOURCE_ITEM_CONFIGURATION);
->getTableName('inventory_low_stock_notification_configuration');

$select = $connection->select()
->from($sourceItemConfigurationTable)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
namespace Magento\InventoryLowQuantityNotification\Model\ResourceModel\SourceItemConfiguration;

use Magento\Framework\App\ResourceConnection;
use Magento\InventoryLowQuantityNotification\Setup\Operation\CreateSourceConfigurationTable;
use Magento\InventoryLowQuantityNotificationApi\Api\Data\SourceItemConfigurationInterface;

/**
Expand Down Expand Up @@ -42,7 +41,7 @@ public function execute(array $sourceItemConfigurations)
}
$connection = $this->resourceConnection->getConnection();
$tableName = $this->resourceConnection
->getTableName(CreateSourceConfigurationTable::TABLE_NAME_SOURCE_ITEM_CONFIGURATION);
->getTableName('inventory_low_stock_notification_configuration');

$columnsSql = $this->buildColumnsSqlPart([
SourceItemConfigurationInterface::SOURCE_CODE,
Expand Down
Loading

0 comments on commit 8c8cfa1

Please sign in to comment.