@@ -362,6 +362,57 @@ public static function upgradeXmlFiles(): void
362362 }
363363 }
364364
365+ public static function upgradeIniFile (): void
366+ {
367+ $ iniFile = 'facturascripts.ini ' ;
368+
369+ // verificamos que el archivo existe
370+ if (false === file_exists ($ iniFile )) {
371+ echo "* No se encontró el archivo facturascripts.ini. \n" ;
372+ return ;
373+ }
374+
375+ // leemos el contenido del archivo
376+ $ fileContent = file_get_contents ($ iniFile );
377+
378+ // parseamos el archivo ini para obtener los valores actuales
379+ $ iniArray = parse_ini_file ($ iniFile );
380+
381+ // verificamos si ya tiene min_version definido
382+ if (isset ($ iniArray ['min_version ' ])) {
383+ $ currentMinVersion = (float ) $ iniArray ['min_version ' ];
384+
385+ // si ya es 2025 o superior, no hacemos nada
386+ if ($ currentMinVersion >= 2025 ) {
387+ echo "* facturascripts.ini ya tiene min_version = " . $ currentMinVersion . " (no requiere actualización). \n" ;
388+ return ;
389+ }
390+ }
391+
392+ // actualizamos min_version a 2025
393+ $ pattern = '/^(\s*min_version\s*=\s*)[\d\.]+(.*)$/m ' ;
394+ if (preg_match ($ pattern , $ fileContent )) {
395+ // si existe min_version, lo reemplazamos
396+ $ newContent = preg_replace ($ pattern , '${1}2025${2} ' , $ fileContent );
397+ } else {
398+ // si no existe min_version, lo agregamos después de version
399+ $ versionPattern = '/^(\s*version\s*=\s*[\d\.]+.*\n)/m ' ;
400+ if (preg_match ($ versionPattern , $ fileContent )) {
401+ $ newContent = preg_replace ($ versionPattern , '${1}min_version = 2025 ' . "\n" , $ fileContent );
402+ } else {
403+ // si no hay version, agregamos al final
404+ $ newContent = rtrim ($ fileContent ) . "\nmin_version = 2025 \n" ;
405+ }
406+ }
407+
408+ // guardamos el archivo actualizado
409+ if (file_put_contents ($ iniFile , $ newContent )) {
410+ echo '* ' . $ iniFile . self ::OK ;
411+ } else {
412+ echo "* Error al actualizar el archivo " . $ iniFile . "\n" ;
413+ }
414+ }
415+
365416 private static function getFilesByExtension (string $ folder , string $ extension , &$ files = array ()): array
366417 {
367418 // obtenemos la lista de archivos y carpetas
0 commit comments