From 5927c57889e53577019a4cd438f5e032e3d9aa40 Mon Sep 17 00:00:00 2001 From: Matthias Schmidt Date: Sat, 27 Apr 2013 16:05:38 +0200 Subject: [PATCH] Fixes bug and cleans up code --- .../files/lib/action/APIAction.class.php | 8 ++++---- .../data/VersionableDatabaseObject.class.php | 8 ++++---- .../VersionableDatabaseObjectAction.class.php | 20 ++++++------------- .../VersionableDatabaseObjectEditor.class.php | 8 ++++---- .../system/version/VersionHandler.class.php | 10 +++++----- 5 files changed, 23 insertions(+), 31 deletions(-) diff --git a/wcfsetup/install/files/lib/action/APIAction.class.php b/wcfsetup/install/files/lib/action/APIAction.class.php index 6b7e330b64..de214e1ba2 100644 --- a/wcfsetup/install/files/lib/action/APIAction.class.php +++ b/wcfsetup/install/files/lib/action/APIAction.class.php @@ -74,8 +74,8 @@ final class APIAction extends AbstractAjaxAction { /** * Checks fields, prunes given array and returns it - * - * @return array + * + * @return array */ protected function prune(IRESTfulResponse $object) { $prunedArray = array(); @@ -91,8 +91,8 @@ final class APIAction extends AbstractAjaxAction { /** * Tries to find class and returns class name and controller. - * - * @return array + * + * @return array */ protected function getClassData($controller, $application = 'wcf') { $className = $application.'\\data\\'.$controller.'\\'.ucfirst($controller); diff --git a/wcfsetup/install/files/lib/data/VersionableDatabaseObject.class.php b/wcfsetup/install/files/lib/data/VersionableDatabaseObject.class.php index a4750353f6..b4f2bb5329 100644 --- a/wcfsetup/install/files/lib/data/VersionableDatabaseObject.class.php +++ b/wcfsetup/install/files/lib/data/VersionableDatabaseObject.class.php @@ -13,7 +13,7 @@ use wcf\system\version\VersionHandler; * @subpackage data * @category Community Framework */ -abstract class VersionableDatabaseObject extends DatabaseObject { +abstract class VersionableDatabaseObject extends DatabaseObject { /** * name of the versionable object type * @var string @@ -21,7 +21,7 @@ abstract class VersionableDatabaseObject extends DatabaseObject { public $versionableObjectTypeName = ''; /** - * Returns suffix of database tables. + * Returns suffix of the version database table. * * @return string */ @@ -30,7 +30,7 @@ abstract class VersionableDatabaseObject extends DatabaseObject { } /** - * Returns name of index in version table. + * Returns name of index in version database table. * * @return string */ @@ -39,7 +39,7 @@ abstract class VersionableDatabaseObject extends DatabaseObject { } /** - * Returns all versions of this database object + * Returns all versions of this database object. * * @return array */ diff --git a/wcfsetup/install/files/lib/data/VersionableDatabaseObjectAction.class.php b/wcfsetup/install/files/lib/data/VersionableDatabaseObjectAction.class.php index dee71f0967..e3f405d7c8 100644 --- a/wcfsetup/install/files/lib/data/VersionableDatabaseObjectAction.class.php +++ b/wcfsetup/install/files/lib/data/VersionableDatabaseObjectAction.class.php @@ -14,7 +14,7 @@ use wcf\system\version\VersionHandler; */ abstract class VersionableDatabaseObjectAction extends AbstractDatabaseObjectAction { /** - * Validates restoring a version + * Validates restoring a version. */ public function validateRestoreRevision() { parent::validateUpdate(); @@ -28,9 +28,6 @@ abstract class VersionableDatabaseObjectAction extends AbstractDatabaseObjectAct $this->readObjects(); } - // get index name - $indexName = call_user_func(array($this->className, 'getDatabaseTableIndexName')); - // get ids $objectIDs = array(); foreach ($this->objects as $object) { @@ -49,12 +46,10 @@ abstract class VersionableDatabaseObjectAction extends AbstractDatabaseObjectAct $this->readObjects(); } - // get index name - $indexName = call_user_func(array($this->className, 'getDatabaseTableIndexName')); - if (isset($this->parameters['data'])) { foreach ($this->objects as $object) { - $this->update($this->parameters['data']); + $object->update($this->parameters['data']); + // create revision retroactively $this->createRevision(); } @@ -66,7 +61,7 @@ abstract class VersionableDatabaseObjectAction extends AbstractDatabaseObjectAct */ protected function createRevision() { $indexName = call_user_func(array($this->className, 'getDatabaseTableIndexName')); - + foreach ($this->objects as $object) { call_user_func(array($this->className, 'createRevision'), array_merge($object->getData(), array($indexName => $object->getObjectID()))); } @@ -80,9 +75,6 @@ abstract class VersionableDatabaseObjectAction extends AbstractDatabaseObjectAct $this->readObjects(); } - // get index name - $indexName = call_user_func(array($this->className, 'getDatabaseTableIndexName')); - // get ids $objectIDs = array(); foreach ($this->objects as $object) { @@ -100,12 +92,12 @@ abstract class VersionableDatabaseObjectAction extends AbstractDatabaseObjectAct if (empty($this->objects)) { $this->readObjects(); } - + // currently we only support restoring one version foreach ($this->objects as $object) { $objectType = VersionHandler::getInstance()->getObjectTypeByName($object->versionableObjectTypeName); $restoreObject = VersionHandler::getInstance()->getVersionByID($objectType->objectTypeID, $this->parameters['restoreObjectID']); - + $this->parameters['data'] = $restoreObject->getData(); } diff --git a/wcfsetup/install/files/lib/data/VersionableDatabaseObjectEditor.class.php b/wcfsetup/install/files/lib/data/VersionableDatabaseObjectEditor.class.php index 3cf6b9b078..cb524e67ed 100644 --- a/wcfsetup/install/files/lib/data/VersionableDatabaseObjectEditor.class.php +++ b/wcfsetup/install/files/lib/data/VersionableDatabaseObjectEditor.class.php @@ -6,7 +6,7 @@ use wcf\system\WCF; * Abstract class for all versionable editor classes. * * @author Jeffrey Reichardt - * @copyright 2001-2012 WoltLab GmbH + * @copyright 2001-2013 WoltLab GmbH * @license GNU Lesser General Public License * @package com.woltlab.wcf * @subpackage data @@ -38,10 +38,10 @@ abstract class VersionableDatabaseObjectEditor extends DatabaseObjectEditor { // return new object $id = WCF::getDB()->getInsertID(static::getDatabaseVersionTableName(), static::getDatabaseVersionTableIndexName()); - + return new static::$baseClass($id); } - + /** * @see wcf\data\IEditableObject::delete() */ @@ -59,7 +59,7 @@ abstract class VersionableDatabaseObjectEditor extends DatabaseObjectEditor { $sql = "DELETE FROM ".static::getDatabaseVersionTableName()." WHERE ".static::getDatabaseTableIndexName()." = ?"; $statement = WCF::getDB()->prepareStatement($sql); - + WCF::getDB()->beginTransaction(); foreach ($objectIDs as $objectID) { $statement->execute(array($objectID)); diff --git a/wcfsetup/install/files/lib/system/version/VersionHandler.class.php b/wcfsetup/install/files/lib/system/version/VersionHandler.class.php index 91a7d7bc00..85962503ab 100644 --- a/wcfsetup/install/files/lib/system/version/VersionHandler.class.php +++ b/wcfsetup/install/files/lib/system/version/VersionHandler.class.php @@ -57,8 +57,8 @@ class VersionHandler extends SingletonFactory { /** * Returns the database object with the given version id. * - * @param integer $objectTypeID - * @param integer $versionID + * @param integer $objectTypeID + * @param integer $versionID * @return wcf\data\VersionableDatabaseObject */ public function getVersionByID($objectTypeID, $versionID) { @@ -70,7 +70,7 @@ class VersionHandler extends SingletonFactory { } /** - * Gets the object type with the given id. + * Returns the object type with the given id. * * @param integer $objectTypeID * @return wcf\data\object\type\ObjectType @@ -84,9 +84,9 @@ class VersionHandler extends SingletonFactory { } /** - * Gets the object type with the given name. + * Returns the object type with the given name. * - * @param string $objectTypeName + * @param string $objectTypeName * @return wcf\data\object\type\ObjectType */ public function getObjectTypeByName($objectTypeName) { -- 2.20.1