Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
skudeferredcalculations.php
1<?php
2
4
8use Closure;
9
13trait SkuDeferredCalculations
14{
15 private static bool $isBackgroundJobAdded = false;
16
17 protected function isActionWithDefferedCalculation(Action $action): bool
18 {
19 $actions = [
20 'add',
21 'update',
22 'delete',
23 ];
24
25 return in_array($action->getName(), $actions, true);
26 }
27
35 final protected function processBeforeDeferredCalculationAction(): void
36 {
38 }
39
47 final protected function processAfterDeferredCalculationAction(): void
48 {
50 self::addBackgroundJob();
51 }
52
53 private static function addBackgroundJob(): void
54 {
55 if (self::$isBackgroundJobAdded)
56 {
57 return;
58 }
59 self::$isBackgroundJobAdded = true;
60
61 $callback = Closure::fromCallable([
62 Sku::class,
63 'calculate'
64 ]);
65
66 Application::getInstance()->addBackgroundJob($callback);
67 }
68}
static enableDeferredCalculation()
Definition sku.php:87
static disableDeferredCalculation()
Definition sku.php:97