Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

can set position of file with dol_move #31201

Merged
merged 8 commits into from
Sep 30, 2024
Merged
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
2 changes: 1 addition & 1 deletion dev/tools/phan/baseline.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand Down
20 changes: 14 additions & 6 deletions htdocs/api/class/api_documents.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -662,23 +662,22 @@ 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
*
* @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)) {
Expand Down Expand Up @@ -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);
Expand Down
6 changes: 6 additions & 0 deletions htdocs/core/lib/files.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
14 changes: 9 additions & 5 deletions test/phpunit/RestAPIDocumentTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php
/* Copyright (C) 2010 Laurent Destailleur <[email protected]>
* Copyright (C) 2023 Alexandre Janniaux <[email protected]>
/* Copyright (C) 2010 Laurent Destailleur <[email protected]>
* Copyright (C) 2023 Alexandre Janniaux <[email protected]>
* Copyright (C) 2024 Frédéric France <[email protected]>
*
* 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
Expand Down Expand Up @@ -131,7 +132,8 @@ public function testPushDocument()
'filecontent' => "content text",
'fileencoding' => "",
'overwriteifexists' => 0,
'createdirifnotexists' => 0
'createdirifnotexists' => 0,
'position' => 0,
);

$param = '';
Expand Down Expand Up @@ -161,7 +163,8 @@ public function testPushDocument()
'filecontent' => "content text",
'fileencoding' => "",
'overwriteifexists' => 0,
'createdirifnotexists' => 0
'createdirifnotexists' => 0,
'position' => 0,
);

$param = '';
Expand Down Expand Up @@ -189,7 +192,8 @@ public function testPushDocument()
'filecontent' => "content text",
'fileencoding' => "",
'overwriteifexists' => 0,
'createdirifnotexists' => 1
'createdirifnotexists' => 1,
'position' => 0,
);

$param = '';
Expand Down
Loading