2
0
forked from Wavyzz/dolibarr

Works on enhancement of project module

Fix: add triggers
This commit is contained in:
Regis Houssin
2010-03-05 11:30:22 +00:00
parent 87dccc1e76
commit 36ab2be4da
7 changed files with 83 additions and 28 deletions

View File

@@ -104,7 +104,8 @@ class Commande extends CommonObject
}
/** \brief Cree la commande depuis une propale existante
/**
* \brief Cree la commande depuis une propale existante
* \param user Utilisateur qui cree
* \param propale_id id de la propale qui sert de modele
*/

View File

@@ -239,6 +239,10 @@ class InterfaceDemo
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
}
elseif ($action == 'PROPAL_DELETE')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
}
// Contracts
elseif ($action == 'CONTRACT_CREATE')

View File

@@ -35,11 +35,6 @@ function project_prepare_head($object)
$head[$h][2] = 'project';
$h++;
$head[$h][0] = DOL_URL_ROOT.'/projet/contact.php?id='.$object->id;
$head[$h][1] = $langs->trans("ProjectContact");
$head[$h][2] = 'contact';
$h++;
$head[$h][0] = DOL_URL_ROOT.'/projet/tasks/fiche.php?id='.$object->id;
$head[$h][1] = $langs->trans("Tasks");
$head[$h][2] = 'tasks';
@@ -58,6 +53,11 @@ function project_prepare_head($object)
$h++;
}
$head[$h][0] = DOL_URL_ROOT.'/projet/contact.php?id='.$object->id;
$head[$h][1] = $langs->trans("ProjectContact");
$head[$h][2] = 'contact';
$h++;
$head[$h][0] = DOL_URL_ROOT.'/projet/document.php?id='.$object->id;
/*$filesdir = $conf->projet->dir_output . "/" . dol_sanitizeFileName($object->ref);
include_once(DOL_DOCUMENT_ROOT.'/lib/files.lib.php');

View File

@@ -211,9 +211,9 @@ if ($_REQUEST['action'] == 'confirm_reopen' && $_REQUEST['confirm'] == 'yes')
if ($_REQUEST["action"] == 'confirm_delete' && $_REQUEST["confirm"] == "yes" && $user->rights->projet->supprimer)
{
$project = new Project($db);
$project->id = $_GET["id"];
$project->fetch($_GET["id"]);
$result=$project->delete($user);
if ($result >= 0)
if ($result > 0)
{
Header("Location: index.php");
exit;
@@ -483,7 +483,7 @@ else
}
// Close
if ($project->statut != 2 && $user->rights->projet->creer)
if ($project->statut == 1 && $user->rights->projet->creer)
{
if ($userAccess)
{

View File

@@ -49,7 +49,6 @@ class Project extends CommonObject
var $date_end;
var $socid;
var $user_author_id; //!< Id of project creator. Not defined if shared project.
//var $user_resp_id; //!< Id of project responsible. Not defined if shared project.
var $public; //!< Tell if this is a public or private project
var $note_private;
var $note_public;
@@ -350,13 +349,45 @@ class Project extends CommonObject
*/
function delete($user, $notrigger=0)
{
global $conf;
$this->db->begin();
$sql = "DELETE FROM ".MAIN_DB_PREFIX."projet";
$sql.= " WHERE rowid=".$this->id;
dol_syslog("Project::delete sql=".$sql, LOG_DEBUG);
$resql = $this->db->query($sql);
if ($resql)
{
// We remove directory
$projectref = dol_sanitizeFileName($this->ref);
if ($conf->projet->dir_output)
{
$dir = $conf->projet->dir_output . "/" . $projectref ;
$file = $conf->projet->dir_output . "/" . $projectref . "/" . $projectref . ".pdf";
if (file_exists($file))
{
//project_delete_preview($this->db, $this->id, $this->ref);
if (!dol_delete_file($file))
{
$this->error='ErrorFailToDeleteFile';
$this->db->rollback();
return 0;
}
}
if (file_exists($dir))
{
$res=@dol_delete_dir($dir);
if (! $res)
{
$this->error='ErrorFailToDeleteDir';
$this->db->rollback();
return 0;
}
}
}
if (! $notrigger)
{
// Call triggers
@@ -367,12 +398,15 @@ class Project extends CommonObject
// End call triggers
}
dol_syslog("Project::delete sql=".$sql, LOG_DEBUG);
$this->db->commit();
return 1;
}
else
{
$this->error=$this->db->lasterror();
dol_syslog("Project::delete ".$this->error, LOG_ERR);
$this->db->rollback();
return -1;
}
}

View File

@@ -115,7 +115,7 @@ class Task extends CommonObject
$sql.= ", ".$user->id;
$sql.= ", ".($this->date_start!=''?$this->db->idate($this->date_start):'null');
$sql.= ", ".($this->date_end!=''?$this->db->idate($this->date_end):'null');
$sql.= ", ".$this->progress;
$sql.= ", ".($this->progress!=''?$this->progress:0);
$sql.= ")";
$this->db->begin();

View File

@@ -519,7 +519,7 @@ class Propal extends CommonObject
* \return int <0 if KO, >=0 if OK
* \remarks this->ref can be set or empty. If empty, we will use "(PROV)"
*/
function create($user='')
function create($user='', $notrigger=0)
{
global $langs,$conf,$mysoc;
$error=0;
@@ -660,6 +660,8 @@ class Propal extends CommonObject
// Mise a jour infos denormalisees
$resql=$this->update_price();
if ($resql)
{
if (! $notrigger)
{
// Appel des triggers
include_once(DOL_DOCUMENT_ROOT . "/interfaces.class.php");
@@ -667,6 +669,7 @@ class Propal extends CommonObject
$result=$interface->run_triggers('PROPAL_CREATE',$this,$user,$langs,$conf);
if ($result < 0) { $error++; $this->errors=$interface->errors; }
// Fin appel triggers
}
$this->db->commit();
dol_syslog("Propal::ass::Create done id=".$this->id);
@@ -949,7 +952,7 @@ class Propal extends CommonObject
* \param user Objet utilisateur qui valide
* \return int <0 si ko, >=0 si ok
*/
function valid($user)
function valid($user, $notrigger=0)
{
global $conf,$langs;
@@ -965,12 +968,15 @@ class Propal extends CommonObject
{
$this->use_webcal=($conf->global->PHPWEBCALENDAR_PROPALSTATUS=='always'?1:0);
if (! $notrigger)
{
// Appel des triggers
include_once(DOL_DOCUMENT_ROOT . "/interfaces.class.php");
$interface=new Interfaces($this->db);
$result=$interface->run_triggers('PROPAL_VALIDATE',$this,$user,$langs,$conf);
if ($result < 0) { $error++; $this->errors=$interface->errors; }
// Fin appel triggers
}
$this->db->commit();
return 1;
@@ -1562,7 +1568,7 @@ class Propal extends CommonObject
* \brief Efface propal
* \param user Objet du user qui efface
*/
function delete($user)
function delete($user, $notrigger=0)
{
global $conf;
@@ -1603,6 +1609,16 @@ class Propal extends CommonObject
}
}
if (! $notrigger)
{
// Call triggers
include_once(DOL_DOCUMENT_ROOT . "/interfaces.class.php");
$interface=new Interfaces($this->db);
$result=$interface->run_triggers('PROPAL_DELETE',$this,$user,$langs,$conf);
if ($result < 0) { $error++; $this->errors=$interface->errors; }
// End call triggers
}
dol_syslog("Suppression de la proposition $this->id par $user->id", LOG_DEBUG);
$this->db->commit();
return 1;