openrat-cms

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit 506f5495f7bca3663ca09b54503544d3432a3d7c
parent 11572a2550e6524f429fb5e985723813f920a6b3
Author: Jan Dankert <devnull@localhost>
Date:   Fri,  8 Dec 2017 22:10:05 +0100

Neue Datenbankversion 9 mit neuem Objekttyp 'url'.

Diffstat:
db/DbUpdate.class.php | 2+-
db/update/DBVersion000009.class.php | 59+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 60 insertions(+), 1 deletion(-)

diff --git a/db/DbUpdate.class.php b/db/DbUpdate.class.php @@ -2,7 +2,7 @@ use database\Database; -define('OR_DB_SUPPORTED_VERSION',8); +define('OR_DB_SUPPORTED_VERSION',9); define('OR_DB_STATUS_UPDATE_PROGRESS', 0); define('OR_DB_STATUS_UPDATE_SUCCESS' , 1); diff --git a/db/update/DBVersion000009.class.php b/db/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','INT',0,null,$not_nullable); + $this->addColumn('url','url','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