| Current Path : /var/www/homesaver/www/bitrix/install/ |
| Current File : /var/www/homesaver/www/bitrix/install/index.php |
<?php
CModule::IncludeModule('catalog');
class ofdferma extends CModule
{
var $MODULE_ID = 'ofdferma';
var $MODULE_VERSION;
var $MODULE_VERSION_DATE;
var $MODULE_NAME;
var $MODULE_DESCRIPTION;
var $MODULE_CSS;
function __construct()
{
$arModuleVersion = [];
$path = str_replace('\\', '/', __FILE__);
$path = substr($path, 0, strlen($path) - strlen('/index.php'));
include($path . '/version.php');
if (is_array($arModuleVersion) && array_key_exists('VERSION', $arModuleVersion)) {
$this->MODULE_VERSION = $arModuleVersion['VERSION'];
$this->MODULE_VERSION_DATE = $arModuleVersion['VERSION_DATE'];
}
$this->MODULE_NAME = 'OFD.ru Ferma';
$this->MODULE_DESCRIPTION = 'Модуль интеграции с сервисом Ferma от OFD.ru';
}
function GetModuleRightList()
{
// @todo
return [
'reference_id' => ['D', 'R'],
'reference' => [
'[D] Доступ закрыт',
'[R] Просмотр чеков',
],
];
}
function DoInstall()
{
global $DOCUMENT_ROOT, $APPLICATION;
$this->InstallDB();
$this->MigrateDB();
$this->insertMissedVatValues();
$this->InstallFiles();
$this->registerModule();
$APPLICATION->IncludeAdminFile('Установка модуля OFD.Ferma', $DOCUMENT_ROOT . '/bitrix/modules/ofdferma/install/step.php');
return true;
}
function DoUninstall()
{
global $DOCUMENT_ROOT, $APPLICATION;
$this->UninstallDB();
$this->UninstallFiles();
$this->unregisterModule();
$APPLICATION->IncludeAdminFile('Деинсталляция модуля OFD.Ferma', $DOCUMENT_ROOT . '/bitrix/modules/ofdferma/install/unstep.php');
return true;
}
private function registerModule()
{
// устанавливаем опцию обработки устаревших событий в интернет магазине
COption::SetOptionString('sale', 'EXPIRATION_PROCESSING_EVENTS', 'Y');
RegisterModuleDependences('sale', 'OnSalePayOrder', 'ofdferma', 'CMainOfdFerma', 'onSalePayOrder');
RegisterModuleDependences('sale', 'OnSalePayOrder', 'ofdferma', 'CMainOfdFerma', 'onSalePayCancelOrder');
RegisterModuleDependences('main', 'OnAdminListDisplay', 'ofdferma', 'CMainOfdFerma', 'onAdminListDisplay');
RegisterModuleDependences('main', 'OnAdminContextMenuShow', 'ofdferma', 'CMainOfdFerma', 'onAdminContextMenuShow');
RegisterModule($this->MODULE_ID);
}
private function unregisterModule()
{
// опицию не снимаем, т.к. это может привести к непредвиденным последствиям
// COption::SetOptionInt('sale', 'EXPIRATION_PROCESSING_EVENTS', 'N');
UnRegisterModuleDependences('sale', 'OnSalePayOrder', 'ofdferma', 'CMainOfdFerma', 'onSalePayOrder');
UnRegisterModuleDependences('sale', 'OnSalePayOrder', 'ofdferma', 'CMainOfdFerma', 'onSalePayCancelOrder');
UnRegisterModuleDependences('main', 'OnAdminListDisplay', 'ofdferma', 'CMainOfdFerma', 'onAdminListDisplay');
UnRegisterModuleDependences('main', 'OnAdminContextMenuShow', 'ofdferma', 'CMainOfdFerma', 'onAdminContextMenuShow');
UnRegisterModule($this->MODULE_ID);
}
public function InstallDB()
{
global $DB, $DBType, $APPLICATION;
if (!$DB->Query('SELECT \'x\' FROM b_ofdferma_receipt', true)) {
$errors = $DB->RunSQLBatch($_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/ofdferma/install/' . $DBType . '/install.sql');
}
if (!empty($errors)) {
$APPLICATION->ThrowException(implode('', $errors));
return false;
}
return true;
}
public function MigrateDB()
{
global $DB, $DBType, $APPLICATION;
if (!$DB->Query('SELECT \'x\' FROM b_ofdferma_receipt', true)) {
return;
}
// if (!$DB->Query('SELECT PAYMENT_METHOD FROM b_ofdferma_receipt limit 1', true)) {
// $errors = $DB->RunSQLBatch($_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/ofdferma/install/' . $DBType . '/migrate-231019.sql');
//
// if (!empty($errors)) {
// $APPLICATION->ThrowException(implode('', $errors));
//
// return false;
// }
// }
return true;
}
public function UninstallDB($arParams = [])
{
global $DB, $DBType, $APPLICATION;
if (array_key_exists('savedata', $arParams) && $arParams['savedata'] != 'Y') {
$errors = $DB->RunSQLBatch($_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/blog/install/' . $DBType . '/uninstall.sql');
if (!empty($errors)) {
$APPLICATION->ThrowException(implode('', $errors));
return false;
}
}
return true;
}
public function InstallFiles()
{
CopyDirFiles($_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/ofdferma/install/admin', $_SERVER['DOCUMENT_ROOT'] . '/bitrix/admin', true);
CopyDirFiles($_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/ofdferma/install/js', $_SERVER['DOCUMENT_ROOT'] . '/bitrix/js/ofdferma', true, true);
CopyDirFiles($_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/ofdferma/install/css', $_SERVER['DOCUMENT_ROOT'] . '/bitrix/css/ofdferma', true, true);
}
public function UninstallFiles()
{
DeleteDirFilesEx('/bitrix/js/ofdferma/');
DeleteDirFilesEx('/bitrix/css/ofdferma/');
DeleteDirFiles($_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/ofdferma/install/admin', $_SERVER['DOCUMENT_ROOT'] . '/bitrix/admin');
}
private function insertMissedVatValues()
{
$vatList = CCatalogVat::GetList();
$need = [
'Без НДС' => '0.00',
'НДС 0 %' => '0.00',
'НДС 10 %' => '10.00',
'НДС 20 %' => '20.00',
'Вычисленный НДС 10 %/110 %' => '11.00',
'Вычисленный НДС 20 %/120 %' => '24.00',
];
$exists = [];
while ($vat = $vatList->NavNext()) {
$exists[] = $vat['NAME'];
}
foreach ($need as $name => $rate) {
if (in_array($name, $exists, true)) {
continue;
}
CCatalogVat::Add([
'ACTIVE' => 'Y',
'C_SORT' => 500,
'NAME' => $name,
'RATE' => $rate,
]);
}
}
}