Server IP : 80.87.202.40 / Your IP : 216.73.216.169 Web Server : Apache System : Linux rospirotorg.ru 5.14.0-539.el9.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Dec 5 22:26:13 UTC 2024 x86_64 User : bitrix ( 600) PHP Version : 8.2.27 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /home/bitrix/ext_www/ilovecveti.ru/bitrix/modules/sproduction.datasync/lib/ |
Upload File : |
<?php /** * Datasync * * @mail support@s-production.online * @link s-production.online */ namespace SProduction\Datasync; \Bitrix\Main\Loader::includeModule("iblock"); \Bitrix\Main\Loader::includeModule("sale"); use Bitrix\Main, Bitrix\Main\Type, Bitrix\Main\Entity, Bitrix\Main\Localization\Loc, Bitrix\Main\SiteTable, Bitrix\Sale, Bitrix\Main\Engine\CurrentUser; Loc::loadMessages(__FILE__); class Controller { const MODULE_ID = 'sproduction.datasync'; const APP_HANDLER = '/bitrix/sprod_dsync_auth.php'; public static $SERVER_ADDR; protected static $MANUAL_RUN = false; public static function getServerAddr() { if (!self::$SERVER_ADDR) { self::$SERVER_ADDR = Settings::get("site"); } return self::$SERVER_ADDR; } public static function getAppLink() { $link = self::getServerAddr() . self::APP_HANDLER; return $link; } public static function setBulkRun() { self::$MANUAL_RUN = true; Rest::setBulkRun(); } public static function isBulkRun() { return self::$MANUAL_RUN; } /** * Sync by event of product created/updated */ public static function eventOnIBlockElementChanged(array $fields) { FileLog::setLabel(); if (! \Bitrix\Main\Loader::includeModule(self::MODULE_ID) || ! Rest::checkConnection() || ! CheckState::isSyncActive() || ! Settings::isAllowEventProcess(CurrentUser::get()->getId())) { return; } // Get product data $item_id = $fields['ID']; FileLog::put('(eventOnIBlockElementChanged) id ' . print_r($item_id, true)); FileLog::put('(eventOnIBlockElementChanged) fields ' . print_r($fields, true)); if ($item_id) { // // Protection against duplication // if ($is_new) { // FileLog::put('(eventOnProductChanged) new product ' . $product_id); // PortalAddLock::add($product_id); // } // Cache sync queries $queue = new StoreEventsQueue(); $queue->add($item_id); sleep(1); $products_ids = $queue->getAndClear(50); // Sync SyncPortal::syncProducts($products_ids); } } /** * -- OLD FUNCTION -- * Sync by event of product created/updated */ public static function eventOnProductChanged(\Bitrix\Main\Event $event) {} /** * Sync by event of product deleted */ public static function eventOnProductDelete(\Bitrix\Main\Event $event) { FileLog::setLabel(); if (! \Bitrix\Main\Loader::includeModule(self::MODULE_ID) || ! Rest::checkConnection() || ! CheckState::isSyncActive() || ! Settings::isAllowEventProcess(CurrentUser::get()->getId())) { return; } // Get product data $item_id = $event->getParameter("id"); $item_id = (is_array($item_id) && isset($item_id['ID'])) ? $item_id['ID'] : $item_id; FileLog::put('(eventOnProductDelete) id ' . print_r($item_id, true)); if ($item_id) { // TODO Cache sync queries //sleep(2); // Sync SyncPortal::deleteProducts([$item_id]); } } /** * Sync by event of product price updated */ public static function eventOnPriceChanged(\Bitrix\Main\Event $event) { FileLog::setLabel(); if (! \Bitrix\Main\Loader::includeModule(self::MODULE_ID) || ! Rest::checkConnection() || ! CheckState::isSyncActive() || ! Settings::isAllowEventProcess(CurrentUser::get()->getId())) { return; } // Get product data $fields = $event->getParameter("fields"); FileLog::put('(eventOnPriceChanged) fields ' . print_r($fields, true)); if (isset($fields['PRODUCT_ID']) && $fields['PRODUCT_ID']) { SyncPortal::syncPrices([$fields['PRODUCT_ID']]); } } /** * Sync by event of section created/updated */ public static function eventOnIBlockSectionChanged(array $fields) { FileLog::setLabel(); if (! \Bitrix\Main\Loader::includeModule(self::MODULE_ID) || ! Rest::checkConnection() || ! CheckState::isSyncActive() || ! Settings::isAllowEventProcess(CurrentUser::get()->getId())) { return; } // Get product data $item_id = $fields['ID'] ?? false; if ($item_id) { FileLog::put('(eventOnIBlockSectionChanged) id ' . print_r($item_id, true)); // // Protection against duplication // if ($is_new) { // FileLog::put('(eventOnIBlockSectionChanged) new product ' . $product_id); // PortalAddLock::add($product_id); // } // TODO Cache sync queries //sleep(2); // Sync SyncPortal::syncSections([$item_id]); } } /** * Sync by event of section deleted */ public static function eventOnIBlockSectionDelete(int $item_id) { FileLog::setLabel(); if (! \Bitrix\Main\Loader::includeModule(self::MODULE_ID) || ! Rest::checkConnection() || ! CheckState::isSyncActive() || ! Settings::isAllowEventProcess(CurrentUser::get()->getId())) { return; } // Get section data FileLog::put('(eventOnIBlockSectionDelete) id ' . print_r($item_id, true)); if ($item_id) { // TODO Cache sync queries //sleep(2); // Sync SyncPortal::deleteSections([$item_id]); } } }