[TikiWiki-commits] [Git][tikiwiki/tiki][28.x] [BP][FIX] File Gallery: Respect archive limit by deleting oldest versions when exceeded
"Olivier Kango \(@olivierkango\) via TikiWiki-cvs" <[email protected]>
| Newsgroups | gmane.comp.cms.tiki.cvs |
|---|---|
| Message-ID | <68af142d68b1b_2cd7370588c3@gitlab-sidekiq-low-urgency-cpu-bound-v2-75c5d7f49c-w9rk9.mail> |
Olivier Kango pushed to branch 28.x at Tiki Wiki CMS Groupware / Tiki
Commits:
52786cb7 by Olivier Kango at 2025-08-27T17:13:38+03:00
[BP][FIX] File Gallery: Respect archive limit by deleting oldest versions when exceeded
---
* [FIX] File Gallery: Respect archive limit by deleting oldest versions when exceeded
---
* [FIX] Remove ORDER BY clause from COUNT(*) subquery to avoid SQL error on strict servers
See merge request tikiwiki/tiki!7570
(cherry picked from commit f6ad49a19f1984392ed65241badb5e2df9928435)
See merge request tikiwiki/tiki!7640
- - - - -
2 changed files:
- lib/core/Tiki/FileGallery/SaveHandler.php
- lib/filegals/filegallib.php
Changes:
=====================================
lib/core/Tiki/FileGallery/SaveHandler.php
=====================================
@@ -7,6 +7,7 @@
namespace Tiki\FileGallery;
use TikiLib;
+use Tiki\FileGallery\File as TikiFile;
class SaveHandler
{
@@ -212,12 +213,18 @@ class SaveHandler
if ($archives['cant'] >= $count_archives) {
$toRemove = [];
- foreach ($archives['data'] as $i => $values) {
+ // Remove only the oldest archived versions to keep the latest ones within the archive limit
+ $archivesToDelete = array_slice($archives['data'], 0, $archives['count'] - $count_archives);
+
+
+ foreach ($archivesToDelete as $values) {
$toRemove[] = $values['fileId'];
$definition->delete(new TikiFile($values));
}
$this->filesTable->deleteMultiple(['fileId' => $this->filesTable->in($toRemove)]);
+
+ \Feedback::success(tr('%0 archive(s) max allowed — %1 older version(s) have been deleted for file %2.', $count_archives, count($toRemove), $file->name));
}
}
if ($prefs['fgal_keep_fileId'] != 'y') {
=====================================
lib/filegals/filegallib.php
=====================================
@@ -2818,8 +2818,8 @@ class FileGalLib extends TikiLib
}
$need_everything = ( $with_subgals_size && ( $sort_mode == 'size_asc' || $sort_mode == 'filesize_asc' ) );
if (! $need_everything) {
- $numQuery = preg_replace("/^SELECT.*?FROM/", "SELECT COUNT(*) FROM", $query);
- $numQuery = preg_replace("/ ORDER BY .*$/", "", $numQuery);
+ $numQuery = preg_replace("/ ORDER BY .*$/", "", $query);
+ $numQuery = "SELECT COUNT(*) FROM (" . $numQuery . ") AS grouped";
$numResults = $this->getOne($numQuery, $bindvars);
$limit = $offset == -1 ? 0 : $offset;
$limit .= ', ' . ($maxRecords == -1 ? PHP_INT_MAX : $maxRecords);
View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/52786cb7e58cf7be81742f7594288abe65f4a1c4
--
View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/52786cb7e58cf7be81742f7594288abe65f4a1c4
You're receiving this email because of your account on gitlab.com.
_______________________________________________
TikiWiki-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tikiwiki-cvs