This commit is contained in:
Bellord
2026-06-03 11:11:05 +03:00
parent 207d793b07
commit 47271d9413
9 changed files with 130 additions and 9 deletions
+1 -1
View File
@@ -4,6 +4,6 @@
"namespace": "Bx\\Nullable", "namespace": "Bx\\Nullable",
"gitUrl": "https://bitbucket.org/bellord13/bx.null/", "gitUrl": "https://bitbucket.org/bellord13/bx.null/",
"version": "1.0.0", "version": "1.0.0",
"date": "2025-01-01 00:00:00", "date": "2026-01-01 00:00:00",
"deps": ["wt.core"] "deps": ["wt.core"]
} }
+1 -1
View File
@@ -1,2 +1,2 @@
<? <?php
$MESS['MAIN_OPTIONS_PARAMETERS'] = 'Общие'; $MESS['MAIN_OPTIONS_PARAMETERS'] = 'Общие';
@@ -1,2 +1,2 @@
<? <?php
$MESS['CONTEXT_PROFILE_DELETE_CONFIRM'] = 'Удалить %s?'; $MESS['CONTEXT_PROFILE_DELETE_CONFIRM'] = 'Удалить %s?';
@@ -3,7 +3,6 @@
use Bx\Nullable\ORM\NullableTable; use Bx\Nullable\ORM\NullableTable;
use Wt\Core\Admin\TableRowAdminPage; 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');
/** /**
@@ -15,6 +14,4 @@ $AdminPageTableRow = new TableRowAdminPage($ormTable, $_REQUEST, '/bitrix/admin/
$AdminPageTableRow->checkPermission(); $AdminPageTableRow->checkPermission();
$AdminPageTableRow->start(); $AdminPageTableRow->start();
\CJSCore::Init('jquery');
require_once($_SERVER['DOCUMENT_ROOT'].'/bitrix/modules/main/include/epilog_admin.php'); require_once($_SERVER['DOCUMENT_ROOT'].'/bitrix/modules/main/include/epilog_admin.php');
@@ -1,2 +1,2 @@
<? <?php
$MESS['MAIN_OPTIONS_PARAMETERS'] = 'Общие'; $MESS['MAIN_OPTIONS_PARAMETERS'] = 'Общие';
@@ -1,2 +1,2 @@
<? <?php
$MESS['CONTEXT_PROFILE_DELETE_CONFIRM'] = 'Удалить %s?'; $MESS['CONTEXT_PROFILE_DELETE_CONFIRM'] = 'Удалить %s?';
+2
View File
@@ -108,6 +108,8 @@ copy_folder_safe($nullableEntity->getPath(), $newEntity->getPath(), true, true,
'/\.module\.json/', '/\.module\.json/',
'/clone\.php/', '/clone\.php/',
'/readme\.md/', '/readme\.md/',
'/src\/\.env$/',
'/src\/config\.php$/',
], function ($d1, &$d2) use ($nullableEntity, $newEntity){ ], function ($d1, &$d2) use ($nullableEntity, $newEntity){
$lastModuleName = collect(explode('.', $newEntity->fields()->id))->last(); $lastModuleName = collect(explode('.', $newEntity->fields()->id))->last();
$lastNullableModuleName = collect(explode('.', $nullableEntity->fields()->id))->last(); $lastNullableModuleName = collect(explode('.', $nullableEntity->fields()->id))->last();
+122
View File
@@ -0,0 +1,122 @@
<?php
use Wt\Core\App\ModuleEntity;
require './../wt.core/include.php';
$curPath = __DIR__;
$newPath = realpath($argv[1]);
$newEntity = __getModuleEntity($newPath);
$nullableEntity = __getModuleEntity(__DIR__);
function copy_folder_safe($d1, $d2, $upd = true, $force = true, $exclude = [], $handler = null) {
$cm = 0;
preg_filter($exclude, $exclude, $d1, -1, $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) {
return;
}
$d = dir( $d1 );
while ( false !== ( $entry = $d->read() ) ) {
if ( $entry != '.' && $entry != '..' )
copy_folder_safe( "$d1/$entry", "$d2/$entry", $upd, $force, $exclude, $handler);
}
$d->close();
}
else {
$ok = copy_safe( $d1, $d2, $upd );
}
}
function mkdir_safe( $dir, $force ) {
if (file_exists($dir)) {
if (is_dir($dir)) return $dir;
elseif (!$force) return false;
unlink($dir);
}
return (mkdir($dir, 0777, true)) ? $dir : false;
}
function copy_safe ($f1, $f2, $upd) {
$time1 = filemtime($f1);
if (file_exists($f2)) {
$time2 = filemtime($f2);
if ($time2 >= $time1 && $upd) return false;
}
$ok = copy($f1, $f2);
if ($ok) touch($f2, $time1);
return $ok;
}
function fs_log($str) {
return;
$log = fopen('./fs_log.txt', 'a');
$time = date('Y-m-d H:i:s');
fwrite($log, "$str ($time)\n");
fclose($log);
}
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);
$new_file = $orig_file;
$cr = 0;
$new_file = str_replace($nullableEntity->getLangPrefix(), $newEntity->getLangPrefix(), $new_file, $cr);
$new_file = str_replace($nullableEntity->getId(), $newEntity->getId(), $new_file, $cr);
$new_file = str_replace($nullableEntity->getPrefix(), $newEntity->getPrefix(), $new_file, $cr);
$new_file = str_replace($nullableEntity->getNamespace(), $newEntity->getNamespace(), $new_file, $cr);
$new_file = str_replace(
ucfirst($nullableEntity->getProductCode()) . ': ' . ucfirst($nullableEntity->getProductCode()),
ucfirst($newEntity->getProductCode()) . ': ' . ucfirst($newEntity->getProductCode()),
$new_file,
$cr
);
$new_file = str_replace(ucfirst($nullableEntity->getProductCode()), ucfirst($newEntity->getProductCode()), $new_file, $cr);
$new_file = str_replace(ucfirst($nullableEntity->getCompanyCode()), ucfirst($newEntity->getCompanyCode()), $new_file, $cr);
$new_file = str_replace($nullableEntity->getProductCode(), $newEntity->getProductCode(), $new_file, $cr);
$new_file = str_replace($nullableEntity->getCompanyCode(), $newEntity->getCompanyCode(), $new_file, $cr);
echo $cr . ' ' .$path . PHP_EOL;
if($orig_file != $new_file){
file_put_contents($path, $new_file);
}
}
}
}
echo $newEntity->getId() . PHP_EOL;
copy_folder_safe($nullableEntity->getPath(), $newEntity->getPath(), true, true, [
'/\.git$/',
'/\.module\.json/',
'/clone\.php/',
'/readme\.md/',
'/src\/\.env$/',
'/src\/config\.php$/',
], 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);
+1 -1
View File
@@ -1,3 +1,3 @@
1) создаем папку с модулем 1) создаем папку с модулем
2) копируем и конфигурируем файл .module.json 2) копируем и конфигурируем файл .module.json
3) запускаем php -f clone.php ./path_to_new_module 3) запускаем php -f clone.php ../path_to_new_module