diff --git a/SeedDMS_Core/Core/inc.ClassFolder.php b/SeedDMS_Core/Core/inc.ClassFolder.php index 49db688f3..cd6dd5ab0 100644 --- a/SeedDMS_Core/Core/inc.ClassFolder.php +++ b/SeedDMS_Core/Core/inc.ClassFolder.php @@ -2076,6 +2076,40 @@ class SeedDMS_Core_Folder extends SeedDMS_Core_Object { return $resArr[0]; } /* }}} */ + /** + * Reorder documents of folder + * + * Fix the sequence numbers of all documents in the folder, by assigning new + * numbers starting from 1 incrementing by 1. This can be necessary if sequence + * numbers are not unique which makes manual reordering for documents with + * identical sequence numbers impossible. + * + * @return bool false in case of an error, otherwise true + */ + function reorderDocuments() { /* {{{ */ + $db = $this->_dms->getDB(); + + $queryStr = "SELECT `id` FROM `tblDocuments` WHERE `folder` = " . (int) $this->_id; + $resArr = $db->getResultArray($queryStr); + if (is_bool($resArr) && $resArr == false) + return false; + + $db->startTransaction(); + $no = 1.0; + foreach($resArr as $doc) { + $queryStr = "UPDATE `tblDocuments` SET `sequence` = " . $no . " WHERE `id` = ". $doc['id']; + if (!$db->getResult($queryStr)) { + $db->rollbackTransaction(); + return false; + } + $no += 1.0; + } + $db->commitTransaction(); + + return true; + } /* }}} */ + + } ?> diff --git a/SeedDMS_Core/package.xml b/SeedDMS_Core/package.xml index b983a42fd..becb75ddc 100644 --- a/SeedDMS_Core/package.xml +++ b/SeedDMS_Core/package.xml @@ -2028,7 +2028,7 @@ add method SeedDMS_Core_DatabaseAccess::setLogFp() - SeedDMS_Core_DMS::createPasswordRequest() creates a cryptographically secure hash - fix sql error when deleting a folder attribute - add SeedDMS_Core_Attribute::getParsedValue() and use it in SeedDMS_Core_Object::getAttributeValue() -- add SeedDMS_Core_DMS::getDuplicateSequenceNo() +- add SeedDMS_Core_DMS::getDuplicateSequenceNo() and SeedDMS_Core_Folder::reorderDocuments()