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

@ -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,10 +1650,14 @@ 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);
$alreadycreated = $projecttocreate->fetch(0, '', $msgid);
if ($alreadycreated == 0)
{
if ($thirdpartystatic->id > 0) if ($thirdpartystatic->id > 0)
{ {
$projecttocreate->socid = $thirdpartystatic->id; $projecttocreate->socid = $thirdpartystatic->id;
@ -1696,7 +1700,7 @@ class EmailCollector extends CommonObject
// Set project ref if not yet defined // Set project ref if not yet defined
if (empty($projecttocreate->ref)) if (empty($projecttocreate->ref))
{ {
// Get next project Ref // Get next Ref
$defaultref = ''; $defaultref = '';
$modele = empty($conf->global->PROJECT_ADDON) ? 'mod_project_simple' : $conf->global->PROJECT_ADDON; $modele = empty($conf->global->PROJECT_ADDON) ? 'mod_project_simple' : $conf->global->PROJECT_ADDON;
@ -1716,9 +1720,6 @@ class EmailCollector extends CommonObject
if ($filefound) if ($filefound)
{ {
$result = dol_include_once($reldir."core/modules/project/".$modele.'.php');
$modProject = new $classname;
if ($savesocid > 0) if ($savesocid > 0)
{ {
if ($savesocid != $projecttocreate->socid) if ($savesocid != $projecttocreate->socid)
@ -1733,7 +1734,9 @@ class EmailCollector extends CommonObject
} }
} }
$defaultref = $modProject->getNextValue(($thirdpartystatic->id > 0 ? $thirdpartystatic : null), $projecttocreate); $result = dol_include_once($reldir."core/modules/project/".$modele.'.php');
$modModuleToUseForNextValue = new $classname;
$defaultref = $modModuleToUseForNextValue->getNextValue(($thirdpartystatic->id > 0 ? $thirdpartystatic : null), $projecttocreate);
} }
$projecttocreate->ref = $defaultref; $projecttocreate->ref = $defaultref;
} }
@ -1758,10 +1761,15 @@ class EmailCollector extends CommonObject
} }
} }
} }
// Create event }
// Create ticket
elseif ($operation['type'] == 'ticket') elseif ($operation['type'] == 'ticket')
{ {
$tickettocreate = new Ticket($this->db); $tickettocreate = new Ticket($this->db);
$alreadycreated = $tickettocreate->fetch(0, '', '', $msgid);
if ($alreadycreated == 0)
{
if ($thirdpartystatic->id > 0) if ($thirdpartystatic->id > 0)
{ {
$tickettocreate->socid = $thirdpartystatic->id; $tickettocreate->socid = $thirdpartystatic->id;
@ -1807,7 +1815,7 @@ class EmailCollector extends CommonObject
// Set ticket ref if not yet defined // Set ticket ref if not yet defined
if (empty($tickettocreate->ref)) if (empty($tickettocreate->ref))
{ {
// Get next project Ref // Get next Ref
$defaultref = ''; $defaultref = '';
$modele = empty($conf->global->TICKET_ADDON) ? 'mod_ticket_simple' : $conf->global->TICKET_ADDON; $modele = empty($conf->global->TICKET_ADDON) ? 'mod_ticket_simple' : $conf->global->TICKET_ADDON;
@ -1827,9 +1835,6 @@ class EmailCollector extends CommonObject
if ($filefound) if ($filefound)
{ {
$result = dol_include_once($reldir."core/modules/ticket/".$modele.'.php');
$modTicket = new $classname;
if ($savesocid > 0) if ($savesocid > 0)
{ {
if ($savesocid != $tickettocreate->socid) if ($savesocid != $tickettocreate->socid)
@ -1844,7 +1849,9 @@ class EmailCollector extends CommonObject
} }
} }
$defaultref = $modTicket->getNextValue(($thirdpartystatic->id > 0 ? $thirdpartystatic : null), $tickettocreate); $result = dol_include_once($reldir."core/modules/ticket/".$modele.'.php');
$modModuleToUseForNextValue = new $classname;
$defaultref = $modModuleToUseForNextValue->getNextValue(($thirdpartystatic->id > 0 ? $thirdpartystatic : null), $tickettocreate);
} }
$tickettocreate->ref = $defaultref; $tickettocreate->ref = $defaultref;
} }
@ -1869,11 +1876,15 @@ class EmailCollector extends CommonObject
} }
} }
} }
}
// Create candidature // Create candidature
elseif ($operation['type'] == 'candidature') elseif ($operation['type'] == 'candidature')
{ {
$candidaturetocreate = new RecruitmentCandidature($this->db); $candidaturetocreate = new RecruitmentCandidature($this->db);
$alreadycreated = $candidaturetocreate->fetch(0, '', $msgid);
if ($alreadycreated == 0)
{
$description = $descriptiontitle; $description = $descriptiontitle;
$description = dol_concatdesc($description, "-----"); $description = dol_concatdesc($description, "-----");
$description = dol_concatdesc($description, $descriptionmeta); $description = dol_concatdesc($description, $descriptionmeta);
@ -1898,7 +1909,7 @@ class EmailCollector extends CommonObject
$candidaturetocreate->note_private = $descriptionfull; $candidaturetocreate->note_private = $descriptionfull;
$candidaturetocreate->entity = $conf->entity; $candidaturetocreate->entity = $conf->entity;
$candidaturetocreate->email_msgid = $msgid; $candidaturetocreate->email_msgid = $msgid;
$candidaturetocreate->status = 0; $candidaturetocreate->status = $candidaturetocreate::STATUS_DRAFT;
//$candidaturetocreate->fk_contact = $contactstatic->id; //$candidaturetocreate->fk_contact = $contactstatic->id;
// Overwrite values with values extracted from source email. // Overwrite values with values extracted from source email.
@ -1906,9 +1917,9 @@ class EmailCollector extends CommonObject
$errorforthisaction = $this->overwritePropertiesOfObject($candidaturetocreate, $operation['actionparam'], $messagetext, $subject, $header); $errorforthisaction = $this->overwritePropertiesOfObject($candidaturetocreate, $operation['actionparam'], $messagetext, $subject, $header);
// Set candidature ref if not yet defined // Set candidature ref if not yet defined
/*if (empty($candidaturetocreate->ref)) /*if (empty($candidaturetocreate->ref)) We do not need this because we create object in draft status
{ {
// Get next project Ref // Get next Ref
$defaultref = ''; $defaultref = '';
$modele = empty($conf->global->CANDIDATURE_ADDON) ? 'mod_candidature_simple' : $conf->global->CANDIDATURE_ADDON; $modele = empty($conf->global->CANDIDATURE_ADDON) ? 'mod_candidature_simple' : $conf->global->CANDIDATURE_ADDON;
@ -1928,9 +1939,6 @@ class EmailCollector extends CommonObject
if ($filefound) if ($filefound)
{ {
$result = dol_include_once($reldir."core/modules/ticket/".$modele.'.php');
$modCandidature = new $classname;
if ($savesocid > 0) if ($savesocid > 0)
{ {
if ($savesocid != $candidaturetocreate->socid) if ($savesocid != $candidaturetocreate->socid)
@ -1945,7 +1953,9 @@ class EmailCollector extends CommonObject
} }
} }
$defaultref = $modCandidature->getNextValue(($thirdpartystatic->id > 0 ? $thirdpartystatic : null), $tickettocreate); $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; $candidaturetocreate->ref = $defaultref;
}*/ }*/
@ -1964,6 +1974,7 @@ class EmailCollector extends CommonObject
} }
} }
} }
}
// Create event specific on hook // Create event specific on hook
// this code action is hook..... for support this call // this code action is hook..... for support this call
elseif (substr($operation['type'], 0, 4) == 'hook') { elseif (substr($operation['type'], 0, 4) == 'hook') {

View File

@ -471,9 +471,10 @@ class Project extends CommonObject
* *
* @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
* @param string $email_msgid Email msgid
* @return int >0 if OK, 0 if not found, <0 if KO * @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;
@ -486,10 +487,13 @@ class Project extends CommonObject
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

@ -335,11 +335,14 @@ class RecruitmentCandidature extends CommonObject
* *
* @param int $id Id object * @param int $id Id object
* @param string $ref Ref * @param string $ref Ref
* @param string $email_msgid Email msgid
* @return int <0 if KO, 0 if not found, >0 if OK * @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

@ -473,9 +473,10 @@ class Ticket extends CommonObject
* @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
* @param string $email_msgid Email msgid
* @return int <0 if KO, >0 if OK * @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)."'";
} }
} }