Added modification log
authorAlexander Ebert <ebert@woltlab.com>
Mon, 11 Jun 2012 13:18:58 +0000 (15:18 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Mon, 11 Jun 2012 13:18:58 +0000 (15:18 +0200)
com.woltlab.wcf/objectTypeDefinition.xml
wcfsetup/install/files/lib/data/modification/log/ModificationLog.class.php [new file with mode: 0644]
wcfsetup/install/files/lib/data/modification/log/ModificationLogAction.class.php [new file with mode: 0644]
wcfsetup/install/files/lib/data/modification/log/ModificationLogEditor.class.php [new file with mode: 0644]
wcfsetup/install/files/lib/data/modification/log/ModificationLogList.class.php [new file with mode: 0644]
wcfsetup/install/files/lib/system/log/modification/ModificationLogHandler.class.php [new file with mode: 0644]
wcfsetup/setup/db/install.sql

index ab88252e9bfc6553788232b0e9ba419040c69877..2bfd62e2de8ff5cd2b9066cb8989b21798cafbd6 100644 (file)
@@ -13,5 +13,9 @@
                        <interfacename>wcf\system\category\ICategoryType</interfacename>
                        <name>com.woltlab.wcf.category</name>
                </definition>
+               
+               <definition>
+                       <name>com.woltlab.wcf.modifiableContent</name>
+               </definition>
        </import>
 </data>
\ 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 (file)
index 0000000..c95ce05
--- /dev/null
@@ -0,0 +1,25 @@
+<?php
+namespace wcf\data\modification\log;
+use wcf\data\DatabaseObject;
+
+/**
+ * Represents a modification log.
+ * 
+ * @author     Alexander Ebert
+ * @copyright  2001-2012 WoltLab GmbH
+ * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @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 (file)
index 0000000..b14c4bc
--- /dev/null
@@ -0,0 +1,15 @@
+<?php
+namespace wcf\data\modification\log;
+use wcf\data\AbstractDatabaseObjectAction;
+
+/**
+ * Executes modification log-related actions.
+ * 
+ * @author     Alexander Ebert
+ * @copyright  2001-2012 WoltLab GmbH
+ * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @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 (file)
index 0000000..6e4cac3
--- /dev/null
@@ -0,0 +1,20 @@
+<?php
+namespace wcf\data\modification\log;
+use wcf\data\DatabaseObjectEditor;
+
+/**
+ * Provides functions to edit modification logs.
+ * 
+ * @author     Alexander Ebert
+ * @copyright  2001-2012 WoltLab GmbH
+ * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @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 (file)
index 0000000..4b9b508
--- /dev/null
@@ -0,0 +1,20 @@
+<?php
+namespace wcf\data\modification\log;
+use wcf\data\DatabaseObjectList;
+
+/**
+ * Represents a list of modification logs.
+ * 
+ * @author     Alexander Ebert
+ * @copyright  2001-2012 WoltLab GmbH
+ * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @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 (file)
index 0000000..0903cba
--- /dev/null
@@ -0,0 +1,99 @@
+<?php
+namespace wcf\system\log\modification;
+use wcf\data\modification\log\ModificationLogEditor;
+use wcf\data\object\type\ObjectTypeCache;
+use wcf\system\database\util\PreparedStatementConditionBuilder;
+use wcf\system\exception\SystemException;
+use wcf\system\SingletonFactory;
+use wcf\system\WCF;
+
+/**
+ * Handles modification logs.
+ *
+ * @author     Alexander Ebert
+ * @copyright  2001-2012 WoltLab GmbH
+ * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package    com.woltlab.wcf
+ * @subpackage system.log.modification
+ * @category   Community Framework
+ */
+class ModificationLogHandler extends SingletonFactory {
+       /**
+        * list of object types
+        * @var array<wcf\data\object\type\ObjectType>
+        */
+       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<integer>  $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
index 30c71b2f5b774e31da694689c0a99b11d4af4b1d..ee57c7d48a877859cf1e8fc632b26602c2e559f1 100644 (file)
@@ -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;