websiteWebsite
codingteam CodingTeam
A free forge, lightweight and extensible.

 

Browse the code

Revision log Information on the revision
Revision: 332 (differences)
Author: xbright
Log message: * Welcome 2010 :)
Change revision:
#!/usr/bin/php
<?php
#    This file is a part of CodingTeam. See <http://www.codingteam.net>.
#    Copyright (C) 2007-2010 CodingTeam (See AUTHORS and THANKS for details)
#
#    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 <http://www.gnu.org/licenses/>.
 
/* Upgrade from 0.9.1 to 0.9.2
 *
 * This script add new SQL configuration keys to the database and update 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('global', 'authorize-anonymous-posts', 'true', 'Authorize content posted by anonymous.')
);
 
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_admins` ADD `powers` tinytext collate utf8_bin NOT NULL AFTER `role`',
  'ALTER TABLE `projects_versions` ADD `posid` int(11) NOT NULL AFTER `status`',
 
  'CREATE TABLE IF NOT EXISTS `projects_i18n` ( '.
  '  `id` int(11) NOT NULL auto_increment, '.
  '  `projectid` int(11) NOT NULL, '.
  '  `baselang` varchar(5) collate utf8_bin NOT NULL, '.
  '  `references` tinytext collate utf8_bin NOT NULL, '.
  '  `text` text collate utf8_bin NOT NULL, '.
  '  `is_translated` tinytext collate utf8_bin NOT NULL, '.
  '  `is_active` tinyint(1) NOT NULL, '.
  '  PRIMARY KEY  (`id`) '.
  ') ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin AUTO_INCREMENT=1 ;',
 
  'CREATE TABLE IF NOT EXISTS `projects_i18n_proposals` ( '.
  '  `id` int(11) NOT NULL auto_increment, '.
  '  `text_id` int(11) NOT NULL, '.
  '  `authorid` int(11) NOT NULL, '.
  '  `text` text collate utf8_bin NOT NULL, '.
  '  `type` enum(\'translation\',\'reformulation\',\'correction\') collate utf8_bin NOT NULL, '.
  '  `lang` varchar(5) collate utf8_bin NOT NULL, '.
  '  `datetime` datetime NOT NULL, '.
  '  PRIMARY KEY  (`id`) '.
  ') ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin AUTO_INCREMENT=1 ;',
 
  'ALTER TABLE `projects_i18n` '.
  '  ADD CONSTRAINT `constr_projects_projectid11` FOREIGN KEY (projectid) REFERENCES projects(id) ON DELETE CASCADE;',
 
  'ALTER TABLE `projects_i18n_proposals` '.
  '  ADD CONSTRAINT `constr_projects_i18n_textid` FOREIGN KEY (text_id) REFERENCES projects_i18n(id) ON DELETE CASCADE;',
);
 
foreach ($rules as $rule)
{
    $rs = $ct_db->dbclass->prepare($rule);
    $rs->execute();
}
?>