Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalidate indexers in RecurringData #26163

Closed
58 changes: 58 additions & 0 deletions app/code/Magento/Customer/Setup/Patch/Data/ReindexCustomerGrid.php
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.
*/

namespace Magento\Customer\Setup\Patch\Data;

use Magento\Customer\Model\Customer;
use Magento\Framework\Indexer\IndexerRegistry;
use Magento\Framework\Setup\Patch\DataPatchInterface;

/**
* Perform a full reindex to ensure the grid table exists
*/
class ReindexCustomerGrid implements DataPatchInterface
{
/**
* @var IndexerRegistry
*/
protected $indexerRegistry;

/**
* ReindexCustomerGrid constructor.
* @param IndexerRegistry $indexerRegistry
*/
public function __construct(
IndexerRegistry $indexerRegistry
) {
$this->indexerRegistry = $indexerRegistry;
}

/**
* @inheritDoc
*/
public function apply()
{
$indexer = $this->indexerRegistry->get(Customer::CUSTOMER_GRID_INDEXER_ID);
$indexer->reindexAll();
return $this;
}

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

/**
* @inheritDoc
*/
public function getAliases()
{
return [];
}
}
4 changes: 2 additions & 2 deletions app/code/Magento/Customer/Setup/RecurringData.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ public function __construct(IndexerRegistry $indexerRegistry)
}

/**
* {@inheritdoc}
* @inheritDoc
*/
public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
{
$indexer = $this->indexerRegistry->get(Customer::CUSTOMER_GRID_INDEXER_ID);
$indexer->reindexAll();
$indexer->invalidate();
}
}
58 changes: 58 additions & 0 deletions app/code/Magento/Theme/Setup/Patch/Data/ReindexConfigGrid.php
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.
*/

namespace Magento\Theme\Setup\Patch\Data;

use Magento\Framework\Indexer\IndexerRegistry;
use Magento\Framework\Setup\Patch\DataPatchInterface;
use Magento\Theme\Model\Data\Design\Config;

/**
* Perform a full reindex to ensure the grid table exists
*/
class ReindexConfigGrid implements DataPatchInterface
{
/**
* @var IndexerRegistry
*/
protected $indexerRegistry;

/**
* ReindexConfigGrid constructor
* @param IndexerRegistry $indexerRegistry
*/
public function __construct(
IndexerRegistry $indexerRegistry
) {
$this->indexerRegistry = $indexerRegistry;
}

/**
* @inheritDoc
*/
public function apply()
{
$indexer = $this->indexerRegistry->get(Config::DESIGN_CONFIG_GRID_INDEXER_ID);
$indexer->reindexAll();
return $this;
}

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

/**
* @inheritDoc
*/
public function getAliases()
{
return [];
}
}
4 changes: 2 additions & 2 deletions app/code/Magento/Theme/Setup/RecurringData.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ public function __construct(Registration $themeRegistration, IndexerRegistry $in
}

/**
* {@inheritdoc}
* @inheritDoc
*/
public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
{
$indexer = $this->indexerRegistry->get(Config::DESIGN_CONFIG_GRID_INDEXER_ID);
$indexer->reindexAll();
$indexer->invalidate();
$this->themeRegistration->register();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ private function getCustomerGridLockExpire(): ?string
* Test if customer account lock on too many failed authentication attempts triggers customer grid reindex
*
* @magentoDataFixture Magento/Customer/_files/customer.php
* @magentoDataFixture Magento/Customer/_files/customer_grid_indexer_ensure_valid.php
* @magentoAppIsolation enabled
* @magentoDbIsolation disabled
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\Customer\Setup;

use Magento\Customer\Model\Customer;
use Magento\Framework\Indexer\IndexerRegistry;
use Magento\Framework\Indexer\StateInterface;
use Magento\Framework\Shell;
use Magento\TestFramework\Helper\Bootstrap;

/**
* Integration test for recurring data setup task
*/
class UpgradeTest extends \PHPUnit\Framework\TestCase
{
/** @var \Magento\Indexer\Model\Indexer */
protected $indexer;

/** @var Shell */
protected $shell;

protected function setUp()
{
$objectManager = Bootstrap::getObjectManager();
$indexerRegistry = $objectManager->create(IndexerRegistry::class);
$this->indexer = $indexerRegistry->get(Customer::CUSTOMER_GRID_INDEXER_ID);
$this->shell = $objectManager->create(Shell::class);
}

/**
* Clean up shared dependencies
*/
protected function tearDown()
{
$this->indexer->reindexAll();
}

public function testSetupUpgrade()
{
$this->shell->execute(
PHP_BINARY . ' -f %s setup:upgrade',
[BP . '/bin/magento']
);

$this->assertSame(
StateInterface::STATUS_INVALID,
$this->indexer->getStatus()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,10 @@
$indexerRegistry = $objectManager->create(\Magento\Framework\Indexer\IndexerRegistry::class);
$indexer = $indexerRegistry->get(\Magento\Customer\Model\Customer::CUSTOMER_GRID_INDEXER_ID);
$indexer->setScheduled(true);

// Because integration tests don't run cron, we need to manually ensure the
// index isn't still invalid as that will cause asumptions in the tests to no
// longer hold.
if ($indexer->isInvalid()) {
$indexer->reindexAll();
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,10 @@
$indexerRegistry = $objectManager->create(\Magento\Framework\Indexer\IndexerRegistry::class);
$indexer = $indexerRegistry->get(\Magento\Customer\Model\Customer::CUSTOMER_GRID_INDEXER_ID);
$indexer->setScheduled(false);

// Because integration tests don't run cron, we need to manually ensure the
// index isn't still invalid as that will cause asumptions in the tests to no
// longer hold.
if ($indexer->isInvalid()) {
$indexer->reindexAll();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
/** @var Magento\Framework\Indexer\IndexerRegistry $indexerRegistry */
$indexerRegistry = $objectManager->create(\Magento\Framework\Indexer\IndexerRegistry::class);
$indexer = $indexerRegistry->get(\Magento\Customer\Model\Customer::CUSTOMER_GRID_INDEXER_ID);

// Because integration tests don't run cron, we need to manually ensure the
// index isn't still invalid as that will cause asumptions in the tests to no
// longer hold.
if ($indexer->isInvalid()) {
$indexer->reindexAll();
}