This commit is contained in:
2024-10-06 23:09:22 +03:00
parent d8b103fe33
commit af604aa607
9 changed files with 80 additions and 40 deletions
+12 -12
View File
@@ -2,22 +2,22 @@
IncludeModuleLangFile(__FILE__); IncludeModuleLangFile(__FILE__);
return array( return [
'MAIN' => array( 'MAIN' => [
'TITLE' => GetMessage('MAIN_OPTIONS_PARAMETERS'), 'TITLE' => GetMessage('MAIN_OPTIONS_PARAMETERS'),
'THEME' => 'Y', 'THEME' => 'Y',
'OPTIONS' => array( 'OPTIONS' => [
), ],
), ],
'TEST' => array( 'TEST' => [
'TITLE' => 'test', 'TITLE' => 'test',
'OPTIONS' => array( 'OPTIONS' => [
'TEST' => array( 'TEST' => [
'TITLE' => 'test_setting', 'TITLE' => 'test_setting',
'TYPE' => 'text', 'TYPE' => 'text',
'DEFAULT' => '', 'DEFAULT' => '',
), ],
), ],
), ],
); ];
@@ -7,7 +7,7 @@ use Wt\Core\Admin\TableAdminPage;
require_once($_SERVER['DOCUMENT_ROOT'].'/bitrix/modules/main/include/prolog_admin.php'); require_once($_SERVER['DOCUMENT_ROOT'].'/bitrix/modules/main/include/prolog_admin.php');
/** /**
* @var $ormTable NullableTable * @var NullableTable $ormTable
*/ */
$ormTable = resolve(NullableTable::class); $ormTable = resolve(NullableTable::class);
@@ -7,7 +7,7 @@ use Wt\Core\Admin\TableRowAdminPage;
require_once($_SERVER['DOCUMENT_ROOT'].'/bitrix/modules/main/include/prolog_admin_before.php'); require_once($_SERVER['DOCUMENT_ROOT'].'/bitrix/modules/main/include/prolog_admin_before.php');
require_once($_SERVER['DOCUMENT_ROOT'].'/bitrix/modules/main/include/prolog_admin_after.php'); require_once($_SERVER['DOCUMENT_ROOT'].'/bitrix/modules/main/include/prolog_admin_after.php');
/** /**
* @var $ormTable NullableTable * @var NullableTable $ormTable
*/ */
$ormTable = resolve(NullableTable::class); $ormTable = resolve(NullableTable::class);
+24 -6
View File
@@ -9,13 +9,16 @@ $newPath = realpath($argv[1]);
$newEntity = __getModuleEntity($newPath); $newEntity = __getModuleEntity($newPath);
$nullableEntity = __getModuleEntity(__DIR__); $nullableEntity = __getModuleEntity(__DIR__);
function copy_folder_safe($d1, $d2, $upd = true, $force = true, $exclude = []) { function copy_folder_safe($d1, $d2, $upd = true, $force = true, $exclude = [], $handler = null) {
$cm = 0; $cm = 0;
str_replace($exclude, $exclude, $d1, $cm); str_replace($exclude, $exclude, $d1, $cm);
if($cm){ if($cm){
echo 'skip ' . $d1 . PHP_EOL; echo 'skip ' . $d1 . PHP_EOL;
return; return;
} }
if(is_callable($handler)){
call_user_func_array($handler, [$d1, &$d2]);
}
if ( is_dir( $d1 ) ) { if ( is_dir( $d1 ) ) {
$d2 = mkdir_safe( $d2, $force ); $d2 = mkdir_safe( $d2, $force );
if (!$d2) { if (!$d2) {
@@ -24,7 +27,7 @@ function copy_folder_safe($d1, $d2, $upd = true, $force = true, $exclude = []) {
$d = dir( $d1 ); $d = dir( $d1 );
while ( false !== ( $entry = $d->read() ) ) { while ( false !== ( $entry = $d->read() ) ) {
if ( $entry != '.' && $entry != '..' ) if ( $entry != '.' && $entry != '..' )
copy_folder_safe( "$d1/$entry", "$d2/$entry", $upd, $force, $exclude); copy_folder_safe( "$d1/$entry", "$d2/$entry", $upd, $force, $exclude, $handler);
} }
$d->close(); $d->close();
} }
@@ -61,8 +64,8 @@ function fs_log($str) {
fclose($log); fclose($log);
} }
function _fix($newPath, ModuleEntity $newEntity, ModuleEntity $nullableEntity){ function _fix(ModuleEntity $newEntity, ModuleEntity $nullableEntity){
$d = new RecursiveDirectoryIterator( $newPath ); $d = new RecursiveDirectoryIterator( $newEntity->getPath() );
foreach( new RecursiveIteratorIterator( $d, 1 ) as $path ){ foreach( new RecursiveIteratorIterator( $d, 1 ) as $path ){
if( is_file( $path ) && str_ends_with($path, '.php')){ if( is_file( $path ) && str_ends_with($path, '.php')){
$orig_file = file_get_contents($path); $orig_file = file_get_contents($path);
@@ -74,6 +77,13 @@ function _fix($newPath, ModuleEntity $newEntity, ModuleEntity $nullableEntity){
$new_file = str_replace($nullableEntity->fields()->prefix, $newEntity->fields()->prefix, $new_file, $cr); $new_file = str_replace($nullableEntity->fields()->prefix, $newEntity->fields()->prefix, $new_file, $cr);
$new_file = str_replace($nullableEntity->getNamespace(), $newEntity->getNamespace(), $new_file, $cr); $new_file = str_replace($nullableEntity->getNamespace(), $newEntity->getNamespace(), $new_file, $cr);
$lastModuleName = collect(explode('.', $newEntity->fields()->id))->last();
$lastNullableModuleName = collect(explode('.', $nullableEntity->fields()->id))->last();
$new_file = str_replace(ucfirst($lastNullableModuleName), ucfirst($lastModuleName), $new_file, $cr);
$new_file = str_replace(strtolower($lastNullableModuleName), strtolower($lastModuleName), $new_file, $cr);
echo $cr . ' ' .$path . PHP_EOL; echo $cr . ' ' .$path . PHP_EOL;
if($orig_file != $new_file){ if($orig_file != $new_file){
@@ -90,5 +100,13 @@ copy_folder_safe($nullableEntity->getPath(), $newEntity->getPath(), true, true,
'.git', '.git',
'clone.php', 'clone.php',
'.module.json', '.module.json',
]); ], function ($d1, &$d2) use ($nullableEntity, $newEntity){
_fix($newPath, $newEntity, $nullableEntity); $lastModuleName = collect(explode('.', $newEntity->fields()->id))->last();
$lastNullableModuleName = collect(explode('.', $nullableEntity->fields()->id))->last();
$d2 = str_replace(ucfirst($lastNullableModuleName), ucfirst($lastModuleName), $d2, $cr);
$d2 = str_replace(strtolower($lastNullableModuleName), strtolower($lastModuleName), $d2, $cr);
});
_fix($newEntity, $nullableEntity);
+41 -19
View File
@@ -1,4 +1,4 @@
<? <?php
use Bitrix\Main\EventManager; use Bitrix\Main\EventManager;
@@ -9,11 +9,11 @@ class bx_nullable extends \CModule
public $module = []; public $module = [];
var $MODULE_GROUP_RIGHTS = 'Y'; var $MODULE_GROUP_RIGHTS = 'Y';
function __construct() public function __construct()
{ {
$module = []; $module = [];
if(file_exists(__DIR__.'/../.module.json')){ if (file_exists(__DIR__ . '/../.module.json')) {
$module = json_decode(file_get_contents(__DIR__.'/../.module.json'), true); $module = json_decode(file_get_contents(__DIR__ . '/../.module.json'), true);
} }
$this->module = $module; $this->module = $module;
@@ -31,12 +31,12 @@ class bx_nullable extends \CModule
} }
function DoInstall() public function DoInstall()
{ {
global $DOCUMENT_ROOT, $APPLICATION; global $APPLICATION;
if(is_array($this->module['deps'])){ if (is_array($this->module['deps'])) {
foreach ($this->module['deps'] as $moduleId){ foreach ($this->module['deps'] as $moduleId) {
if (!\Bitrix\Main\Loader::includeModule($moduleId)) { if (!\Bitrix\Main\Loader::includeModule($moduleId)) {
$APPLICATION->ThrowException("Module {$moduleId} not installed!"); $APPLICATION->ThrowException("Module {$moduleId} not installed!");
return false; return false;
@@ -44,13 +44,13 @@ class bx_nullable extends \CModule
} }
} }
if (!CheckVersion(PHP_VERSION, "5.4.0")) { if (!CheckVersion(PHP_VERSION, '5.4.0')) {
$APPLICATION->ThrowException('Php version required more 5.4.0'); $APPLICATION->ThrowException('Php version required more 5.4.0');
return false; return false;
} }
RegisterModule($this->MODULE_ID); RegisterModule($this->MODULE_ID);
RegisterModuleDependences("main", "OnPageStart", $this->MODULE_ID); RegisterModuleDependences('main', 'OnPageStart', $this->MODULE_ID);
$this->InstallEvents(); $this->InstallEvents();
$this->InstallCatalogExport(); $this->InstallCatalogExport();
@@ -58,37 +58,59 @@ class bx_nullable extends \CModule
return true; return true;
} }
function DoUninstall() public function DoUninstall()
{ {
global $DOCUMENT_ROOT, $APPLICATION; global $APPLICATION;
UnRegisterModule($this->MODULE_ID); UnRegisterModule($this->MODULE_ID);
UnRegisterModuleDependences("main", "OnPageStart", $this->MODULE_ID, "", ""); UnRegisterModuleDependences('main', 'OnPageStart', $this->MODULE_ID, '', '');
$this->UnInstallEvents(); $this->UnInstallEvents();
$this->UnInstallCatalogExport(); $this->UnInstallCatalogExport();
return true; return true;
} }
function InstallCatalogExport() public function InstallCatalogExport()
{ {
if(is_dir(__DIR__."/catalog_export") && \Bitrix\Main\Loader::includeModule('catalog')){ if (is_dir(__DIR__ . '/catalog_export') && \Bitrix\Main\Loader::includeModule('catalog')) {
CopyDirFiles(__DIR__."/catalog_export", $_SERVER["DOCUMENT_ROOT"].CATALOG_PATH2EXPORTS, true, true); CopyDirFiles(__DIR__ . '/catalog_export', $_SERVER['DOCUMENT_ROOT'] . CATALOG_PATH2EXPORTS, true, true);
} }
return true; return true;
} }
function UnInstallCatalogExport() public function UnInstallCatalogExport()
{ {
return true; return true;
} }
function InstallEvents() 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; return true;
} }
function UnInstallEvents() 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; return true;
} }
} }