117 lines
3.4 KiB
PHP
117 lines
3.4 KiB
PHP
<?php
|
|
|
|
use Bitrix\Main\EventManager;
|
|
use Bitrix\Main\Loader;
|
|
|
|
IncludeModuleLangFile(__FILE__);
|
|
|
|
class bx_nullable extends \CModule
|
|
{
|
|
public $module = [];
|
|
public $MODULE_GROUP_RIGHTS = 'Y';
|
|
|
|
public function __construct()
|
|
{
|
|
$module = [];
|
|
if (file_exists(__DIR__ . '/../.module.json')) {
|
|
$module = json_decode(file_get_contents(__DIR__ . '/../.module.json'), true);
|
|
}
|
|
|
|
$this->module = $module;
|
|
|
|
$this->MODULE_ID = $module['id'];
|
|
$this->MODULE_VERSION = $module['version'];
|
|
$this->MODULE_VERSION_DATE = $module['date'];
|
|
|
|
$langPrefix = $module['prefix'];
|
|
|
|
$this->PARTNER_NAME = GetMessage("{$langPrefix}_partner_name");
|
|
$this->PARTNER_URI = GetMessage("{$langPrefix}_partner_uri");
|
|
$this->MODULE_NAME = GetMessage("{$langPrefix}_module_name");
|
|
$this->MODULE_DESCRIPTION = GetMessage("{$langPrefix}_module_description");
|
|
}
|
|
|
|
|
|
public function DoInstall()
|
|
{
|
|
global $APPLICATION;
|
|
|
|
if (is_array($this->module['deps'])) {
|
|
foreach ($this->module['deps'] as $moduleId) {
|
|
if (!Loader::includeModule($moduleId)) {
|
|
$APPLICATION->ThrowException("Module {$moduleId} not installed!");
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
|
|
if (!(version_compare(PHP_VERSION, '8.0.0') >= 0)) {
|
|
$APPLICATION->ThrowException('Php version required more 8.0.0');
|
|
return false;
|
|
}
|
|
|
|
RegisterModule($this->MODULE_ID);
|
|
RegisterModuleDependences('main', 'OnPageStart', $this->MODULE_ID);
|
|
$this->InstallEvents();
|
|
$this->InstallCatalogExport();
|
|
|
|
|
|
return true;
|
|
}
|
|
|
|
public function DoUninstall()
|
|
{
|
|
global $APPLICATION;
|
|
UnRegisterModule($this->MODULE_ID);
|
|
UnRegisterModuleDependences('main', 'OnPageStart', $this->MODULE_ID, '', '');
|
|
$this->UnInstallEvents();
|
|
$this->UnInstallCatalogExport();
|
|
return true;
|
|
}
|
|
|
|
public function InstallCatalogExport()
|
|
{
|
|
if (is_dir(__DIR__ . '/catalog_export') && Loader::includeModule('catalog')) {
|
|
CopyDirFiles(__DIR__ . '/catalog_export', $_SERVER['DOCUMENT_ROOT'] . CATALOG_PATH2EXPORTS, true, true);
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public function UnInstallCatalogExport()
|
|
{
|
|
return true;
|
|
}
|
|
|
|
|
|
public function InstallEvents()
|
|
{
|
|
if (class_exists('\Bitrix\Main\EventManager')) {
|
|
$eventManager = EventManager::getInstance();
|
|
// $eventManager->registerEventHandler(
|
|
// 'main',
|
|
// 'OnPageStart',
|
|
// $this->MODULE_ID,
|
|
// 'Bx\Nullable\Handler\Handler',
|
|
// 'exec',
|
|
// 100
|
|
// );
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public function UnInstallEvents()
|
|
{
|
|
if (class_exists('\Bitrix\Main\EventManager')) {
|
|
$eventManager = \Bitrix\Main\EventManager::getInstance();
|
|
// $eventManager->unRegisterEventHandler(
|
|
// 'main',
|
|
// 'OnPageStart',
|
|
// $this->MODULE_ID,
|
|
// 'Bx\Nullable\Handler\Handler',
|
|
// 'exec'
|
|
// );
|
|
}
|
|
|
|
return true;
|
|
}
|
|
} |