<?php
require_once(dirname(__FILE__).'/../../upgrade.php');
class remove_dupe_glossary extends UPGRADE
{
	/**
	* IsAlreadyUpgraded
	* Do we need to run this classes upgrade script or not ?
	*
	* @return bool true if the upgrade has already run, otherwise false
	*/
	function IsAlreadyUpgraded()
	{
		$all= $GLOBALS['AKB_DB']->FetchOne("SELECT COUNT(*) FROM `".$GLOBALS['tablePrefix']."glossary`");
		$unique = $GLOBALS['AKB_DB']->FetchOne("SELECT COUNT(DISTINCT glossWord) FROM `".$GLOBALS['tablePrefix']."glossary`");

		// If we have already renamed the column, this test can be skipped
		if ($unique === false) {
			return true;
		}

		return ($all == $unique);
	}

	/**
	* Upgrade
	* Do the actual upgrade of this component. If this is successful all
	* subsequent calls to IsAlreadyUpgraded should return true
	*
	* @return void
	*/
	function Upgrade()
	{
		echo "Some duplicate glossary terms were detected. Please remove the duplicate terms from the glossary table in the database before proceeding.";
		die();
	}

}
?>
