);
foreach ($objectTypes as $objectTypeID => $objectType) {
- $processorObject = $objectType->getProcessor();
-
$sql = "SELECT *
- FROM ".$processorObject::getDatabaseVersionTableName();
+ FROM ". call_user_func(array($objectType->className, 'getDatabaseVersionTableName'));
$statement = WCF::getDB()->prepareStatement($sql);
$statement->execute(array());
while ($row = $statement->fetchArray()) {
$object = new $objectType->className(null, $row);
- $data['versions'][$objectTypeID][$object->{$processorObject::getDatabaseIndexName()}] = $object;
- $data['versionIDs'][$objectTypeID][$object->{$processorObject::getDatabaseIndexName()}][] = $object->{$processorObject::getDatabaseVersionTableIndexName()};
+ $data['versions'][$objectTypeID][$object->{call_user_func(array($objectType->className, 'getDatabaseIndexName'))}] = $object;
+ $data['versionIDs'][$objectTypeID][$object->{call_user_func(array($objectType->className, 'getDatabaseIndexName'))}][] = $object->{call_user_func(array($objectType->className, 'getDatabaseVersionTableIndexName'))};
}
}
*/
public function getColumns($tableName) {
$columns = array();
+ $regex = new Regex('([a-z]+)\(([0-9]+)\)', Regex::CASE_INSENSITIVE);
+
$sql = "SHOW COLUMNS FROM ".$tableName;
$statement = $this->dbObj->prepareStatement($sql);
$statement->execute();
while ($row = $statement->fetchArray()) {
- $typeMatches = Regex::compile('([a-z]+)\(([0-9]+)\)', Regex::CASE_INSENSITIVE)->match($row['Type']);
+ $regex->match($row['Type']);
+ $typeMatches = $regex->getMatches();
+ if(empty($typeMatches)) continue;
$columns[] = array('name' => $row['Field'], 'data' => array(
'type' => $typeMatches[1],
'length' => $typeMatches[2],
- 'notNull' => (($row['Null'] == 'YES') ? true : false),
+ 'notNull' => (($row['Null'] == 'YES') ? false : true),
'key' => (($row['Key'] == 'PRI') ? 'PRIMARY' : (($row['Key'] == 'UNI') ? 'UNIQUE' : '')),
'default' => $row['Default'],
'autoIncrement' => ($row['Extra'] == 'auto_increment' ? true : false)
use wcf\data\package\Package;
use wcf\data\package\PackageEditor;
use wcf\system\application\ApplicationHandler;
+use wcf\data\object\type\ObjectTypeCache;
use wcf\system\cache\builder\TemplateListenerCacheBuilder;
use wcf\system\cache\builder\TemplateListenerCodeCacheBuilder;
use wcf\system\cache\CacheHandler;
use wcf\system\setup\Installer;
use wcf\system\style\StyleHandler;
use wcf\system\user\storage\UserStorageHandler;
-use wcf\system\version\VersionHandler;
use wcf\system\WCF;
use wcf\util\FileUtil;
use wcf\util\HeaderUtil;
* Restructure version tables.
*/
protected function restructureVersionTables() {
- $objectTypes = VersionHandler::getInstance()->getObjectTypes();
+ $objectTypes = ObjectTypeCache::getInstance()->getObjectTypes('com.woltlab.wcf.versionableObject');
if (empty($objectTypes)) {
return;
// base structure of version tables
$versionTableBaseColumns = array();
- $versionTableBaseColumns[] = array('name' => 'versionID', 'data' => array('type' => 'INT', 'key' => 'PRIMARY', 'autoIncrement' => 'AUTO_INCREMENT'));
- $versionTableBaseColumns[] = array('name' => 'versionUserID', 'data' => array('type' => 'INT'));
+ $versionTableBaseColumns[] = array('name' => 'versionID', 'data' => array('type' => 'INT', 'length' => 10, 'key' => 'PRIMARY', 'autoIncrement' => 'AUTO_INCREMENT'));
+ $versionTableBaseColumns[] = array('name' => 'versionUserID', 'data' => array('type' => 'INT', 'length' => 10));
$versionTableBaseColumns[] = array('name' => 'versionUsername', 'data' => array('type' => 'VARCHAR', 'length' => 255));
- $versionTableBaseColumns[] = array('name' => 'versionTime', 'data' => array('type' => 'INT'));
+ $versionTableBaseColumns[] = array('name' => 'versionTime', 'data' => array('type' => 'INT', 'length' => 10));
foreach ($objectTypes as $objectType) {
// get structure of base table
- $baseTableColumns = WCF::getDB()->getEditor()->getColumns($objectType::getDatabaseTableName());
+ $baseTableColumns = WCF::getDB()->getEditor()->getColumns(call_user_func(array($objectType->className, 'getDatabaseTableName')));
+
+ // remove primary key from base table columns
+ foreach($baseTableColumns as $key => $column) {
+ if($column['data']['key'] == 'PRIMARY') {
+ $baseTableColumns[$key]['data']['key'] = '';
+ }
+ $baseTableColumns[$key]['data']['autoIncrement'] = false;
+ }
+
// get structure of version table
- $versionTableColumns = WCF::getDB()->getEditor()->getColumns($objectType::getDatabaseVersionTableName());
+ $versionTableColumns = array();
+ try {
+ $versionTableColumns = WCF::getDB()->getEditor()->getColumns(call_user_func(array($objectType->className, 'getDatabaseVersionTableName')));
+ }
+ catch (\Exception $e) { }
if (empty($versionTableColumns)) {
$columns = array_merge($versionTableBaseColumns, $baseTableColumns);
-
- WCF::getDB()->getEditor()->createTable($objectType::getDatabaseVersionTableName(), $columns);
+ WCF::getDB()->getEditor()->createTable(call_user_func(array($objectType->className, 'getDatabaseVersionTableName')), $columns);
}
else {
// check garbage columns in versioned table
foreach ($versionTableColumns as $columnData) {
if (!array_search($columnData['name'], $baseTableColumns, true)) {
// delete column
- WCF::getDB()->getEditor()->dropColumn($objectType::getDatabaseVersionTableName(), $columnData['name']);
+ WCF::getDB()->getEditor()->dropColumn(call_user_func(array($objectType->className, 'getDatabaseVersionTableName')), $columnData['name']);
}
}
foreach ($baseTableColumns as $columnData) {
if (!array_search($columnData['name'], $versionTableColumns, true)) {
// add colum
- WCF::getDB()->getEditor()->addColumn($objectType::getDatabaseVersionTableName(), $columnData['name'], $columnData['data']);
+ WCF::getDB()->getEditor()->addColumn(call_user_func(array($objectType->className, 'getDatabaseVersionTableName')), $columnData['name'], $columnData['data']);
}
}
}