From 459b2958a010a48b0b5fc6cd3fd40684c0676045 Mon Sep 17 00:00:00 2001 From: Bellord Date: Mon, 19 Oct 2026 21:50:19 +0300 Subject: [PATCH] fix --- default_config.php | 4 ++++ lib/Facade/DefaultServiceFacade.php | 2 +- lib/Handlers/SpiderHandler.php | 26 ++++++++++++++++++++++++++ 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/default_config.php b/default_config.php index a542cc8..51328a6 100644 --- a/default_config.php +++ b/default_config.php @@ -10,6 +10,7 @@ return [ 'catalog_group_id_list' => [], 'spider' => [ + 'code' => 'element', 'micro_task_period' => 60, 'expire' => 300, 'period' => 86400, @@ -79,5 +80,8 @@ return [ 'catalog:OnGetDiscountResult' => [ ['Bx\Discount\Handlers\CatalogDiscount', 'onGetDiscountResult'], ], + 'wt.core:OnAppSpiderListEnd' => [ + ['Bx\Discount\Handlers\SpiderHandler', 'clearCache'], + ], ] ]; \ No newline at end of file diff --git a/lib/Facade/DefaultServiceFacade.php b/lib/Facade/DefaultServiceFacade.php index 3503e28..b7b2fb8 100644 --- a/lib/Facade/DefaultServiceFacade.php +++ b/lib/Facade/DefaultServiceFacade.php @@ -15,7 +15,7 @@ class DefaultServiceFacade extends AFacade { return $this->app->container()->make(ElementSpider::class, [ discountApp()->module()->getId(), - 'element', + discountApp()->config('spider.code', 'element'), discountApp()->config('spider.micro_task_period', 60), discountApp()->config('spider.expire', 3600), discountApp()->config('spider.period', 86400), diff --git a/lib/Handlers/SpiderHandler.php b/lib/Handlers/SpiderHandler.php index fd74227..8599578 100644 --- a/lib/Handlers/SpiderHandler.php +++ b/lib/Handlers/SpiderHandler.php @@ -2,8 +2,34 @@ namespace Bx\Discount\Handlers; +use Bitrix\Main\Composite\Page; +use Bitrix\Main\Data\Cache; +use Wt\Core\Spiders\ListSpider; + class SpiderHandler { + /** + * Обработчик события OnAppSpiderListEnd + * + * @param ListSpider $listSpider + * @return bool|void Возвращаем false, если нужно прервать выполнение цикла событий + */ + public static function clearCache($listSpider) + { + if($listSpider->getCode() !== discountApp()->config('spider.code')){ + return; + } + + // 1. Очистка стандартного (неуправляемого) и управляемого кэша (Managed Cache) + $cache = Cache::createInstance(); + $cache->cleanDir(); + + // 4. Нормальная очистка композита (HTML) + if (class_exists('\Bitrix\Main\Composite\Page')) { + $page = Page::getInstance(); + $page->deleteAll(); + } + } public static function saleDiscountOnAfterAdd() {