Fix deletion/creation of extrafields.

This commit is contained in:
Laurent Destailleur 2022-04-12 15:26:21 +02:00
parent 599c90ae6b
commit 386b8bee5e

View File

@ -466,7 +466,12 @@ if ($dirins && $action == 'initsqlextrafields' && !empty($module)) {
dolReplaceInFile($destfile2, $arrayreplacement);
} else {
$langs->load("errors");
setEventMessages($langs->trans('ErrorFailToCreateFile', ''), null, 'errors');
if ($result1 <= 0) {
setEventMessages($langs->trans('ErrorFailToCreateFile', $destfile1), null, 'errors');
}
if ($result2 <= 0) {
setEventMessages($langs->trans('ErrorFailToCreateFile', $destfile2), null, 'errors');
}
}
// TODO Enable in class the property $isextrafieldmanaged = 1
}
@ -780,6 +785,19 @@ if ($dirins && $action == 'confirm_removefile' && !empty($module)) {
if (!$result) {
setEventMessages($langs->trans("ErrorFailToDeleteFile", basename($filetodelete)), null, 'errors');
} else {
// If we delete a sql file
if (preg_match('/\.sql$/', $relativefilename)) {
if (preg_match('/\.key\.sql$/', $relativefilename)) {
$relativefilename = preg_replace('/\.key\.sql$/', '.sql', $relativefilename);
$filetodelete = $dirins.'/'.$relativefilename;
$result = dol_delete_file($filetodelete);
} elseif (preg_match('/\.sql$/', $relativefilename)) {
$relativefilename = preg_replace('/\.sql$/', '.key.sql', $relativefilename);
$filetodelete = $dirins.'/'.$relativefilename;
$result = dol_delete_file($filetodelete);
}
}
if (dol_is_dir_empty($dirtodelete)) {
dol_delete_dir($dirtodelete);
}
@ -1641,7 +1659,6 @@ if ($action == 'savefile' && empty($cancel)) {
$content = GETPOST('editfilecontent', $check);
// Save file on disk
if ($content) {
dol_delete_file($pathoffile);
@ -2573,8 +2590,9 @@ if ($module == 'initmodule') {
print '<div class="fichehalfleft smallxxx">';
print '<span class="fa fa-file-o"></span> '.$langs->trans("ClassFile").' : <strong>'.($realpathtoclass ? '' : '<strike>').preg_replace('/^'.strtolower($module).'\//', '', $pathtoclass).($realpathtoclass ? '' : '</strike>').'</strong>';
print ' <a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?tab='.$tab.'&tabobj='.$tabobj.'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=editfile&token='.newToken().'&format=php&file='.urlencode($pathtoclass).'">'.img_picto($langs->trans("Edit"), 'edit').'</a>';
// API file
print '<br>';
print '<span class="fa fa-file-o"></span> '.$langs->trans("ApiClassFile").' : <strong>'.($realpathtoapi ? '' : '<strike>').preg_replace('/^'.strtolower($module).'\//', '', $pathtoapi).($realpathtoapi ? '' : '</strike>').'</strong>';
print '<span class="fa fa-file-o"></span> '.$langs->trans("ApiClassFile").' : <strong>'.($realpathtoapi ? '' : '<strike>').(dol_is_file($realpathtoapi)?'':'<span class="opacitymedium">').preg_replace('/^'.strtolower($module).'\//', '', $pathtoapi).(dol_is_file($realpathtoapi)?'':'</span>').($realpathtoapi ? '' : '</strike>').'</strong>';
if (dol_is_file($realpathtoapi)) {
print ' <a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?tab='.$tab.'&tabobj='.$tabobj.'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=editfile&token='.newToken().'&format=php&file='.urlencode($pathtoapi).'">'.img_picto($langs->trans("Edit"), 'edit').'</a>';
print ' ';
@ -2591,7 +2609,7 @@ if ($module == 'initmodule') {
}
// PHPUnit
print '<br>';
print '<span class="fa fa-file-o"></span> '.$langs->trans("TestClassFile").' : <strong>'.($realpathtophpunit ? '' : '<strike>').preg_replace('/^'.strtolower($module).'\//', '', $pathtophpunit).($realpathtophpunit ? '' : '</strike>').'</strong>';
print '<span class="fa fa-file-o"></span> '.$langs->trans("TestClassFile").' : <strong>'.($realpathtophpunit ? '' : '<strike>').(dol_is_file($realpathtophpunit)?'':'<span class="opacitymedium">').preg_replace('/^'.strtolower($module).'\//', '', $pathtophpunit).(dol_is_file($realpathtophpunit)?'':'</span>').($realpathtophpunit ? '' : '</strike>').'</strong>';
if (dol_is_file($realpathtophpunit)) {
print ' <a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?tab='.$tab.'&tabobj='.$tabobj.'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=editfile&token='.newToken().'&format=php&file='.urlencode($pathtophpunit).'">'.img_picto($langs->trans("Edit"), 'edit').'</a>';
print ' ';
@ -2624,7 +2642,7 @@ if ($module == 'initmodule') {
print ' <a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?tab='.$tab.'&tabobj='.$tabobj.'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=editfile&token='.newToken().'&format=sql&file='.urlencode($pathtosqlkey).'">'.img_picto($langs->trans("Edit"), 'edit').'</a>';
//print ' &nbsp; <a href="'.$_SERVER["PHP_SELF"].'">'.$langs->trans("RunSql").'</a>';
print '<br>';
print '<span class="fa fa-file-o"></span> '.$langs->trans("SqlFileExtraFields").' : <strong>'.($realpathtosqlextra ? '' : '<strike>').preg_replace('/^'.strtolower($module).'\//', '', $pathtosqlextra).($realpathtosqlextra ? '' : '</strike>').'</strong>';
print '<span class="fa fa-file-o"></span> '.$langs->trans("SqlFileExtraFields").' : <strong>'.($realpathtosqlextra ? '' : '<strike>').(dol_is_file($realpathtosqlextra) && dol_is_file($realpathtosqlextrakey) ? '' : '<span class="opacitymedium">').preg_replace('/^'.strtolower($module).'\//', '', $pathtosqlextra).(dol_is_file($realpathtosqlextra) && dol_is_file($realpathtosqlextrakey) ? '' : '</span">').($realpathtosqlextra ? '' : '</strike>').'</strong>';
if (dol_is_file($realpathtosqlextra) && dol_is_file($realpathtosqlextrakey)) {
print ' <a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?tab='.$tab.'&tabobj='.$tabobj.'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=editfile&token='.newToken().'&file='.urlencode($pathtosqlextra).'">'.img_picto($langs->trans("Edit"), 'edit').'</a>';
print ' ';
@ -2636,7 +2654,7 @@ if ($module == 'initmodule') {
}
//print ' &nbsp; <a href="'.$_SERVER["PHP_SELF"].'">'.$langs->trans("RunSql").'</a>';
print '<br>';
print '<span class="fa fa-file-o"></span> '.$langs->trans("SqlFileKeyExtraFields").' : <strong>'.($realpathtosqlextrakey ? '' : '<strike>').preg_replace('/^'.strtolower($module).'\//', '', $pathtosqlextrakey).($realpathtosqlextrakey ? '' : '</strike>').'</strong>';
print '<span class="fa fa-file-o"></span> '.$langs->trans("SqlFileKeyExtraFields").' : <strong>'.($realpathtosqlextrakey ? '' : '<strike>').(dol_is_file($realpathtosqlextra) && dol_is_file($realpathtosqlextrakey) ? '' : '<span class="opacitymedium">').preg_replace('/^'.strtolower($module).'\//', '', $pathtosqlextrakey).(dol_is_file($realpathtosqlextra) && dol_is_file($realpathtosqlextrakey) ? '' : '</span">').($realpathtosqlextrakey ? '' : '</strike>').'</strong>';
if (dol_is_file($realpathtosqlextra) && dol_is_file($realpathtosqlextrakey)) {
print ' <a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?tab='.$tab.'&tabobj='.$tabobj.'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=editfile&token='.newToken().'&format=sql&file='.urlencode($pathtosqlextrakey).'">'.img_picto($langs->trans("Edit"), 'edit').'</a>';
print ' ';