<?php


namespace IPS\chatbox\setup\upg_22009;

/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
	header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
	exit;
}

/**
 * 2.2.9 Upgrade Code
 */
class _Upgrade
{
	public function step1()
	{
		if( \IPS\Db::i()->checkForColumn( 'core_ignored_users', 'ignore_chatboxplus' ) )
		{
			if( \IPS\Db::i()->checkForTable( 'chatbox_ignored_users' ) )
			{
				foreach( \IPS\Db::i()->select( '*', 'core_ignored_users', array( 'ignore_chatboxplus=?', 1 ) ) as $row )
				{
					\IPS\Db::i()->insert( 'chatbox_ignored_users', array(
						'ignore_owner_id'		=> $row['ignore_owner_id'],
						'ignore_ignore_id'		=> $row['ignore_ignore_id'],
					) );
					
					if ( $row['ignore_messages'] == 0 && $row['ignore_topics'] == 0 && $row['ignore_signatures'] == 0 && $row['ignore_mentions'] == 0 )
					{
						\IPS\Db::i()->delete( 'core_ignored_users', array( 'ignore_id=?', $row['ignore_id'] ) );
					}
				}
			}
			\IPS\Db::i()->dropColumn( 'core_ignored_users', 'ignore_chatboxplus' );
		}

		return TRUE;
	}

}