order documents by id, return null if getDocumentByOriginalFilename() does not find any documents

This commit is contained in:
Uwe Steinmann 2021-09-22 09:41:23 +02:00
parent 96f8c1db21
commit b6452faa9b

View File

@ -787,12 +787,15 @@ class SeedDMS_Core_DMS {
* This function searches a document by the name of the last document
* version and restricts the search
* to given folder if passed as the second parameter.
* 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 original file
* @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 getDocumentByOriginalFilename($name, $folder=null) { /* {{{ */
$name = trim($name);
if (!$name) return false;
if (!$this->db->createTemporaryTable("ttcontentid")) {
@ -806,14 +809,14 @@ class SeedDMS_Core_DMS {
"WHERE `tblDocumentContent`.`orgFileName` = " . $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 */