<?php
/*
* @package LabCMS
* @copyright (c) 2006 Alexander Levin aka Loki (loki_angel@mail.ru)
* @support http://labcms.ru
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*/
	$success=true;
Db::instance()->query("DROP TABLE IF EXISTS ?_access;");
Db::instance()->query("DROP TABLE IF EXISTS ?_config;");
Db::instance()->query("DROP TABLE IF EXISTS ?_group_inc; "); 
Db::instance()->query("INSERT IGNORE INTO ?_groups (`group_id`, `parent_id`, `group_name`) VALUES(-1, 0, 'Незарегистрированные');");
Db::instance()->query("INSERT IGNORE INTO ?_groups (`group_id`, `parent_id`, `group_name`) VALUES(1, 0, 'Суперадминистратор');");
Db::instance()->query("INSERT IGNORE INTO ?_groups (`group_id`, `parent_id`, `group_name`) VALUES(2, -1, 'Пользователи');");
Db::instance()->query("UPDATE ?_groups SET parent_id=2 WHERE group_id NOT IN (-1, 1, 2);");
Db::instance()->query("ALTER TABLE ?_includes DROP `id`,  DROP `group_id`;");
Db::instance()->query("ALTER TABLE ?_includes DROP INDEX `tree_id`;");
Db::instance()->query("ALTER TABLE ?_includes DROP INDEX `module_id`;");
Db::instance()->query("ALTER TABLE ?_includes ADD PRIMARY KEY ( `tree_id` , `module_id` );");
Db::instance()->query("ALTER TABLE ?_modules ADD `depends` VARCHAR( 60 ) NULL AFTER `section` ;");
Db::instance()->query("ALTER TABLE ?_modules CHANGE `section` `section` VARCHAR( 60 ) CHARACTER SET utf8 COLLATE utf8_general_ci NULL ;");
Db::instance()->query("ALTER TABLE ?_modules DROP `search` ;");
//Db::instance()->query("ALTER TABLE ?_users CHANGE `referal` `referral` INT( 11 ) NULL DEFAULT NULL;");
Db::instance()->query("ALTER TABLE ?_tree_val ADD `parent_id` INT NOT NULL AFTER `tree_id` ;");
Db::instance()->query("UPDATE ?_tree_val tv, ?_tree t SET tv.parent_id=t.parent_id WHERE t.tree_id=tv.tree_id ;");
Db::instance()->query("DROP TABLE ?_tree;");
Db::instance()->query("RENAME TABLE ?_tree_val  TO ?_tree ;");
Db::instance()->query("ALTER TABLE ?_tree DROP `group_id` ;");
Db::instance()->query("ALTER TABLE ?_tree CHANGE `tree_id` `tree_id` INT( 11 ) NOT NULL AUTO_INCREMENT  ; ");
Db::instance()->query("UPDATE ?_modules SET `module` = 'admin_tree/' WHERE `module` = 'tree/' ;");
Db::instance()->query("UPDATE ?_modules SET `module` = 'admin_modules/' WHERE `module` = 'modules/' ;");
Db::instance()->query("UPDATE ?_modules SET `module` = 'admin_users/' WHERE `module` = 'users/' ;");
Db::instance()->query("UPDATE ?_modules SET `module` = 'admin_pages/' WHERE `module` = 'pages/' ;");
Db::instance()->query("DELETE FROM ?_modules WHERE `module` = 'config/';");
Db::instance()->query("INSERT ?_modules (`module`, `name`, `section`, `component`, `static`, `disable` ) VALUES('admin_groups/', 'группы', 'core', 1, 0, 0);");
Db::instance()->query("INSERT ?_tree (`parent_id`, `tree_name`, `menu`, `path`, `show` ) VALUES(2, 'группы', 1, '/groups', 1);");
Db::instance()->query("INSERT ?_includes (`tree_id`, `module_id`) VALUES((SELECT `tree_id` FROM ?_tree WHERE `path`='/groups' AND `tree_name`='группы' AND `parent_id`=2), (SELECT `module_id` FROM ?_modules WHERE `module`='admin_groups/'));");
Db::instance()->query("ALTER TABLE ?_pages CHANGE `page_text` `page_text` MEDIUMTEXT CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL;");
Db::instance()->query("UPDATE ?_users SET `group_id` = '-1' WHERE `user_id` = -1;");
Db::instance()->query("UPDATE ?_users SET `group_id` = '-1' WHERE `login` = '' ;");