<?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("ALTER TABLE ?_tree ADD `symlink` INT NOT NULL AFTER `parent_id`");
$params=Db::instance()->selectCol("SELECT tree_id AS ARRAY_KEY, params FROM ?_tree WHERE params LIKE '%id=%'");
if ($params) foreach ($params as $tree_id=>$param) {
	$arr=explode("&", $param);
	foreach ($arr as $key=>$item) {
		if (preg_match('/^id=(\d+)$/i', $item, $id)) {
			$id=$id[1];
			unset($arr[$key]);
			$new_params=implode('&', $arr);
			Db::instance()->query("UPDATE ?_tree SET symlink=?, params=? WHERE tree_id=?", $id, $new_params, $tree_id);
			break;
		}
	}
}
