fix
This commit is contained in:
+12
-12
@@ -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' => '',
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
+1
-1
@@ -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);
|
||||
|
||||
+1
-1
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
+37
-15
@@ -1,4 +1,4 @@
|
||||
<?
|
||||
<?php
|
||||
|
||||
use Bitrix\Main\EventManager;
|
||||
|
||||
@@ -9,7 +9,7 @@ class bx_nullable extends \CModule
|
||||
public $module = [];
|
||||
var $MODULE_GROUP_RIGHTS = 'Y';
|
||||
|
||||
function __construct()
|
||||
public function __construct()
|
||||
{
|
||||
$module = [];
|
||||
if (file_exists(__DIR__ . '/../.module.json')) {
|
||||
@@ -31,9 +31,9 @@ class bx_nullable extends \CModule
|
||||
}
|
||||
|
||||
|
||||
function DoInstall()
|
||||
public function DoInstall()
|
||||
{
|
||||
global $DOCUMENT_ROOT, $APPLICATION;
|
||||
global $APPLICATION;
|
||||
|
||||
if (is_array($this->module['deps'])) {
|
||||
foreach ($this->module['deps'] as $moduleId) {
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user