<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

/**
 * Video Player - by Duktee
 *
 * @package		Video Player
 * @version		Version 2.5
 * @author		Benjamin David
 * @copyright	Copyright (c) 2011 - Duktee
 * @license		http://duktee.com/addons/video-player/license
 * @link		http://duktee.com/addons/video-player/
 *
 */
 
class Videoplayer_upd {

	var $version = '2.5';
	
	/* constructor */
	
	function __construct()
	{
		// Make a local reference to the ExpressionEngine super object
		$this->EE =& get_instance();
	}

	// --------------------------------------------------------------------

	/**
	 * Module Installer
	 *
	 * @access	public
	 * @return	bool
	 */
	 
	function install()
	{
		$this->EE->load->dbforge();

		$data = array(
			'module_name' => 'Videoplayer',
			'module_version' => $this->version,
			'has_cp_backend' => 'y',
			'has_publish_fields' => 'n'
		);

		$this->EE->db->insert('modules', $data);
		
		
		/* actions */
		$data = array(
			'class'		=> 'Videoplayer' ,
			'method'	=> 'ajax'
		);
		
		$this->EE->db->insert('actions', $data);

		return TRUE;

	}
	
	// --------------------------------------------------------------------

	/**
	 * Module Uninstaller
	 *
	 * @access	public
	 * @return	bool
	 */
	 
	function uninstall()
	{
		$this->EE->load->dbforge();

		$this->EE->db->select('module_id');
		
		$query = $this->EE->db->get_where('modules', array('module_name' => 'Videoplayer'));
		
		$this->EE->db->where('module_id', $query->row('module_id'));
		$this->EE->db->delete('module_member_groups');
		
		
		// remove actions
		
		$this->EE->db->where('class', 'Videoplayer');
		$this->EE->db->delete('actions');

		
		// remove module
		
		$this->EE->db->where('module_name', 'Videoplayer');
		$this->EE->db->delete('modules');
		
		return TRUE;
	}

	// --------------------------------------------------------------------

	/**
	 * Module Updater
	 *
	 * @access	public
	 * @return	bool
	 */	
	
	function update($current='')
	{
		if ($current == $this->version)
		{
			return FALSE;
		}

		
		if ($current < '2.4')
		{
		
			// Turn off backend
			
			$data = array(
				'module_name' => 'Videoplayer',
				'has_cp_backend' => 'n',
			);
			
			$this->EE->db->where('module_name', "Videoplayer");
			$this->EE->db->update('modules', $data);
			
			
			// Add "ajax" action
			
			$data = array(
				'class'		=> 'Videoplayer' ,
				'method'	=> 'ajax'
			);
			
			$this->EE->db->insert('actions', $data);
			
		}
		
		return TRUE;
	}
	
}
/* END Class */

/* End of file upd.videoplayer.php */
/* Location: ./system/expressionengine/third_party/videoplayer/upd.videoplayer.php */