#!/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.3 to 0.9.4 * * This script updates the SQL tables schema. * * http://codingteam.net/project/codingteam/doc/HowToUpgrade */ // But where are we? $base = dirname(__FILE__); $whereis = '/scripts/upgrade'; $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('global', 'title', 'CodingTeam', 'The title of your forge.') ); 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` CHANGE `scm` `scm` enum(\'git\',\'mercurial\',\'subversion\') collate utf8_bin NOT NULL', 'ALTER TABLE `projects` CHANGE `translations` `translations` text collate utf8_bin NOT NULL', 'ALTER TABLE `projects_commits` CHANGE `prev_rev` `prev_rev` text collate utf8_bin NOT NULL', 'ALTER TABLE `projects_commits` CHANGE `new_rev` `new_rev` text collate utf8_bin NOT NULL', 'ALTER TABLE `users` ADD `unread_messages` int(11) NOT NULL AFTER `lang`', 'ALTER TABLE `users` ADD `dashboard_lastelement` tinytext collate utf8_bin NOT NULL AFTER `notifs`', 'CREATE TABLE IF NOT EXISTS `teams` ( `id` int(11) NOT NULL, `name` tinytext COLLATE utf8_bin NOT NULL, `dbname` varchar(50) COLLATE utf8_bin NOT NULL, `rule` enum(\'public\',\'restricted\',\'private\') COLLATE utf8_bin NOT NULL, `logo` tinytext COLLATE utf8_bin NOT NULL, `text` text COLLATE utf8_bin NOT NULL, `allow_nl2br` tinyint(1) NOT NULL, `date` datetime NOT NULL, `leader_id` int(11) NOT NULL, `related_projects` tinytext COLLATE utf8_bin NOT NULL, `activate_mailinglist` tinyint(1) NOT NULL, `xmppchatroom` tinytext COLLATE utf8_bin NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;', 'CREATE TABLE IF NOT EXISTS `teams_members` ( `team_id` int(11) NOT NULL, `user_id` int(11) NOT NULL, `activate_mailinglist` tinyint(1) NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;' ); foreach ($rules as $rule) { $rs = $ct_db->dbclass->prepare($rule); $rs->execute(); } ?>