#!/usr/bin/php . // Copyright © 2007-2014 Erwan Briand // // This program is free software: you can redistribute it and/or modify it // under the terms of the GNU Affero General Public License as published by // the Free Software Foundation, version 3 only. // // This program is distributed in the hope that it will be useful, but // WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY // or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public // License for more details. // // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see . /* Upgrade from 0.9.2 to 0.9.3 * * This script updates the SQL tables schema. * * http://codingteam.net/project/codingteam/doc/HowToUpgrade */ // But where are we? $base = dirname(__FILE__); $whereis = '/scripts/miscellaneous'; $length = -mb_strlen($whereis); $basedir = mb_substr($base, 0, $length); define('CT_BASEDIR', $basedir); // Check if the configuration file exist if (!file_exists($basedir.'/inc/codingteam.cfg')) die ('There are no configuration file. CodingTeam cannot start.'); // Read the configuration and connect to the database layer $xml = simplexml_load_file($basedir.'/inc/codingteam.cfg'); $db_type = $xml->db->type; $db_hostname = $xml->db->hostname; $db_database = $xml->db->database; $db_username = $xml->db->username; $db_password = $xml->db->password; // Database connection require($basedir.'/inc/classes/db.php'); $ct_db = new Database($db_type, $db_hostname, $db_database, $db_username, $db_password); // New SQL configuration keys $config = array( array('jabber', 'allow-notifications', 'false', 'true or false if you don\t want to allow notifications over XMPP.') ); foreach ($config as $key) $ct_db->insert('config', array('group' => $key[0], 'field' => $key[1], 'value' => $key[2], 'text' => $key[3])); // Update table schemas $rules = array( 'ALTER TABLE `projects` ADD `scm` enum(\'mercurial\',\'subversion\') collate utf8_bin NOT NULL AFTER `popularity`', 'ALTER TABLE `projects` ADD `features` tinytext NULL AFTER `scm`', 'CREATE TABLE IF NOT EXISTS `messages` ( '. ' `id` int(11) NOT NULL auto_increment, '. ' `sender_id` int(11) NOT NULL, '. ' `recipient_id` int(11) NOT NULL, '. ' `datetime` datetime NOT NULL, '. ' `subject` tinytext NOT NULL, '. ' `message` text NOT NULL, '. ' `allow_nl2br` tinyint(1) NOT NULL, '. ' `read_sender` tinyint(1) NOT NULL, '. ' `read_recipient` tinyint(1) NOT NULL, '. ' PRIMARY KEY ( `id` ) '. ') ENGINE = InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin AUTO_INCREMENT=1 ;', 'CREATE TABLE IF NOT EXISTS `messages_answers` ( '. ' `id` int(11) NOT NULL auto_increment, '. ' `pid` int(11) NOT NULL, '. ' `sender_id` int(11) NOT NULL, '. ' `recipient_id` int(11) NOT NULL, '. ' `datetime` datetime NOT NULL, '. ' `message` text NOT NULL, '. ' `allow_nl2br` tinyint(1) NOT NULL, '. ' `read_sender` tinyint(1) NOT NULL, '. ' `read_recipient` tinyint(1) NOT NULL, '. ' PRIMARY KEY ( `id` ) '. ') ENGINE = InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin AUTO_INCREMENT=1 ;', 'CREATE TABLE IF NOT EXISTS `notifications` ( '. ' `id` int(11) NOT NULL auto_increment, '. ' `jabberid` tinytext collate utf8_bin NOT NULL, '. ' `subject` tinytext collate utf8_bin NOT NULL, '. ' `notification` text collate utf8_bin NOT NULL, '. ' PRIMARY KEY (`id`) '. ') ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin AUTO_INCREMENT=1 ;', 'UPDATE `projects` SET scm=\'subversion\' WHERE scm=\'\'', "ALTER TABLE `users` ADD `notifs` enum('mail','xmpp','no') collate utf8_bin NOT NULL" ); foreach ($rules as $rule) { $rs = $ct_db->dbclass->prepare($rule); $rs->execute(); } ?>