<?php
/*======================================================================*\
|| #################################################################### ||
|| # ---------------------------------------------------------------- # ||
|| # Copyright ©2013 Fillip Hannisdal AKA Revan/NeoRevan/Belazor 	  # ||
|| # All Rights Reserved. 											  # ||
|| # This file may not be redistributed in whole or significant part. # ||
|| # ---------------------------------------------------------------- # ||
|| # You are not allowed to use this on your server unless the files  # ||
|| # you downloaded were done so with permission.					  # ||
|| # ---------------------------------------------------------------- # ||
|| #################################################################### ||
\*======================================================================*/

if (!is_object($vbulletin->db))
{
	exit;
}

// ########################################################################
// ######################### START MAIN SCRIPT ############################
// ########################################################################

if (defined('IN_CONTROL_PANEL'))
{
	define('ECHO_CRON_LOG', true);
}

$itemIds = array();
foreach (VBSHOP::$cache['item'] as $itemid => $item)
{
	if ($item['itemtypeid'] == 'autobump')
	{
		// Store this
		$itemIds[] = $itemid;
	}
}

$items = VBSHOP::$db->fetchAll('
	SELECT
		user.*,
		purchase.*,
		shopinventory.*
	FROM $dbtech_vbshop_purchase AS purchase
	LEFT JOIN $dbtech_vbshop_item AS item ON (item.itemid = purchase.featureid)
	LEFT JOIN $dbtech_vbshop_shopinventory AS shopinventory ON (
		shopinventory.itemid = item.itemid AND
		shopinventory.shopid = purchase.shopid
	)
	LEFT JOIN $user AS user ON(user.userid = purchase.userid)
	WHERE purchase.active = \'1\'
		AND purchase.feature = \'item\'
		AND purchase.featureid :queryList
', array(
	':queryList' => VBSHOP::$db->queryList($itemIds)
));
foreach ($items as $item)
{
	// Construct the array proper
	$item = array_merge(VBSHOP::$cache['item'][$item['itemid']], $item);
	
	// Init the item
	$itemobj = VBSHOP::init_item($item);
	
	if (method_exists($itemobj, 'autoBump'))
	{
		// Deactivate the item
		$itemobj->autoBump();

		log_cron_action('Bumped thread from item: ' . $item['title'] . ' from user: ' . $item['username'], $nextitem);
	}	
}

log_cron_action('Threads Bumped', $nextitem);