Skip to content

Commit 361e5f0

Browse files
author
Carlos Garcia
committed
feat: add upgradeIniFile method to FileUpdater for updating min_version in facturascripts.ini
1 parent 9386c19 commit 361e5f0

File tree

3 files changed

+54
-2
lines changed

3 files changed

+54
-2
lines changed

fsmaker.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -790,6 +790,7 @@ private function upgradeAction(): void
790790
FileUpdater::upgradePhpFiles();
791791
FileUpdater::upgradeXmlFiles();
792792
FileUpdater::upgradeTwigFiles();
793+
FileUpdater::upgradeIniFile();
793794
}
794795
}
795796

samples/facturascripts.ini.sample

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
name = '[[NAME]]'
22
description = '[[NAME]]'
33
version = 0.1
4-
min_version = 2024.93
4+
min_version = 2025
55

66
;Campos opcionales:
7-
;min_php = 7.4
7+
;min_php = 8.2
88
;require = 'TPVneo'
99
;require_php = 'soap'
1010
;compatible = 'Tickets'

src/FileUpdater.php

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)