|
| 1 | +--- Model/Indexer/Page.php 2019-02-20 11:46:32.000000000 +0300 |
| 2 | ++++ Model/Indexer/Page.php 2019-09-20 16:36:59.000000000 +0300 |
| 3 | +@@ -43,13 +43,9 @@ class Page implements Magento\Framework\ |
| 4 | + $this->output = $output; |
| 5 | + } |
| 6 | + |
| 7 | +- public function execute($ids) |
| 8 | ++ public function execute($ids) |
| 9 | + { |
| 10 | +- } |
| 11 | +- |
| 12 | +- public function executeFull() |
| 13 | +- { |
| 14 | +- if (!$this->configHelper->getApplicationID() |
| 15 | ++ if (!$this->configHelper->getApplicationID() |
| 16 | + || !$this->configHelper->getAPIKey() |
| 17 | + || !$this->configHelper->getSearchOnlyAPIKey()) { |
| 18 | + $errorMessage = 'Algolia reindexing failed: |
| 19 | +@@ -74,17 +70,29 @@ class Page implements Magento\Framework\ |
| 20 | + } |
| 21 | + |
| 22 | + if ($this->isPagesInAdditionalSections($storeId)) { |
| 23 | +- $this->queue->addToQueue($this->fullAction, 'rebuildStorePageIndex', ['store_id' => $storeId], 1); |
| 24 | ++ $this->queue->addToQueue( |
| 25 | ++ $this->fullAction, |
| 26 | ++ 'rebuildStorePageIndex', |
| 27 | ++ ['store_id' => $storeId, 'page_ids' => $ids], |
| 28 | ++ is_array($ids) ? count($ids) : 1 |
| 29 | ++ ); |
| 30 | + } |
| 31 | + } |
| 32 | + } |
| 33 | + |
| 34 | ++ public function executeFull() |
| 35 | ++ { |
| 36 | ++ $this->execute(null); |
| 37 | ++ } |
| 38 | ++ |
| 39 | + public function executeList(array $ids) |
| 40 | + { |
| 41 | ++ $this->execute($ids); |
| 42 | + } |
| 43 | + |
| 44 | + public function executeRow($id) |
| 45 | + { |
| 46 | ++ $this->execute([$id]); |
| 47 | + } |
| 48 | + |
| 49 | + private function isPagesInAdditionalSections($storeId) |
| 50 | +--- Model/Indexer/PageObserver.php 1970-01-01 03:00:00.000000000 +0300 |
| 51 | ++++ Model/Indexer/PageObserver.php 2019-09-20 16:42:26.000000000 +0300 |
| 52 | +@@ -0,0 +1,42 @@ |
| 53 | ++<?php |
| 54 | ++ |
| 55 | ++namespace Algolia\AlgoliaSearch\Model\Indexer; |
| 56 | ++ |
| 57 | ++use Magento\Framework\Indexer\IndexerRegistry; |
| 58 | ++use Magento\Framework\Model\AbstractModel; |
| 59 | ++ |
| 60 | ++class PageObserver |
| 61 | ++{ |
| 62 | ++ private $indexer; |
| 63 | ++ |
| 64 | ++ public function __construct(IndexerRegistry $indexerRegistry) |
| 65 | ++ { |
| 66 | ++ $this->indexer = $indexerRegistry->get('algolia_pages'); |
| 67 | ++ } |
| 68 | ++ |
| 69 | ++ public function beforeSave( |
| 70 | ++ \Magento\Cms\Model\ResourceModel\Page $pageResource, |
| 71 | ++ AbstractModel $page |
| 72 | ++ ) { |
| 73 | ++ $pageResource->addCommitCallback(function () use ($page) { |
| 74 | ++ if (!$this->indexer->isScheduled()) { |
| 75 | ++ $this->indexer->reindexRow($page->getId()); |
| 76 | ++ } |
| 77 | ++ }); |
| 78 | ++ |
| 79 | ++ return [$page]; |
| 80 | ++ } |
| 81 | ++ |
| 82 | ++ public function beforeDelete( |
| 83 | ++ \Magento\Cms\Model\ResourceModel\Page $pageResource, |
| 84 | ++ AbstractModel $page |
| 85 | ++ ) { |
| 86 | ++ $pageResource->addCommitCallback(function () use ($page) { |
| 87 | ++ if (!$this->indexer->isScheduled()) { |
| 88 | ++ $this->indexer->reindexRow($page->getId()); |
| 89 | ++ } |
| 90 | ++ }); |
| 91 | ++ |
| 92 | ++ return [$page]; |
| 93 | ++ } |
| 94 | ++} |
| 95 | +--- etc/di.xml 2019-02-20 11:46:32.000000000 +0300 |
| 96 | ++++ etc/di.xml 2019-09-20 16:43:43.000000000 +0300 |
| 97 | +@@ -1,5 +1,8 @@ |
| 98 | + <?xml version="1.0"?> |
| 99 | + <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"> |
| 100 | ++ <type name="Magento\Cms\Model\ResourceModel\Page"> |
| 101 | ++ <plugin name="algoliaPages" type="Algolia\AlgoliaSearch\Model\Indexer\PageObserver"/> |
| 102 | ++ </type> |
| 103 | + <type name="Magento\Catalog\Model\ResourceModel\Product"> |
| 104 | + <plugin name="algoliaProducts" type="Algolia\AlgoliaSearch\Model\Indexer\ProductObserver"/> |
| 105 | + </type> |
| 106 | +--- etc/mview.xml 2019-02-20 11:46:32.000000000 +0300 |
| 107 | ++++ etc/mview.xml 2019-09-20 16:44:50.000000000 +0300 |
| 108 | +@@ -3,6 +3,9 @@ |
| 109 | + <view id="algolia_suggestions" class="Algolia\AlgoliaSearch\Model\Indexer\Suggestion" group="indexer"> |
| 110 | + </view> |
| 111 | + <view id="algolia_pages" class="Algolia\AlgoliaSearch\Model\Indexer\Page" group="indexer"> |
| 112 | ++ <subscriptions> |
| 113 | ++ <table name="cms_page" entity_column="page_id" /> |
| 114 | ++ </subscriptions> |
| 115 | + </view> |
| 116 | + <view id="algolia_additional_sections" class="Algolia\AlgoliaSearch\Model\Indexer\Page" group="indexer"> |
| 117 | + </view> |
0 commit comments