Skip to content

Instantly share code, notes, and snippets.

@bka
Created July 24, 2022 08:20
Show Gist options
  • Save bka/a4165b8c8bf8fd6b6778d49937012d5c to your computer and use it in GitHub Desktop.
Save bka/a4165b8c8bf8fd6b6778d49937012d5c to your computer and use it in GitHub Desktop.
<?php
/* Test script for reproducing https://github.com/magento/magento2/issues/35616
*
* 1. Mode of catalog_product_price indexer must be update by schedule.
*
* 2. Place this script into $MAGE_ROOT/scripts/index-buster.php
*
* 3. Execute it `php scripts/index-buster.php`. Do not terminate it. Wait for output to be ready.
*
* 4. In another terminal run `php bin/magento indexer:status` and confirm items in backlog
*
* e.g. idle (2604 in backlog)
*
* 5. Execute `php bin/magento cron:run --group index`
*
*/
require __DIR__ . '/../app/bootstrap.php';
$bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $_SERVER);
$app = $bootstrap->createApplication(\Magento\Framework\App\Http::class);
function getConnection() {
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$resource = $objectManager->get(\Magento\Framework\App\ResourceConnection::class);
$connection = $resource->getConnection();
return $connection;
}
function getPriceCount() {
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$resourceConnection = $objectManager->get(\Magento\Framework\App\ResourceConnection::class);
$connection = $resourceConnection->getConnection();
$result = [];
$result = $connection->fetchAll("SELECT count(*) as cnt FROM catalog_product_index_price;");
return $result[0]['cnt'];
}
function getProductCollection() {
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$productCollection = $objectManager->get(\Magento\Catalog\Model\ResourceModel\Product\Collection::class);
return $productCollection;
}
echo "Adding entity ids to changelog, please wait...\n";
foreach (getProductCollection() as $product) {
$productId = $product->getId();
getConnection()->insertMultiple("catalog_product_price_cl", ['entity_id' => $productId]);
}
echo "Ready, now watching count of catalog_product_index_price table...\n";
echo "You may now execute cron index process\n";
$currentCnt = 0;
while(true) {
$date = (new \DateTime('now'))->format('d/M/Y h:i:s.u');
$cnt = getPriceCount();
if ($cnt != $currentCnt) {
$str = $date . ": count changed from " . $currentCnt . " to " . $cnt . "\n";
echo $str;
}
$currentCnt = $cnt;
usleep(10);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment