diff --git a/SeedDMS_Core/Core/inc.ClassFolder.php b/SeedDMS_Core/Core/inc.ClassFolder.php index 11cb88026..f0a3b092a 100644 --- a/SeedDMS_Core/Core/inc.ClassFolder.php +++ b/SeedDMS_Core/Core/inc.ClassFolder.php @@ -2068,6 +2068,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 1b514eec2..5f75fd99e 100644 --- a/SeedDMS_Core/package.xml +++ b/SeedDMS_Core/package.xml @@ -29,7 +29,7 @@ - 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()