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; else if (!$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->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); $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){ file_put_contents($path, $new_file); } } } } echo $newEntity->getId() . PHP_EOL; copy_folder_safe($nullableEntity->getPath(), $newEntity->getPath(), true, true, [ '.git', 'clone.php', '.module.json', ], 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);