<?php
IncludeModuleLangFile(__FILE__);
use Bitrix\Main\Loader;
use Bitrix\Main\Localization\Loc;
use Bitrix\Main\ModuleManager;
use Bitrix\Main\Config\Option;
use Bitrix\Main\EventManager;
\CModule::IncludeModule('iblock');
\CModule::IncludeModule('main');
class MyClass
{
// создаем обработчик события "OnAfterIBlockElementAdd"
function OnAfterIBlockElementAddHandler3(&$arFields)
{
file_put_contents($_SERVER['DOCUMENT_ROOT'].'/log_dev.txt', FILE.':'.LINE.PHP_EOL.print_r($arFields, true)."\n", FILE_APPEND);
}
}
class ulrusy_log extends CModule
{
var $MODULE_ID = 'ulrusy.log';
function __construct()
{
$arModuleVersion = array();
include(__DIR__.'/version.php');
$this->MODULE_ID = 'ulrusy.log';
$this->MODULE_VERSION = $arModuleVersion["VERSION"];
$this->MODULE_VERSION_DATE = $arModuleVersion["VERSION_DATE"];
$this->MODULE_NAME = GetMessage("ULRUSY_LOG_MODULE_NAME");
$this->MODULE_DESCRIPTION = GetMessage("ULRUSY_LOG_MODULE_DESCRIPTION");
$this->SHOW_SUPER_ADMIN_GROUP_RIGHTS = 'Y';
$this->MODULE_GROUP_RIGHTS = 'Y';
}
function DoInstall()
{
$this->InstallDB();
RegisterModule($this->MODULE_ID);
Loader::includeModule($this->MODULE_ID);
$GLOBALS['APPLICATION']->IncludeAdminFile(GetMessage("ULRUSY_LOG_INSTALL_TITLE"), $_SERVER["DOCUMENT_ROOT"]."/local/modules/ulrusy.log/install/step.php");
}
function DoUninstall()
{
global $DOCUMENT_ROOT, $APPLICATION;
if($_REQUEST["step"]<2)
{
$APPLICATION->IncludeAdminFile(GetMessage("ULRUSY_LOG_UNINSTALL_TITLE"), $DOCUMENT_ROOT."/local/modules/ulrusy.log/install/unstep1.php");
}
elseif($_REQUEST["step"]==2)
{
$this->UnInstallDB(array(
"savedata" => $_REQUEST["savedata"],
));
UnRegisterModule($this->MODULE_ID);
$APPLICATION->IncludeAdminFile(GetMessage("ULRUSY_LOG_UNINSTALL_TITLE"), $DOCUMENT_ROOT."/local/modules/ulrusy.log/install/unstep2.php");
}
}
function InstallDB()
{
global $APPLICATION, $DB;
if(!$DB->Query("SELECT '*' FROM b_ulrusy_log", true))
$DB->RunSQLBatch($_SERVER['DOCUMENT_ROOT']."/local/modules/ulrusy.log/install/db/".mb_strtolower($DB->type)."/install.sql");
$eventManager = EventManager::getInstance();
$eventManager->registerEventHandlerCompatible('iblock', 'OnAfterIBlockElementAdd', 'ulrusy.log', 'MyClass', 'OnAfterIBlockElementAddHandler3');
unset($eventManager);
return true;
}
function UnInstallDB($arParams = Array())
{
global $APPLICATION, $DB, $errors;
if ($arParams['savedata'])
{
$res = $DB->RunSQLBatch($_SERVER['DOCUMENT_ROOT']."/local/modules/ulrusy.log/install/db/mysql/uninstall.sql");
Option::delete($this->MODULE_ID);
}
$eventManager = EventManager::getInstance();
$eventManager->unRegisterEventHandler('iblock', 'OnAfterIBlockElementAdd', 'ulrusy.log', 'MyClass', 'OnAfterIBlockElementAddHandler3');
unset($eventManager);
return true;
}
}
<?php
......................
class red_october extends CModule
{
function installDB()
{
Loader::includeModule($this->MODULE_ID);
//Регистрация события
$eventManager = \Bitrix\Main\EventManager::getInstance();
$eventManager->registerEventHandlerCompatible(
'',
'DollarExchangeRateOnAfterUpdate',
'red.october',
'\\red\\october\\Events\\RecordDataFinalSellingPrice',
'RecordData'
);
...................
}
........................
function unInstallDB()
{
//Отмена регистрации события
$eventManager = \Bitrix\Main\EventManager::getInstance();
$eventManager->unRegisterEventHandler(
'',
'DollarExchangeRateOnBeforeUpdate',
'red.october',
'\\red\\october\\Events\\RecordDataFinalSellingPrice',
'RecordData'
);
}
}
?>
<?
namespace red\october\Events;
class RecordDataFinalSellingPrice
{
public static function RecordData($recordId)
{
\Bitrix\Main\Diag\Debug::writeToFile($recordId, $varName = __DIR__, $fileName = "/local/debug/debug.log");
}
}