Esempio n. 1
0
function create_tables()
{
    global $dbh;
    create_table("events", "`eid` int(11) unsigned NOT NULL auto_increment,\n" . "`cid` int(11) unsigned NOT NULL,\n" . "`owner` int(11) unsigned NOT NULL default 0,\n" . "`subject` varchar(255) collate utf8_unicode_ci NOT NULL,\n" . "`description` text collate utf8_unicode_ci NOT NULL,\n" . "`readonly` tinyint(1) NOT NULL default 0,\n" . "`catid` int(11) unsigned default NULL,\n" . "`ctime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,\n" . "`mtime` timestamp NULL DEFAULT NULL,\n" . "PRIMARY KEY (`eid`)\n", "AUTO_INCREMENT=1");
    create_table("occurrences", "`oid` int(11) unsigned NOT NULL auto_increment,\n" . "`eid` int(11) unsigned NOT NULL,\n" . "`start_date` date default NULL,\n" . "`end_date` date default NULL,\n" . "`start_ts` timestamp NULL default NULL,\n" . "`end_ts` timestamp NULL default NULL,\n" . "`time_type` tinyint(4) NOT NULL default '0',\n" . "PRIMARY KEY  (`oid`),\n" . "KEY `eid` (`eid`)\n", "AUTO_INCREMENT=1");
    create_table("users", "`uid` int(11) unsigned NOT NULL auto_increment,\n" . "`username` varchar(32) collate utf8_unicode_ci NOT NULL,\n" . "`password` varchar(32) collate utf8_unicode_ci NOT NULL default '',\n" . "`admin` tinyint(4) NOT NULL DEFAULT '0',\n" . "`password_editable` tinyint(1) NOT NULL DEFAULT '1',\n" . "`timezone` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,\n" . "`language` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,\n" . "`gid` int(11),\n" . "PRIMARY KEY (`uid`),\n" . "UNIQUE KEY `username` (`username`)\n", "AUTO_INCREMENT=1");
    create_table("groups", "`gid` int(11) NOT NULL AUTO_INCREMENT,\n" . "`cid` int(11),\n" . "`name` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,\n" . "PRIMARY KEY (`gid`)\n");
    create_table("user_groups", "`gid` int(11),\n" . "`uid` int(11)\n");
    create_logins_table();
    create_table("permissions", "`cid` int(11) unsigned NOT NULL,\n" . "`uid` int(11) unsigned NOT NULL,\n" . "`read` tinyint(1) NOT NULL,\n" . "`write` tinyint(1) NOT NULL,\n" . "`readonly` tinyint(1) NOT NULL,\n" . "`modify` tinyint(1) NOT NULL,\n" . "`admin` tinyint(1) NOT NULL,\n" . "UNIQUE KEY `cid` (`cid`,`uid`)\n");
    create_table("calendars", "`cid` int(11) unsigned NOT NULL auto_increment,\n" . "`hours_24` tinyint(1) NOT NULL DEFAULT 0,\n" . "`date_format` tinyint(1) NOT NULL DEFAULT 0,\n" . "`week_start` tinyint(1) NOT NULL DEFAULT 0,\n" . "`subject_max` smallint(5) unsigned NOT NULL DEFAULT 50,\n" . "`events_max` tinyint(4) unsigned NOT NULL DEFAULT 8,\n" . "`title` varchar(255) COLLATE utf8_unicode_ci NOT NULL DEFAULT 'PHP-Calendar',\n" . "`anon_permission` tinyint(1) NOT NULL DEFAULT 1,\n" . "`timezone` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,\n" . "`language` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,\n" . "`theme` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,\n" . "PRIMARY KEY  (`cid`)\n", "AUTO_INCREMENT=1");
    create_table("categories", "`catid` int(11) unsigned NOT NULL auto_increment,\n" . "`cid` int(11) unsigned NOT NULL,\n" . "`gid` int(11) unsigned DEFAULT NULL,\n" . "`name` varchar(255) collate utf8_unicode_ci NOT NULL,\n" . "`text_color` varchar(255) collate utf8_unicode_ci default NULL,\n" . "`bg_color` varchar(255) collate utf8_unicode_ci default NULL,\n" . "PRIMARY KEY  (`catid`),\n" . "KEY `cid` (`cid`)\n", "AUTO_INCREMENT=1");
    create_version_table();
}
Esempio n. 2
0
    $error_flag = true;
} else {
    echo "<tr>\n\n\t\t\t\t<td>UPDATED TABLE " . PRFX . "TABLE_CUSTOMER_MOBILE_PHONE</td>\n\n\t\t\t\t<td><font color=\"green\"><b>OK</b></font></td>\n\n\t\t\t</tr>\n";
}
function update_customer_mobile_phone($db)
{
    $q = "ALTER TABLE `" . PRFX . "TABLE_CUSTOMER` CHANGE `CUSTOMER_MOBILE_PHONE` `CUSTOMER_MOBILE_PHONE` VARCHAR(40)";
    $rs = $db->Execute($q);
    if (!$rs) {
        return false;
    } else {
        return true;
    }
}
// Adding Version Number to Database
if (!create_version_table($db)) {
    echo "<tr>\n\n\t\t\t<td>CREATED TABLE " . PRFX . "VERSION</td>\n\n\t\t\t<td><font color=\"red\"><b>Failed:</b></font> " . $db->ErrorMsg() . "</td>\n\n\t\t</tr>\n";
    $error_flag = true;
} else {
    echo "<tr>\n\n\t\t\t\t<td>CREATED TABLE " . PRFX . "VERSION</td>\n\n\t\t\t\t<td><font color=\"green\"><b>OK</b></font></td>\n\n\t\t\t</tr>\n";
}
// CREATING VERSION NUMBER TABLE
function create_version_table($db)
{
    $q = "CREATE TABLE IF NOT EXISTS `" . PRFX . "VERSION` (`VERSION_ID` INT NOT NULL ,`VERSION_NAME` VARCHAR( 10 ) NOT NULL ,`VERSION_INSTALLED` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP ) ENGINE=MyISAM ";
    if (!($rs = $db->execute($q))) {
        return false;
    } else {
        return true;
    }
}
Esempio n. 3
0
$updates = get_version_diff($cur_version, $update_version, isset($opts['f']));
if (count($updates) <= 0) {
    if ($cur_version == $update_version) {
        output_string("Database is already up to date.\n");
    } else {
        if (version_gte_update($cur_version, $update_version)) {
            output_string("Cannot downgrade the database version.\nSelect a version higher than the current version: {$cur_version}.\n");
        } else {
            output_string("Not sure why there are no updates...?\n");
        }
    }
    exit;
}
output_string("Updating from {$cur_version} -> {$update_version}.");
// Create the version table if it hasn't already been created.
create_version_table();
// Run the updates.
foreach ($updates as $version => $filename) {
    // Add in file so we can update.
    require_once $filename;
    $func = 'update_version_' . str_replace('.', '_', $version);
    $queries = array();
    if (function_exists($func)) {
        output_string("Running version {$version} update...\n");
        // Populate the queries array.
        call_user_func($func, $force_update);
        // Start the queries.
        run_update_queries();
        // Update the version.
        update_version_table($version);
        output_string("Completed version {$version} updates.");