feat: add AdminSearchController for AJAX search functionality
This commit is contained in:
44
override/controllers/admin/AdminSearchController.php
Normal file
44
override/controllers/admin/AdminSearchController.php
Normal 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,
|
||||
]));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user