diff --git a/dev/tools/phan/baseline.txt b/dev/tools/phan/baseline.txt index 1c990c53c7862..aa16693222899 100644 --- a/dev/tools/phan/baseline.txt +++ b/dev/tools/phan/baseline.txt @@ -58,7 +58,7 @@ return [ 'htdocs/adherents/stats/index.php' => ['PhanTypeInvalidDimOffset'], 'htdocs/admin/fckeditor.php' => ['PhanTypeMismatchArgumentProbablyReal'], 'htdocs/api/class/api_access.class.php' => ['PhanPluginUnknownArrayMethodParamType', 'PhanUndeclaredProperty'], - 'htdocs/api/class/api_documents.class.php' => ['PhanPluginDuplicateExpressionBinaryOp', 'PhanPluginUnknownArrayMethodReturnType', 'PhanPossiblyUndeclaredVariable'], + 'htdocs/api/class/api_documents.class.php' => ['PhanPluginUnknownArrayMethodParamType', 'PhanPluginDuplicateExpressionBinaryOp', 'PhanPluginUnknownArrayMethodReturnType', 'PhanPossiblyUndeclaredVariable'], 'htdocs/api/class/api_login.class.php' => ['PhanPluginUnknownArrayMethodReturnType'], 'htdocs/api/class/api_setup.class.php' => ['PhanPluginUnknownArrayMethodReturnType'], 'htdocs/api/class/api_status.class.php' => ['PhanPluginUnknownArrayMethodReturnType'], diff --git a/htdocs/api/class/api_documents.class.php b/htdocs/api/class/api_documents.class.php index 74e846d8b4774..7c7c624603bbd 100644 --- a/htdocs/api/class/api_documents.class.php +++ b/htdocs/api/class/api_documents.class.php @@ -662,6 +662,9 @@ public function get($id) { * @param string $fileencoding File encoding (''=no encoding, 'base64'=Base 64) * @param int $overwriteifexists Overwrite file if exists (1 by default) * @param int $createdirifnotexists Create subdirectories if the doesn't exists (1 by default) + * @param int $position Position + * @param string $cover Cover info + * @param array $array_options array of options * @return string * * @url POST /upload @@ -669,16 +672,12 @@ public function get($id) { * @throws RestException 400 Bad Request * @throws RestException 403 Access denied * @throws RestException 404 Object not found - * @throws RestException 500 Error on file operationw + * @throws RestException 500 Error on file operation */ - public function post($filename, $modulepart, $ref = '', $subdir = '', $filecontent = '', $fileencoding = '', $overwriteifexists = 0, $createdirifnotexists = 1) + public function post($filename, $modulepart, $ref = '', $subdir = '', $filecontent = '', $fileencoding = '', $overwriteifexists = 0, $createdirifnotexists = 1, $position = 0, $cover = '', $array_options = []) { global $conf; - //var_dump($modulepart); - //var_dump($filename); - //var_dump($filecontent);exit; - $modulepartorig = $modulepart; if (empty($modulepart)) { @@ -939,6 +938,15 @@ public function post($filename, $modulepart, $ref = '', $subdir = '', $fileconte $moreinfo['src_object_type'] = $object->table_element; $moreinfo['src_object_id'] = $object->id; } + if (!empty($array_options)) { + $moreinfo = array_merge($moreinfo, ["array_options" => $array_options]); + } + if (!empty($position)) { + $moreinfo = array_merge($moreinfo, ["position" => $position]); + } + if (!empty($cover)) { + $moreinfo = array_merge($moreinfo, ["cover" => $cover]); + } // Move the temporary file at its final emplacement $result = dol_move($destfiletmp, $dest_file, '0', $overwriteifexists, 1, 1, $moreinfo); diff --git a/htdocs/core/lib/files.lib.php b/htdocs/core/lib/files.lib.php index 1852eadebeb47..cf63c00e9954b 100644 --- a/htdocs/core/lib/files.lib.php +++ b/htdocs/core/lib/files.lib.php @@ -1137,6 +1137,12 @@ function dol_move($srcfile, $destfile, $newmask = '0', $overwriteifexists = 1, $ if (!empty($moreinfo) && !empty($moreinfo['src_object_id'])) { $ecmfile->src_object_id = $moreinfo['src_object_id']; } + if (!empty($moreinfo) && !empty($moreinfo['position'])) { + $ecmfile->position = $moreinfo['position']; + } + if (!empty($moreinfo) && !empty($moreinfo['cover'])) { + $ecmfile->cover = $moreinfo['cover']; + } $resultecm = $ecmfile->create($user); if ($resultecm < 0) { diff --git a/test/phpunit/RestAPIDocumentTest.php b/test/phpunit/RestAPIDocumentTest.php index e0e84b03dd589..897a306ae71bd 100644 --- a/test/phpunit/RestAPIDocumentTest.php +++ b/test/phpunit/RestAPIDocumentTest.php @@ -1,6 +1,7 @@ - * Copyright (C) 2023 Alexandre Janniaux +/* Copyright (C) 2010 Laurent Destailleur + * Copyright (C) 2023 Alexandre Janniaux + * Copyright (C) 2024 Frédéric France * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -131,7 +132,8 @@ public function testPushDocument() 'filecontent' => "content text", 'fileencoding' => "", 'overwriteifexists' => 0, - 'createdirifnotexists' => 0 + 'createdirifnotexists' => 0, + 'position' => 0, ); $param = ''; @@ -161,7 +163,8 @@ public function testPushDocument() 'filecontent' => "content text", 'fileencoding' => "", 'overwriteifexists' => 0, - 'createdirifnotexists' => 0 + 'createdirifnotexists' => 0, + 'position' => 0, ); $param = ''; @@ -189,7 +192,8 @@ public function testPushDocument() 'filecontent' => "content text", 'fileencoding' => "", 'overwriteifexists' => 0, - 'createdirifnotexists' => 1 + 'createdirifnotexists' => 1, + 'position' => 0, ); $param = '';