From 1321f0bdb56df0a5a32e1df948d8400fb1759a64 Mon Sep 17 00:00:00 2001 From: Marcel Werk Date: Fri, 14 Oct 2011 21:32:00 +0200 Subject: [PATCH] Added generic update counters method --- .../lib/data/DatabaseObjectEditor.class.php | 22 +++++++++++++++++++ .../files/lib/data/IEditableObject.class.php | 7 ++++++ 2 files changed, 29 insertions(+) diff --git a/wcfsetup/install/files/lib/data/DatabaseObjectEditor.class.php b/wcfsetup/install/files/lib/data/DatabaseObjectEditor.class.php index 51de770660..453d3741e8 100644 --- a/wcfsetup/install/files/lib/data/DatabaseObjectEditor.class.php +++ b/wcfsetup/install/files/lib/data/DatabaseObjectEditor.class.php @@ -69,6 +69,28 @@ abstract class DatabaseObjectEditor extends DatabaseObjectDecorator implements I $statement->execute($statementParameters); } + /** + * @see wcf\data\IEditableObject::updateCounters() + */ + public function updateCounters(array $counters = array()) { + if (!count($counters)) return; + + $updateSQL = ''; + $statementParameters = array(); + foreach ($counters as $key => $value) { + if (!empty($updateSQL)) $updateSQL .= ', '; + $updateSQL .= $key . ' = ' . $key . ' + ?'; + $statementParameters[] = $value; + } + $statementParameters[] = $this->__get(static::getDatabaseTableIndexName()); + + $sql = "UPDATE ".static::getDatabaseTableName()." + SET ".$updateSQL." + WHERE ".static::getDatabaseTableIndexName()." = ?"; + $statement = WCF::getDB()->prepareStatement($sql); + $statement->execute($statementParameters); + } + /** * @see wcf\data\IEditableObject::delete() */ diff --git a/wcfsetup/install/files/lib/data/IEditableObject.class.php b/wcfsetup/install/files/lib/data/IEditableObject.class.php index cdc126c94b..47c13c7d07 100644 --- a/wcfsetup/install/files/lib/data/IEditableObject.class.php +++ b/wcfsetup/install/files/lib/data/IEditableObject.class.php @@ -27,6 +27,13 @@ interface IEditableObject extends IStorableObject { */ public function update(array $parameters = array()); + /** + * Updates the counters of this object. + * + * @param array $counters + */ + public function updateCounters(array $counters = array()); + /** * Deletes this object. */ -- 2.20.1