order documents by id in getDocumentByName(), return null if not document was found

This commit is contained in:
Uwe Steinmann 2021-09-22 09:40:25 +02:00
parent b777b786dd
commit 96f8c1db21

View File

@ -748,12 +748,12 @@ class SeedDMS_Core_DMS {
*
* This function searches a document by its name and restricts the search
* to the given folder if passed as the second parameter.
* If there are more than one document with that name, then only the first
* one will be returned.
* If there are more than one document with that name, then only the
* one with the highest id will be returned.
*
* @param string $name
* @param object $folder
* @return SeedDMS_Core_Document|boolean found document or false
* @param string $name Name of the document
* @param object $folder parent folder of document
* @return SeedDMS_Core_Document|null|boolean found document or null if not document was found or false in case of an error
*/
function getDocumentByName($name, $folder=null) { /* {{{ */
$name = trim($name);
@ -765,14 +765,14 @@ class SeedDMS_Core_DMS {
"WHERE `tblDocuments`.`name` = " . $this->db->qstr($name);
if($folder)
$queryStr .= " AND `tblDocuments`.`folder` = ". $folder->getID();
$queryStr .= " LIMIT 1";
$queryStr .= " ORDER BY `tblDocuments`.`id` DESC LIMIT 1";
$resArr = $this->db->getResultArray($queryStr);
if (is_bool($resArr) && !$resArr)
return false;
if(!$resArr)
return false;
return null;
$row = $resArr[0];
/** @var SeedDMS_Core_Document $document */