Fix: Add message if delete can(t be done because of joined files.

This commit is contained in:
Laurent Destailleur 2008-12-30 22:42:28 +00:00
parent ac7b9da097
commit 5165e2e093
5 changed files with 41 additions and 18 deletions

View File

@ -83,12 +83,22 @@ if ($_REQUEST['action'] == 'confirm_delete' && $_REQUEST['confirm'] == 'yes')
{ {
$propal = new Propal($db, 0, $_GET['propalid']); $propal = new Propal($db, 0, $_GET['propalid']);
$propal->fetch($_GET['propalid']); $propal->fetch($_GET['propalid']);
$propal->delete($user); $result=$propal->delete($user);
$propalid = 0; $propalid = 0;
$brouillon = 1; $brouillon = 1;
if ($result > 0)
{
Header('Location: '.$_SERVER["PHP_SELF"]);
exit;
}
else
{
$langs->load("errors");
if ($propal->error == 'ErrorFailToDeleteDir') $mesg='<div class="error">'.$langs->trans('ErrorFailedToDeleteJoinedFiles').'</div>';
else $mesg='<div class="error">'.$propal->error.'</div>';
}
} }
Header('Location: '.$_SERVER["PHP_SELF"]);
exit;
} }
/* /*
@ -135,7 +145,7 @@ if ($_REQUEST['action'] == 'confirm_validate' && $_REQUEST['confirm'] == 'yes' &
} }
else else
{ {
$mesg='<div class="error">'.$fac->error.'</div>'; $mesg='<div class="error">'.$propal->error.'</div>';
} }
} }
@ -846,7 +856,7 @@ if ($_GET['propalid'] > 0)
* *
*/ */
if ($mesg) print "$mesg<br>"; if ($mesg) print $mesg."<br>";
$propal = new Propal($db); $propal = new Propal($db);
$propal->fetch($_GET['propalid']); $propal->fetch($_GET['propalid']);

View File

@ -6,6 +6,8 @@ ErrorFailToDeleteFile=Failed to remove file '<b>%s</b>'.
ErrorFailToCreateFile=Failed to create file '<b>%s</b>'. ErrorFailToCreateFile=Failed to create file '<b>%s</b>'.
ErrorFailToRenameDir=Failed to rename directory '<b>%s</b>' into '<b>%s</b>'. ErrorFailToRenameDir=Failed to rename directory '<b>%s</b>' into '<b>%s</b>'.
ErrorFailToCreateDir=Failed to create directory '<b>%s</b>'. ErrorFailToCreateDir=Failed to create directory '<b>%s</b>'.
ErrorFailToDeleteDir=Failed to delete directory '<b>%s</b>'.
ErrorFailedToDeleteJoinedFiles=Can not delete entity because there is some joined files. Remove join files first.
ErrorThisContactIsAlreadyDefinedAsThisType=This contact is already defined as contact for this type. ErrorThisContactIsAlreadyDefinedAsThisType=This contact is already defined as contact for this type.
ErrorCashAccountAcceptsOnlyCashMoney=This bank account is a cash account, so it accepts payments of type cash only. ErrorCashAccountAcceptsOnlyCashMoney=This bank account is a cash account, so it accepts payments of type cash only.
ErrorFromToAccountsMustDiffers=Source and targets bank accounts must be different. ErrorFromToAccountsMustDiffers=Source and targets bank accounts must be different.

View File

@ -6,6 +6,8 @@ ErrorFailToCreateFile=Echec de la cr
ErrorFailToDeleteFile=Echec de l'effacement du fichier '<b>%s</b>'. ErrorFailToDeleteFile=Echec de l'effacement du fichier '<b>%s</b>'.
ErrorFailToRenameDir=Echec du renommage du répertoire '<b>%s</b>' en '<b>%s</b>'. ErrorFailToRenameDir=Echec du renommage du répertoire '<b>%s</b>' en '<b>%s</b>'.
ErrorFailToCreateDir=Echec de création du répertoire '<b>%s</b>'. ErrorFailToCreateDir=Echec de création du répertoire '<b>%s</b>'.
ErrorFailToDeleteDir=Echec de la suppression du répertoire '<b>%s</b>'.
ErrorFailedToDeleteJoinedFiles=Impossible de supprimer l'entité car il existe des pièces jointes. Supprimer d'abord les pièces jointes.
ErrorThisContactIsAlreadyDefinedAsThisType=Ce contact est déjà défini comme contact pour ce type. ErrorThisContactIsAlreadyDefinedAsThisType=Ce contact est déjà défini comme contact pour ce type.
ErrorCashAccountAcceptsOnlyCashMoney=Ce compte bancaire est de type caisse et n'accepte que les mode de réglement de type <b>espèce</b>. ErrorCashAccountAcceptsOnlyCashMoney=Ce compte bancaire est de type caisse et n'accepte que les mode de réglement de type <b>espèce</b>.
ErrorFromToAccountsMustDiffers=Le compte source et destination doivent etre différents. ErrorFromToAccountsMustDiffers=Le compte source et destination doivent etre différents.

View File

@ -1999,8 +1999,10 @@ function dol_delete_file($file)
} }
/** /**
\brief Effacement d'un r<EFBFBD>pertoire * \brief Remove a directory
\param file R<EFBFBD>pertoire a effacer * \param file Directory to delete
* \return boolean True if success, false if error
* \remarks If directory is not empty, return false
*/ */
function dol_delete_dir($dir) function dol_delete_dir($dir)
{ {
@ -2008,10 +2010,10 @@ function dol_delete_dir($dir)
} }
/** /**
\brief Effacement d'un r<EFBFBD>pertoire $dir et de son arborescence * \brief Remove a directory $dir and its subdirectories
\param file R<EFBFBD>pertoire a effacer * \param file Dir to delete
\param count Compteur pour comptage nb elements supprim<EFBFBD>s * \param count Counter to count nb of deleted elements
\return int Nombre de fichier+rep<EFBFBD>rtoires supprim<EFBFBD>s * \return int Number of files and directory removed
*/ */
function dol_delete_dir_recursive($dir,$count=0) function dol_delete_dir_recursive($dir,$count=0)
{ {

View File

@ -1408,7 +1408,9 @@ class Propal extends CommonObject
*/ */
function delete($user) function delete($user)
{ {
global $conf,$langs; global $conf;
$this->db->begin();
$sql = "DELETE FROM ".MAIN_DB_PREFIX."propaldet WHERE fk_propal = ".$this->id; $sql = "DELETE FROM ".MAIN_DB_PREFIX."propaldet WHERE fk_propal = ".$this->id;
if ( $this->db->query($sql) ) if ( $this->db->query($sql) )
@ -1416,8 +1418,7 @@ class Propal extends CommonObject
$sql = "DELETE FROM ".MAIN_DB_PREFIX."propal WHERE rowid = ".$this->id; $sql = "DELETE FROM ".MAIN_DB_PREFIX."propal WHERE rowid = ".$this->id;
if ( $this->db->query($sql) ) if ( $this->db->query($sql) )
{ {
// We remove directory
// On efface le r<>pertoire du pdf
$propalref = sanitizeFileName($this->ref); $propalref = sanitizeFileName($this->ref);
if ($conf->propal->dir_output) if ($conf->propal->dir_output)
{ {
@ -1429,30 +1430,36 @@ class Propal extends CommonObject
if (!dol_delete_file($file)) if (!dol_delete_file($file))
{ {
$this->error=$langs->trans("ErrorCanNotDeleteFile",$file); $this->error='ErrorFailToDeleteFile';
$this->db->rollback();
return 0; return 0;
} }
} }
if (file_exists($dir)) if (file_exists($dir))
{ {
if (!dol_delete_dir($dir)) $res=@dol_delete_dir($dir);
if (! $res)
{ {
$this->error=$langs->trans("ErrorCanNotDeleteDir",$dir); $this->error='ErrorFailToDeleteDir';
$this->db->rollback();
return 0; return 0;
} }
} }
} }
dolibarr_syslog("Suppression de la proposition $this->id par $user->id"); dolibarr_syslog("Suppression de la proposition $this->id par $user->id", LOG_DEBUG);
$this->db->commit();
return 1; return 1;
} }
else else
{ {
$this->db->rollback();
return -2; return -2;
} }
} }
else else
{ {
$this->db->rollback();
return -1; return -1;
} }
} }