Created
October 2, 2022 21:21
-
-
Save collymore/44e57696580b668f1cf6e4a49d4ede66 to your computer and use it in GitHub Desktop.
Reindexes Algolia products that have been modified since a specific date
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Magento\Framework\App\Bootstrap; | |
/** | |
* Reindexes Algolia products that have been modified since a specific date | |
*/ | |
require __DIR__ . '/../app/bootstrap.php'; | |
$bootstrap = Bootstrap::create(BP, $_SERVER); | |
$objectManager = $bootstrap->getObjectManager(); | |
$state = $objectManager->get('\Magento\Framework\App\State'); | |
$state->setAreaCode('adminhtml'); | |
$resource = $objectManager->get('Magento\Framework\App\ResourceConnection'); | |
$connection = $resource->getConnection(); | |
$algoliaDataHelper = $objectManager->get('Algolia\AlgoliaSearch\Helper\Data'); | |
$algoliaHelper = $objectManager->get('Algolia\AlgoliaSearch\Helper\AlgoliaHelper'); | |
$ten = []; | |
$count = 0; | |
********************** | |
/*** Config Values ***/ | |
********************** | |
* | |
* $emailToNotifiyOnComplete = ''; | |
* | |
* $dateSince = '2022-04-19 14:42:53'; | |
* $indexId = 1; | |
* $batchSize = 500; | |
* | |
*********************** | |
/*** !Config Values ***/ | |
*********************** | |
$query = "select * from catalog_product_entity where updated_at > '{$dateSince}' order by entity_id desc"; | |
$results = $connection->fetchAll($query); | |
$i = 0; | |
$algoliaEnable= []; | |
foreach($results as $prod ){ | |
$i++; | |
$algoliaEnable[] = $prod['entity_id']; | |
if($i % $batchSize == 0){ | |
$algoliaDataHelper->rebuildStoreProductIndex($indexId, $algoliaEnable); | |
$algoliaEnable = []; | |
$i = 0; | |
echo "\n Sent {$batchSize} : ".$i; | |
} | |
} | |
if(count($algoliaEnable) > 0){ | |
$algoliaDataHelper->rebuildStoreProductIndex($indexId, $algoliaEnable); | |
} | |
if($emailToNotifiyOnComplete){ | |
$resultsCount = $results; | |
mail($emailToNotifiyOnComplete, "Completed Algolia Indexing ID {$indexId} : {$resultsCount} Items"); | |
} | |
echo "done"; | |
die(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment