<?php
/*======================================================================*\
|| #################################################################### ||
|| # vBulletin 5.0.0 Beta 10
|| # ---------------------------------------------------------------- # ||
|| # Copyright �2000-2012 vBulletin Solutions Inc. All Rights Reserved. ||
|| # This file may not be redistributed in whole or significant part. # ||
|| # ---------------- VBULLETIN IS NOT FREE SOFTWARE ---------------- # ||
|| # http://www.vbulletin.com | http://www.vbulletin.com/license.html # ||
|| #################################################################### ||
\*======================================================================*/
/*
if (!isset($GLOBALS['vbulletin']->db))
{
	exit;
}
*/

class vB_Upgrade_500a11 extends vB_Upgrade_Version
{
	/*Constants=====================================================================*/

	/*Properties====================================================================*/

	/**
	* The short version of the script
	*
	* @var	string
	*/
	public $SHORT_VERSION = '500a11';

	/**
	* The long version of the script
	*
	* @var	string
	*/
	public $LONG_VERSION  = '5.0.0 Alpha 11';

	/**
	* Versions that can upgrade to this script
	*
	* @var	string
	*/
	public $PREV_VERSION = '5.0.0 Alpha 10';

	/**
	* Beginning version compatibility
	*
	* @var	string
	*/
	public $VERSION_COMPAT_STARTS = '';

	/**
	* Ending version compatibility
	*
	* @var	string
	*/
	public $VERSION_COMPAT_ENDS   = '';
	
	function step_1()
	{
		$this->skip_message();
	}
	
	function step_2()
	{
		$this->skip_message();
	}
	
	/**
	 * Report / Flag
	 */
	function step_3()
	{
		// New Reports Channel
		$existing = $this->db->query_first("SELECT nodeid FROM " . TABLE_PREFIX . "node WHERE protected = 1 AND oldcontenttypeid = 9997");

		if (empty($existing))
		{
			$contenttype = $this->db->query_first("
			SELECT contenttypeid
			FROM " . TABLE_PREFIX . "contenttype
			WHERE class = 'Channel'
			");
			$channelContentTypeId = $contenttype['contenttypeid'];

			$query = "
			INSERT INTO " . TABLE_PREFIX . "node
				(contenttypeid, publishdate, userid, title, htmltitle, parentid, description, oldid, oldcontenttypeid, showpublished, protected)
			VALUES
				($channelContentTypeId, " . TIMENOW . ", 1, 'Reports', 'Reports', 2, 'Reports / Flags', 1, 9997, 0, 1)
			";
			$this->show_message(sprintf($this->phrase['vbphrase']['update_table'], 'node'));
			$this->db->query_write(
				$query);
			$nodeid = $this->db->insert_id();
			$query = "
			INSERT INTO " . TABLE_PREFIX . "channel	(nodeid)
			VALUES($nodeid)
			";
			$this->show_message(sprintf($this->phrase['vbphrase']['update_table'], 'node'));
			$this->db->query_write(
				$query);

			$query = "
			INSERT INTO " . TABLE_PREFIX . "closure
				(parent, child, depth )
			VALUES
				($nodeid, $nodeid, 0),
				(1, $nodeid, 1)
			";
			$this->db->query_write(
				$query);
		}
		else
		{
			$this->skip_message();
		}

		$contenttype = $this->db->query_first("
			SELECT contenttypeid FROM " . TABLE_PREFIX . "contenttype
			WHERE class = 'Report'");
		if (empty($contenttype) OR empty($contenttype['contenttypeid']))
		{
			$this->run_query(
			sprintf($this->phrase['vbphrase']['update_table'], TABLE_PREFIX . 'contenttype'),
			"INSERT INTO " . TABLE_PREFIX . "contenttype(class,
			packageid,	canplace,	cansearch,	cantag,	canattach,	isaggregator)
			SELECT 'Report', packageid, '0', '0', '0', '0', '0'  FROM " . TABLE_PREFIX . "package where class = 'vBForum';");
		}
		else
		{
			$this->skip_message();
		}

		$this->run_query(
		sprintf($this->phrase['vbphrase']['create_table'], TABLE_PREFIX . 'link'),
		"
			CREATE TABLE " . TABLE_PREFIX . "report (
				nodeid INT UNSIGNED NOT NULL,
				reportnodeid INT UNSIGNED NOT NULL DEFAULT '0',
				closed SMALLINT(5) UNSIGNED NOT NULL DEFAULT '0',
				PRIMARY KEY (nodeid),
				KEY (reportnodeid, closed)
			)
		",
		self::MYSQL_ERROR_TABLE_EXISTS
		);
	}
}

/*======================================================================*\
|| ####################################################################
|| # 
|| # CVS: $RCSfile$ - $Revision: 35750 $
|| ####################################################################
\*======================================================================*/