Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions admin/attachments_setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@
// Example with a yes / no select
setup_print_on_off('ATTACHMENTS_INCLUDE_PRODUCT_LINES');
setup_print_on_off('ATTACHMENTS_INCLUDE_OBJECT_LINKED');
setup_print_on_off('ATTACHMENTS_INCLUDE_PROJECT_LINKED'); // InfraS add

if (!empty($conf->ecm->enabled))
{
Expand Down
17 changes: 15 additions & 2 deletions class/actions_attachments.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ class ActionsAttachments extends \attachments\RetroCompatCommonHookActions
, 'AttachmentsTitleFactureFournisseur' => 35
, 'AttachmentsTitleFicheInter' => 40
, 'AttachmentsSociete' => 50
, 'AttachmentsTitleTask' =>60
, 'AttachmentsTitleProject' => 55
, 'AttachmentsTitleTask' => 60
, 'AttachmentsTitleEcm' => 500
);

Expand All @@ -71,6 +72,7 @@ class ActionsAttachments extends \attachments\RetroCompatCommonHookActions
, 'fichinter' => 'AttachmentsTitleFicheInter'
, 'societe' => 'AttachmentsSociete'
, 'ecm' => 'AttachmentsTitleEcm'
, 'project' => 'AttachmentsTitleProject'
, 'project_task' => 'AttachmentsTitleTask'
, 'shipping' => 'AttachmentsShipping'
);
Expand Down Expand Up @@ -127,10 +129,20 @@ function doActions($parameters, &$object, &$action, $hookmanager)

$this->current_object = $object;
if (getDolGlobalString('ATTACHMENTS_INCLUDE_OBJECT_LINKED')) {
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);
}
Comment on lines +132 to +145
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 😊

}

if (empty($this->current_object->linkedObjects[$this->current_object->element])) $this->current_object->linkedObjects[$this->current_object->element] = array();
Expand Down Expand Up @@ -195,6 +207,7 @@ function doActions($parameters, &$object, &$action, $hookmanager)
$sub_element_to_use = '';
$subdir = '';
if ($element === 'fichinter') $element_to_use = 'ficheinter';
elseif ($element === 'project') $element_to_use = 'projet';
elseif ($element === 'order_supplier') { $element_to_use = 'fournisseur'; $subdir = '/commande'; }
elseif ($element === 'invoice_supplier') { $element_to_use = 'fournisseur'; $sub_element_to_use = 'facture'; /* $subdir is defined in the next loop */ }
elseif ($element === 'shipping') {$element_to_use = 'expedition'; $subdir = '/sending';}
Expand Down Expand Up @@ -481,7 +494,7 @@ private function nyandog($key, $fullpathselecteddir, $dir = '')

if (is_dir($fullname))
{
$this->nyandog($key, $fullname, $file);
$this->nyandog($key, $fullname.(str_ends_with($fullname, '/') ? '' : '/'), $file);
}
elseif (is_file($fullname))
{
Expand Down
4 changes: 3 additions & 1 deletion langs/en_US/attachments.lang
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ AbricotNeedUpdate = The 'Abricot' module need to be update
# SETUP
ATTACHMENTS_INCLUDE_PRODUCT_LINES = Search files related to products /services of the current document
ATTACHMENTS_INCLUDE_OBJECT_LINKED = Search files related to the linked objects of the current document
ATTACHMENTS_INCLUDE_PROJECT_LINKED = Search files related to the linked project of the current document (requires activation of previous option)
ATTACHMENTS_ECM_SCANDIR = Search files in the following folder

# FORMCONFIRM
Expand All @@ -28,8 +29,9 @@ AttachmentsTitleFactureFournisseur = Vendor Invoice
AttachmentsTitleFicheInter = Intervention
AttachmentsSociete = Company
AttachmentsTitleEcm = Documents (EDM)
AttachmentsShipping = Shipping
AttachmentsTitleProject = Project
AttachmentsTitleTask = Task
AttachmentsShipping = Shipping

AttachmentsFiltered = Elements corresponding to your search term
AttachmentsSelectedOnTotalAvailable = Number of selected elements on total available
2 changes: 2 additions & 0 deletions langs/fr_FR/attachments.lang
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ AbricotNeedUpdate=Le module abricot doit être mis à jour
# SETUP
ATTACHMENTS_INCLUDE_PRODUCT_LINES=Activer la recherche dans les fichiers provenant des produits/services du document courant
ATTACHMENTS_INCLUDE_OBJECT_LINKED=Activer la recherche dans les fichiers provenant des éléments liés au document courant
ATTACHMENTS_INCLUDE_PROJECT_LINKED=Activer la recherche dans les fichiers provenant du projet lié au document courant (nécessite l'activation de l'option précédente)
ATTACHMENTS_ECM_SCANDIR=Activer la recherche dans le répertoire suivant

# FORMCONFIRM
Expand All @@ -27,6 +28,7 @@ AttachmentsTitleFactureFournisseur=Facture fournisseur
AttachmentsTitleFicheInter=Intervention
AttachmentsSociete=Société
AttachmentsTitleEcm=Documents (GED)
AttachmentsTitleProject=Projet
AttachmentsTitleTask=Tâches
AttachmentsShipping=Expedition

Expand Down