diff --git a/admin/main/config.php b/admin/main/config.php index ce885d5..7972348 100644 --- a/admin/main/config.php +++ b/admin/main/config.php @@ -2,22 +2,22 @@ IncludeModuleLangFile(__FILE__); -return array( - 'MAIN' => array( +return [ + 'MAIN' => [ 'TITLE' => GetMessage('MAIN_OPTIONS_PARAMETERS'), 'THEME' => 'Y', - 'OPTIONS' => array( + 'OPTIONS' => [ - ), - ), - 'TEST' => array( + ], + ], + 'TEST' => [ 'TITLE' => 'test', - 'OPTIONS' => array( - 'TEST' => array( + 'OPTIONS' => [ + 'TEST' => [ 'TITLE' => 'test_setting', 'TYPE' => 'text', 'DEFAULT' => '', - ), - ), - ), -); \ No newline at end of file + ], + ], + ], +]; \ No newline at end of file diff --git a/admin/main/submenu/null_table/index.php b/admin/main/submenu/nullable_table/index.php similarity index 93% rename from admin/main/submenu/null_table/index.php rename to admin/main/submenu/nullable_table/index.php index 741a2d3..bba3249 100644 --- a/admin/main/submenu/null_table/index.php +++ b/admin/main/submenu/nullable_table/index.php @@ -7,7 +7,7 @@ use Wt\Core\Admin\TableAdminPage; require_once($_SERVER['DOCUMENT_ROOT'].'/bitrix/modules/main/include/prolog_admin.php'); /** - * @var $ormTable NullableTable + * @var NullableTable $ormTable */ $ormTable = resolve(NullableTable::class); diff --git a/admin/main/submenu/null_table/lang/ru/index.php b/admin/main/submenu/nullable_table/lang/ru/index.php similarity index 100% rename from admin/main/submenu/null_table/lang/ru/index.php rename to admin/main/submenu/nullable_table/lang/ru/index.php diff --git a/admin/main/submenu/null_table/menu.php b/admin/main/submenu/nullable_table/menu.php similarity index 100% rename from admin/main/submenu/null_table/menu.php rename to admin/main/submenu/nullable_table/menu.php diff --git a/admin/main/submenu/null_table/submenu/row/index.php b/admin/main/submenu/nullable_table/submenu/row/index.php similarity index 95% rename from admin/main/submenu/null_table/submenu/row/index.php rename to admin/main/submenu/nullable_table/submenu/row/index.php index 77caa45..c615f08 100644 --- a/admin/main/submenu/null_table/submenu/row/index.php +++ b/admin/main/submenu/nullable_table/submenu/row/index.php @@ -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_after.php'); /** - * @var $ormTable NullableTable + * @var NullableTable $ormTable */ $ormTable = resolve(NullableTable::class); diff --git a/admin/main/submenu/null_table/submenu/row/lang/ru/config.php b/admin/main/submenu/nullable_table/submenu/row/lang/ru/config.php similarity index 100% rename from admin/main/submenu/null_table/submenu/row/lang/ru/config.php rename to admin/main/submenu/nullable_table/submenu/row/lang/ru/config.php diff --git a/admin/main/submenu/null_table/submenu/row/menu.php b/admin/main/submenu/nullable_table/submenu/row/menu.php similarity index 100% rename from admin/main/submenu/null_table/submenu/row/menu.php rename to admin/main/submenu/nullable_table/submenu/row/menu.php diff --git a/clone.php b/clone.php index 4247e7c..47ab37a 100644 --- a/clone.php +++ b/clone.php @@ -9,13 +9,16 @@ $newPath = realpath($argv[1]); $newEntity = __getModuleEntity($newPath); $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; str_replace($exclude, $exclude, $d1, $cm); if($cm){ echo 'skip ' . $d1 . PHP_EOL; return; } + if(is_callable($handler)){ + call_user_func_array($handler, [$d1, &$d2]); + } if ( is_dir( $d1 ) ) { $d2 = mkdir_safe( $d2, $force ); if (!$d2) { @@ -24,7 +27,7 @@ function copy_folder_safe($d1, $d2, $upd = true, $force = true, $exclude = []) { $d = dir( $d1 ); while ( false !== ( $entry = $d->read() ) ) { 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(); } @@ -61,8 +64,8 @@ function fs_log($str) { fclose($log); } -function _fix($newPath, ModuleEntity $newEntity, ModuleEntity $nullableEntity){ - $d = new RecursiveDirectoryIterator( $newPath ); +function _fix(ModuleEntity $newEntity, ModuleEntity $nullableEntity){ + $d = new RecursiveDirectoryIterator( $newEntity->getPath() ); foreach( new RecursiveIteratorIterator( $d, 1 ) as $path ){ if( is_file( $path ) && str_ends_with($path, '.php')){ $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->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; if($orig_file != $new_file){ @@ -90,5 +100,13 @@ copy_folder_safe($nullableEntity->getPath(), $newEntity->getPath(), true, true, '.git', 'clone.php', '.module.json', -]); -_fix($newPath, $newEntity, $nullableEntity); +], function ($d1, &$d2) use ($nullableEntity, $newEntity){ + $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); diff --git a/install/index.php b/install/index.php index d546c5f..1e0c863 100644 --- a/install/index.php +++ b/install/index.php @@ -1,4 +1,4 @@ -module = $module; @@ -25,18 +25,18 @@ class bx_nullable extends \CModule $langPrefix = $module['prefix']; $this->PARTNER_NAME = GetMessage("{$langPrefix}_partner_name"); - $this->PARTNER_URI = GetMessage("{$langPrefix}_partner_uri"); + $this->PARTNER_URI = GetMessage("{$langPrefix}_partner_uri"); $this->MODULE_NAME = GetMessage("{$langPrefix}_module_name"); $this->MODULE_DESCRIPTION = GetMessage("{$langPrefix}_module_description"); } - function DoInstall() + public function DoInstall() { - global $DOCUMENT_ROOT, $APPLICATION; + global $APPLICATION; - if(is_array($this->module['deps'])){ - foreach ($this->module['deps'] as $moduleId){ + if (is_array($this->module['deps'])) { + foreach ($this->module['deps'] as $moduleId) { if (!\Bitrix\Main\Loader::includeModule($moduleId)) { $APPLICATION->ThrowException("Module {$moduleId} not installed!"); 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'); return false; } RegisterModule($this->MODULE_ID); - RegisterModuleDependences("main", "OnPageStart", $this->MODULE_ID); + RegisterModuleDependences('main', 'OnPageStart', $this->MODULE_ID); $this->InstallEvents(); $this->InstallCatalogExport(); @@ -58,37 +58,59 @@ class bx_nullable extends \CModule return true; } - function DoUninstall() + public function DoUninstall() { - global $DOCUMENT_ROOT, $APPLICATION; + global $APPLICATION; UnRegisterModule($this->MODULE_ID); - UnRegisterModuleDependences("main", "OnPageStart", $this->MODULE_ID, "", ""); + UnRegisterModuleDependences('main', 'OnPageStart', $this->MODULE_ID, '', ''); $this->UnInstallEvents(); $this->UnInstallCatalogExport(); return true; } - function InstallCatalogExport() + public function InstallCatalogExport() { - if(is_dir(__DIR__."/catalog_export") && \Bitrix\Main\Loader::includeModule('catalog')){ - CopyDirFiles(__DIR__."/catalog_export", $_SERVER["DOCUMENT_ROOT"].CATALOG_PATH2EXPORTS, true, true); + if (is_dir(__DIR__ . '/catalog_export') && \Bitrix\Main\Loader::includeModule('catalog')) { + CopyDirFiles(__DIR__ . '/catalog_export', $_SERVER['DOCUMENT_ROOT'] . CATALOG_PATH2EXPORTS, true, true); } return true; } - function UnInstallCatalogExport() + public function UnInstallCatalogExport() { 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; } - 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; } } \ No newline at end of file