NEW Can delete dir content in media and ECM module recursively

This commit is contained in:
Laurent Destailleur 2018-02-19 23:52:45 +01:00
parent 9230c6757b
commit 5f51af505f
4 changed files with 42 additions and 13 deletions

View File

@ -3652,7 +3652,7 @@ class Form
$more.='<tr>'; $more.='<tr>';
$more.='<td>'.$input['label'].' </td><td align="left">'; $more.='<td>'.$input['label'].' </td><td align="left">';
$more.='<input type="checkbox" class="flat'.$morecss.'" id="'.$input['name'].'" name="'.$input['name'].'"'.$moreattr; $more.='<input type="checkbox" class="flat'.$morecss.'" id="'.$input['name'].'" name="'.$input['name'].'"'.$moreattr;
if (! is_bool($input['value']) && $input['value'] != 'false') $more.=' checked'; if (! is_bool($input['value']) && $input['value'] != 'false' && $input['value'] != '0') $more.=' checked';
if (is_bool($input['value']) && $input['value']) $more.=' checked'; if (is_bool($input['value']) && $input['value']) $more.=' checked';
if (isset($input['disabled'])) $more.=' disabled'; if (isset($input['disabled'])) $more.=' disabled';
$more.=' /></td>'; $more.=' /></td>';

View File

@ -327,9 +327,10 @@ class EcmDirectory // extends CommonObject
* *
* @param User $user User that delete * @param User $user User that delete
* @param string $mode 'all'=delete all, 'databaseonly'=only database entry, 'fileonly' (not implemented) * @param string $mode 'all'=delete all, 'databaseonly'=only database entry, 'fileonly' (not implemented)
* @param int $deletedirrecursive 1=Agree to delete content recursiveley (otherwise an error will be returned when trying to delete)
* @return int <0 if KO, >0 if OK * @return int <0 if KO, >0 if OK
*/ */
function delete($user, $mode='all') function delete($user, $mode='all', $deletedirrecursive=0)
{ {
global $conf, $langs; global $conf, $langs;
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
@ -368,7 +369,14 @@ class EcmDirectory // extends CommonObject
if ($mode != 'databaseonly') if ($mode != 'databaseonly')
{ {
$file = $conf->ecm->dir_output . "/" . $relativepath; $file = $conf->ecm->dir_output . "/" . $relativepath;
$result=@dol_delete_dir($file); if ($deletedirrecursive)
{
$result=@dol_delete_dir_recursive($file, 0, 0);
}
else
{
$result=@dol_delete_dir($file, 0);
}
} }
if ($result || ! @is_dir(dol_osencode($file))) if ($result || ! @is_dir(dol_osencode($file)))

View File

@ -156,10 +156,12 @@ if ($action == 'confirm_deletedir' && $confirm == 'yes')
$backtourl = DOL_URL_ROOT."/ecm/index.php"; $backtourl = DOL_URL_ROOT."/ecm/index.php";
if ($module == 'medias') $backtourl = DOL_URL_ROOT."/website/index.php?file_manager=1"; if ($module == 'medias') $backtourl = DOL_URL_ROOT."/website/index.php?file_manager=1";
$deletedirrecursive = (GETPOST('deletedirrecursive','alpha') == 'on' ? 1 : 0);
if ($module == 'ecm') if ($module == 'ecm')
{ {
// Fetch was already done // Fetch was already done
$result=$ecmdir->delete($user); $result=$ecmdir->delete($user, 'all', $deletedirrecursive);
if ($result <= 0) if ($result <= 0)
{ {
$langs->load('errors'); $langs->load('errors');
@ -167,8 +169,15 @@ if ($action == 'confirm_deletedir' && $confirm == 'yes')
} }
} }
else else
{
if ($deletedirrecursive)
{
$resbool = dol_delete_dir_recursive($upload_dir, 0, 1);
}
else
{ {
$resbool = dol_delete_dir($upload_dir, 1); $resbool = dol_delete_dir($upload_dir, 1);
}
if ($resbool) $result = 1; if ($resbool) $result = 1;
else else
{ {
@ -475,8 +484,8 @@ if ($action != 'edit' && $action != 'delete')
print '<a class="butActionRefused" href="#" title="'.$langs->trans("NotAllowed").'">'.$langs->trans('ECMAddSection').'</a>'; print '<a class="butActionRefused" href="#" title="'.$langs->trans("NotAllowed").'">'.$langs->trans('ECMAddSection').'</a>';
} }
if (count($filearrayall) == 0) //if (count($filearrayall) == 0)
{ //{
if ($permtoadd) if ($permtoadd)
{ {
print '<a class="butActionDelete" href="'.$_SERVER['PHP_SELF'].'?action=delete_dir'.($module?'&module='.$module:'').'&section='.$section.'">'.$langs->trans('Delete').'</a>'; print '<a class="butActionDelete" href="'.$_SERVER['PHP_SELF'].'?action=delete_dir'.($module?'&module='.$module:'').'&section='.$section.'">'.$langs->trans('Delete').'</a>';
@ -485,14 +494,14 @@ if ($action != 'edit' && $action != 'delete')
{ {
print '<a class="butActionDeleteRefused" href="#" title="'.$langs->trans("NotAllowed").'">'.$langs->trans('Delete').'</a>'; print '<a class="butActionDeleteRefused" href="#" title="'.$langs->trans("NotAllowed").'">'.$langs->trans('Delete').'</a>';
} }
} /*}
else else
{ {
if (count($filearray) > 0) if (count($filearray) > 0)
print '<a class="butActionRefused" href="#" title="'.$langs->trans("CannotRemoveDirectoryContainsFiles").'">'.$langs->trans('Delete').'</a>'; print '<a class="butActionRefused" href="#" title="'.$langs->trans("CannotRemoveDirectoryContainsFiles").'">'.$langs->trans('Delete').'</a>';
else else
print '<a class="butActionRefused" href="#" title="'.$langs->trans("CannotRemoveDirectoryContainsFilesOrDirs").'">'.$langs->trans('Delete').'</a>'; print '<a class="butActionRefused" href="#" title="'.$langs->trans("CannotRemoveDirectoryContainsFilesOrDirs").'">'.$langs->trans('Delete').'</a>';
} }*/
print '</div>'; print '</div>';
} }
@ -506,7 +515,17 @@ if ($action == 'delete')
if ($action == 'delete_dir') if ($action == 'delete_dir')
{ {
$relativepathwithoutslash=preg_replace('/[\/]$/','',$relativepath); $relativepathwithoutslash=preg_replace('/[\/]$/','',$relativepath);
print $form->formconfirm($_SERVER["PHP_SELF"].'?section='.GETPOST('section','alpha').($module?'&module='.$module:''), $langs->trans('DeleteSection'), $langs->trans('ConfirmDeleteSection',$relativepathwithoutslash), 'confirm_deletedir', '', 1, 1);
//Form to close proposal (signed or not)
if (count($filearrayall) > 0)
{
$langs->load("other");
$formquestion = array(
array('type' => 'checkbox', 'name' => 'deletedirrecursive', 'label' => $langs->trans("ContentOfDirectoryIsNotEmpty").'<br>'.$langs->trans("DeleteAlsoContentRecursively"),'value' => '0') // Field to complete private note (not replace)
);
}
print $form->formconfirm($_SERVER["PHP_SELF"].'?section='.GETPOST('section','alpha').($module?'&module='.$module:''), $langs->trans('DeleteSection'), $langs->trans('ConfirmDeleteSection',$relativepathwithoutslash), 'confirm_deletedir', $formquestion, 1, 1);
} }

View File

@ -22,6 +22,8 @@ JumpToLogin=Disconnected. Go to login page...
MessageForm=Message on online payment form MessageForm=Message on online payment form
MessageOK=Message on validated payment return page MessageOK=Message on validated payment return page
MessageKO=Message on canceled payment return page MessageKO=Message on canceled payment return page
ContentOfDirectoryIsNotEmpty=Content of this directory is not empty.
DeleteAlsoContentRecursively=Check to delete all content recursiveley
YearOfInvoice=Year of invoice date YearOfInvoice=Year of invoice date
PreviousYearOfInvoice=Previous year of invoice date PreviousYearOfInvoice=Previous year of invoice date