From 009395443778102b1e159619e21f7e0a99f1bc9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20St=C5=99=C3=ADbrn=C3=BD?= <35335130+kubajznik@users.noreply.github.com> Date: Wed, 15 Mar 2023 16:00:20 +0100 Subject: [PATCH 1/2] NEW Support contact in post() document API When uploading a document via the API, add the modulepart "contact". By this, documents linked to a contact can be uploaded. --- htdocs/api/class/api_documents.class.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/htdocs/api/class/api_documents.class.php b/htdocs/api/class/api_documents.class.php index 78442622c7e..5ab7de3f384 100644 --- a/htdocs/api/class/api_documents.class.php +++ b/htdocs/api/class/api_documents.class.php @@ -666,13 +666,22 @@ class Documents extends DolibarrApi $modulepart = 'propale'; require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php'; $object = new Propal($this->db); + } elseif ($modulepart == 'contact' || $modulepart == 'socpeople') { + $modulepart = 'contact'; + require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php'; + $object = new Contact($this->db); + $fetchbyid = true; } else { // TODO Implement additional moduleparts throw new RestException(500, 'Modulepart '.$modulepart.' not implemented yet.'); } if (is_object($object)) { - $result = $object->fetch('', $ref); + if ($fetchbyid) { + $result = $object->fetch($ref); + } else { + $result = $object->fetch('', $ref); + } if ($result == 0) { throw new RestException(404, "Object with ref '".$ref."' was not found."); From 932f561fd044ba1b3280a3edd80dd2dab232fe25 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 17 Mar 2023 21:07:30 +0100 Subject: [PATCH 2/2] Update api_documents.class.php --- htdocs/api/class/api_documents.class.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/htdocs/api/class/api_documents.class.php b/htdocs/api/class/api_documents.class.php index 5ab7de3f384..7cd84d656da 100644 --- a/htdocs/api/class/api_documents.class.php +++ b/htdocs/api/class/api_documents.class.php @@ -607,7 +607,8 @@ class Documents extends DolibarrApi if ($ref) { $tmpreldir = ''; - + $fetchbyid = false; + if ($modulepart == 'facture' || $modulepart == 'invoice') { $modulepart = 'facture';