Debug recruitment module

This commit is contained in:
Laurent Destailleur 2020-08-23 18:04:52 +02:00
parent a4c34c2bc5
commit bd7261a449
7 changed files with 322 additions and 301 deletions

View File

@ -7763,11 +7763,11 @@ abstract class CommonObject
$sql = 'SELECT '.$fieldlist; $sql = 'SELECT '.$fieldlist;
$sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element; $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element;
if (!empty($id)) $sql .= ' WHERE rowid = '.$id; if (!empty($id)) $sql .= ' WHERE rowid = '.$id;
elseif (!empty($ref)) $sql .= " WHERE ref = ".$this->quote($ref, $this->fields['ref']); elseif (!empty($ref)) $sql .= " WHERE ref = ".$this->quote($ref, $this->fields['ref']);
else $sql .= ' WHERE 1 = 1'; // usage with empty id and empty ref is very rare else $sql .= ' WHERE 1 = 1'; // usage with empty id and empty ref is very rare
if (empty($id) && isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) $sql .= ' AND entity IN ('.getEntity($this->table_element).')'; if (empty($id) && isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) $sql .= ' AND entity IN ('.getEntity($this->table_element).')';
if ($morewhere) $sql .= $morewhere; if ($morewhere) $sql .= $morewhere;
$sql .= ' LIMIT 1'; // This is a fetch, to be sure to get only one record $sql .= ' LIMIT 1'; // This is a fetch, to be sure to get only one record
$res = $this->db->query($sql); $res = $this->db->query($sql);

View File

@ -1574,7 +1574,7 @@ class EmailCollector extends CommonObject
elseif ($operation['type'] == 'recordevent') elseif ($operation['type'] == 'recordevent')
{ {
$alreadycreated = 0; $alreadycreated = 0;
// TODO Check if $msg ID already in database for $conf->entity // TODO Check if $msgid already in database for $conf->entity
if (!$alreadycreated) if (!$alreadycreated)
{ {
@ -1650,318 +1650,329 @@ class EmailCollector extends CommonObject
} }
} }
} }
// Create event // Create project / lead
elseif ($operation['type'] == 'project') elseif ($operation['type'] == 'project')
{ {
$projecttocreate = new Project($this->db); $projecttocreate = new Project($this->db);
if ($thirdpartystatic->id > 0)
{
$projecttocreate->socid = $thirdpartystatic->id;
if ($thirdpartyfoundby) $descriptionmeta = dol_concatdesc($descriptionmeta, 'Third party found from '.$thirdpartyfoundby);
}
if ($contactstatic->id > 0)
{
$projecttocreate->contact_id = $contactstatic->id;
if ($contactfoundby) $descriptionmeta = dol_concatdesc($descriptionmeta, 'Contact/address found from '.$contactfoundby);
}
$description = $descriptiontitle; $alreadycreated = $projecttocreate->fetch(0, '', $msgid);
$description = dol_concatdesc($description, "-----"); if ($alreadycreated == 0)
$description = dol_concatdesc($description, $descriptionmeta); {
$description = dol_concatdesc($description, "-----"); if ($thirdpartystatic->id > 0)
$description = dol_concatdesc($description, $messagetext); {
$projecttocreate->socid = $thirdpartystatic->id;
if ($thirdpartyfoundby) $descriptionmeta = dol_concatdesc($descriptionmeta, 'Third party found from '.$thirdpartyfoundby);
}
if ($contactstatic->id > 0)
{
$projecttocreate->contact_id = $contactstatic->id;
if ($contactfoundby) $descriptionmeta = dol_concatdesc($descriptionmeta, 'Contact/address found from '.$contactfoundby);
}
$descriptionfull = $description; $description = $descriptiontitle;
$descriptionfull = dol_concatdesc($descriptionfull, "----- Header"); $description = dol_concatdesc($description, "-----");
$descriptionfull = dol_concatdesc($descriptionfull, $header); $description = dol_concatdesc($description, $descriptionmeta);
$description = dol_concatdesc($description, "-----");
$description = dol_concatdesc($description, $messagetext);
$id_opp_status = dol_getIdFromCode($this->db, 'PROSP', 'c_lead_status', 'code', 'rowid'); $descriptionfull = $description;
$percent_opp_status = dol_getIdFromCode($this->db, 'PROSP', 'c_lead_status', 'code', 'percent'); $descriptionfull = dol_concatdesc($descriptionfull, "----- Header");
$descriptionfull = dol_concatdesc($descriptionfull, $header);
$projecttocreate->title = $subject; $id_opp_status = dol_getIdFromCode($this->db, 'PROSP', 'c_lead_status', 'code', 'rowid');
$projecttocreate->date_start = $date; $percent_opp_status = dol_getIdFromCode($this->db, 'PROSP', 'c_lead_status', 'code', 'percent');
$projecttocreate->date_end = '';
$projecttocreate->opp_status = $id_opp_status;
$projecttocreate->opp_percent = $percent_opp_status;
$projecttocreate->description = dol_concatdesc(dolGetFirstLineOfText(dol_string_nohtmltag($description, 2), 10), '...'.$langs->transnoentities("SeePrivateNote").'...');
$projecttocreate->note_private = $descriptionfull;
$projecttocreate->entity = $conf->entity;
$projecttocreate->email_msgid = $msgid;
// Overwrite values with values extracted from source email. $projecttocreate->title = $subject;
// This may overwrite any $projecttocreate->xxx properties. $projecttocreate->date_start = $date;
$savesocid = $projecttocreate->socid; $projecttocreate->date_end = '';
$errorforthisaction = $this->overwritePropertiesOfObject($projecttocreate, $operation['actionparam'], $messagetext, $subject, $header); $projecttocreate->opp_status = $id_opp_status;
$projecttocreate->opp_percent = $percent_opp_status;
$projecttocreate->description = dol_concatdesc(dolGetFirstLineOfText(dol_string_nohtmltag($description, 2), 10), '...'.$langs->transnoentities("SeePrivateNote").'...');
$projecttocreate->note_private = $descriptionfull;
$projecttocreate->entity = $conf->entity;
$projecttocreate->email_msgid = $msgid;
// Set project ref if not yet defined // Overwrite values with values extracted from source email.
if (empty($projecttocreate->ref)) // This may overwrite any $projecttocreate->xxx properties.
{ $savesocid = $projecttocreate->socid;
// Get next project Ref $errorforthisaction = $this->overwritePropertiesOfObject($projecttocreate, $operation['actionparam'], $messagetext, $subject, $header);
$defaultref = '';
$modele = empty($conf->global->PROJECT_ADDON) ? 'mod_project_simple' : $conf->global->PROJECT_ADDON;
// Search template files // Set project ref if not yet defined
$file = ''; $classname = ''; $filefound = 0; $reldir = ''; if (empty($projecttocreate->ref))
$dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']); {
foreach ($dirmodels as $reldir) // Get next Ref
{ $defaultref = '';
$file = dol_buildpath($reldir."core/modules/project/".$modele.'.php', 0); $modele = empty($conf->global->PROJECT_ADDON) ? 'mod_project_simple' : $conf->global->PROJECT_ADDON;
if (file_exists($file))
{
$filefound = 1;
$classname = $modele;
break;
}
}
if ($filefound) // Search template files
{ $file = ''; $classname = ''; $filefound = 0; $reldir = '';
$result = dol_include_once($reldir."core/modules/project/".$modele.'.php'); $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
$modProject = new $classname; foreach ($dirmodels as $reldir)
{
$file = dol_buildpath($reldir."core/modules/project/".$modele.'.php', 0);
if (file_exists($file))
{
$filefound = 1;
$classname = $modele;
break;
}
}
if ($savesocid > 0) if ($filefound)
{ {
if ($savesocid != $projecttocreate->socid) if ($savesocid > 0)
{ {
$errorforactions++; if ($savesocid != $projecttocreate->socid)
setEventMessages('You loaded a thirdparty (id='.$savesocid.') and you force another thirdparty id (id='.$projecttocreate->socid.') by setting socid in operation with a different value', null, 'errors'); {
} $errorforactions++;
} else { setEventMessages('You loaded a thirdparty (id='.$savesocid.') and you force another thirdparty id (id='.$projecttocreate->socid.') by setting socid in operation with a different value', null, 'errors');
if ($projecttocreate->socid > 0) }
{ } else {
$thirdpartystatic->fetch($projecttocreate->socid); if ($projecttocreate->socid > 0)
} {
} $thirdpartystatic->fetch($projecttocreate->socid);
}
}
$defaultref = $modProject->getNextValue(($thirdpartystatic->id > 0 ? $thirdpartystatic : null), $projecttocreate); $result = dol_include_once($reldir."core/modules/project/".$modele.'.php');
} $modModuleToUseForNextValue = new $classname;
$projecttocreate->ref = $defaultref; $defaultref = $modModuleToUseForNextValue->getNextValue(($thirdpartystatic->id > 0 ? $thirdpartystatic : null), $projecttocreate);
} }
$projecttocreate->ref = $defaultref;
}
if ($errorforthisaction) if ($errorforthisaction)
{ {
$errorforactions++; $errorforactions++;
} else { } else {
if (empty($projecttocreate->ref) || (is_numeric($projecttocreate->ref) && $projecttocreate->ref <= 0)) if (empty($projecttocreate->ref) || (is_numeric($projecttocreate->ref) && $projecttocreate->ref <= 0))
{ {
$errorforactions++; $errorforactions++;
$this->error = 'Failed to create project: Can\'t get a valid value for the field ref with numbering template = '.$modele.', thirdparty id = '.$thirdpartystatic->id; $this->error = 'Failed to create project: Can\'t get a valid value for the field ref with numbering template = '.$modele.', thirdparty id = '.$thirdpartystatic->id;
} else { } else {
// Create project // Create project
$result = $projecttocreate->create($user); $result = $projecttocreate->create($user);
if ($result <= 0) if ($result <= 0)
{ {
$errorforactions++; $errorforactions++;
$this->error = 'Failed to create project: '.$langs->trans($projecttocreate->error); $this->error = 'Failed to create project: '.$langs->trans($projecttocreate->error);
$this->errors = $projecttocreate->errors; $this->errors = $projecttocreate->errors;
} }
} }
} }
}
} }
// Create event // Create ticket
elseif ($operation['type'] == 'ticket') elseif ($operation['type'] == 'ticket')
{ {
$tickettocreate = new Ticket($this->db); $tickettocreate = new Ticket($this->db);
if ($thirdpartystatic->id > 0)
{
$tickettocreate->socid = $thirdpartystatic->id;
$tickettocreate->fk_soc = $thirdpartystatic->id;
if ($thirdpartyfoundby) $descriptionmeta = dol_concatdesc($descriptionmeta, 'Third party found from '.$thirdpartyfoundby);
}
if ($contactstatic->id > 0)
{
$tickettocreate->contact_id = $contactstatic->id;
if ($contactfoundby) $descriptionmeta = dol_concatdesc($descriptionmeta, 'Contact/address found from '.$contactfoundby);
}
$description = $descriptiontitle; $alreadycreated = $tickettocreate->fetch(0, '', '', $msgid);
$description = dol_concatdesc($description, "-----"); if ($alreadycreated == 0)
$description = dol_concatdesc($description, $descriptionmeta); {
$description = dol_concatdesc($description, "-----"); if ($thirdpartystatic->id > 0)
$description = dol_concatdesc($description, $messagetext); {
$tickettocreate->socid = $thirdpartystatic->id;
$tickettocreate->fk_soc = $thirdpartystatic->id;
if ($thirdpartyfoundby) $descriptionmeta = dol_concatdesc($descriptionmeta, 'Third party found from '.$thirdpartyfoundby);
}
if ($contactstatic->id > 0)
{
$tickettocreate->contact_id = $contactstatic->id;
if ($contactfoundby) $descriptionmeta = dol_concatdesc($descriptionmeta, 'Contact/address found from '.$contactfoundby);
}
$descriptionfull = $description; $description = $descriptiontitle;
$descriptionfull = dol_concatdesc($descriptionfull, "----- Header"); $description = dol_concatdesc($description, "-----");
$descriptionfull = dol_concatdesc($descriptionfull, $header); $description = dol_concatdesc($description, $descriptionmeta);
$description = dol_concatdesc($description, "-----");
$description = dol_concatdesc($description, $messagetext);
$tickettocreate->subject = $subject; $descriptionfull = $description;
$tickettocreate->message = $description; $descriptionfull = dol_concatdesc($descriptionfull, "----- Header");
$tickettocreate->type_code = 0; $descriptionfull = dol_concatdesc($descriptionfull, $header);
$tickettocreate->category_code = null;
$tickettocreate->severity_code = null;
$tickettocreate->origin_email = $from;
$tickettocreate->fk_user_create = $user->id;
$tickettocreate->datec = $date;
$tickettocreate->fk_project = $projectstatic->id;
$tickettocreate->notify_tiers_at_create = 0;
$tickettocreate->note_private = $descriptionfull;
$tickettocreate->entity = $conf->entity;
$tickettocreate->email_msgid = $msgid;
//$tickettocreate->fk_contact = $contactstatic->id;
// Overwrite values with values extracted from source email. $tickettocreate->subject = $subject;
// This may overwrite any $projecttocreate->xxx properties. $tickettocreate->message = $description;
$savesocid = $tickettocreate->socid; $tickettocreate->type_code = 0;
$errorforthisaction = $this->overwritePropertiesOfObject($tickettocreate, $operation['actionparam'], $messagetext, $subject, $header); $tickettocreate->category_code = null;
$tickettocreate->severity_code = null;
$tickettocreate->origin_email = $from;
$tickettocreate->fk_user_create = $user->id;
$tickettocreate->datec = $date;
$tickettocreate->fk_project = $projectstatic->id;
$tickettocreate->notify_tiers_at_create = 0;
$tickettocreate->note_private = $descriptionfull;
$tickettocreate->entity = $conf->entity;
$tickettocreate->email_msgid = $msgid;
//$tickettocreate->fk_contact = $contactstatic->id;
// Set ticket ref if not yet defined // Overwrite values with values extracted from source email.
if (empty($tickettocreate->ref)) // This may overwrite any $projecttocreate->xxx properties.
{ $savesocid = $tickettocreate->socid;
// Get next project Ref $errorforthisaction = $this->overwritePropertiesOfObject($tickettocreate, $operation['actionparam'], $messagetext, $subject, $header);
$defaultref = '';
$modele = empty($conf->global->TICKET_ADDON) ? 'mod_ticket_simple' : $conf->global->TICKET_ADDON;
// Search template files // Set ticket ref if not yet defined
$file = ''; $classname = ''; $filefound = 0; $reldir = ''; if (empty($tickettocreate->ref))
$dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']); {
foreach ($dirmodels as $reldir) // Get next Ref
{ $defaultref = '';
$file = dol_buildpath($reldir."core/modules/ticket/".$modele.'.php', 0); $modele = empty($conf->global->TICKET_ADDON) ? 'mod_ticket_simple' : $conf->global->TICKET_ADDON;
if (file_exists($file))
{
$filefound = 1;
$classname = $modele;
break;
}
}
if ($filefound) // Search template files
{ $file = ''; $classname = ''; $filefound = 0; $reldir = '';
$result = dol_include_once($reldir."core/modules/ticket/".$modele.'.php'); $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
$modTicket = new $classname; foreach ($dirmodels as $reldir)
{
$file = dol_buildpath($reldir."core/modules/ticket/".$modele.'.php', 0);
if (file_exists($file))
{
$filefound = 1;
$classname = $modele;
break;
}
}
if ($savesocid > 0) if ($filefound)
{ {
if ($savesocid != $tickettocreate->socid) if ($savesocid > 0)
{ {
$errorforactions++; if ($savesocid != $tickettocreate->socid)
setEventMessages('You loaded a thirdparty (id='.$savesocid.') and you force another thirdparty id (id='.$tickettocreate->socid.') by setting socid in operation with a different value', null, 'errors'); {
} $errorforactions++;
} else { setEventMessages('You loaded a thirdparty (id='.$savesocid.') and you force another thirdparty id (id='.$tickettocreate->socid.') by setting socid in operation with a different value', null, 'errors');
if ($tickettocreate->socid > 0) }
{ } else {
$thirdpartystatic->fetch($tickettocreate->socid); if ($tickettocreate->socid > 0)
} {
} $thirdpartystatic->fetch($tickettocreate->socid);
}
}
$defaultref = $modTicket->getNextValue(($thirdpartystatic->id > 0 ? $thirdpartystatic : null), $tickettocreate); $result = dol_include_once($reldir."core/modules/ticket/".$modele.'.php');
} $modModuleToUseForNextValue = new $classname;
$tickettocreate->ref = $defaultref; $defaultref = $modModuleToUseForNextValue->getNextValue(($thirdpartystatic->id > 0 ? $thirdpartystatic : null), $tickettocreate);
} }
$tickettocreate->ref = $defaultref;
}
if ($errorforthisaction) if ($errorforthisaction)
{ {
$errorforactions++; $errorforactions++;
} else { } else {
if (is_numeric($tickettocreate->ref) && $tickettocreate->ref <= 0) if (is_numeric($tickettocreate->ref) && $tickettocreate->ref <= 0)
{ {
$errorforactions++; $errorforactions++;
$this->error = 'Failed to create ticket: Can\'t get a valid value for the field ref with numbering template = '.$modele.', thirdparty id = '.$thirdpartystatic->id; $this->error = 'Failed to create ticket: Can\'t get a valid value for the field ref with numbering template = '.$modele.', thirdparty id = '.$thirdpartystatic->id;
} else { } else {
// Create project // Create project
$result = $tickettocreate->create($user); $result = $tickettocreate->create($user);
if ($result <= 0) if ($result <= 0)
{ {
$errorforactions++; $errorforactions++;
$this->error = 'Failed to create ticket: '.$langs->trans($tickettocreate->error); $this->error = 'Failed to create ticket: '.$langs->trans($tickettocreate->error);
$this->errors = $tickettocreate->errors; $this->errors = $tickettocreate->errors;
} }
} }
} }
}
} }
// Create candidature // Create candidature
elseif ($operation['type'] == 'candidature') elseif ($operation['type'] == 'candidature')
{ {
$candidaturetocreate = new RecruitmentCandidature($this->db); $candidaturetocreate = new RecruitmentCandidature($this->db);
$description = $descriptiontitle; $alreadycreated = $candidaturetocreate->fetch(0, '', $msgid);
$description = dol_concatdesc($description, "-----"); if ($alreadycreated == 0)
$description = dol_concatdesc($description, $descriptionmeta);
$description = dol_concatdesc($description, "-----");
$description = dol_concatdesc($description, $messagetext);
$descriptionfull = $description;
$descriptionfull = dol_concatdesc($descriptionfull, "----- Header");
$descriptionfull = dol_concatdesc($descriptionfull, $header);
$candidaturetocreate->subject = $subject;
$candidaturetocreate->message = $description;
$candidaturetocreate->type_code = 0;
$candidaturetocreate->category_code = null;
$candidaturetocreate->severity_code = null;
$candidaturetocreate->email = $from;
//$candidaturetocreate->lastname = $langs->trans("Anonymous").' - '.$from;
$candidaturetocreate->fk_user_creat = $user->id;
$candidaturetocreate->date_creation = $date;
$candidaturetocreate->fk_project = $projectstatic->id;
$candidaturetocreate->description = $description;
$candidaturetocreate->note_private = $descriptionfull;
$candidaturetocreate->entity = $conf->entity;
$candidaturetocreate->email_msgid = $msgid;
$candidaturetocreate->status = 0;
//$candidaturetocreate->fk_contact = $contactstatic->id;
// Overwrite values with values extracted from source email.
// This may overwrite any $projecttocreate->xxx properties.
$errorforthisaction = $this->overwritePropertiesOfObject($candidaturetocreate, $operation['actionparam'], $messagetext, $subject, $header);
// Set candidature ref if not yet defined
/*if (empty($candidaturetocreate->ref))
{ {
// Get next project Ref $description = $descriptiontitle;
$defaultref = ''; $description = dol_concatdesc($description, "-----");
$modele = empty($conf->global->CANDIDATURE_ADDON) ? 'mod_candidature_simple' : $conf->global->CANDIDATURE_ADDON; $description = dol_concatdesc($description, $descriptionmeta);
$description = dol_concatdesc($description, "-----");
$description = dol_concatdesc($description, $messagetext);
// Search template files $descriptionfull = $description;
$file = ''; $classname = ''; $filefound = 0; $reldir = ''; $descriptionfull = dol_concatdesc($descriptionfull, "----- Header");
$dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']); $descriptionfull = dol_concatdesc($descriptionfull, $header);
foreach ($dirmodels as $reldir)
{
$file = dol_buildpath($reldir."core/modules/ticket/".$modele.'.php', 0);
if (file_exists($file))
{
$filefound = 1;
$classname = $modele;
break;
}
}
if ($filefound) $candidaturetocreate->subject = $subject;
{ $candidaturetocreate->message = $description;
$result = dol_include_once($reldir."core/modules/ticket/".$modele.'.php'); $candidaturetocreate->type_code = 0;
$modCandidature = new $classname; $candidaturetocreate->category_code = null;
$candidaturetocreate->severity_code = null;
$candidaturetocreate->email = $from;
//$candidaturetocreate->lastname = $langs->trans("Anonymous").' - '.$from;
$candidaturetocreate->fk_user_creat = $user->id;
$candidaturetocreate->date_creation = $date;
$candidaturetocreate->fk_project = $projectstatic->id;
$candidaturetocreate->description = $description;
$candidaturetocreate->note_private = $descriptionfull;
$candidaturetocreate->entity = $conf->entity;
$candidaturetocreate->email_msgid = $msgid;
$candidaturetocreate->status = $candidaturetocreate::STATUS_DRAFT;
//$candidaturetocreate->fk_contact = $contactstatic->id;
if ($savesocid > 0) // Overwrite values with values extracted from source email.
{ // This may overwrite any $projecttocreate->xxx properties.
if ($savesocid != $candidaturetocreate->socid) $errorforthisaction = $this->overwritePropertiesOfObject($candidaturetocreate, $operation['actionparam'], $messagetext, $subject, $header);
{
$errorforactions++;
setEventMessages('You loaded a thirdparty (id='.$savesocid.') and you force another thirdparty id (id='.$candidaturetocreate->socid.') by setting socid in operation with a different value', null, 'errors');
}
} else {
if ($candidaturetocreate->socid > 0)
{
$thirdpartystatic->fetch($candidaturetocreate->socid);
}
}
$defaultref = $modCandidature->getNextValue(($thirdpartystatic->id > 0 ? $thirdpartystatic : null), $tickettocreate); // Set candidature ref if not yet defined
} /*if (empty($candidaturetocreate->ref)) We do not need this because we create object in draft status
$candidaturetocreate->ref = $defaultref; {
}*/ // Get next Ref
$defaultref = '';
$modele = empty($conf->global->CANDIDATURE_ADDON) ? 'mod_candidature_simple' : $conf->global->CANDIDATURE_ADDON;
if ($errorforthisaction) // Search template files
{ $file = ''; $classname = ''; $filefound = 0; $reldir = '';
$errorforactions++; $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
} else { foreach ($dirmodels as $reldir)
// Create project {
$result = $candidaturetocreate->create($user); $file = dol_buildpath($reldir."core/modules/ticket/".$modele.'.php', 0);
if ($result <= 0) if (file_exists($file))
{ {
$errorforactions++; $filefound = 1;
$this->error = 'Failed to create ticket: '.join(', ', $candidaturetocreate->errors); $classname = $modele;
$this->errors = $candidaturetocreate->errors; break;
} }
}
if ($filefound)
{
if ($savesocid > 0)
{
if ($savesocid != $candidaturetocreate->socid)
{
$errorforactions++;
setEventMessages('You loaded a thirdparty (id='.$savesocid.') and you force another thirdparty id (id='.$candidaturetocreate->socid.') by setting socid in operation with a different value', null, 'errors');
}
} else {
if ($candidaturetocreate->socid > 0)
{
$thirdpartystatic->fetch($candidaturetocreate->socid);
}
}
$result = dol_include_once($reldir."core/modules/ticket/".$modele.'.php');
$modModuleToUseForNextValue = new $classname;
$defaultref = $modModuleToUseForNextValue->getNextValue(($thirdpartystatic->id > 0 ? $thirdpartystatic : null), $tickettocreate);
}
$candidaturetocreate->ref = $defaultref;
}*/
if ($errorforthisaction)
{
$errorforactions++;
} else {
// Create project
$result = $candidaturetocreate->create($user);
if ($result <= 0)
{
$errorforactions++;
$this->error = 'Failed to create ticket: '.join(', ', $candidaturetocreate->errors);
$this->errors = $candidaturetocreate->errors;
}
}
} }
} }
// Create event specific on hook // Create event specific on hook

View File

@ -469,11 +469,12 @@ class Project extends CommonObject
/** /**
* Get object from database * Get object from database
* *
* @param int $id Id of object to load * @param int $id Id of object to load
* @param string $ref Ref of project * @param string $ref Ref of project
* @return int >0 if OK, 0 if not found, <0 if KO * @param string $email_msgid Email msgid
* @return int >0 if OK, 0 if not found, <0 if KO
*/ */
public function fetch($id, $ref = '') public function fetch($id, $ref = '', $email_msgid = '')
{ {
global $conf; global $conf;
@ -485,11 +486,14 @@ class Project extends CommonObject
$sql .= " FROM ".MAIN_DB_PREFIX."projet"; $sql .= " FROM ".MAIN_DB_PREFIX."projet";
if (!empty($id)) if (!empty($id))
{ {
$sql .= " WHERE rowid=".$id; $sql .= " WHERE rowid = ".$id;
} elseif (!empty($ref)) } else {
{ $sql .= " WHERE entity IN (".getEntity('project').")";
$sql .= " WHERE ref='".$this->db->escape($ref)."'"; if (! empty($ref)) {
$sql .= " AND entity IN (".getEntity('project').")"; $sql .= " AND ref = '".$this->db->escape($ref)."'";
} else {
$sql .= " AND email_msgid = '".$this->db->escape($email_msgid)."'";
}
} }
dol_syslog(get_class($this)."::fetch", LOG_DEBUG); dol_syslog(get_class($this)."::fetch", LOG_DEBUG);

View File

@ -333,13 +333,16 @@ class RecruitmentCandidature extends CommonObject
/** /**
* Load object in memory from the database * Load object in memory from the database
* *
* @param int $id Id object * @param int $id Id object
* @param string $ref Ref * @param string $ref Ref
* @return int <0 if KO, 0 if not found, >0 if OK * @param string $email_msgid Email msgid
* @return int <0 if KO, 0 if not found, >0 if OK
*/ */
public function fetch($id, $ref = null) public function fetch($id, $ref = null, $email_msgid = '')
{ {
$result = $this->fetchCommon($id, $ref); $morewhere = '';
if ($email_msgid) $morewhere = " AND email_msgid = '".$this->db->escape($email_msgid)."'";
$result = $this->fetchCommon($id, $ref, $morewhere);
if ($result > 0 && !empty($this->table_element_line)) $this->fetchLines(); if ($result > 0 && !empty($this->table_element_line)) $this->fetchLines();
return $result; return $result;
} }

View File

@ -204,7 +204,7 @@ if ($object->id > 0)
$objthirdparty = $object; $objthirdparty = $object;
$objcon = new stdClass(); $objcon = new stdClass();
$out = '&origin='.$object->element.'&originid='.$object->id; $out = '&origin='.$object->element.'@recruitment&originid='.$object->id;
$permok = $user->rights->agenda->myactions->create; $permok = $user->rights->agenda->myactions->create;
if ((!empty($objthirdparty->id) || !empty($objcon->id)) && $permok) if ((!empty($objthirdparty->id) || !empty($objcon->id)) && $permok)
{ {

View File

@ -204,7 +204,7 @@ if ($object->id > 0)
$objthirdparty = $object; $objthirdparty = $object;
$objcon = new stdClass(); $objcon = new stdClass();
$out = '&origin='.$object->element.'&originid='.$object->id; $out = '&origin='.$object->element.'@recruitment&originid='.$object->id;
$permok = $user->rights->agenda->myactions->create; $permok = $user->rights->agenda->myactions->create;
if ((!empty($objthirdparty->id) || !empty($objcon->id)) && $permok) if ((!empty($objthirdparty->id) || !empty($objcon->id)) && $permok)
{ {

View File

@ -470,12 +470,13 @@ class Ticket extends CommonObject
/** /**
* Load object in memory from the database * Load object in memory from the database
* *
* @param int $id Id object * @param int $id Id object
* @param string $ref Ref * @param string $ref Ref
* @param string $track_id Track id, a hash like ref * @param string $track_id Track id, a hash like ref
* @return int <0 if KO, >0 if OK * @param string $email_msgid Email msgid
* @return int <0 if KO, >0 if OK
*/ */
public function fetch($id = '', $ref = '', $track_id = '') public function fetch($id = '', $ref = '', $track_id = '', $email_msgid = '')
{ {
global $langs; global $langs;
@ -520,10 +521,12 @@ class Ticket extends CommonObject
$sql .= " WHERE t.rowid = ".$this->db->escape($id); $sql .= " WHERE t.rowid = ".$this->db->escape($id);
} else { } else {
$sql .= " WHERE t.entity IN (".getEntity($this->element, 1).")"; $sql .= " WHERE t.entity IN (".getEntity($this->element, 1).")";
if ($track_id) { if (! empty($ref)) {
$sql .= " AND t.track_id = '".$this->db->escape($track_id)."'";
} elseif ($ref) {
$sql .= " AND t.ref = '".$this->db->escape($ref)."'"; $sql .= " AND t.ref = '".$this->db->escape($ref)."'";
} elseif ($track_id) {
$sql .= " AND t.track_id = '".$this->db->escape($track_id)."'";
} else {
$sql .= " AND t.email_msgid = '".$this->db->escape($email_msgid)."'";
} }
} }