Skip to content

Commit

Permalink
tweak(Tinebase/Notes): cleanup notes now respects DELETED_DATA_RETENT…
Browse files Browse the repository at this point in the history
…ION_TIME
  • Loading branch information
pschuele committed Mar 18, 2024
1 parent 3606d28 commit 5570b78
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
2 changes: 1 addition & 1 deletion tine20/Tinebase/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -2122,7 +2122,7 @@ public function removeObsoleteData(?Tinebase_DateTime $beforeDate = null, array
$this->_purgeTables($beforeDate, $orderedTables);

if ($doEverything) {
Tinebase_Notes::getInstance()->removeObsoleteData();
Tinebase_Notes::getInstance()->removeObsoleteData(beforeDate: $beforeDate);

// TODO implement
/*
Expand Down
27 changes: 19 additions & 8 deletions tine20/Tinebase/Notes.php
Original file line number Diff line number Diff line change
Expand Up @@ -918,9 +918,7 @@ public function getAllNotes($orderBy = null, $limit = null, $offset = null)
$stmt = $this->_db->query($select);
$rows = $stmt->fetchAll(Zend_Db::FETCH_ASSOC);

$result = new Tinebase_Record_RecordSet('Tinebase_Model_Note', $rows, true);

return $result;
return new Tinebase_Record_RecordSet('Tinebase_Model_Note', $rows, true);
}

/**
Expand Down Expand Up @@ -949,14 +947,19 @@ public function has(array $_ids, $_getDeleted = false)
/**
* @param bool $purge
* @param int $offset
* @param bool|null $dryrun
* @param ?bool $dryrun
* @param ?Tinebase_DateTime $beforeDate
* @return int
* @throws Tinebase_Exception_AccessDenied
* @throws Tinebase_Exception_InvalidArgument
*/
public function removeObsoleteData(bool $purge = false, int $offset = 0, ?bool $dryrun = null): int
{
$limit = 1000;
public function removeObsoleteData(
bool $purge = false,
int $offset = 0,
?bool $dryrun = null,
?Tinebase_DateTime $beforeDate = null
): int {
$limit = 100;

$controllers = [];
$models = [];
Expand All @@ -969,11 +972,19 @@ public function removeObsoleteData(bool $purge = false, int $offset = 0, ?bool $
$purgeCountEmptyUpdate = 0;

do {
$notes = $this->getAllNotes('id ASC', $limit, $offset);
$notes = $this->getAllNotes('creation_time ASC', $limit, $offset);
$offset += $limit;

/** @var Tinebase_Model_Note $note */
foreach ($notes as $note) {
if ($beforeDate && $note->creation_time->isLater($beforeDate)) {
if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__
. ' Retention time reached - we keep the rest');
}
return $deletedCount;
}

if ($note->note_type_id === Tinebase_Model_Note::SYSTEM_NOTE_AVSCAN) {
// we only keep the avscan notes of last month
if ($note->creation_time->isEarlier($oneMonthBefore)) {
Expand Down

0 comments on commit 5570b78

Please sign in to comment.