# # 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, either version 3 of the # License, or (at your option) any later version. # # 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 . define('PATH', dirname(__FILE__) . '/'); require(PATH.'config.php'); require(PATH.'includes/db.php'); //connect to the database. $db = new DB(DB_HOST, DB_PORT, DB_USER, DB_PASSWORD); if (!$db) die('MySQL error! Check your config.php'); else { $db->select(DB_NAME); $querysett = $db->send("SELECT `value` FROM `settings` WHERE `category`='db_version'"); $db_version = mysql_result($querysett, 0); if (!$db_version) $query = $db->send("INSERT INTO `settings` VALUES (1, 'db_version', '0');"); //Let's check if the database has the column 'shorter_service' $query = mysql_list_fields(DB_NAME, 'users'); $array = array(); for ($i = 0; $i < mysql_num_fields($query); $i++) $array[] = mysql_field_name($query, $i); if (!isset($db_version)) { if (!array_search('shorter_service', $array)) { if (!$db->send('ALTER TABLE `users` ADD `shorter_service` VARCHAR( 255 ) NOT NULL DEFAULT \'a:3:{s:7:"service";s:7:"default";s:4:"data";s:0:"";s:7:"preview";b:0;}\';')) { die('There was an error while trying to update the database. Please contact Jisko at http://answers.launchpad.net/jisko. Error: `shorter_service`'); } } } elseif ($db_version == 0) { if (!$db->send('ALTER TABLE `users` ADD `post_tweets` SMALLINT( 1 ) NULL AFTER `twitter_password`')) { die('There was an error while trying to update the database. Please contact Jisko at http://answers.launchpad.net/jisko. Error: `post_tweets`'); } $db->send('UPDATE `settings` SET `value`=\'1\' WHERE `category`=\'db_version\''); } if (!isset($db_version)) { $query = $db->send("CREATE TABLE IF NOT EXISTS `tags_c` ( `id` int(11) NOT NULL auto_increment, `name` varchar(255) character set utf8 collate utf8_unicode_ci NOT NULL, `timestamp` int(11) NOT NULL, `founder` varchar(255) NOT NULL, KEY `id` (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=7 ;"); $query = $db->send("CREATE TABLE IF NOT EXISTS `tags_n` ( `id` int(11) NOT NULL auto_increment, `note_id` int(11) NOT NULL, `tag` varchar(255) NOT NULL, `timestamp` int(11) NOT NULL, `poster` int(11) NOT NULL, KEY `id` (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=14 ;"); $query = $db->send("CREATE TABLE `settings` ( `id` int(11) NOT NULL auto_increment, `category` varchar(255) NOT NULL, `value` varchar(255) NOT NULL, KEY `id` (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=2 ; "); } if (!unlink(PATH.'update.php')) die('OK: If there were no errors, please erase this file and then you can run Jisko'); else header('Location: index.php'); } ?>