commit 2939a23b624386e3c02adc9683ae754ee0b73e11
parent 0af8817619eddb93481bdf5fe7b1c1e75f9ca550
Author: Jan Dankert <devnull@localhost>
Date: Fri, 12 Jan 2018 23:19:40 +0100
Datenbank-Updateskripte in eigenes Modul auslagern.
Diffstat:
29 files changed, 875 insertions(+), 871 deletions(-)
diff --git a/db/.htaccess b/db/.htaccess
@@ -1,2 +0,0 @@
-order deny,allow
-deny from all-
\ No newline at end of file
diff --git a/db/DbUpdate.class.php b/db/DbUpdate.class.php
@@ -1,115 +0,0 @@
-<?php
-
-use database\Database;
-
-define('OR_DB_SUPPORTED_VERSION',11);
-
-define('OR_DB_STATUS_UPDATE_PROGRESS', 0);
-define('OR_DB_STATUS_UPDATE_SUCCESS' , 1);
-
-class DbUpdate
-{
- /**
- * @param Database $db
- */
- function update(Database $db )
- {
- $version = $this->getDbVersion($db);
-
- if ( $version == OR_DB_SUPPORTED_VERSION )
- // Cool, der aktuelle DB-Stand passt zu dieser Version. Das ist auch der Normalfall. Weiter so.
- return;
-
- if ( $version > OR_DB_SUPPORTED_VERSION )
- // Oh oh, in der Datenbank ist eine neue Version, als wir unterstüzten.
- throw new \LogicException('Actual DB version is not supported.',"DB-Version is $version, but this is OpenRat ".OR_VERSION." which only supports version ".OR_DB_SUPPORTED_VERSION );
-
- if ( ! $db->conf['auto_update'])
- throw new \LogicException('DB Update necessary.',"DB-Version is $version. Auto-Update is disabled, but this is OpenRat ".OR_VERSION." needs the version ".OR_DB_SUPPORTED_VERSION );
-
- for( $installVersion = $version + 1; $installVersion <= OR_DB_SUPPORTED_VERSION; $installVersion++ )
- {
- if ( $installVersion > 2 ) // Up to version 2 there was no table 'version'.
- {
- $db->start();
- $sql = $db->sql('INSERT INTO {{version}} (id,version,status,installed) VALUES( {id},{version},{status},{time} )',$db->id);
- $sql->setInt('id' , $installVersion);
- $sql->setInt('version', $installVersion);
- $sql->setInt('status' , OR_DB_STATUS_UPDATE_PROGRESS);
- $sql->setInt('time' , time() );
- $sql->query();
- $db->commit();
- }
-
- $updaterClassName = 'DBVersion'.str_pad($installVersion, 6, '0', STR_PAD_LEFT);
- require(OR_DBCLASSES_DIR.'update/'.$updaterClassName.'.class.php');
-
- $db->start();
- /** @var \database\DbVersion $updater */
- $updater = new $updaterClassName( $db );
-
- $updater->update();
- $db->commit();
-
- if ( $installVersion > 2 )
- {
- $db->start();
- $sql = $db->sql('UPDATE {{version}} SET status={status},installed={time} WHERE version={version}',$db->id);
- $sql->setInt('status' , OR_DB_STATUS_UPDATE_SUCCESS);
- $sql->setInt('version', $installVersion);
- $sql->setInt('time' , time() );
- $sql->query();
- $db->commit();
- }
- }
- }
-
-
-
-
- private function getDbVersion( Database $db )
- {
- $sql = $db->sql('SELECT 1 FROM {{version}}',$db->id);
- $versionTableExists = $sql->testQuery();
-
- if ( $versionTableExists )
- {
- // Prüfen, ob die vorherigen Updates fehlerfrei sind.
- $sql = $db->sql(<<<SQL
- SELECT COUNT(*) FROM {{version}} WHERE STATUS=0
-SQL
- ,$db->id);
- $countErrors = $sql->getOne();
- if ( $countErrors > 0 )
- throw new \LogicException('Database error','there are dirty versions (means: versions with status 0), see table VERSION for details.');
-
- // Aktuelle Version ermitteln.
- $sql = $db->sql(<<<SQL
- SELECT MAX(version) FROM {{version}}
-SQL
- ,$db->id);
- $version = $sql->getOne();
-
- if ( is_numeric($version) )
- return $version; // Aktuelle Version.s
- else
- // Tabelle 'version' ist noch leer.
- // Tabelle 'version' wurde in Version 2 angelegt.
- return 2;
- }
- else
- {
- $sql = $db->sql('SELECT 1 FROM {{project}}',$db->id);
- $projectTableExists = $sql->testQuery();
-
- if ( $projectTableExists )
- // Entspricht dem Stand vor Einführung der automatischen Migration.
- return 1;
- else
- // Es gibt gar keine Tabellen, es muss also alles neu angelegt werden.
- return 0;
- }
- }
-}
-
-?>-
\ No newline at end of file
diff --git a/db/update/DBVersion000001.class.php b/db/update/DBVersion000001.class.php
@@ -1,353 +0,0 @@
-<?php
-
-use database\Database;
-use database\DbVersion;
-
-
-/**
- * Baseline database structure.
- *
- * @author dankert
- *
- */
-class DBVersion000001 extends DbVersion
-{
- public function update()
- {
- $not_nullable = false;
- $nullable = true;
-
- $this->addTable('project');
-
- $this->addColumn('project','name' ,OR_DB_COLUMN_TYPE_VARCHAR, 128,null,$not_nullable);
- $this->addColumn('project','target_dir' ,OR_DB_COLUMN_TYPE_VARCHAR, 255,null,$not_nullable);
- $this->addColumn('project','ftp_url' ,OR_DB_COLUMN_TYPE_VARCHAR, 255,null,$not_nullable);
- $this->addColumn('project','ftp_passive' ,OR_DB_COLUMN_TYPE_INT ,null,null,$not_nullable);
- $this->addColumn('project','cmd_after_publish' ,OR_DB_COLUMN_TYPE_VARCHAR, 255,null,$not_nullable);
- $this->addColumn('project','content_negotiation',OR_DB_COLUMN_TYPE_INT , 1, 0,$not_nullable);
- $this->addColumn('project','cut_index' ,OR_DB_COLUMN_TYPE_INT , 1, 0,$not_nullable);
-
- $this->addPrimaryKey('project','id');
- $this->addIndex('project','name');
-
- /*
- *
- $this->addColumn('id',OR_DB_COLUMN_TYPE_INT,null,null,$not_nullable);
- $this->addColumn('name',OR_DB_COLUMN_TYPE_VARCHAR,128,null,$not_nullable);
- $this->addColumn('target_dir',OR_DB_COLUMN_TYPE_VARCHAR,255,null,$not_nullable);
- $this->addColumn('ftp_url',OR_DB_COLUMN_TYPE_VARCHAR,255,null,$not_nullable);
- $this->addColumn('ftp_passive',OR_DB_COLUMN_TYPE_INT,1,0,$not_nullable);
- $this->addColumn('cmd_after_publish',OR_DB_COLUMN_TYPE_VARCHAR,255,null,$not_nullable);
- $this->addColumn('content_negotiation',OR_DB_COLUMN_TYPE_INT,1,0,$not_nullable);
- $this->addColumn('cut_$this->addIndex('',OR_DB_COLUMN_TYPE_INT);',1,0,$not_nullable);
- $this->addPrimaryKey('','id');
- close_table
- unique_$this->addIndex('','name');
- */
-
-
-
-
- $this->addTable('user');
- $this->addColumn('user','name',OR_DB_COLUMN_TYPE_VARCHAR,128,null,$not_nullable);
- $this->addColumn('user','password',OR_DB_COLUMN_TYPE_VARCHAR,50,null,$not_nullable);
- $this->addColumn('user','ldap_dn',OR_DB_COLUMN_TYPE_VARCHAR,255,null,$not_nullable);
- $this->addColumn('user','fullname',OR_DB_COLUMN_TYPE_VARCHAR,128,null,$not_nullable);
- $this->addColumn('user','tel',OR_DB_COLUMN_TYPE_VARCHAR,128,null,$not_nullable);
- $this->addColumn('user','mail',OR_DB_COLUMN_TYPE_VARCHAR,255,null,$not_nullable);
- $this->addColumn('user','descr',OR_DB_COLUMN_TYPE_VARCHAR,255,null,$not_nullable);
- $this->addColumn('user','style',OR_DB_COLUMN_TYPE_VARCHAR,64,null,$not_nullable);
- $this->addColumn('user','is_admin',OR_DB_COLUMN_TYPE_INT,1,0,$not_nullable);
- $this->addPrimaryKey('user','id');
- $this->addUniqueIndex('user','name');
-
- $this->addTable('group');
- $this->addColumn('group','name',OR_DB_COLUMN_TYPE_VARCHAR,100,null,$not_nullable);
- $this->addPrimaryKey('group','id');
- $this->addUniqueIndex('group','name');
-
- $this->addTable('object');
- $this->addColumn('object','parentid',OR_DB_COLUMN_TYPE_INT,null,null,$nullable);
- $this->addColumn('object','projectid',OR_DB_COLUMN_TYPE_INT,0,0,$not_nullable);
- $this->addColumn('object','filename',OR_DB_COLUMN_TYPE_VARCHAR,255,null,$not_nullable);
- $this->addColumn('object','orderid',OR_DB_COLUMN_TYPE_INT,0,null,$not_nullable);
- $this->addColumn('object','create_date',OR_DB_COLUMN_TYPE_INT,0,null,$not_nullable);
- $this->addColumn('object','create_userid',OR_DB_COLUMN_TYPE_INT,0,null,$nullable);
- $this->addColumn('object','lastchange_date',OR_DB_COLUMN_TYPE_INT,0,null,$not_nullable);
- $this->addColumn('object','lastchange_userid',OR_DB_COLUMN_TYPE_INT,0,null,$nullable);
- $this->addColumn('object','is_folder',OR_DB_COLUMN_TYPE_INT,1,null,$not_nullable);
- $this->addColumn('object','is_file',OR_DB_COLUMN_TYPE_INT,1,null,$not_nullable);
- $this->addColumn('object','is_page',OR_DB_COLUMN_TYPE_INT,1,null,$not_nullable);
- $this->addColumn('object','is_link',OR_DB_COLUMN_TYPE_INT,1,null,$not_nullable);
- $this->addPrimaryKey('object','id');
- $this->addConstraint('object','projectid','project','id');
- $this->addConstraint('object','lastchange_userid','user','id');
- $this->addConstraint('object','create_userid','user','id');
-
- $this->addIndex('object','parentid');
- $this->addIndex('object','projectid');
- $this->addIndex('object','is_folder');
- $this->addIndex('object','is_file');
- $this->addIndex('object','is_page');
- $this->addIndex('object','is_link');
- $this->addIndex('object','orderid');
- $this->addIndex('object','create_userid');
- $this->addIndex('object','lastchange_userid');
- $this->addUniqueIndex('object','parentid,filename');
-
-
-
-
- $this->addTable('template');
- $this->addColumn('template','projectid',OR_DB_COLUMN_TYPE_INT,null,null,$not_nullable);
- $this->addColumn('template','name',OR_DB_COLUMN_TYPE_VARCHAR,50,null,$not_nullable);
- $this->addPrimaryKey('template','id');
- $this->addConstraint('template','projectid','project','id');
-
- $this->addIndex('template','projectid');
- $this->addIndex('template','name');
- $this->addUniqueIndex('template','projectid,name');
-
-
-
- $this->addTable('language');
- $this->addColumn('language','projectid',OR_DB_COLUMN_TYPE_INT,0,null,$not_nullable);
- $this->addColumn('language','isocode',OR_DB_COLUMN_TYPE_VARCHAR,10,null,$not_nullable);
- $this->addColumn('language','name',OR_DB_COLUMN_TYPE_VARCHAR,50,null,$not_nullable);
- $this->addColumn('language','is_default',OR_DB_COLUMN_TYPE_INT,1,0,$not_nullable);
- $this->addPrimaryKey('language','id');
- $this->addConstraint('language','projectid','project','id');
- $this->addUniqueIndex('language','projectid,isocode');
-
-
-
-
- $this->addTable('page');
- $this->addColumn('page','objectid',OR_DB_COLUMN_TYPE_INT,0,null,$not_nullable);
- $this->addColumn('page','templateid',OR_DB_COLUMN_TYPE_INT,0,null,$not_nullable);
- $this->addPrimaryKey('page','id');
- $this->addConstraint('page','templateid','template','id');
- $this->addConstraint('page','objectid','object','id');
-
- $this->addUniqueIndex('page','objectid');
- $this->addIndex('page','templateid');
-
-
-
-
- $this->addTable('projectmodel');
- $this->addColumn('projectmodel','projectid',OR_DB_COLUMN_TYPE_INT,0,null,$not_nullable);
- $this->addColumn('projectmodel','name',OR_DB_COLUMN_TYPE_VARCHAR,50,null,$not_nullable);
- $this->addColumn('projectmodel','extension',OR_DB_COLUMN_TYPE_VARCHAR,10,null,$nullable);
- $this->addColumn('projectmodel','is_default',OR_DB_COLUMN_TYPE_INT,1,0,$not_nullable);
- $this->addPrimaryKey('projectmodel','id');
- $this->addConstraint('projectmodel','projectid','project','id');
-
- $this->addIndex('projectmodel','projectid');
- $this->addUniqueIndex('projectmodel','projectid,name');
-
-
- $this->addTable('element');
- $this->addColumn('element','templateid',OR_DB_COLUMN_TYPE_INT,0,0,$not_nullable);
- $this->addColumn('element','name',OR_DB_COLUMN_TYPE_VARCHAR,50,null,$not_nullable);
- $this->addColumn('element','descr',OR_DB_COLUMN_TYPE_VARCHAR,255,null,$not_nullable);
- $this->addColumn('element','type',OR_DB_COLUMN_TYPE_VARCHAR,20,null,$not_nullable);
- $this->addColumn('element','subtype',OR_DB_COLUMN_TYPE_VARCHAR,20,null,$nullable);
- $this->addColumn('element','with_icon',OR_DB_COLUMN_TYPE_INT,1,0,$not_nullable);
- $this->addColumn('element','dateformat',OR_DB_COLUMN_TYPE_VARCHAR,100,null,$nullable);
- $this->addColumn('element','wiki',OR_DB_COLUMN_TYPE_INT,1,0,$nullable);
- $this->addColumn('element','html',OR_DB_COLUMN_TYPE_INT,1,0,$nullable);
- $this->addColumn('element','all_languages',OR_DB_COLUMN_TYPE_INT,1,0,$not_nullable);
- $this->addColumn('element','writable',OR_DB_COLUMN_TYPE_INT,1,0,$not_nullable);
- $this->addColumn('element','decimals',OR_DB_COLUMN_TYPE_INT,0,null,$nullable);
- $this->addColumn('element','dec_point',OR_DB_COLUMN_TYPE_VARCHAR,5,null,$nullable);
- $this->addColumn('element','thousand_sep',OR_DB_COLUMN_TYPE_VARCHAR,1,null,$nullable);
- $this->addColumn('element','code',OR_DB_COLUMN_TYPE_TEXT,null,null,$nullable);
- $this->addColumn('element','default_text',OR_DB_COLUMN_TYPE_TEXT,null,null,$nullable);
- $this->addColumn('element','folderobjectid',OR_DB_COLUMN_TYPE_INT,null,null,$nullable);
- $this->addColumn('element','default_objectid',OR_DB_COLUMN_TYPE_INT,null,null,$nullable);
- $this->addPrimaryKey('element','id');
- $this->addConstraint('element','default_objectid','object','id');
- $this->addConstraint('element','folderobjectid','object','id');
- $this->addConstraint('element','templateid','template','id');
-
- $this->addIndex('element','templateid');
- $this->addIndex('element','name');
- $this->addUniqueIndex('element','templateid,name');
-
-
-
-
- $this->addTable('file');
- $this->addColumn('file','objectid',OR_DB_COLUMN_TYPE_INT,0,null,$not_nullable);
- $this->addColumn('file','extension',OR_DB_COLUMN_TYPE_VARCHAR,10,null,$not_nullable);
- $this->addColumn('file','size',OR_DB_COLUMN_TYPE_INT,0,null,$not_nullable);
- $this->addColumn('file','value',OR_DB_COLUMN_TYPE_BLOB,null,null,$not_nullable);
- $this->addPrimaryKey('file','id');
- $this->addConstraint('file','objectid','object','id');
-
- $this->addUniqueIndex('file','objectid');
-
-
-
- $this->addTable('folder');
- $this->addColumn('folder','objectid',OR_DB_COLUMN_TYPE_INT,0,null,$not_nullable);
- $this->addPrimaryKey('folder','id');
- $this->addConstraint('folder','objectid','object','id');
-
- $this->addUniqueIndex('folder','objectid');
-
-
-
-
-
- $this->addTable('link');
- $this->addColumn('link','objectid',OR_DB_COLUMN_TYPE_INT,0,null,$not_nullable);
- $this->addColumn('link','link_objectid',OR_DB_COLUMN_TYPE_INT,null,null,$nullable);
- $this->addColumn('link','url',OR_DB_COLUMN_TYPE_VARCHAR,255,null,$nullable);
- $this->addPrimaryKey('link','id');
- $this->addConstraint('link','objectid','object','id');
- $this->addConstraint('link','link_objectid','object','id');
-
- $this->addUniqueIndex('link','objectid');
- $this->addIndex('link','link_objectid');
-
-
-
-
-
- $this->addTable('name');
- $this->addColumn('name','objectid',OR_DB_COLUMN_TYPE_INT,0,null,$not_nullable);
- $this->addColumn('name','name',OR_DB_COLUMN_TYPE_VARCHAR,255,null,$not_nullable);
- $this->addColumn('name','descr',OR_DB_COLUMN_TYPE_VARCHAR,255,null,$not_nullable);
- $this->addColumn('name','languageid',OR_DB_COLUMN_TYPE_INT,0,null,$not_nullable);
- $this->addPrimaryKey('name','id');
- $this->addConstraint('name','objectid','object','id');
- $this->addConstraint('name','languageid','language','id');
-
- $this->addIndex('name','objectid');
- $this->addIndex('name','languageid');
- $this->addUniqueIndex('name','objectid,languageid');
-
-
-
-
-
- $this->addTable('templatemodel');
- $this->addColumn('templatemodel','templateid',OR_DB_COLUMN_TYPE_INT,0,null,$not_nullable);
- $this->addColumn('templatemodel','projectmodelid',OR_DB_COLUMN_TYPE_INT,0,null,$not_nullable);
- $this->addColumn('templatemodel','extension',OR_DB_COLUMN_TYPE_VARCHAR,10,null,$nullable);
- $this->addColumn('templatemodel',OR_DB_COLUMN_TYPE_TEXT,OR_DB_COLUMN_TYPE_TEXT,null,null,$not_nullable);
- $this->addPrimaryKey('templatemodel','id');
- $this->addConstraint('templatemodel','templateid','template','id');
- $this->addConstraint('templatemodel','projectmodelid','projectmodel','id');
-
- $this->addIndex('templatemodel','templateid');
- $this->addUniqueIndex('templatemodel','templateid,extension');
- $this->addUniqueIndex('templatemodel','templateid,projectmodelid');
-
-
-
-
-
- $this->addTable('usergroup');
- $this->addColumn('usergroup','userid',OR_DB_COLUMN_TYPE_INT,null,null,$not_nullable);
- $this->addColumn('usergroup','groupid',OR_DB_COLUMN_TYPE_INT,null,null,$not_nullable);
- $this->addPrimaryKey('usergroup','id');
- $this->addConstraint('usergroup','groupid','group','id');
- $this->addConstraint('usergroup','userid','user','id');
-
- $this->addIndex('usergroup','groupid');
- $this->addIndex('usergroup','userid');
- $this->addUniqueIndex('usergroup','userid,groupid');
-
-
-
-
- $this->addTable('value');
- $this->addColumn('value','pageid',OR_DB_COLUMN_TYPE_INT,0,null,$not_nullable);
- $this->addColumn('value','languageid',OR_DB_COLUMN_TYPE_INT,null,null,$not_nullable);
- $this->addColumn('value','elementid',OR_DB_COLUMN_TYPE_INT,0,null,$not_nullable);
- $this->addColumn('value','linkobjectid',OR_DB_COLUMN_TYPE_INT,null,null,$nullable);
- $this->addColumn('value',OR_DB_COLUMN_TYPE_TEXT,OR_DB_COLUMN_TYPE_TEXT,null,null,$nullable);
- $this->addColumn('value','number',OR_DB_COLUMN_TYPE_INT,null,null,$nullable);
- $this->addColumn('value','date',OR_DB_COLUMN_TYPE_INT,null,null,$nullable);
- $this->addColumn('value','active',OR_DB_COLUMN_TYPE_INT,0,null,$not_nullable);
- $this->addColumn('value','lastchange_date',OR_DB_COLUMN_TYPE_INT,0,null,$not_nullable);
- $this->addColumn('value','lastchange_userid',OR_DB_COLUMN_TYPE_INT,null,null,$nullable);
- $this->addColumn('value','publish',OR_DB_COLUMN_TYPE_INT,null,null,$not_nullable);
- $this->addPrimaryKey('value','id');
- $this->addConstraint('value','pageid','page','id');
- $this->addConstraint('value','elementid','element','id');
- $this->addConstraint('value','languageid','language','id');
- $this->addConstraint('value','lastchange_userid','user','id');
- $this->addConstraint('value','linkobjectid','object','id');
-
- $this->addIndex('value','pageid');
- $this->addIndex('value','languageid');
- $this->addIndex('value','elementid');
- $this->addIndex('value','active');
- $this->addIndex('value','lastchange_date');
- $this->addIndex('value','publish');
-
-
-
-
-
- $this->addTable('acl');
- $this->addColumn('acl','userid',OR_DB_COLUMN_TYPE_INT,null,null,$nullable);
- $this->addColumn('acl','groupid',OR_DB_COLUMN_TYPE_INT,null,null,$nullable);
- $this->addColumn('acl','objectid',OR_DB_COLUMN_TYPE_INT,null,null,$not_nullable);
- $this->addColumn('acl','languageid',OR_DB_COLUMN_TYPE_INT,0,null,$nullable);
- $this->addColumn('acl','is_write',OR_DB_COLUMN_TYPE_INT,1,0,$not_nullable);
- $this->addColumn('acl','is_prop',OR_DB_COLUMN_TYPE_INT,1,0,$not_nullable);
- $this->addColumn('acl','is_create_folder',OR_DB_COLUMN_TYPE_INT,1,0,$not_nullable);
- $this->addColumn('acl','is_create_file',OR_DB_COLUMN_TYPE_INT,1,0,$not_nullable);
- $this->addColumn('acl','is_create_link',OR_DB_COLUMN_TYPE_INT,1,0,$not_nullable);
- $this->addColumn('acl','is_create_page',OR_DB_COLUMN_TYPE_INT,1,0,$not_nullable);
- $this->addColumn('acl','is_delete',OR_DB_COLUMN_TYPE_INT,1,0,$not_nullable);
- $this->addColumn('acl','is_release',OR_DB_COLUMN_TYPE_INT,1,0,$not_nullable);
- $this->addColumn('acl','is_publish',OR_DB_COLUMN_TYPE_INT,1,0,$not_nullable);
- $this->addColumn('acl','is_grant',OR_DB_COLUMN_TYPE_INT,1,0,$not_nullable);
- $this->addColumn('acl','is_transmit',OR_DB_COLUMN_TYPE_INT,1,0,$not_nullable);
- $this->addPrimaryKey('acl','id');
- $this->addConstraint('acl','groupid','group','id');
- $this->addConstraint('acl','userid','user','id');
- $this->addConstraint('acl','objectid','object','id');
- $this->addConstraint('acl','languageid','language','id');
-
- $this->addIndex('acl','userid');
- $this->addIndex('acl','groupid');
- $this->addIndex('acl','languageid');
- $this->addIndex('acl','objectid');
- $this->addIndex('acl','is_transmit');
-
- $this->afterUpdate( $this->getDb() );
- }
-
-
-
- /**
- * Initialisieren der frisch aktualisierten Datenbank.
- *
- * @param DB $db
- */
- private function afterUpdate( Database $db )
- {
- // Benutzer zählen.
- $sql = $db->sql('SELECT COUNT(*) From {{user}}',$db->id);
- $countUsers = $sql->getOne();
-
- // Wenn noch kein Benutzer vorhanden, dann einen anlegen.
- if ( $countUsers == 0 )
- {
- $sql = $db->sql("INSERT INTO {{user}} (id,name,password,ldap_dn,fullname,tel,mail,descr,style,is_admin) VALUES(1,'admin','admin','','Administrator','','','Account for administration tasks.','default',1)",$db->id);
- $sql->query();
- $db->commit();
- }
- }
-
-
-}
-
-?>-
\ No newline at end of file
diff --git a/db/update/DBVersion000002.class.php b/db/update/DBVersion000002.class.php
@@ -1,25 +0,0 @@
-<?php
-use database\DbVersion;
-/**
- * new table: version.
- *
- * @author dankert
- *
- */
-class DBVersion000002 extends DbVersion
-{
- public function update()
- {
- $this->addTable('version');
-
- $this->addColumn('version','version' ,OR_DB_COLUMN_TYPE_INT,null,null,false);
- $this->addColumn('version','status' ,OR_DB_COLUMN_TYPE_INT,null,null,false);
- $this->addColumn('version','installed',OR_DB_COLUMN_TYPE_INT,null,null,false);
-
- $this->addPrimaryKey ('version','id' );
- $this->addIndex ('version','status' );
- $this->addUniqueIndex('version','version' );
- }
-}
-
-?>-
\ No newline at end of file
diff --git a/db/update/DBVersion000003.class.php b/db/update/DBVersion000003.class.php
@@ -1,16 +0,0 @@
-<?php
-use database\DbVersion;
-/**
- * Dummy version.
- * @author dankert
- *
- */
-class DBVersion000003 extends DbVersion
-{
- public function update()
- {
- // Dummy version.
- }
-}
-
-?>-
\ No newline at end of file
diff --git a/db/update/DBVersion000004.class.php b/db/update/DBVersion000004.class.php
@@ -1,26 +0,0 @@
-<?php
-use database\DbVersion;
-
-/**
- * Add Columns for user language and user timezone.
- *
- * @author dankert
- *
- */
-class DBVersion000004 extends DbVersion
-{
- public function update()
- {
- $not_nullable = false;
- $nullable = true;
-
- // Add user language
- $this->addColumn('user','language',OR_DB_COLUMN_TYPE_VARCHAR, 2,null,$nullable);
-
- // Add user timezone
- $this->addColumn('user','timezone',OR_DB_COLUMN_TYPE_VARCHAR,64,null,$nullable);
-
- }
-}
-
-?>-
\ No newline at end of file
diff --git a/db/update/DBVersion000005.class.php b/db/update/DBVersion000005.class.php
@@ -1,33 +0,0 @@
-<?php
-use database\DbVersion;
-
-/**
- * Security enhancements.
- *
- * @author dankert
- *
- */
-class DBVersion000005 extends DbVersion
-{
- public function update()
- {
- $not_nullable = false;
- $nullable = true;
-
- // longer Passwords! 50 is not enough.
- $this->addColumn('user','password_hash',OR_DB_COLUMN_TYPE_VARCHAR,255,null,$not_nullable);
-
- $db = $this->getDb();
- $table = $this->getTableName('user');
- $updateStmt = $db->sql('UPDATE '.$table.
- ' SET password_hash=password'
- );
- $updateStmt->query();
-
- $this->dropColumn('user','password');
-
- $this->addColumn('user','password_salt',OR_DB_COLUMN_TYPE_VARCHAR,255,null,$not_nullable);
- }
-}
-
-?>-
\ No newline at end of file
diff --git a/db/update/DBVersion000006.class.php b/db/update/DBVersion000006.class.php
@@ -1,37 +0,0 @@
-<?php
-use database\DbVersion;
-
-/**
- * Security enhancements.
- *
- * @author dankert
- *
- */
-class DBVersion000006 extends DbVersion
-{
- public function update()
- {
- $not_nullable = false;
- $nullable = true;
-
- $this->addColumn('user','password_expires',OR_DB_COLUMN_TYPE_INT,0,null,$nullable);
-
- $this->addColumn('user','last_login' ,OR_DB_COLUMN_TYPE_INT,0,null,$nullable);
-
- $this->addColumn('user','password_algo' ,OR_DB_COLUMN_TYPE_INT,0,2,$not_nullable);
-
- // Setting Password algo. Passwords beginning with '$' are (old) MD5-hashes.
-
- // SUBSTR(s,pos,length) is supported by MySql,Postgres,SQLite
- // SUBSTRING(s FROM pos FOR length) is NOT supported by SQLite
- $table = $this->getTableName('user');
- $db = $this->getDb();
- $updateAlgoStmt = $db->sql('UPDATE '.$table.
- ' SET password_algo=1 WHERE SUBSTR(password_hash,1,1) = '."'$'".';'
- );
- $updateAlgoStmt->query();
-
- }
-}
-
-?>-
\ No newline at end of file
diff --git a/db/update/DBVersion000007.class.php b/db/update/DBVersion000007.class.php
@@ -1,39 +0,0 @@
-<?php
-use database\DbVersion;
-use security\Password;
-
-/**
- * Security enhancements.
- *
- * @author dankert
- *
- */
-class DBVersion000007 extends DbVersion
-{
- public function update()
- {
- $not_nullable = false;
- $nullable = true;
-
- $this->addColumn('user','otp_secret' ,OR_DB_COLUMN_TYPE_VARCHAR,255,null,$nullable );
-
- $table = $this->getTableName('user');
- $db = $this->getDb();
- $stmt = $db->sql('SELECT id FROM '.$table);
- foreach($stmt->getCol() as $userid )
- {
- $secret = Password::randomHexString(64);
- $stmt = $db->sql('UPDATE '.$table.' SET otp_secret={secret} WHERE id={id}');
- $stmt->setString('secret',$secret);
- $stmt->setInt('id',$userid);
- $stmt->query();
- }
-
- $this->addColumn('user','totp' ,OR_DB_COLUMN_TYPE_INT , 1, 0,$not_nullable);
- $this->addColumn('user','hotp_counter',OR_DB_COLUMN_TYPE_INT , 0, 0,$not_nullable);
- $this->addColumn('user','hotp' ,OR_DB_COLUMN_TYPE_INT , 1, 0,$not_nullable);
-
- }
-}
-
-?>-
\ No newline at end of file
diff --git a/db/update/DBVersion000008.class.php b/db/update/DBVersion000008.class.php
@@ -1,55 +0,0 @@
-<?php
-use database\DbVersion;
-use security\Password;
-
-/**
- * Creates a type column in table OBJECT. Now added types have no need for new table columns.
- *
- * @author dankert
- *
- */
-class DBVersion000008 extends DbVersion
-{
- /**
- *
- */
- public function update()
- {
- $not_nullable = false;
- $nullable = true;
-
- $this->addColumn('object','typeid',OR_DB_COLUMN_TYPE_INT,2,0,$not_nullable);
- $this->addIndex('object','typeid');
-
- // Converting old values...
- $db = $this->getDb();
- $table = $this->getTableName('object');
-
- $updateStmt = $db->sql('UPDATE '.$table.
- ' SET typeid=1 WHERE is_folder=1'
- );
- $updateStmt->query();
-
- $updateStmt = $db->sql('UPDATE '.$table.
- ' SET typeid=2 WHERE is_file=1'
- );
- $updateStmt->query();
-
- $updateStmt = $db->sql('UPDATE '.$table.
- ' SET typeid=3 WHERE is_page=1'
- );
- $updateStmt->query();
-
- $updateStmt = $db->sql('UPDATE '.$table.
- ' SET typeid=4 WHERE is_link=1'
- );
- $updateStmt->query();
-
- $this->dropColumn('object','is_folder');
- $this->dropColumn('object','is_file');
- $this->dropColumn('object','is_page');
- $this->dropColumn('object','is_link');
- }
-}
-
-?>-
\ No newline at end of file
diff --git a/db/update/DBVersion000009.class.php b/db/update/DBVersion000009.class.php
@@ -1,58 +0,0 @@
-<?php
-use database\DbVersion;
-use security\Password;
-
-/**
- * New Object type 'url'.
- *
- * In this Version 9 we are creating a table 'url' and are copying
- * the selected entries from table 'link' to 'url'.
- *
- * @author dankert
- *
- */
-class DBVersion000009 extends DbVersion
-{
- /**
- *
- */
- public function update()
- {
- $not_nullable = false;
- $nullable = true;
-
- // Creating new table 'url'
- $this->addTable('url');
- $this->addColumn('url','objectid',OR_DB_COLUMN_TYPE_INT,0,null,$not_nullable);
- $this->addColumn('url','url',OR_DB_COLUMN_TYPE_VARCHAR,255,null,$not_nullable);
-
- $this->addPrimaryKey('url','id');
- $this->addConstraint('url','objectid','object','id');
-
- $this->addUniqueIndex('url','objectid');
-
- // Copying values from table 'link' to new table 'url'
- $db = $this->getDb();
-
- $insertStmt = $db->sql('INSERT INTO '.$this->getTableName('url').
- ' (id,objectid,url) SELECT id,objectid,url FROM '.$this->getTableName('link').' WHERE url is not null'
- );
- $insertStmt->query();
-
- // Updating the typeid for URL entrys in table 'object'
- $updateStmt = $db->sql('UPDATE '.$this->getTableName('object').
- ' SET typeid='.OR_TYPEID_URL.' WHERE id IN (SELECT objectid FROM '.$this->getTableName('url').')'
- );
- $updateStmt->query();
-
- // Remove old entrys in table 'link'
- $updateStmt = $db->sql('DELETE FROM '.$this->getTableName('link').' WHERE url is not null'
- );
- $updateStmt->query();
-
- // Cleanup: Drop unused column.
- $this->dropColumn('link','url');
- }
-}
-
-?>-
\ No newline at end of file
diff --git a/db/update/DBVersion000010.class.php b/db/update/DBVersion000010.class.php
@@ -1,38 +0,0 @@
-<?php
-use database\DbVersion;
-use security\Password;
-
-/**
- * Filetype 'file' is now devided into 'file' (unchanged), 'image' (new) and OR_DB_COLUMN_TYPE_TEXT (new).
- *
- * @author dankert
- *
- */
-class DBVersion000010 extends DbVersion
-{
- /**
- *
- */
- public function update()
- {
- $db = $this->getDb();
- $tableObject = $this->getTableName('object');
- $tableFile = $this->getTableName('file');
-
- $updateStmt = $db->sql('UPDATE '.$tableObject.
- ' SET typeid=6 WHERE id IN (SELECT objectid FROM '.$tableFile.
- " WHERE extension IN ('gif','png','jpeg','jpg','svg','tiff') )"
- );
- $updateStmt->query();
-
- $updateStmt = $db->sql('UPDATE '.$tableObject.
- ' SET typeid=7 WHERE id IN (SELECT objectid FROM '.$tableFile.
- " WHERE extension IN ('css',OR_DB_COLUMN_TYPE_TEXT,'txt','js','html','xml','log','ini','gpx') )"
- );
- $updateStmt->query();
-
-
- }
-}
-
-?>-
\ No newline at end of file
diff --git a/db/update/DBVersion000011.class.php b/db/update/DBVersion000011.class.php
@@ -1,58 +0,0 @@
-<?php
-
-use database\DbVersion;
-use security\Password;
-
-/**
- * Project gets new columns.
- *
- * @author dankert
- *
- */
-class DBVersion000011 extends DbVersion
-{
- /**
- *
- */
- public function update()
- {
- $not_nullable = false;
- $nullable = true;
-
-
- $this->addColumn('project', 'url', OR_DB_COLUMN_TYPE_VARCHAR, 255, '', $not_nullable);
- $this->addColumn('project', 'flags', OR_DB_COLUMN_TYPE_INT, 11, 0, $not_nullable);
-
- $db = $this->getDb();
- $tableProject = $this->getTableName('project');
-
- // Update the url
- $updateStmt = $db->sql(<<<SQL
-UPDATE $tableProject
- SET url= CONCAT('//',name)
-SQL
- );
- $updateStmt->query();
-
- // Update the new flags
- $updateStmt = $db->sql(<<<SQL
-UPDATE $tableProject
- SET flags=flags+1 WHERE cut_index=1
-SQL
- );
- $updateStmt->query();
-
- $updateStmt = $db->sql(<<<SQL
-UPDATE $tableProject
- SET flags=flags+2 WHERE content_negotiation=1
-SQL
- );
- $updateStmt->query();
-
- // now the information is hold in column 'flags', so we can delete the old columns.
- $this->dropColumn('project', 'cut_index');
- $this->dropColumn('project', 'content_negotiation');
- }
-}
-
-?>-
\ No newline at end of file
diff --git a/modules/cms-core/action/LoginAction.class.php b/modules/cms-core/action/LoginAction.class.php
@@ -2184,9 +2184,6 @@ class LoginAction extends Action
throw new OpenRatException('DATABASE_ERROR_CONNECTION', $e->getMessage());
}
- // Datenbank aktualisieren, sofern notwendig.
- require_once(OR_DBCLASSES_DIR . 'DbUpdate.class.' . PHP_EXT);
-
$updater = new DbUpdate();
$updater->update($db);
diff --git a/modules/cms-core/require.php b/modules/cms-core/require.php
@@ -2,6 +2,7 @@
// Require other modules
require_once(__DIR__ . '/../database/require.php');
+require_once(__DIR__ . '/../database-update/require.php');
require_once(__DIR__ . '/../util/require.php');
require_once(__DIR__ . '/../configuration/require.php');
require_once(__DIR__ . '/../security/require.php');
diff --git a/modules/database-update/.htaccess b/modules/database-update/.htaccess
@@ -0,0 +1,2 @@
+order deny,allow
+deny from all+
\ No newline at end of file
diff --git a/modules/database-update/DbUpdate.class.php b/modules/database-update/DbUpdate.class.php
@@ -0,0 +1,115 @@
+<?php
+
+use database\Database;
+
+define('OR_DB_SUPPORTED_VERSION',11);
+
+define('OR_DB_STATUS_UPDATE_PROGRESS', 0);
+define('OR_DB_STATUS_UPDATE_SUCCESS' , 1);
+
+class DbUpdate
+{
+ /**
+ * @param Database $db
+ */
+ function update(Database $db )
+ {
+ $version = $this->getDbVersion($db);
+
+ if ( $version == OR_DB_SUPPORTED_VERSION )
+ // Cool, der aktuelle DB-Stand passt zu dieser Version. Das ist auch der Normalfall. Weiter so.
+ return;
+
+ if ( $version > OR_DB_SUPPORTED_VERSION )
+ // Oh oh, in der Datenbank ist eine neue Version, als wir unterstüzten.
+ throw new \LogicException('Actual DB version is not supported.',"DB-Version is $version, but this is OpenRat ".OR_VERSION." which only supports version ".OR_DB_SUPPORTED_VERSION );
+
+ if ( ! $db->conf['auto_update'])
+ throw new \LogicException('DB Update necessary.',"DB-Version is $version. Auto-Update is disabled, but this is OpenRat ".OR_VERSION." needs the version ".OR_DB_SUPPORTED_VERSION );
+
+ for( $installVersion = $version + 1; $installVersion <= OR_DB_SUPPORTED_VERSION; $installVersion++ )
+ {
+ if ( $installVersion > 2 ) // Up to version 2 there was no table 'version'.
+ {
+ $db->start();
+ $sql = $db->sql('INSERT INTO {{version}} (id,version,status,installed) VALUES( {id},{version},{status},{time} )',$db->id);
+ $sql->setInt('id' , $installVersion);
+ $sql->setInt('version', $installVersion);
+ $sql->setInt('status' , OR_DB_STATUS_UPDATE_PROGRESS);
+ $sql->setInt('time' , time() );
+ $sql->query();
+ $db->commit();
+ }
+
+ $updaterClassName = 'DBVersion'.str_pad($installVersion, 6, '0', STR_PAD_LEFT);
+ require(__DIR__.'/update/'.$updaterClassName.'.class.php');
+
+ $db->start();
+ /** @var \database\DbVersion $updater */
+ $updater = new $updaterClassName( $db );
+
+ $updater->update();
+ $db->commit();
+
+ if ( $installVersion > 2 )
+ {
+ $db->start();
+ $sql = $db->sql('UPDATE {{version}} SET status={status},installed={time} WHERE version={version}',$db->id);
+ $sql->setInt('status' , OR_DB_STATUS_UPDATE_SUCCESS);
+ $sql->setInt('version', $installVersion);
+ $sql->setInt('time' , time() );
+ $sql->query();
+ $db->commit();
+ }
+ }
+ }
+
+
+
+
+ private function getDbVersion( Database $db )
+ {
+ $sql = $db->sql('SELECT 1 FROM {{version}}',$db->id);
+ $versionTableExists = $sql->testQuery();
+
+ if ( $versionTableExists )
+ {
+ // Prüfen, ob die vorherigen Updates fehlerfrei sind.
+ $sql = $db->sql(<<<SQL
+ SELECT COUNT(*) FROM {{version}} WHERE STATUS=0
+SQL
+ ,$db->id);
+ $countErrors = $sql->getOne();
+ if ( $countErrors > 0 )
+ throw new \LogicException('Database error','there are dirty versions (means: versions with status 0), see table VERSION for details.');
+
+ // Aktuelle Version ermitteln.
+ $sql = $db->sql(<<<SQL
+ SELECT MAX(version) FROM {{version}}
+SQL
+ ,$db->id);
+ $version = $sql->getOne();
+
+ if ( is_numeric($version) )
+ return $version; // Aktuelle Version.s
+ else
+ // Tabelle 'version' ist noch leer.
+ // Tabelle 'version' wurde in Version 2 angelegt.
+ return 2;
+ }
+ else
+ {
+ $sql = $db->sql('SELECT 1 FROM {{project}}',$db->id);
+ $projectTableExists = $sql->testQuery();
+
+ if ( $projectTableExists )
+ // Entspricht dem Stand vor Einführung der automatischen Migration.
+ return 1;
+ else
+ // Es gibt gar keine Tabellen, es muss also alles neu angelegt werden.
+ return 0;
+ }
+ }
+}
+
+?>+
\ No newline at end of file
diff --git a/modules/database-update/require.php b/modules/database-update/require.php
@@ -0,0 +1,5 @@
+<?php
+
+require_once(__DIR__ . '/DbUpdate.class.php');
+
+?>+
\ No newline at end of file
diff --git a/modules/database-update/update/DBVersion000001.class.php b/modules/database-update/update/DBVersion000001.class.php
@@ -0,0 +1,353 @@
+<?php
+
+use database\Database;
+use database\DbVersion;
+
+
+/**
+ * Baseline database structure.
+ *
+ * @author dankert
+ *
+ */
+class DBVersion000001 extends DbVersion
+{
+ public function update()
+ {
+ $not_nullable = false;
+ $nullable = true;
+
+ $this->addTable('project');
+
+ $this->addColumn('project','name' ,OR_DB_COLUMN_TYPE_VARCHAR, 128,null,$not_nullable);
+ $this->addColumn('project','target_dir' ,OR_DB_COLUMN_TYPE_VARCHAR, 255,null,$not_nullable);
+ $this->addColumn('project','ftp_url' ,OR_DB_COLUMN_TYPE_VARCHAR, 255,null,$not_nullable);
+ $this->addColumn('project','ftp_passive' ,OR_DB_COLUMN_TYPE_INT ,null,null,$not_nullable);
+ $this->addColumn('project','cmd_after_publish' ,OR_DB_COLUMN_TYPE_VARCHAR, 255,null,$not_nullable);
+ $this->addColumn('project','content_negotiation',OR_DB_COLUMN_TYPE_INT , 1, 0,$not_nullable);
+ $this->addColumn('project','cut_index' ,OR_DB_COLUMN_TYPE_INT , 1, 0,$not_nullable);
+
+ $this->addPrimaryKey('project','id');
+ $this->addIndex('project','name');
+
+ /*
+ *
+ $this->addColumn('id',OR_DB_COLUMN_TYPE_INT,null,null,$not_nullable);
+ $this->addColumn('name',OR_DB_COLUMN_TYPE_VARCHAR,128,null,$not_nullable);
+ $this->addColumn('target_dir',OR_DB_COLUMN_TYPE_VARCHAR,255,null,$not_nullable);
+ $this->addColumn('ftp_url',OR_DB_COLUMN_TYPE_VARCHAR,255,null,$not_nullable);
+ $this->addColumn('ftp_passive',OR_DB_COLUMN_TYPE_INT,1,0,$not_nullable);
+ $this->addColumn('cmd_after_publish',OR_DB_COLUMN_TYPE_VARCHAR,255,null,$not_nullable);
+ $this->addColumn('content_negotiation',OR_DB_COLUMN_TYPE_INT,1,0,$not_nullable);
+ $this->addColumn('cut_$this->addIndex('',OR_DB_COLUMN_TYPE_INT);',1,0,$not_nullable);
+ $this->addPrimaryKey('','id');
+ close_table
+ unique_$this->addIndex('','name');
+ */
+
+
+
+
+ $this->addTable('user');
+ $this->addColumn('user','name',OR_DB_COLUMN_TYPE_VARCHAR,128,null,$not_nullable);
+ $this->addColumn('user','password',OR_DB_COLUMN_TYPE_VARCHAR,50,null,$not_nullable);
+ $this->addColumn('user','ldap_dn',OR_DB_COLUMN_TYPE_VARCHAR,255,null,$not_nullable);
+ $this->addColumn('user','fullname',OR_DB_COLUMN_TYPE_VARCHAR,128,null,$not_nullable);
+ $this->addColumn('user','tel',OR_DB_COLUMN_TYPE_VARCHAR,128,null,$not_nullable);
+ $this->addColumn('user','mail',OR_DB_COLUMN_TYPE_VARCHAR,255,null,$not_nullable);
+ $this->addColumn('user','descr',OR_DB_COLUMN_TYPE_VARCHAR,255,null,$not_nullable);
+ $this->addColumn('user','style',OR_DB_COLUMN_TYPE_VARCHAR,64,null,$not_nullable);
+ $this->addColumn('user','is_admin',OR_DB_COLUMN_TYPE_INT,1,0,$not_nullable);
+ $this->addPrimaryKey('user','id');
+ $this->addUniqueIndex('user','name');
+
+ $this->addTable('group');
+ $this->addColumn('group','name',OR_DB_COLUMN_TYPE_VARCHAR,100,null,$not_nullable);
+ $this->addPrimaryKey('group','id');
+ $this->addUniqueIndex('group','name');
+
+ $this->addTable('object');
+ $this->addColumn('object','parentid',OR_DB_COLUMN_TYPE_INT,null,null,$nullable);
+ $this->addColumn('object','projectid',OR_DB_COLUMN_TYPE_INT,0,0,$not_nullable);
+ $this->addColumn('object','filename',OR_DB_COLUMN_TYPE_VARCHAR,255,null,$not_nullable);
+ $this->addColumn('object','orderid',OR_DB_COLUMN_TYPE_INT,0,null,$not_nullable);
+ $this->addColumn('object','create_date',OR_DB_COLUMN_TYPE_INT,0,null,$not_nullable);
+ $this->addColumn('object','create_userid',OR_DB_COLUMN_TYPE_INT,0,null,$nullable);
+ $this->addColumn('object','lastchange_date',OR_DB_COLUMN_TYPE_INT,0,null,$not_nullable);
+ $this->addColumn('object','lastchange_userid',OR_DB_COLUMN_TYPE_INT,0,null,$nullable);
+ $this->addColumn('object','is_folder',OR_DB_COLUMN_TYPE_INT,1,null,$not_nullable);
+ $this->addColumn('object','is_file',OR_DB_COLUMN_TYPE_INT,1,null,$not_nullable);
+ $this->addColumn('object','is_page',OR_DB_COLUMN_TYPE_INT,1,null,$not_nullable);
+ $this->addColumn('object','is_link',OR_DB_COLUMN_TYPE_INT,1,null,$not_nullable);
+ $this->addPrimaryKey('object','id');
+ $this->addConstraint('object','projectid','project','id');
+ $this->addConstraint('object','lastchange_userid','user','id');
+ $this->addConstraint('object','create_userid','user','id');
+
+ $this->addIndex('object','parentid');
+ $this->addIndex('object','projectid');
+ $this->addIndex('object','is_folder');
+ $this->addIndex('object','is_file');
+ $this->addIndex('object','is_page');
+ $this->addIndex('object','is_link');
+ $this->addIndex('object','orderid');
+ $this->addIndex('object','create_userid');
+ $this->addIndex('object','lastchange_userid');
+ $this->addUniqueIndex('object','parentid,filename');
+
+
+
+
+ $this->addTable('template');
+ $this->addColumn('template','projectid',OR_DB_COLUMN_TYPE_INT,null,null,$not_nullable);
+ $this->addColumn('template','name',OR_DB_COLUMN_TYPE_VARCHAR,50,null,$not_nullable);
+ $this->addPrimaryKey('template','id');
+ $this->addConstraint('template','projectid','project','id');
+
+ $this->addIndex('template','projectid');
+ $this->addIndex('template','name');
+ $this->addUniqueIndex('template','projectid,name');
+
+
+
+ $this->addTable('language');
+ $this->addColumn('language','projectid',OR_DB_COLUMN_TYPE_INT,0,null,$not_nullable);
+ $this->addColumn('language','isocode',OR_DB_COLUMN_TYPE_VARCHAR,10,null,$not_nullable);
+ $this->addColumn('language','name',OR_DB_COLUMN_TYPE_VARCHAR,50,null,$not_nullable);
+ $this->addColumn('language','is_default',OR_DB_COLUMN_TYPE_INT,1,0,$not_nullable);
+ $this->addPrimaryKey('language','id');
+ $this->addConstraint('language','projectid','project','id');
+ $this->addUniqueIndex('language','projectid,isocode');
+
+
+
+
+ $this->addTable('page');
+ $this->addColumn('page','objectid',OR_DB_COLUMN_TYPE_INT,0,null,$not_nullable);
+ $this->addColumn('page','templateid',OR_DB_COLUMN_TYPE_INT,0,null,$not_nullable);
+ $this->addPrimaryKey('page','id');
+ $this->addConstraint('page','templateid','template','id');
+ $this->addConstraint('page','objectid','object','id');
+
+ $this->addUniqueIndex('page','objectid');
+ $this->addIndex('page','templateid');
+
+
+
+
+ $this->addTable('projectmodel');
+ $this->addColumn('projectmodel','projectid',OR_DB_COLUMN_TYPE_INT,0,null,$not_nullable);
+ $this->addColumn('projectmodel','name',OR_DB_COLUMN_TYPE_VARCHAR,50,null,$not_nullable);
+ $this->addColumn('projectmodel','extension',OR_DB_COLUMN_TYPE_VARCHAR,10,null,$nullable);
+ $this->addColumn('projectmodel','is_default',OR_DB_COLUMN_TYPE_INT,1,0,$not_nullable);
+ $this->addPrimaryKey('projectmodel','id');
+ $this->addConstraint('projectmodel','projectid','project','id');
+
+ $this->addIndex('projectmodel','projectid');
+ $this->addUniqueIndex('projectmodel','projectid,name');
+
+
+ $this->addTable('element');
+ $this->addColumn('element','templateid',OR_DB_COLUMN_TYPE_INT,0,0,$not_nullable);
+ $this->addColumn('element','name',OR_DB_COLUMN_TYPE_VARCHAR,50,null,$not_nullable);
+ $this->addColumn('element','descr',OR_DB_COLUMN_TYPE_VARCHAR,255,null,$not_nullable);
+ $this->addColumn('element','type',OR_DB_COLUMN_TYPE_VARCHAR,20,null,$not_nullable);
+ $this->addColumn('element','subtype',OR_DB_COLUMN_TYPE_VARCHAR,20,null,$nullable);
+ $this->addColumn('element','with_icon',OR_DB_COLUMN_TYPE_INT,1,0,$not_nullable);
+ $this->addColumn('element','dateformat',OR_DB_COLUMN_TYPE_VARCHAR,100,null,$nullable);
+ $this->addColumn('element','wiki',OR_DB_COLUMN_TYPE_INT,1,0,$nullable);
+ $this->addColumn('element','html',OR_DB_COLUMN_TYPE_INT,1,0,$nullable);
+ $this->addColumn('element','all_languages',OR_DB_COLUMN_TYPE_INT,1,0,$not_nullable);
+ $this->addColumn('element','writable',OR_DB_COLUMN_TYPE_INT,1,0,$not_nullable);
+ $this->addColumn('element','decimals',OR_DB_COLUMN_TYPE_INT,0,null,$nullable);
+ $this->addColumn('element','dec_point',OR_DB_COLUMN_TYPE_VARCHAR,5,null,$nullable);
+ $this->addColumn('element','thousand_sep',OR_DB_COLUMN_TYPE_VARCHAR,1,null,$nullable);
+ $this->addColumn('element','code',OR_DB_COLUMN_TYPE_TEXT,null,null,$nullable);
+ $this->addColumn('element','default_text',OR_DB_COLUMN_TYPE_TEXT,null,null,$nullable);
+ $this->addColumn('element','folderobjectid',OR_DB_COLUMN_TYPE_INT,null,null,$nullable);
+ $this->addColumn('element','default_objectid',OR_DB_COLUMN_TYPE_INT,null,null,$nullable);
+ $this->addPrimaryKey('element','id');
+ $this->addConstraint('element','default_objectid','object','id');
+ $this->addConstraint('element','folderobjectid','object','id');
+ $this->addConstraint('element','templateid','template','id');
+
+ $this->addIndex('element','templateid');
+ $this->addIndex('element','name');
+ $this->addUniqueIndex('element','templateid,name');
+
+
+
+
+ $this->addTable('file');
+ $this->addColumn('file','objectid',OR_DB_COLUMN_TYPE_INT,0,null,$not_nullable);
+ $this->addColumn('file','extension',OR_DB_COLUMN_TYPE_VARCHAR,10,null,$not_nullable);
+ $this->addColumn('file','size',OR_DB_COLUMN_TYPE_INT,0,null,$not_nullable);
+ $this->addColumn('file','value',OR_DB_COLUMN_TYPE_BLOB,null,null,$not_nullable);
+ $this->addPrimaryKey('file','id');
+ $this->addConstraint('file','objectid','object','id');
+
+ $this->addUniqueIndex('file','objectid');
+
+
+
+ $this->addTable('folder');
+ $this->addColumn('folder','objectid',OR_DB_COLUMN_TYPE_INT,0,null,$not_nullable);
+ $this->addPrimaryKey('folder','id');
+ $this->addConstraint('folder','objectid','object','id');
+
+ $this->addUniqueIndex('folder','objectid');
+
+
+
+
+
+ $this->addTable('link');
+ $this->addColumn('link','objectid',OR_DB_COLUMN_TYPE_INT,0,null,$not_nullable);
+ $this->addColumn('link','link_objectid',OR_DB_COLUMN_TYPE_INT,null,null,$nullable);
+ $this->addColumn('link','url',OR_DB_COLUMN_TYPE_VARCHAR,255,null,$nullable);
+ $this->addPrimaryKey('link','id');
+ $this->addConstraint('link','objectid','object','id');
+ $this->addConstraint('link','link_objectid','object','id');
+
+ $this->addUniqueIndex('link','objectid');
+ $this->addIndex('link','link_objectid');
+
+
+
+
+
+ $this->addTable('name');
+ $this->addColumn('name','objectid',OR_DB_COLUMN_TYPE_INT,0,null,$not_nullable);
+ $this->addColumn('name','name',OR_DB_COLUMN_TYPE_VARCHAR,255,null,$not_nullable);
+ $this->addColumn('name','descr',OR_DB_COLUMN_TYPE_VARCHAR,255,null,$not_nullable);
+ $this->addColumn('name','languageid',OR_DB_COLUMN_TYPE_INT,0,null,$not_nullable);
+ $this->addPrimaryKey('name','id');
+ $this->addConstraint('name','objectid','object','id');
+ $this->addConstraint('name','languageid','language','id');
+
+ $this->addIndex('name','objectid');
+ $this->addIndex('name','languageid');
+ $this->addUniqueIndex('name','objectid,languageid');
+
+
+
+
+
+ $this->addTable('templatemodel');
+ $this->addColumn('templatemodel','templateid',OR_DB_COLUMN_TYPE_INT,0,null,$not_nullable);
+ $this->addColumn('templatemodel','projectmodelid',OR_DB_COLUMN_TYPE_INT,0,null,$not_nullable);
+ $this->addColumn('templatemodel','extension',OR_DB_COLUMN_TYPE_VARCHAR,10,null,$nullable);
+ $this->addColumn('templatemodel',OR_DB_COLUMN_TYPE_TEXT,OR_DB_COLUMN_TYPE_TEXT,null,null,$not_nullable);
+ $this->addPrimaryKey('templatemodel','id');
+ $this->addConstraint('templatemodel','templateid','template','id');
+ $this->addConstraint('templatemodel','projectmodelid','projectmodel','id');
+
+ $this->addIndex('templatemodel','templateid');
+ $this->addUniqueIndex('templatemodel','templateid,extension');
+ $this->addUniqueIndex('templatemodel','templateid,projectmodelid');
+
+
+
+
+
+ $this->addTable('usergroup');
+ $this->addColumn('usergroup','userid',OR_DB_COLUMN_TYPE_INT,null,null,$not_nullable);
+ $this->addColumn('usergroup','groupid',OR_DB_COLUMN_TYPE_INT,null,null,$not_nullable);
+ $this->addPrimaryKey('usergroup','id');
+ $this->addConstraint('usergroup','groupid','group','id');
+ $this->addConstraint('usergroup','userid','user','id');
+
+ $this->addIndex('usergroup','groupid');
+ $this->addIndex('usergroup','userid');
+ $this->addUniqueIndex('usergroup','userid,groupid');
+
+
+
+
+ $this->addTable('value');
+ $this->addColumn('value','pageid',OR_DB_COLUMN_TYPE_INT,0,null,$not_nullable);
+ $this->addColumn('value','languageid',OR_DB_COLUMN_TYPE_INT,null,null,$not_nullable);
+ $this->addColumn('value','elementid',OR_DB_COLUMN_TYPE_INT,0,null,$not_nullable);
+ $this->addColumn('value','linkobjectid',OR_DB_COLUMN_TYPE_INT,null,null,$nullable);
+ $this->addColumn('value',OR_DB_COLUMN_TYPE_TEXT,OR_DB_COLUMN_TYPE_TEXT,null,null,$nullable);
+ $this->addColumn('value','number',OR_DB_COLUMN_TYPE_INT,null,null,$nullable);
+ $this->addColumn('value','date',OR_DB_COLUMN_TYPE_INT,null,null,$nullable);
+ $this->addColumn('value','active',OR_DB_COLUMN_TYPE_INT,0,null,$not_nullable);
+ $this->addColumn('value','lastchange_date',OR_DB_COLUMN_TYPE_INT,0,null,$not_nullable);
+ $this->addColumn('value','lastchange_userid',OR_DB_COLUMN_TYPE_INT,null,null,$nullable);
+ $this->addColumn('value','publish',OR_DB_COLUMN_TYPE_INT,null,null,$not_nullable);
+ $this->addPrimaryKey('value','id');
+ $this->addConstraint('value','pageid','page','id');
+ $this->addConstraint('value','elementid','element','id');
+ $this->addConstraint('value','languageid','language','id');
+ $this->addConstraint('value','lastchange_userid','user','id');
+ $this->addConstraint('value','linkobjectid','object','id');
+
+ $this->addIndex('value','pageid');
+ $this->addIndex('value','languageid');
+ $this->addIndex('value','elementid');
+ $this->addIndex('value','active');
+ $this->addIndex('value','lastchange_date');
+ $this->addIndex('value','publish');
+
+
+
+
+
+ $this->addTable('acl');
+ $this->addColumn('acl','userid',OR_DB_COLUMN_TYPE_INT,null,null,$nullable);
+ $this->addColumn('acl','groupid',OR_DB_COLUMN_TYPE_INT,null,null,$nullable);
+ $this->addColumn('acl','objectid',OR_DB_COLUMN_TYPE_INT,null,null,$not_nullable);
+ $this->addColumn('acl','languageid',OR_DB_COLUMN_TYPE_INT,0,null,$nullable);
+ $this->addColumn('acl','is_write',OR_DB_COLUMN_TYPE_INT,1,0,$not_nullable);
+ $this->addColumn('acl','is_prop',OR_DB_COLUMN_TYPE_INT,1,0,$not_nullable);
+ $this->addColumn('acl','is_create_folder',OR_DB_COLUMN_TYPE_INT,1,0,$not_nullable);
+ $this->addColumn('acl','is_create_file',OR_DB_COLUMN_TYPE_INT,1,0,$not_nullable);
+ $this->addColumn('acl','is_create_link',OR_DB_COLUMN_TYPE_INT,1,0,$not_nullable);
+ $this->addColumn('acl','is_create_page',OR_DB_COLUMN_TYPE_INT,1,0,$not_nullable);
+ $this->addColumn('acl','is_delete',OR_DB_COLUMN_TYPE_INT,1,0,$not_nullable);
+ $this->addColumn('acl','is_release',OR_DB_COLUMN_TYPE_INT,1,0,$not_nullable);
+ $this->addColumn('acl','is_publish',OR_DB_COLUMN_TYPE_INT,1,0,$not_nullable);
+ $this->addColumn('acl','is_grant',OR_DB_COLUMN_TYPE_INT,1,0,$not_nullable);
+ $this->addColumn('acl','is_transmit',OR_DB_COLUMN_TYPE_INT,1,0,$not_nullable);
+ $this->addPrimaryKey('acl','id');
+ $this->addConstraint('acl','groupid','group','id');
+ $this->addConstraint('acl','userid','user','id');
+ $this->addConstraint('acl','objectid','object','id');
+ $this->addConstraint('acl','languageid','language','id');
+
+ $this->addIndex('acl','userid');
+ $this->addIndex('acl','groupid');
+ $this->addIndex('acl','languageid');
+ $this->addIndex('acl','objectid');
+ $this->addIndex('acl','is_transmit');
+
+ $this->afterUpdate( $this->getDb() );
+ }
+
+
+
+ /**
+ * Initialisieren der frisch aktualisierten Datenbank.
+ *
+ * @param DB $db
+ */
+ private function afterUpdate( Database $db )
+ {
+ // Benutzer zählen.
+ $sql = $db->sql('SELECT COUNT(*) From {{user}}',$db->id);
+ $countUsers = $sql->getOne();
+
+ // Wenn noch kein Benutzer vorhanden, dann einen anlegen.
+ if ( $countUsers == 0 )
+ {
+ $sql = $db->sql("INSERT INTO {{user}} (id,name,password,ldap_dn,fullname,tel,mail,descr,style,is_admin) VALUES(1,'admin','admin','','Administrator','','','Account for administration tasks.','default',1)",$db->id);
+ $sql->query();
+ $db->commit();
+ }
+ }
+
+
+}
+
+?>+
\ No newline at end of file
diff --git a/modules/database-update/update/DBVersion000002.class.php b/modules/database-update/update/DBVersion000002.class.php
@@ -0,0 +1,25 @@
+<?php
+use database\DbVersion;
+/**
+ * new table: version.
+ *
+ * @author dankert
+ *
+ */
+class DBVersion000002 extends DbVersion
+{
+ public function update()
+ {
+ $this->addTable('version');
+
+ $this->addColumn('version','version' ,OR_DB_COLUMN_TYPE_INT,null,null,false);
+ $this->addColumn('version','status' ,OR_DB_COLUMN_TYPE_INT,null,null,false);
+ $this->addColumn('version','installed',OR_DB_COLUMN_TYPE_INT,null,null,false);
+
+ $this->addPrimaryKey ('version','id' );
+ $this->addIndex ('version','status' );
+ $this->addUniqueIndex('version','version' );
+ }
+}
+
+?>+
\ No newline at end of file
diff --git a/modules/database-update/update/DBVersion000003.class.php b/modules/database-update/update/DBVersion000003.class.php
@@ -0,0 +1,16 @@
+<?php
+use database\DbVersion;
+/**
+ * Dummy version.
+ * @author dankert
+ *
+ */
+class DBVersion000003 extends DbVersion
+{
+ public function update()
+ {
+ // Dummy version.
+ }
+}
+
+?>+
\ No newline at end of file
diff --git a/modules/database-update/update/DBVersion000004.class.php b/modules/database-update/update/DBVersion000004.class.php
@@ -0,0 +1,26 @@
+<?php
+use database\DbVersion;
+
+/**
+ * Add Columns for user language and user timezone.
+ *
+ * @author dankert
+ *
+ */
+class DBVersion000004 extends DbVersion
+{
+ public function update()
+ {
+ $not_nullable = false;
+ $nullable = true;
+
+ // Add user language
+ $this->addColumn('user','language',OR_DB_COLUMN_TYPE_VARCHAR, 2,null,$nullable);
+
+ // Add user timezone
+ $this->addColumn('user','timezone',OR_DB_COLUMN_TYPE_VARCHAR,64,null,$nullable);
+
+ }
+}
+
+?>+
\ No newline at end of file
diff --git a/modules/database-update/update/DBVersion000005.class.php b/modules/database-update/update/DBVersion000005.class.php
@@ -0,0 +1,33 @@
+<?php
+use database\DbVersion;
+
+/**
+ * Security enhancements.
+ *
+ * @author dankert
+ *
+ */
+class DBVersion000005 extends DbVersion
+{
+ public function update()
+ {
+ $not_nullable = false;
+ $nullable = true;
+
+ // longer Passwords! 50 is not enough.
+ $this->addColumn('user','password_hash',OR_DB_COLUMN_TYPE_VARCHAR,255,null,$not_nullable);
+
+ $db = $this->getDb();
+ $table = $this->getTableName('user');
+ $updateStmt = $db->sql('UPDATE '.$table.
+ ' SET password_hash=password'
+ );
+ $updateStmt->query();
+
+ $this->dropColumn('user','password');
+
+ $this->addColumn('user','password_salt',OR_DB_COLUMN_TYPE_VARCHAR,255,null,$not_nullable);
+ }
+}
+
+?>+
\ No newline at end of file
diff --git a/modules/database-update/update/DBVersion000006.class.php b/modules/database-update/update/DBVersion000006.class.php
@@ -0,0 +1,37 @@
+<?php
+use database\DbVersion;
+
+/**
+ * Security enhancements.
+ *
+ * @author dankert
+ *
+ */
+class DBVersion000006 extends DbVersion
+{
+ public function update()
+ {
+ $not_nullable = false;
+ $nullable = true;
+
+ $this->addColumn('user','password_expires',OR_DB_COLUMN_TYPE_INT,0,null,$nullable);
+
+ $this->addColumn('user','last_login' ,OR_DB_COLUMN_TYPE_INT,0,null,$nullable);
+
+ $this->addColumn('user','password_algo' ,OR_DB_COLUMN_TYPE_INT,0,2,$not_nullable);
+
+ // Setting Password algo. Passwords beginning with '$' are (old) MD5-hashes.
+
+ // SUBSTR(s,pos,length) is supported by MySql,Postgres,SQLite
+ // SUBSTRING(s FROM pos FOR length) is NOT supported by SQLite
+ $table = $this->getTableName('user');
+ $db = $this->getDb();
+ $updateAlgoStmt = $db->sql('UPDATE '.$table.
+ ' SET password_algo=1 WHERE SUBSTR(password_hash,1,1) = '."'$'".';'
+ );
+ $updateAlgoStmt->query();
+
+ }
+}
+
+?>+
\ No newline at end of file
diff --git a/modules/database-update/update/DBVersion000007.class.php b/modules/database-update/update/DBVersion000007.class.php
@@ -0,0 +1,39 @@
+<?php
+use database\DbVersion;
+use security\Password;
+
+/**
+ * Security enhancements.
+ *
+ * @author dankert
+ *
+ */
+class DBVersion000007 extends DbVersion
+{
+ public function update()
+ {
+ $not_nullable = false;
+ $nullable = true;
+
+ $this->addColumn('user','otp_secret' ,OR_DB_COLUMN_TYPE_VARCHAR,255,null,$nullable );
+
+ $table = $this->getTableName('user');
+ $db = $this->getDb();
+ $stmt = $db->sql('SELECT id FROM '.$table);
+ foreach($stmt->getCol() as $userid )
+ {
+ $secret = Password::randomHexString(64);
+ $stmt = $db->sql('UPDATE '.$table.' SET otp_secret={secret} WHERE id={id}');
+ $stmt->setString('secret',$secret);
+ $stmt->setInt('id',$userid);
+ $stmt->query();
+ }
+
+ $this->addColumn('user','totp' ,OR_DB_COLUMN_TYPE_INT , 1, 0,$not_nullable);
+ $this->addColumn('user','hotp_counter',OR_DB_COLUMN_TYPE_INT , 0, 0,$not_nullable);
+ $this->addColumn('user','hotp' ,OR_DB_COLUMN_TYPE_INT , 1, 0,$not_nullable);
+
+ }
+}
+
+?>+
\ No newline at end of file
diff --git a/modules/database-update/update/DBVersion000008.class.php b/modules/database-update/update/DBVersion000008.class.php
@@ -0,0 +1,55 @@
+<?php
+use database\DbVersion;
+use security\Password;
+
+/**
+ * Creates a type column in table OBJECT. Now added types have no need for new table columns.
+ *
+ * @author dankert
+ *
+ */
+class DBVersion000008 extends DbVersion
+{
+ /**
+ *
+ */
+ public function update()
+ {
+ $not_nullable = false;
+ $nullable = true;
+
+ $this->addColumn('object','typeid',OR_DB_COLUMN_TYPE_INT,2,0,$not_nullable);
+ $this->addIndex('object','typeid');
+
+ // Converting old values...
+ $db = $this->getDb();
+ $table = $this->getTableName('object');
+
+ $updateStmt = $db->sql('UPDATE '.$table.
+ ' SET typeid=1 WHERE is_folder=1'
+ );
+ $updateStmt->query();
+
+ $updateStmt = $db->sql('UPDATE '.$table.
+ ' SET typeid=2 WHERE is_file=1'
+ );
+ $updateStmt->query();
+
+ $updateStmt = $db->sql('UPDATE '.$table.
+ ' SET typeid=3 WHERE is_page=1'
+ );
+ $updateStmt->query();
+
+ $updateStmt = $db->sql('UPDATE '.$table.
+ ' SET typeid=4 WHERE is_link=1'
+ );
+ $updateStmt->query();
+
+ $this->dropColumn('object','is_folder');
+ $this->dropColumn('object','is_file');
+ $this->dropColumn('object','is_page');
+ $this->dropColumn('object','is_link');
+ }
+}
+
+?>+
\ No newline at end of file
diff --git a/modules/database-update/update/DBVersion000009.class.php b/modules/database-update/update/DBVersion000009.class.php
@@ -0,0 +1,58 @@
+<?php
+use database\DbVersion;
+use security\Password;
+
+/**
+ * New Object type 'url'.
+ *
+ * In this Version 9 we are creating a table 'url' and are copying
+ * the selected entries from table 'link' to 'url'.
+ *
+ * @author dankert
+ *
+ */
+class DBVersion000009 extends DbVersion
+{
+ /**
+ *
+ */
+ public function update()
+ {
+ $not_nullable = false;
+ $nullable = true;
+
+ // Creating new table 'url'
+ $this->addTable('url');
+ $this->addColumn('url','objectid',OR_DB_COLUMN_TYPE_INT,0,null,$not_nullable);
+ $this->addColumn('url','url',OR_DB_COLUMN_TYPE_VARCHAR,255,null,$not_nullable);
+
+ $this->addPrimaryKey('url','id');
+ $this->addConstraint('url','objectid','object','id');
+
+ $this->addUniqueIndex('url','objectid');
+
+ // Copying values from table 'link' to new table 'url'
+ $db = $this->getDb();
+
+ $insertStmt = $db->sql('INSERT INTO '.$this->getTableName('url').
+ ' (id,objectid,url) SELECT id,objectid,url FROM '.$this->getTableName('link').' WHERE url is not null'
+ );
+ $insertStmt->query();
+
+ // Updating the typeid for URL entrys in table 'object'
+ $updateStmt = $db->sql('UPDATE '.$this->getTableName('object').
+ ' SET typeid='.OR_TYPEID_URL.' WHERE id IN (SELECT objectid FROM '.$this->getTableName('url').')'
+ );
+ $updateStmt->query();
+
+ // Remove old entrys in table 'link'
+ $updateStmt = $db->sql('DELETE FROM '.$this->getTableName('link').' WHERE url is not null'
+ );
+ $updateStmt->query();
+
+ // Cleanup: Drop unused column.
+ $this->dropColumn('link','url');
+ }
+}
+
+?>+
\ No newline at end of file
diff --git a/modules/database-update/update/DBVersion000010.class.php b/modules/database-update/update/DBVersion000010.class.php
@@ -0,0 +1,38 @@
+<?php
+use database\DbVersion;
+use security\Password;
+
+/**
+ * Filetype 'file' is now devided into 'file' (unchanged), 'image' (new) and OR_DB_COLUMN_TYPE_TEXT (new).
+ *
+ * @author dankert
+ *
+ */
+class DBVersion000010 extends DbVersion
+{
+ /**
+ *
+ */
+ public function update()
+ {
+ $db = $this->getDb();
+ $tableObject = $this->getTableName('object');
+ $tableFile = $this->getTableName('file');
+
+ $updateStmt = $db->sql('UPDATE '.$tableObject.
+ ' SET typeid=6 WHERE id IN (SELECT objectid FROM '.$tableFile.
+ " WHERE extension IN ('gif','png','jpeg','jpg','svg','tiff') )"
+ );
+ $updateStmt->query();
+
+ $updateStmt = $db->sql('UPDATE '.$tableObject.
+ ' SET typeid=7 WHERE id IN (SELECT objectid FROM '.$tableFile.
+ " WHERE extension IN ('css',OR_DB_COLUMN_TYPE_TEXT,'txt','js','html','xml','log','ini','gpx') )"
+ );
+ $updateStmt->query();
+
+
+ }
+}
+
+?>+
\ No newline at end of file
diff --git a/modules/database-update/update/DBVersion000011.class.php b/modules/database-update/update/DBVersion000011.class.php
@@ -0,0 +1,58 @@
+<?php
+
+use database\DbVersion;
+use security\Password;
+
+/**
+ * Project gets new columns.
+ *
+ * @author dankert
+ *
+ */
+class DBVersion000011 extends DbVersion
+{
+ /**
+ *
+ */
+ public function update()
+ {
+ $not_nullable = false;
+ $nullable = true;
+
+
+ $this->addColumn('project', 'url', OR_DB_COLUMN_TYPE_VARCHAR, 255, '', $not_nullable);
+ $this->addColumn('project', 'flags', OR_DB_COLUMN_TYPE_INT, 11, 0, $not_nullable);
+
+ $db = $this->getDb();
+ $tableProject = $this->getTableName('project');
+
+ // Update the url
+ $updateStmt = $db->sql(<<<SQL
+UPDATE $tableProject
+ SET url= CONCAT('//',name)
+SQL
+ );
+ $updateStmt->query();
+
+ // Update the new flags
+ $updateStmt = $db->sql(<<<SQL
+UPDATE $tableProject
+ SET flags=flags+1 WHERE cut_index=1
+SQL
+ );
+ $updateStmt->query();
+
+ $updateStmt = $db->sql(<<<SQL
+UPDATE $tableProject
+ SET flags=flags+2 WHERE content_negotiation=1
+SQL
+ );
+ $updateStmt->query();
+
+ // now the information is hold in column 'flags', so we can delete the old columns.
+ $this->dropColumn('project', 'cut_index');
+ $this->dropColumn('project', 'content_negotiation');
+ }
+}
+
+?>+
\ No newline at end of file