Fixing code formatting and added detailed column information for PostgreSQL
authorKiv4h <jeffrey.reichardt@googlemail.com>
Sun, 30 Dec 2012 15:50:23 +0000 (16:50 +0100)
committerKiv4h <jeffrey.reichardt@googlemail.com>
Sun, 30 Dec 2012 15:50:23 +0000 (16:50 +0100)
wcfsetup/install/files/lib/data/VersionableDatabaseObject.class.php
wcfsetup/install/files/lib/data/VersionableDatabaseObjectAction.class.php
wcfsetup/install/files/lib/data/VersionableDatabaseObjectEditor.class.php
wcfsetup/install/files/lib/system/cache/builder/VersionCacheBuilder.class.php
wcfsetup/install/files/lib/system/database/editor/MySQLDatabaseEditor.class.php
wcfsetup/install/files/lib/system/database/editor/PostgreSQLDatabaseEditor.class.php
wcfsetup/install/files/lib/system/version/VersionHandler.class.php

index 8094c98e9d1cce9dc03a269ef60ce376cadcfd7a..e1f0c8ff470d0e31922051b1c2ed590211484c61 100644 (file)
@@ -4,13 +4,13 @@ use wcf\util\StringUtil;
 
 /**
  * Abstract class for all versionable data classes.
- *
- * @author             Jeffrey Reichardt
+ * 
+ * @author     Jeffrey Reichardt
  * @copyright  2001-2012 WoltLab GmbH
- * @license            GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
  * @package    com.woltlab.wcf
  * @subpackage data
- * @category   Community Framework
+ * @category   Community Framework
  */
 abstract class VersionableDatabaseObject extends DatabaseObject {      
        /**
@@ -21,8 +21,8 @@ abstract class VersionableDatabaseObject extends DatabaseObject {
        
        /**
         * Returns suffix of database tables.
-        *
-        * @return string
+        * 
+        * @return      string
         */
        protected static function getDatabaseVersionTableName() {
                return static::getDatabaseTableName().'_version';
@@ -30,6 +30,8 @@ abstract class VersionableDatabaseObject extends DatabaseObject {
        
        /**
         * Returns name of index in version table.
+        * 
+        * @return      string
         */
        protected static function getDatabaseVersionTableIndexName() {
                return 'version'.ucfirst(static::getDatabaseIndexTableName());
index 83d52436cb899df0e5fde3aa8f333fbbc9c1a9e5..effeaec48f5d437917bcb8d257d510dcc81ef9f0 100644 (file)
@@ -1,32 +1,30 @@
 <?php
 namespace wcf\data;
+use wcf\system\version\VersionHandler;
 
 /**
  * Abstract class for all versionable data actions.
- *
- * @author             Jeffrey Reichardt
+ * 
+ * @author     Jeffrey Reichardt
  * @copyright  2001-2012 WoltLab GmbH
- * @license            GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
  * @package    com.woltlab.wcf
  * @subpackage data
- * @category   Community Framework
+ * @category   Community Framework
  */
 abstract class VersionableDatabaseObjectAction extends AbstractDatabaseObjectAction {
-       
        /**
-        * Validates restoring an version
+        * Validates restoring a version
         */
        public function validateRestore() {
                parent::validateUpdate();
        }
        
        /**
-        * Deletes database object and returns the number of deleted objects.
-        *
-        * @return      integer
+        * @see wcf\data\IDeleteAction::delete()
         */
        public function delete() {
-               if (!count($this->objects)) {
+               if (empty($this->objects)) {
                        $this->readObjects();
                }
                
@@ -44,20 +42,20 @@ abstract class VersionableDatabaseObjectAction extends AbstractDatabaseObjectAct
        }
        
        /**
-        * Updates data.
+        * @see wcf\data\AbstractDatabaseObjectAction::update()
         */
        public function update() {
-               if (!count($this->objects)) {
+               if (empty($this->objects)) {
                        $this->readObjects();
                }
                
-               //get index name
+               // 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']);
-                               //create revision retroactively
+                               // create revision retroactively
                                $this->createRevision();
                        }
                }
@@ -75,10 +73,10 @@ abstract class VersionableDatabaseObjectAction extends AbstractDatabaseObjectAct
        }
        
        /**
-        * Deletes revision.
+        * Deletes revision.
         */
        protected function deleteRevision() {
-               if (!count($this->objects)) {
+               if (empty($this->objects)) {
                        $this->readObjects();
                }
                
@@ -96,14 +94,14 @@ abstract class VersionableDatabaseObjectAction extends AbstractDatabaseObjectAct
        }
        
        /**
-        * Restores an revision.
+        * Restores a revision.
         */
        public function restore() {
-               if (!count($this->objects)) {
+               if (empty($this->objects)) {
                        $this->readObjects();
                }
 
-               //currently we only support restoring one version
+               // currently we only support restoring one version
                foreach($this->objects as $object) {
                        $objectType = VersionHandler::getInstance()->getObjectTypeByName($object->objectTypeName);
                        $restoreObject = VersionHandler::getInstance()->getVersionByID($objectType->objectTypeID, $this->parameters['restoreObjectID']);
index cafca1b7749623be08235d8b5a04e4405f29a101..edc72d37238a1a337d96a7ed981b8b676a8b0345 100644 (file)
@@ -4,17 +4,17 @@ use wcf\system\WCF;
 
 /**
  * Abstract class for all versionable editor classes.
- *
- * @author             Jeffrey Reichardt
+ * 
+ * @author     Jeffrey Reichardt
  * @copyright  2001-2012 WoltLab GmbH
- * @license            GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
  * @package    com.woltlab.wcf
  * @subpackage data
- * @category   Community Framework
+ * @category   Community Framework
  */
 abstract class VersionableDatabaseObjectEditor extends DatabaseObjectEditor {
        /**
-        * @see wcf\data\IEditableObject::create()
+        * @see wcf\data\IEditableObject::create()
         */
        public static function createRevision(array $parameters = array()) {
                $keys = $values = '';
@@ -31,9 +31,8 @@ abstract class VersionableDatabaseObjectEditor extends DatabaseObjectEditor {
                }
                
                // save object
-               $sql = "INSERT INTO     ".static::getDatabaseVersionTableName()."
-                                       (".$keys.")
-                       VALUES          (".$values.")";
+               $sql = "INSERT INTO     ".static::getDatabaseVersionTableName()." (".$keys.")
+                               VALUES (".$values.")";
                $statement = WCF::getDB()->prepareStatement($sql);
                $statement->execute($statementParameters);
                
@@ -44,14 +43,14 @@ abstract class VersionableDatabaseObjectEditor extends DatabaseObjectEditor {
        }
                
        /**
-        * @see wcf\data\IEditableObject::delete()
+        * @see wcf\data\IEditableObject::delete()
         */
        public function deleteRevision(array $objectIDs = array()) {
                static::deleteAll(array($this->__get(static::getDatabaseVersionTableIndexName())));
        }
        
        /**
-        * @see wcf\data\IEditableObject::deleteAll()
+        * @see wcf\data\IEditableObject::deleteAll()
         */
        public static function deleteAll(array $objectIDs = array()) {
                $affectedCount = static::deleteAll($objectIDs);
index e51b8dce0d85f9cf7f0a6e1402156d5897194af9..8acb955fdb9d0f2a460c66b7cc6d78ebef94b956 100644 (file)
@@ -5,20 +5,20 @@ use wcf\system\package\PackageDependencyHandler;
 
 /**
  * Caches the versions for a certain package and object type.
- *
- * @author             Jeffrey Reichardt
+ * 
+ * @author     Jeffrey Reichardt
  * @copyright  2001-2012 WoltLab GmbH
- * @license            GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
  * @package    com.woltlab.wcf
  * @subpackage system.cache.builder
- * @category   Community Framework
+ * @category   Community Framework
  */
 class VersionCacheBuilder implements ICacheBuilder {
        /**
-        * @see wcf\system\cache\ICacheBuilder::getData()
+        * @see wcf\system\cache\ICacheBuilder::getData()
         */
        public function getData(array $cacheResource) { 
-               //get object types
+               // get object types
                $objectTypes = ObjectTypeCache::getInstance()->getObjectTypes('com.woltlab.wcf.versionableObject');
                
                $data = array(
@@ -29,8 +29,7 @@ class VersionCacheBuilder implements ICacheBuilder {
                foreach ($objectTypes as $objectTypeID => $objectType) {
                        $processorObject = $objectType->getProcessor();
                        
-                       $sql = "SELECT 
-                                               * 
+                       $sql = "SELECT * 
                                        FROM ".$processorObject::getDatabaseVersionTableName();
                        $statement = WCF::getDB()->prepareStatement($sql);
                        $statement->execute(array());
@@ -40,7 +39,6 @@ class VersionCacheBuilder implements ICacheBuilder {
                                $data['versions'][$objectTypeID][$object->{$processorObject::getDatabaseIndexName()}] = $object;
                                $data['versionIDs'][$objectTypeID][$object->{$processorObject::getDatabaseIndexName()}][] = $object->{$processorObject::getDatabaseVersionTableIndexName()};
                        }
-                       
                }
                
                return $data;
index 80804e3325074fab3c1051cd1e855d7bcf3b5152..eaa1a67e6e46b0f74c7b37a21c91556e98727cae 100644 (file)
@@ -50,6 +50,7 @@ class MySQLDatabaseEditor extends DatabaseEditor {
                                                                                )
                                                        );
                }
+               
                return $columns;
        }
        
index 49b21ada5708402817bc2b5373cd3695a902748b..08ae8fdc5a8cead873925c43cdf1130e62d4a171 100644 (file)
@@ -36,17 +36,30 @@ class PostgreSQLDatabaseEditor extends DatabaseEditor {
         */
        public function getColumns($tableName) {
                $columns = array();
-               $sql = "SELECT  pg_attribute.attname
+               $sql = "SELECT  pg_attribute.*, pg_type.typname, pg_constraint.contype, pg_attribute.adsrc
                        FROM    pg_attribute,
-                               pg_class
+                               pg_class,
+                               pg_type
+                       LEFT JOIN       pg_constraint ON (pg_constraint.conrelid = pg_class.oid)
+                       LEFT JOIN       pg_attrdef ON (pg_attrdef.adrelid = pg_attribute.attrelid) AND (pg_attrdef.adnum = pg_attribute.attnum)
                        WHERE   pg_class.oid = pg_attribute.attrelid
+                               AND pg_type.oid = pg_attribute.atttypid
                                AND pg_attribute.attnum > 0
                                AND pg_class.relname = ?";
                $statement = $this->dbObj->prepareStatement($sql);
                $statement->execute(array($tableName));
                while ($row = $statement->fetchArray()) {
-                       $columns[] = $row['attname'];
-               }
+               $columns[] = array('name' => $row['attname'], 
+                                                               'data' => array(
+                                                                                       'type' => $row['typname'],
+                                                                                       'length' => $row['attlen'],
+                                                                                       'notNull' => $row['attnotnull'],
+                                                                                       'key' => (($row['contype'] == 'p') ? 'PRIMARY' : (($row['contype'] == 'u') ? 'UNIQUE' : '')),
+                                                                                       'default' => $row['adsrc'],
+                                                                                       'autoIncrement' => ($row['contype'] == 'p')
+                                                                               )
+                                                       );
+               }
                
                return $columns;
        }
index cbbc617f84f6e3c5ebc51c881f7ca94de2f170b9..be1ec7d9e0f701bcbb226efa122756a97216155d 100644 (file)
@@ -7,48 +7,45 @@ use wcf\system\cache\CacheHandler;
 
 /**
  * Handles versions of DatabaseObjects.
- *
- * @author             Jeffrey Reichardt
- * @copyright  2001-2012 WoltLab GmbH
- * @license            GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
- * @package    com.woltlab.wcf
- * @subpackage         system.version
- * @category   Community Framework
+ * 
+ * @author     Jeffrey Reichardt
+ * @copyright  2001-2012 WoltLab GmbH
+ * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package    com.woltlab.wcf
+ * @subpackage system.version
+ * @category   Community Framework
  */
 class VersionHandler extends SingletonFactory {
        /**
         * cached versions
-        *
-        * @var array<wcf\data\VersionableDatabaseObject>
+        * @var array<wcf\data\VersionableDatabaseObject>
         */
        protected $versions = array();
 
        /**
         * maps each version id to its object type id and object type version id
-        * @var array<array>
+        * @var array<array>
         */
        protected $versionIDs = array();
 
        /**
         * mapes the names of the version object types to the object type ids
-        *
-        * @var array<integer>
+        * @var array<integer>
         */
        protected $objectTypeIDs = array();
 
        /**
         * list of version object types
-        *
-        * @var array<wcf\data\object\type>
+        * @var array<wcf\data\object\type>
         */
        protected $objectTypes = array();
 
        /**
         * Returns all version of object with the given object type id and object id.
-        *
-        * @param integer $objectTypeID
-        * @param integer $objectID
-        * @return array<wcf\data\VersionableDatabaseObject>
+        * 
+        * @param       integer $objectTypeID
+        * @param       integer $objectID
+        * @return      array<wcf\data\VersionableDatabaseObject>
         */
        public function getVersions($objectTypeID, $objectID) {
                if (isset($this->versions[$objectTypeID][$objectID])) {
@@ -60,10 +57,10 @@ class VersionHandler extends SingletonFactory {
 
        /**
         * Returns the database object with the given version id.
-        *
-        * @param integer $objectTypeID
-        * @param integer $versionID
-        * @return wcf\data\VersionableDatabaseObject
+        * 
+        * @param       integer $objectTypeID
+        * @param       integer $versionID
+        * @return      wcf\data\VersionableDatabaseObject
         */
        public function getVersionByID($objectTypeID, $versionID) {
                if (isset($this->versionIDs[$objectTypeID][$versionID])) {
@@ -75,9 +72,9 @@ class VersionHandler extends SingletonFactory {
 
        /**
         * Gets the object type with the given id.
-        *
-        * @param integer $objectTypeID
-        * @return wcf\data\object\type\ObjectType
+        * 
+        * @param       integer $objectTypeID
+        * @return      wcf\data\object\type\ObjectType
         */
        public function getObjectType($objectTypeID) {
                if (isset($this->objectTypeIDs[$objectTypeID])) {
@@ -89,9 +86,9 @@ class VersionHandler extends SingletonFactory {
 
        /**
         * Gets the object type with the given name.
-        *
-        * @param string $objectTypeName
-        * @return wcf\data\object\type\ObjectType
+        * 
+        * @param       string  $objectTypeName
+        * @return      wcf\data\object\type\ObjectType
         */
        public function getObjectTypeByName($objectTypeName) {
                if (isset($this->objectTypes[$objectTypeName])) {
@@ -102,7 +99,7 @@ class VersionHandler extends SingletonFactory {
        }
 
        /**
-        * @see wcf\system\SingletonFactory::init()
+        * @see wcf\system\SingletonFactory::init()
         */
        protected function init() {
                $this->objectTypes = ObjectTypeCache::getInstance()->getObjectTypes('com.woltlab.wcf.versionableObject');
@@ -128,10 +125,10 @@ class VersionHandler extends SingletonFactory {
        
        /**
         * Returns a list of object types
-        *
-        * @return array<wcf\data\object\type\ObjectType>
+        * 
+        * @return      array<wcf\data\object\type\ObjectType>
         */
        public function getObjectTypes() {
                return $this->objectTypes;
        }
-}
\ No newline at end of file
+}