128 lines
3.5 KiB
PHP
Executable File
128 lines
3.5 KiB
PHP
Executable File
<?php
|
|
$nomFicAppelant = basename(__FILE__);
|
|
// transformDebug.php
|
|
set_time_limit(0);
|
|
|
|
// === CONFIGURATION ===
|
|
define('ROOT_DIR', '/datas/07Prod/wwwRoot/alpha.wbadm');
|
|
define('LOG_REAL', ROOT_DIR . '/admin/adminInclude/Outillage/transformDebug.txt');
|
|
define('LOG_SIMU', ROOT_DIR . '/admin/adminInclude/Outillage/transformDebug_simulation.txt');
|
|
|
|
$excludedDirs = [
|
|
'/admin/adminInclude/makeCss',
|
|
'/Catalogue/src',
|
|
'/Design/src',
|
|
'/_var/sauvegardes',
|
|
'/admin/adminInclude/Outillage',
|
|
'/admin/themes/dumpTheme/',
|
|
'/_var/factures123/',
|
|
'/_var/facturesSite/',
|
|
];
|
|
|
|
$debugKeys = ['reqInsert', 'reqSelect', 'reqDelete'];
|
|
|
|
// === DEMANDER LE MODE ===
|
|
echo "Choisir le mode (1 = Simulation, 2 = Réel) : ";
|
|
$mode = trim(fgets(STDIN));
|
|
$simulation = ($mode !== '2');
|
|
$logFile = $simulation ? LOG_SIMU : LOG_REAL;
|
|
|
|
$startTime = microtime(true);
|
|
|
|
$log = [];
|
|
$totalAnalyzed = 0;
|
|
$totalModified = 0;
|
|
$modifiedFiles = [];
|
|
|
|
function isExcluded($filePath, $excludedDirs) {
|
|
foreach ($excludedDirs as $dir) {
|
|
if (strpos($filePath, ROOT_DIR . $dir) === 0) {
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
function processFile($filePath, $debugKeys, $simulation, &$log, &$totalAnalyzed, &$totalModified, &$modifiedFiles) {
|
|
$lines = file($filePath);
|
|
$filename = basename($filePath);
|
|
$changed = false;
|
|
|
|
foreach ($lines as $i => $line) {
|
|
$originalLine = $line;
|
|
$trimmed = trim($line);
|
|
|
|
if (!(str_starts_with($trimmed, '{') && str_ends_with($trimmed, '}'))) {
|
|
continue;
|
|
}
|
|
|
|
foreach ($debugKeys as $key) {
|
|
if (
|
|
strpos($line, '<br><b><span class="debugStyle">') !== false &&
|
|
strpos($line, $key) !== false &&
|
|
strpos($line, '$' . $key) !== false
|
|
) {
|
|
$totalAnalyzed++;
|
|
|
|
$nbDollar = preg_match_all('/\$[a-zA-Z0-9_]+/', $line, $matches);
|
|
if ($nbDollar > 1) {
|
|
$log[] = "[IGNORÉ] $filePath:" . ($i + 1) . "\nLigne : $originalLine";
|
|
continue;
|
|
}
|
|
|
|
$newLine = "\t{\$debugMsg .= monDebug(2,['$key' => \$$key],'$filename');}\n";
|
|
$log[] = ($simulation ? "[SIMULATION]" : "[MODIFIÉ]") . " $filePath:" . ($i + 1)
|
|
. "\nAncienne : $originalLineNouvelle : $newLine";
|
|
|
|
if (!$simulation) {
|
|
$lines[$i] = $newLine;
|
|
$changed = true;
|
|
$totalModified++;
|
|
$modifiedFiles[$filePath] = true;
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
if (!$simulation && $changed) {
|
|
file_put_contents($filePath, implode('', $lines));
|
|
}
|
|
}
|
|
|
|
function scanDirectory($dir, $excludedDirs, $debugKeys, $simulation, &$log, &$totalAnalyzed, &$totalModified, &$modifiedFiles) {
|
|
$iterator = new RecursiveIteratorIterator(
|
|
new RecursiveCallbackFilterIterator(
|
|
new RecursiveDirectoryIterator($dir, RecursiveDirectoryIterator::SKIP_DOTS),
|
|
function ($file, $key, $iterator) use ($excludedDirs) {
|
|
$path = $file->getPathname();
|
|
return !isExcluded($path, $excludedDirs);
|
|
}
|
|
)
|
|
);
|
|
|
|
foreach ($iterator as $file) {
|
|
if (pathinfo($file, PATHINFO_EXTENSION) === 'php') {
|
|
processFile($file->getPathname(), $debugKeys, $simulation, $log, $totalAnalyzed, $totalModified, $modifiedFiles);
|
|
}
|
|
}
|
|
}
|
|
|
|
// === LANCEMENT ===
|
|
scanDirectory(ROOT_DIR, $excludedDirs, $debugKeys, $simulation, $log, $totalAnalyzed, $totalModified, $modifiedFiles);
|
|
|
|
// === LOG FINAL ===
|
|
$duration = round(microtime(true) - $startTime, 2);
|
|
$summary = "\n--- Résumé ---\n"
|
|
. "Mode : " . ($simulation ? "Simulation" : "Traitement réel") . "\n"
|
|
. "Lignes analysées : $totalAnalyzed\n"
|
|
. "Lignes modifiées : $totalModified\n"
|
|
. "Fichiers modifiés : " . count($modifiedFiles) . "\n"
|
|
. "Durée : {$duration}s\n";
|
|
|
|
$log[] = $summary;
|
|
file_put_contents($logFile, implode("\n", $log));
|
|
|
|
echo $summary;
|
|
?>
|