diff --git a/Setup/UpgradeSchema.php b/Setup/UpgradeSchema.php index a3b605fa9..b0a314432 100644 --- a/Setup/UpgradeSchema.php +++ b/Setup/UpgradeSchema.php @@ -7,16 +7,34 @@ use Magento\Framework\App\Config\ConfigResource\ConfigInterface; use Magento\Framework\App\ProductMetadataInterface; use Magento\Framework\DB\Ddl\Table; +use Magento\Framework\Indexer\IndexerInterfaceFactory; +use Magento\Framework\Mview\View\SubscriptionFactory; use Magento\Framework\Setup\ModuleContextInterface; use Magento\Framework\Setup\SchemaSetupInterface; use Magento\Framework\Setup\UpgradeSchemaInterface; class UpgradeSchema implements UpgradeSchemaInterface { + /** + * @var ConfigInterface + */ private $config; + /** + * @var IndexerInterfaceFactory + */ + private $indexerFactory; + + /** + * @var ProductMetadataInterface + */ private $productMetadata; + /** + * @var SubscriptionFactory + */ + private $subscriptionFactory; + private $defaultConfigData = [ 'algoliasearch_credentials/credentials/enable_backend' => '1', 'algoliasearch_credentials/credentials/enable_frontend' => '1', @@ -242,10 +260,16 @@ class UpgradeSchema implements UpgradeSchemaInterface ], ]; - public function __construct(ConfigInterface $config, ProductMetadataInterface $productMetadata) - { + public function __construct( + ConfigInterface $config, + IndexerInterfaceFactory $indexerFactory, + ProductMetadataInterface $productMetadata, + SubscriptionFactory $subscriptionFactory + ) { $this->config = $config; + $this->indexerFactory = $indexerFactory; $this->productMetadata = $productMetadata; + $this->subscriptionFactory = $subscriptionFactory; $this->serializeDefaultArrayConfigData(); $this->mergeDefaultDataWithArrayData(); @@ -563,6 +587,20 @@ public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $con $connection->createTable($table); } + if (version_compare($context->getVersion(), '1.12.0', '<')) { + // @see \Magento\Framework\Mview\View::unsubscribe + /** @var \Magento\Framework\Indexer\IndexerInterface $indexer */ + $indexer = $this->indexerFactory->create()->load('algolia_products'); + $subscriptionInstance = $this->subscriptionFactory->create( + [ + 'view' => $indexer->getView(), + 'tableName' => 'catalog_product_index_price', + 'columnName' => 'entity_id', + ] + ); + $subscriptionInstance->remove(); + } + $setup->endSetup(); } diff --git a/etc/mview.xml b/etc/mview.xml index fc73c4a06..b968d66a9 100755 --- a/etc/mview.xml +++ b/etc/mview.xml @@ -35,7 +35,6 @@