Fix: Avoid duplicate directories

This commit is contained in:
Laurent Destailleur 2008-05-04 16:05:17 +00:00
parent 4c2e6df6cb
commit 08426c1b4d
5 changed files with 94 additions and 48 deletions

View File

@ -107,7 +107,8 @@ if ($_POST["action"] == 'add' && $user->rights->ecm->setup)
} }
else else
{ {
$mesg='<div class="error">Error '.$langs->trans($ecmdir->error).'</div>'; $langs->load("errors");
$mesg='<div class="error">'.$langs->trans($ecmdir->error).'</div>';
$_GET["action"] = "create"; $_GET["action"] = "create";
} }
} }
@ -199,7 +200,6 @@ if (! $_GET["action"] || $_GET["action"] == 'delete_section')
// Construit fiche rubrique // Construit fiche rubrique
print $user->rights->ecm->setup;
// Actions buttons // Actions buttons
print '<div class="tabsAction">'; print '<div class="tabsAction">';
if ($user->rights->ecm->setup) if ($user->rights->ecm->setup)

View File

@ -83,50 +83,93 @@ class EcmDirectory // extends CommonObject
$this->fk_user_c=$user->id; $this->fk_user_c=$user->id;
if ($this->fk_parent <= 0) $this->fk_parent=0; if ($this->fk_parent <= 0) $this->fk_parent=0;
// Check parameters // Check if same directory does not exists with this name
// Put here code to add control on parameters values $relativepath=$this->label;
if ($this->fk_parent)
{
$parent = new ECMDirectory($this->db);
$parent->fetch($this->fk_parent);
$relativepath=$parent->getRelativePath().$relativepath;
}
$relativepath=eregi_replace('[\/]+','/',$relativepath); // Avoid duplicate / or \
//print $relativepath.'<br>';
// Insert request $cat = new ECMDirectory($this->db);
$sql = "INSERT INTO ".MAIN_DB_PREFIX."ecm_directories("; $cate_arbo = $cat->get_full_arbo(1);
$sql.= "label,"; $pathfound=0;
$sql.= "fk_parent,"; foreach ($cate_arbo as $key => $categ)
$sql.= "description,"; {
$sql.= "cachenbofdoc,"; $path=eregi_replace('[ -><\/]+','/',$categ['fulllabel']);
$sql.= "date_c,"; //print $path.'<br>';
$sql.= "fk_user_c"; if ($path == $relativepath)
$sql.= ") VALUES ("; {
$sql.= " '".addslashes($this->label)."',"; $pathfound=1;
$sql.= " '".$this->fk_parent."',"; break;
$sql.= " '".addslashes($this->description)."',"; }
$sql.= " ".($this->cachenbofdoc).","; }
$sql.= " ".$this->db->idate($this->date_c).",";
$sql.= " '".$this->fk_user_c."'";
$sql.= ")";
dolibarr_syslog("EcmDirectories::create sql=".$sql, LOG_DEBUG); if ($pathfound)
$resql=$this->db->query($sql); {
if ($resql) $this->error="ErrorDirAlreadyExists";
{ dolibarr_syslog("EcmDirectories::create ".$this->error, LOG_WARNING);
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."ecm_directories"); return -1;
}
else
{
$this->db->begin();
$dir=$conf->ecm->dir_output.'/'.$this->getRelativePath(); // Insert request
$result=create_exdir($dir); $sql = "INSERT INTO ".MAIN_DB_PREFIX."ecm_directories(";
$sql.= "label,";
$sql.= "fk_parent,";
$sql.= "description,";
$sql.= "cachenbofdoc,";
$sql.= "date_c,";
$sql.= "fk_user_c";
$sql.= ") VALUES (";
$sql.= " '".addslashes($this->label)."',";
$sql.= " '".$this->fk_parent."',";
$sql.= " '".addslashes($this->description)."',";
$sql.= " ".($this->cachenbofdoc).",";
$sql.= " ".$this->db->idate($this->date_c).",";
$sql.= " '".$this->fk_user_c."'";
$sql.= ")";
// Appel des triggers dolibarr_syslog("EcmDirectories::create sql=".$sql, LOG_DEBUG);
include_once(DOL_DOCUMENT_ROOT . "/interfaces.class.php"); $resql=$this->db->query($sql);
$interface=new Interfaces($this->db); if ($resql)
$result=$interface->run_triggers('MYOBJECT_CREATE',$this,$user,$langs,$conf); {
if ($result < 0) { $error++; $this->errors=$interface->errors; } $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."ecm_directories");
// Fin appel triggers
return $this->id; $dir=$conf->ecm->dir_output.'/'.$this->getRelativePath();
} $result=create_exdir($dir);
else
{ // Appel des triggers
$this->error="Error ".$this->db->lasterror(); include_once(DOL_DOCUMENT_ROOT . "/interfaces.class.php");
dolibarr_syslog("EcmDirectories::create ".$this->error, LOG_ERR); $interface=new Interfaces($this->db);
return -1; $result=$interface->run_triggers('MYOBJECT_CREATE',$this,$user,$langs,$conf);
} if ($result < 0) { $error++; $this->errors=$interface->errors; }
// Fin appel triggers
if (! $error)
{
$this->db->commit();
return $this->id;
}
else
{
$this->db->rollback();
return -1;
}
}
else
{
$this->error="Error ".$this->db->lasterror();
dolibarr_syslog("EcmDirectories::create ".$this->error, LOG_ERR);
$this->db->rollback();
return -1;
}
}
} }
/** /**

View File

@ -336,6 +336,7 @@ else
print '</div>'; print '</div>';
*/ */
print '<br>';
// End of page // End of page
$db->close(); $db->close();

View File

@ -24,3 +24,4 @@ ErrorTopMenuMustHaveAParentWithId0=A menu of type 'Top' can't have a parent menu
ErrorLeftMenuMustHaveAParentId=A menu of type 'Left' must have a parent id. ErrorLeftMenuMustHaveAParentId=A menu of type 'Left' must have a parent id.
ErrorGenbarCodeNotfound=File not found (Bad path, wrong permissions or access denied by openbasedir parameter) ErrorGenbarCodeNotfound=File not found (Bad path, wrong permissions or access denied by openbasedir parameter)
ErrorFunctionNotAvailableInPHP=Function <b>%s</b> is required for this feature but is not available in this version/setup of PHP. ErrorFunctionNotAvailableInPHP=Function <b>%s</b> is required for this feature but is not available in this version/setup of PHP.
ErrorDirAlreadyExists=A directory with this name already exists.

View File

@ -24,3 +24,4 @@ ErrorTopMenuMustHaveAParentWithId0=Un menu de type 'Top' ne peut avoir de menu p
ErrorLeftMenuMustHaveAParentId=Un menu de type 'Left' doit avoir un id de père. ErrorLeftMenuMustHaveAParentId=Un menu de type 'Left' doit avoir un id de père.
ErrorGenbarCodeNotfound=Fichier introuvable (Mauvais chemin, permissions incorrectes ou accès interdit par le paramètre openbasedir) ErrorGenbarCodeNotfound=Fichier introuvable (Mauvais chemin, permissions incorrectes ou accès interdit par le paramètre openbasedir)
ErrorFunctionNotAvailableInPHP=La fonction <b>%s</b> est requise pour cette fonctionnalité mais n'est pas disponible dans cette version/installation de PHP. ErrorFunctionNotAvailableInPHP=La fonction <b>%s</b> est requise pour cette fonctionnalité mais n'est pas disponible dans cette version/installation de PHP.
ErrorDirAlreadyExists=Un répertoire portant ce nom existe déjà.