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.='<td>'.$input['label'].' </td><td align="left">';
$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 (isset($input['disabled'])) $more.=' disabled';
$more.=' /></td>';

View File

@ -325,11 +325,12 @@ class EcmDirectory // extends CommonObject
/**
* Delete object on database and/or on disk
*
* @param User $user User that delete
* @param string $mode 'all'=delete all, 'databaseonly'=only database entry, 'fileonly' (not implemented)
* @return int <0 if KO, >0 if OK
* @param User $user User that delete
* @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
*/
function delete($user, $mode='all')
function delete($user, $mode='all', $deletedirrecursive=0)
{
global $conf, $langs;
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
@ -368,7 +369,14 @@ class EcmDirectory // extends CommonObject
if ($mode != 'databaseonly')
{
$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)))

View File

@ -156,10 +156,12 @@ if ($action == 'confirm_deletedir' && $confirm == 'yes')
$backtourl = DOL_URL_ROOT."/ecm/index.php";
if ($module == 'medias') $backtourl = DOL_URL_ROOT."/website/index.php?file_manager=1";
$deletedirrecursive = (GETPOST('deletedirrecursive','alpha') == 'on' ? 1 : 0);
if ($module == 'ecm')
{
// Fetch was already done
$result=$ecmdir->delete($user);
$result=$ecmdir->delete($user, 'all', $deletedirrecursive);
if ($result <= 0)
{
$langs->load('errors');
@ -168,7 +170,14 @@ if ($action == 'confirm_deletedir' && $confirm == 'yes')
}
else
{
$resbool = dol_delete_dir($upload_dir, 1);
if ($deletedirrecursive)
{
$resbool = dol_delete_dir_recursive($upload_dir, 0, 1);
}
else
{
$resbool = dol_delete_dir($upload_dir, 1);
}
if ($resbool) $result = 1;
else
{
@ -475,8 +484,8 @@ if ($action != 'edit' && $action != 'delete')
print '<a class="butActionRefused" href="#" title="'.$langs->trans("NotAllowed").'">'.$langs->trans('ECMAddSection').'</a>';
}
if (count($filearrayall) == 0)
{
//if (count($filearrayall) == 0)
//{
if ($permtoadd)
{
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>';
}
}
/*}
else
{
if (count($filearray) > 0)
print '<a class="butActionRefused" href="#" title="'.$langs->trans("CannotRemoveDirectoryContainsFiles").'">'.$langs->trans('Delete').'</a>';
else
print '<a class="butActionRefused" href="#" title="'.$langs->trans("CannotRemoveDirectoryContainsFilesOrDirs").'">'.$langs->trans('Delete').'</a>';
}
}*/
print '</div>';
}
@ -506,7 +515,17 @@ if ($action == 'delete')
if ($action == 'delete_dir')
{
$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
MessageOK=Message on validated 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
PreviousYearOfInvoice=Previous year of invoice date