This commit is contained in:
2024-07-07 12:39:20 +03:00
parent 67484d79f9
commit d8b103fe33
29 changed files with 156 additions and 128 deletions
+43 -12
View File
@@ -1,32 +1,37 @@
<?php
use Wt\Core\App\ModuleEntity;
require './../wt.core/include.php';
$curPath = __DIR__;
$newPath = realpath($argv[1]);
$newEntity = __getModuleEntity($newPath);
$nullEntity = __getModuleEntity(__DIR__);
$nullableEntity = __getModuleEntity(__DIR__);
function copy_folder($d1, $d2, $upd = true, $force = true, $exclude = []) {
function copy_folder_safe($d1, $d2, $upd = true, $force = true, $exclude = []) {
$cm = 0;
str_replace($exclude, $exclude, $d1, $cm);
if($cm){
echo 'skip ' . $d1 . PHP_EOL;
return;
}
if ( is_dir( $d1 ) ) {
$d2 = mkdir_safe( $d2, $force );
if (!$d2) {
fs_log("!!fail $d2");
return;
}
$d = dir( $d1 );
while ( false !== ( $entry = $d->read() ) ) {
if ( $entry != '.' && $entry != '..' )
copy_folder( "$d1/$entry", "$d2/$entry", $upd, $force );
copy_folder_safe( "$d1/$entry", "$d2/$entry", $upd, $force, $exclude);
}
$d->close();
}
else {
$ok = copy_safe( $d1, $d2, $upd );
$ok = ($ok) ? "ok-- " : " -- ";
fs_log("{$ok}$d1");
}
} //function copy_folder
}
function mkdir_safe( $dir, $force ) {
if (file_exists($dir)) {
@@ -35,7 +40,7 @@ function mkdir_safe( $dir, $force ) {
unlink($dir);
}
return (mkdir($dir, 0777, true)) ? $dir : false;
} //function mkdir_safe
}
function copy_safe ($f1, $f2, $upd) {
$time1 = filemtime($f1);
@@ -46,18 +51,44 @@ function copy_safe ($f1, $f2, $upd) {
$ok = copy($f1, $f2);
if ($ok) touch($f2, $time1);
return $ok;
} //function copy_safe
}
function fs_log($str) {
return;
$log = fopen("./fs_log.txt", "a");
$time = date("Y-m-d H:i:s");
$log = fopen('./fs_log.txt', 'a');
$time = date('Y-m-d H:i:s');
fwrite($log, "$str ($time)\n");
fclose($log);
}
function _fix($newPath, ModuleEntity $newEntity, ModuleEntity $nullableEntity){
$d = new RecursiveDirectoryIterator( $newPath );
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->fields()->id, $newEntity->fields()->id, $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);
echo $cr . ' ' .$path . PHP_EOL;
if($orig_file != $new_file){
file_put_contents($path, $new_file);
}
}
}
}
echo $newEntity->getId() . PHP_EOL;
copy_folder($nullEntity->getDir(), $newEntity->getDir());
copy_folder_safe($nullableEntity->getPath(), $newEntity->getPath(), true, true, [
'.git',
'clone.php',
'.module.json',
]);
_fix($newPath, $newEntity, $nullableEntity);