/**
* 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 {
/**
/**
* Returns suffix of database tables.
- *
- * @return string
+ *
+ * @return string
*/
protected static function getDatabaseVersionTableName() {
return static::getDatabaseTableName().'_version';
/**
* Returns name of index in version table.
+ *
+ * @return string
*/
protected static function getDatabaseVersionTableIndexName() {
return 'version'.ucfirst(static::getDatabaseIndexTableName());
<?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();
}
}
/**
- * 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();
}
}
}
/**
- * Deletes revision.
+ * Deletes a revision.
*/
protected function deleteRevision() {
- if (!count($this->objects)) {
+ if (empty($this->objects)) {
$this->readObjects();
}
}
/**
- * 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']);
/**
* 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 = '';
}
// 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);
}
/**
- * @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);
/**
* 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(
foreach ($objectTypes as $objectTypeID => $objectType) {
$processorObject = $objectType->getProcessor();
- $sql = "SELECT
- *
+ $sql = "SELECT *
FROM ".$processorObject::getDatabaseVersionTableName();
$statement = WCF::getDB()->prepareStatement($sql);
$statement->execute(array());
$data['versions'][$objectTypeID][$object->{$processorObject::getDatabaseIndexName()}] = $object;
$data['versionIDs'][$objectTypeID][$object->{$processorObject::getDatabaseIndexName()}][] = $object->{$processorObject::getDatabaseVersionTableIndexName()};
}
-
}
return $data;
)
);
}
+
return $columns;
}
*/
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;
}
/**
* 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])) {
/**
* 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])) {
/**
* 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])) {
/**
* 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])) {
}
/**
- * @see wcf\system\SingletonFactory::init()
+ * @see wcf\system\SingletonFactory::init()
*/
protected function init() {
$this->objectTypes = ObjectTypeCache::getInstance()->getObjectTypes('com.woltlab.wcf.versionableObject');
/**
* 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
+}