<?php
/**
 * Схема таблиц модуля
 * @version $Id: shema.php 794 2010-11-22 14:56:54Z roosit $
 * @package Abricos
 * @subpackage Comment
 * @copyright Copyright (C) 2008 Abricos All rights reserved.
 * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
 * @author Alexander Kuzmin (roosit@abricos.org)
 */

$charset = "CHARACTER SET 'utf8' COLLATE 'utf8_general_ci'";
$updateManager = CMSRegistry::$instance->modules->updateManager; 
$db = CMSRegistry::$instance->db;
$pfx = $db->prefix;

if ($updateManager->isInstall()){
	$db->query_write("
		CREATE TABLE IF NOT EXISTS ".$pfx."cmt_comment (
		  `commentid` int(10) UNSIGNED NOT NULL auto_increment,
		  `parentcommentid` int(10) UNSIGNED NOT NULL,
		  `contentid` int(10) UNSIGNED NOT NULL,
		  `userid` int(10) UNSIGNED NOT NULL,
		  `dateline` int(10) UNSIGNED NOT NULL,
		  `dateedit` int(10) UNSIGNED NOT NULL,
		  `deldate` int(10) UNSIGNED NOT NULL DEFAULT '0',
		  `body` text NOT NULL,
		  `status` int(2) UNSIGNED NOT NULL DEFAULT '0',
		  PRIMARY KEY  (`commentid`),
		  KEY `dateedit` (`dateedit`),
		  KEY `contentid` (`contentid`)
		)".$charset
	);
}

if ($updateManager->isUpdate('0.3.1')){
	CMSRegistry::$instance->modules->GetModule('comment')->permission->Install();
}

if ($updateManager->isUpdate('0.3.2')){
	// таблица будет хранить идентификатор последнего прочитавшего комментария
	$db->query_write("
		CREATE TABLE IF NOT EXISTS ".$pfx."cmt_lastview (
		  `lastviewid` int(10) UNSIGNED NOT NULL auto_increment,
		  `contentid` int(10) UNSIGNED NOT NULL,
		  `userid` int(10) UNSIGNED NOT NULL,
		  `commentid` int(10) UNSIGNED NOT NULL,
		  `dateline` int(10) UNSIGNED NOT NULL,
		  PRIMARY KEY  (`lastviewid`),
		  KEY `userid` (`userid`),
		  KEY `contentid` (`contentid`)
		)".$charset
	);
}

?>