<?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::i()->query("ALTER TABLE ?_config CHANGE `module_id` `module` VARCHAR( 100 ) NOT NULL DEFAULT 'core'");
//удаляем всякие кривые хвосты настроек
Db::i()->query("DELETE FROM ?_config WHERE module NOT IN (SELECT module_id FROM ?_modules) AND module!=0");
Db::i()->query("UPDATE ?_config c SET module=(SELECT module FROM ?_modules m WHERE c.module=m.module_id) WHERE c.module>0");
Db::i()->query("UPDATE ?_config c SET module='core'  WHERE c.module='0'");
Db::i()->query(
	"ALTER TABLE ?_rating_votes DROP PRIMARY KEY ,
	ADD PRIMARY KEY ( `module_id` , `item_id` , `key` , `voter_id` ) "
);
Db::i()->query("DELETE FROM ?_users WHERE user_id=-1");


Db::i()->query(
	"CREATE TABLE IF NOT EXISTS ?_i18n (
	`lang` varchar(10) NOT NULL,
	`context` char(20) NOT NULL default 'none',
	`key` text NOT NULL,
	`value` text,
	PRIMARY KEY  (`lang`,`key`(256),`context`)
	) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin;"
);

if ($dirs=glob(LAB_PATH_KERNEL.'/languages/*', GLOB_ONLYDIR)) {
	foreach ($dirs as $dir) {
		if ('ru'==$dir) continue;
		if (!$files=glob($dir.'/lang.*.php'))  continue;
		$language=basename($dir);
		foreach ($files as $file) {
			$lang=array();
			include $file;
			if (!count($lang)) continue;
			foreach ($lang as $k=>$v) {
				DB::i()->query(
					"INSERT IGNORE INTO ?_i18n (lang, `key`, `value`)
					VALUES(?, ?, ?)",
					$language, $k, $v
				);
			}
			
		}
	}
}


