Skip to content

Conversation

@SylvainLegrand
Copy link

Some customer need to include files from linked project to email.

Comment on lines +132 to +145
if (getDolGlobalString('ATTACHMENTS_INCLUDE_PROJECT_LINKED') && !empty($this->current_object->fk_project)) {
$sql = 'INSERT INTO '.MAIN_DB_PREFIX.'element_element (fk_source, sourcetype, fk_target, targettype) VALUES ('.$this->current_object->id.', "'.$this->current_object->element.'", '.$this->current_object->fk_project.', "project")';
$resql = $this->db->query($sql);
$this->db->free($resql);
}
$this->current_object->fetchObjectLinked();
if(!empty($this->current_object->fk_soc)) $fk_soc = $this->current_object->fk_soc ?? 0;
else $fk_soc = $this->current_object->socid ?? 0;
$this->current_object->linkedObjects['societe'][$fk_soc] = $this->current_object->thirdparty;
if (getDolGlobalString('ATTACHMENTS_INCLUDE_PROJECT_LINKED') && !empty($this->current_object->fk_project)) {
$sql = 'DELETE FROM '.MAIN_DB_PREFIX.'element_element WHERE fk_source = '.$this->current_object->id.' AND sourcetype LIKE "'.$this->current_object->element.'" AND fk_target = '.$this->current_object->fk_project.' AND targettype LIKE "project"';
$resql = $this->db->query($sql);
$this->db->free($resql);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi,

Thanks a lot for your contribution! 🙌 It's great to see improvements being proposed around project-related document handling — definitely a valuable area to enhance.

That said, I wanted to give you some feedback on the current implementation. Right now, the logic creates a link in element_element between the object and the project, and then removes it right after. While this might seem to work, it’s actually a workaround that bypasses Dolibarr’s intended data model and could lead to unintended side effects or performance issues.

👉 In this case, the cleaner and more maintainable approach would be to rely on the native fk_project field. This field is specifically designed to link objects to projects without the need to manually insert or remove records from the object links.

I’d recommend reworking the implementation in that direction. If you need help or an example to guide you, feel free to reach out — I’ll be happy to support.

Thanks again for your PR, and I hope to see more of your contributions in the future 😊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants