From 3a2de7fdef193574245676996514cd828d6d309d Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Mon, 11 Jun 2012 15:18:58 +0200 Subject: [PATCH] Added modification log --- com.woltlab.wcf/objectTypeDefinition.xml | 4 + .../log/ModificationLog.class.php | 25 +++++ .../log/ModificationLogAction.class.php | 15 +++ .../log/ModificationLogEditor.class.php | 20 ++++ .../log/ModificationLogList.class.php | 20 ++++ .../ModificationLogHandler.class.php | 99 +++++++++++++++++++ wcfsetup/setup/db/install.sql | 15 +++ 7 files changed, 198 insertions(+) create mode 100644 wcfsetup/install/files/lib/data/modification/log/ModificationLog.class.php create mode 100644 wcfsetup/install/files/lib/data/modification/log/ModificationLogAction.class.php create mode 100644 wcfsetup/install/files/lib/data/modification/log/ModificationLogEditor.class.php create mode 100644 wcfsetup/install/files/lib/data/modification/log/ModificationLogList.class.php create mode 100644 wcfsetup/install/files/lib/system/log/modification/ModificationLogHandler.class.php diff --git a/com.woltlab.wcf/objectTypeDefinition.xml b/com.woltlab.wcf/objectTypeDefinition.xml index ab88252e9b..2bfd62e2de 100644 --- a/com.woltlab.wcf/objectTypeDefinition.xml +++ b/com.woltlab.wcf/objectTypeDefinition.xml @@ -13,5 +13,9 @@ wcf\system\category\ICategoryType com.woltlab.wcf.category + + + com.woltlab.wcf.modifiableContent + \ No newline at end of file diff --git a/wcfsetup/install/files/lib/data/modification/log/ModificationLog.class.php b/wcfsetup/install/files/lib/data/modification/log/ModificationLog.class.php new file mode 100644 index 0000000000..c95ce05bfa --- /dev/null +++ b/wcfsetup/install/files/lib/data/modification/log/ModificationLog.class.php @@ -0,0 +1,25 @@ + + * @package com.woltlab.wcf + * @subpackage data.modification.log + * @category Community Framework + */ +class ModificationLog extends DatabaseObject { + /** + * @see wcf\data\DatabaseObject::$databaseTableName + */ + protected static $databaseTableName = 'modification_log'; + + /** + * @see wcf\data\DatabaseObject::$databaseTableIndexName + */ + protected static $databaseTableIndexName = 'logID'; +} diff --git a/wcfsetup/install/files/lib/data/modification/log/ModificationLogAction.class.php b/wcfsetup/install/files/lib/data/modification/log/ModificationLogAction.class.php new file mode 100644 index 0000000000..b14c4bc53a --- /dev/null +++ b/wcfsetup/install/files/lib/data/modification/log/ModificationLogAction.class.php @@ -0,0 +1,15 @@ + + * @package com.woltlab.wcf + * @subpackage data.modification.log + * @category Community Framework + */ +class ModificationLogAction extends AbstractDatabaseObjectAction { } diff --git a/wcfsetup/install/files/lib/data/modification/log/ModificationLogEditor.class.php b/wcfsetup/install/files/lib/data/modification/log/ModificationLogEditor.class.php new file mode 100644 index 0000000000..6e4cac379d --- /dev/null +++ b/wcfsetup/install/files/lib/data/modification/log/ModificationLogEditor.class.php @@ -0,0 +1,20 @@ + + * @package com.woltlab.wcf + * @subpackage data.modification.log + * @category Community Framework + */ +class ModificationLogEditor extends DatabaseObjectEditor { + /** + * @see wcf\data\DatabaseObjectDecorator::$baseClass + */ + protected static $baseClass = 'wcf\data\modification\log\ModificationLog'; +} diff --git a/wcfsetup/install/files/lib/data/modification/log/ModificationLogList.class.php b/wcfsetup/install/files/lib/data/modification/log/ModificationLogList.class.php new file mode 100644 index 0000000000..4b9b508ef5 --- /dev/null +++ b/wcfsetup/install/files/lib/data/modification/log/ModificationLogList.class.php @@ -0,0 +1,20 @@ + + * @package com.woltlab.wcf + * @subpackage data.modification.log + * @category Community Framework + */ +class ModificationLogList extends DatabaseObjectList { + /** + * @see wcf\data\DatabaseObjectList::$className + */ + public $className = 'wcf\data\modification\log\ModificationLog'; +} diff --git a/wcfsetup/install/files/lib/system/log/modification/ModificationLogHandler.class.php b/wcfsetup/install/files/lib/system/log/modification/ModificationLogHandler.class.php new file mode 100644 index 0000000000..0903cbaa41 --- /dev/null +++ b/wcfsetup/install/files/lib/system/log/modification/ModificationLogHandler.class.php @@ -0,0 +1,99 @@ + + * @package com.woltlab.wcf + * @subpackage system.log.modification + * @category Community Framework + */ +class ModificationLogHandler extends SingletonFactory { + /** + * list of object types + * @var array + */ + protected $cache = array(); + + /** + * @see wcf\system\SingletonFactory::init() + */ + protected function init() { + $this->cache = ObjectTypeCache::getInstance()->getObjectTypes('com.woltlab.wcf.modifiableContent'); + } + + /** + * Returns object type by object type name. + * + * @param string $objectType + * @return wcf\data\object\type\ObjectType + */ + public function getObjectType($objectType) { + foreach ($this->cache as $objectTypeObj) { + if ($objectTypeObj->objectType == $objectType) { + return $objectTypeObj; + } + } + + return null; + } + + /** + * Adds a new entry to modification log. + * + * @param string $objectType + * @param integer $objectID + * @param string $action + * @param array $data + * @param integer $time + * @param integer $userID + * @param string $username + * @return wcf\data\modification\log\ModificationLog + */ + public function add($objectType, $objectID, $action, array $data = array(), $time = TIME_NOW, $userID = null, $username = null) { + $objectType = $this->getObjectType($objectType); + if ($objectType === null) { + throw new SystemException("Object type '".$objectType."' not found within definition 'com.woltlab.wcf.modifiableContent'"); + } + + return ModificationLogEditor::create(array( + 'objectTypeID' => $objectType->objectTypeID, + 'objectID' => $objectID, + 'userID' => ($userID === null ? WCF::getUser()->userID : $userID), + 'username' => ($username === null ? WCF::getUser()->username : $username), + 'time' => $time, + 'data' => serialize($data) + )); + } + + /** + * Removes log entries. + * + * @param string $objectType + * @param array $objectIDs + */ + public function remove($objectType, array $objectIDs) { + $objectType = $this->getObjectType($objectType); + if ($objectType === null) { + throw new SystemException("Object type '".$objectType."' not found within definition 'com.woltlab.wcf.modifiableContent'"); + } + + $conditions = new PreparedStatementConditionBuilder(); + $conditions->add("objectTypeID = ?", array($objectType->objectTypeID)); + $conditions->add("objectID IN (?)", array($objectIDs)); + + $sql = "DELETE FROM wcf".WCF_N."_modification_log + ".$conditions; + $statement = WCF::getDB()->prepareStatement($sql); + $statement->execute($conditions->getParameters()); + } +} \ No newline at end of file diff --git a/wcfsetup/setup/db/install.sql b/wcfsetup/setup/db/install.sql index 30c71b2f5b..ee57c7d48a 100644 --- a/wcfsetup/setup/db/install.sql +++ b/wcfsetup/setup/db/install.sql @@ -238,6 +238,18 @@ CREATE TABLE wcf1_language_to_package ( UNIQUE KEY languageID (languageID, packageID) ); +DROP TABLE IF EXISTS wcf1_modification_log; +CREATE TABLE wcf1_modification_log ( + logID INT(10) NOT NULL AUTO_INCREMENT PRIMARY KEY, + objectTypeID INT(10) NOT NULL, + objectID INT(10) NOT NULL, + userID INT(10), + username VARCHAR(255) NOT NULL DEFAULT '', + time INT(10) NOT NULL DEFAULT 0, + action VARCHAR(80) NOT NULL, + additionalData MEDIUMTEXT +); + DROP TABLE IF EXISTS wcf1_object_type; CREATE TABLE wcf1_object_type ( objectTypeID INT(10) NOT NULL AUTO_INCREMENT PRIMARY KEY, @@ -785,6 +797,9 @@ ALTER TABLE wcf1_language_item ADD FOREIGN KEY (packageID) REFERENCES wcf1_packa ALTER TABLE wcf1_language_to_package ADD FOREIGN KEY (languageID) REFERENCES wcf1_language (languageID) ON DELETE CASCADE; ALTER TABLE wcf1_language_to_package ADD FOREIGN KEY (packageID) REFERENCES wcf1_package (packageID) ON DELETE CASCADE; +ALTER TABLE wcf1_modification_log ADD FOREIGN KEY (objectTypeID) REFERENCES wcf1_object_type (objectTypeID) ON DELETE CASCADE; +ALTER TABLE wcf1_modification_log ADD FOREIGN KEY (userID) REFERENCES wcf1_user (userID) ON DELETE SET NULL; + ALTER TABLE wcf1_object_type ADD FOREIGN KEY (definitionID) REFERENCES wcf1_object_type_definition (definitionID) ON DELETE CASCADE; ALTER TABLE wcf1_object_type ADD FOREIGN KEY (packageID) REFERENCES wcf1_package (packageID) ON DELETE CASCADE; -- 2.20.1