From d0a4ae88b144d1d6fa03ebd8001f1f2b6807d9a8 Mon Sep 17 00:00:00 2001 From: Florian Mortgat Date: Thu, 24 Jun 2021 10:21:56 +0200 Subject: [PATCH 1/3] NEW: make it easier to set the `keyword`, `keywords` and `description` attributes of an ecm file object --- htdocs/core/lib/files.lib.php | 4 +++- htdocs/ecm/class/ecmfiles.class.php | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/htdocs/core/lib/files.lib.php b/htdocs/core/lib/files.lib.php index 7e34eec5ecd..8e44e30f445 100644 --- a/htdocs/core/lib/files.lib.php +++ b/htdocs/core/lib/files.lib.php @@ -1789,7 +1789,9 @@ function addFileIntoDatabaseIndex($dir, $file, $fullpathorig = '', $mode = 'uplo if (is_object($object) && $object->id > 0) { $ecmfile->src_object_id = $object->id; - $ecmfile->src_object_type = $object->table_element; + if (isset($object->table_element)) $ecmfile->src_object_type = $object->table_element; + if (isset($object->src_object_description)) $ecmfile->description = $object->src_object_description; + if (isset($object->src_object_keyword)) $ecmfile->keyword = $object->src_object_keyword; } if ($setsharekey) { diff --git a/htdocs/ecm/class/ecmfiles.class.php b/htdocs/ecm/class/ecmfiles.class.php index 035a7aee9c6..df18aa13d2f 100644 --- a/htdocs/ecm/class/ecmfiles.class.php +++ b/htdocs/ecm/class/ecmfiles.class.php @@ -288,6 +288,7 @@ class EcmFiles extends CommonObject $sql .= 'fullpath_orig,'; $sql .= 'description,'; $sql .= 'keywords,'; + $sql .= 'keyword,'; $sql .= 'cover,'; $sql .= 'position,'; $sql .= 'gen_or_uploaded,'; @@ -309,6 +310,7 @@ class EcmFiles extends CommonObject $sql .= ' '.(!isset($this->fullpath_orig) ? 'NULL' : "'".$this->db->escape($this->fullpath_orig)."'").','; $sql .= ' '.(!isset($this->description) ? 'NULL' : "'".$this->db->escape($this->description)."'").','; $sql .= ' '.(!isset($this->keywords) ? 'NULL' : "'".$this->db->escape($this->keywords)."'").','; + $sql .= ' '.(!isset($this->keyword) ? 'NULL' : "'".$this->db->escape($this->keyword)."'").','; $sql .= ' '.(!isset($this->cover) ? 'NULL' : "'".$this->db->escape($this->cover)."'").','; $sql .= ' '.$maxposition.','; $sql .= ' '.(!isset($this->gen_or_uploaded) ? 'NULL' : "'".$this->db->escape($this->gen_or_uploaded)."'").','; From 94416072d8a5ae072cfeed77781fb5db8b88c59f Mon Sep 17 00:00:00 2001 From: Florian Mortgat Date: Wed, 30 Jun 2021 09:34:49 +0200 Subject: [PATCH 2/3] FIX after PR feedback: remove uses of `keyword` attribute of EcmFiles (use `keywords` instead) --- htdocs/core/lib/files.lib.php | 4 ++-- htdocs/ecm/class/ecmfiles.class.php | 2 -- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/htdocs/core/lib/files.lib.php b/htdocs/core/lib/files.lib.php index 8e44e30f445..5b2f9fa7f4b 100644 --- a/htdocs/core/lib/files.lib.php +++ b/htdocs/core/lib/files.lib.php @@ -1785,13 +1785,13 @@ function addFileIntoDatabaseIndex($dir, $file, $fullpathorig = '', $mode = 'uplo $ecmfile->fullpath_orig = $fullpathorig; $ecmfile->gen_or_uploaded = $mode; $ecmfile->description = ''; // indexed content - $ecmfile->keyword = ''; // keyword content + $ecmfile->keywords = ''; // keyword content if (is_object($object) && $object->id > 0) { $ecmfile->src_object_id = $object->id; if (isset($object->table_element)) $ecmfile->src_object_type = $object->table_element; if (isset($object->src_object_description)) $ecmfile->description = $object->src_object_description; - if (isset($object->src_object_keyword)) $ecmfile->keyword = $object->src_object_keyword; + if (isset($object->src_object_keywords)) $ecmfile->keywords = $object->src_object_keywords; } if ($setsharekey) { diff --git a/htdocs/ecm/class/ecmfiles.class.php b/htdocs/ecm/class/ecmfiles.class.php index df18aa13d2f..035a7aee9c6 100644 --- a/htdocs/ecm/class/ecmfiles.class.php +++ b/htdocs/ecm/class/ecmfiles.class.php @@ -288,7 +288,6 @@ class EcmFiles extends CommonObject $sql .= 'fullpath_orig,'; $sql .= 'description,'; $sql .= 'keywords,'; - $sql .= 'keyword,'; $sql .= 'cover,'; $sql .= 'position,'; $sql .= 'gen_or_uploaded,'; @@ -310,7 +309,6 @@ class EcmFiles extends CommonObject $sql .= ' '.(!isset($this->fullpath_orig) ? 'NULL' : "'".$this->db->escape($this->fullpath_orig)."'").','; $sql .= ' '.(!isset($this->description) ? 'NULL' : "'".$this->db->escape($this->description)."'").','; $sql .= ' '.(!isset($this->keywords) ? 'NULL' : "'".$this->db->escape($this->keywords)."'").','; - $sql .= ' '.(!isset($this->keyword) ? 'NULL' : "'".$this->db->escape($this->keyword)."'").','; $sql .= ' '.(!isset($this->cover) ? 'NULL' : "'".$this->db->escape($this->cover)."'").','; $sql .= ' '.$maxposition.','; $sql .= ' '.(!isset($this->gen_or_uploaded) ? 'NULL' : "'".$this->db->escape($this->gen_or_uploaded)."'").','; From 924cff44f3230dfc5b261d1f3a3e150d51bb5b17 Mon Sep 17 00:00:00 2001 From: Florian Mortgat Date: Fri, 9 Jul 2021 09:16:27 +0200 Subject: [PATCH 3/3] FIX PR feedback: in `addFileIntoDatabaseIndex`, return error if $object is set with an ID but without a table_element --- htdocs/core/lib/files.lib.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/htdocs/core/lib/files.lib.php b/htdocs/core/lib/files.lib.php index b2244e9b174..45253d6a441 100644 --- a/htdocs/core/lib/files.lib.php +++ b/htdocs/core/lib/files.lib.php @@ -1789,8 +1789,13 @@ function addFileIntoDatabaseIndex($dir, $file, $fullpathorig = '', $mode = 'uplo if (is_object($object) && $object->id > 0) { $ecmfile->src_object_id = $object->id; - if (isset($object->table_element)) $ecmfile->src_object_type = $object->table_element; - if (isset($object->src_object_description)) $ecmfile->description = $object->src_object_description; + if (isset($object->table_element)) { + $ecmfile->src_object_type = $object->table_element; + if (isset($object->src_object_description)) $ecmfile->description = $object->src_object_description; + } else { + dol_syslog('Error: object ' . get_class($object) . ' has no table_element attribute.'); + return -1; + } if (isset($object->src_object_keywords)) $ecmfile->keywords = $object->src_object_keywords; }