feat: add AdminSearchController for AJAX search functionality

This commit is contained in:
2026-02-23 21:16:41 +01:00
parent 9f0e3e6b45
commit b4d95c54c4

View File

@@ -0,0 +1,44 @@
<?php
class AdminSearchController extends AdminSearchControllerCore
{
public function displayAjaxSearchCron()
{
if (!Tools::getValue('id_shop')) {
Context::getContext()->shop->setContext(Shop::CONTEXT_ALL);
} else {
Context::getContext()->shop->setContext(Shop::CONTEXT_SHOP, (int) Tools::getValue('id_shop'));
}
ini_set('max_execution_time', 7200);
$full = (bool) Tools::getValue('full');
$start = microtime(true);
$countBefore = (int) Db::getInstance()->getValue(
'SELECT COUNT(*) FROM `' . _DB_PREFIX_ . 'search_index`'
);
Search::indexation($full);
$countAfter = (int) Db::getInstance()->getValue(
'SELECT COUNT(*) FROM `' . _DB_PREFIX_ . 'search_index`'
);
$elapsed = round(microtime(true) - $start, 2);
if (Tools::getValue('redirect')) {
Tools::redirectAdmin($_SERVER['HTTP_REFERER'] . '&conf=4');
}
header('Content-Type: application/json');
die(json_encode([
'success' => true,
'mode' => $full ? 'full' : 'missing',
'index_entries_before' => $countBefore,
'index_entries_after' => $countAfter,
'entries_added' => $countAfter - $countBefore,
'elapsed_seconds' => $elapsed,
]));
}
}