Skip to content
This repository has been archived by the owner on Dec 27, 2023. It is now read-only.

Commit

Permalink
fix(Tinebase/Tags): fix tag occurrence decrease if already 0
Browse files Browse the repository at this point in the history
  • Loading branch information
pschuele committed Mar 30, 2023
1 parent d58c7eb commit f9b8d1f
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions tine20/Tinebase/Tags.php
Expand Up @@ -899,7 +899,7 @@ protected function _addOccurrence($_tag, $_toAdd)
}

/**
* update tag occurrrence
* update tag occurrence
*
* @param Tinebase_Model_Tag|string $tag
* @param integer $toAddOrRemove
Expand All @@ -912,7 +912,8 @@ protected function _updateOccurrence($tag, $toAddOrRemove)

$tagId = $tag instanceof Tinebase_Model_Tag ? $tag->getId() : $tag;

if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . " de/increasing tag occurrence of $tagId by $toAddOrRemove");
if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) Tinebase_Core::getLogger()->debug(
__METHOD__ . '::' . __LINE__ . " de/increasing tag occurrence of $tagId by $toAddOrRemove");

$quotedIdentifier = $this->_db->quoteIdentifier('occurrence');

Expand All @@ -924,11 +925,14 @@ protected function _updateOccurrence($tag, $toAddOrRemove)
} else {
$toRemove = abs((int) $toAddOrRemove);
$data = array(
'occurrence' => new Zend_Db_Expr('(CASE WHEN (' . $quotedIdentifier . ' - ' . $toRemove . ') > 0 THEN ' . $quotedIdentifier . ' - ' . $toRemove . ' ELSE 0 END)')
'occurrence' => new Zend_Db_Expr('(CASE WHEN '
. $quotedIdentifier . ' > ' . $toRemove . ' THEN '
. $quotedIdentifier . ' - ' . $toRemove . ' ELSE 0 END)')
);
}

$this->_db->update(SQL_TABLE_PREFIX . 'tags', $data, $this->_db->quoteInto($this->_db->quoteIdentifier('id') . ' = ?', $tagId));

$this->_db->update(SQL_TABLE_PREFIX . 'tags', $data,
$this->_db->quoteInto($this->_db->quoteIdentifier('id') . ' = ?', $tagId));
}

/**
Expand Down

0 comments on commit f9b8d1f

Please sign in to comment.