<?php

if (!defined('BASEPATH')) {
    exit('No direct script access allowed');
}

/**
 * Upgrade ciext module to version 1.1.12
 *
 * @author Igor Ratsun
 */
class ciext_upgrade_0 extends Abstract_upgrade
{

    protected $ci;
    protected $where = array();

    public function __construct()
    {
        $this->ci = & get_instance();
        $this->where = array(
            'name'         => 'Upgrade system',
            'page'         => 'upgrade/index',
            'parent_id'    => '5',
            'acl_resource' => 'system',
            'acl_action'   => 'module_manager',
        );
    }

    public function up()
    {
        if (!$this->is_in_admin_menu()) {
            $data = $this->where;
            $data['active'] = 1;
            $this->ci->db->insert('admin_menu', $data);
        }

        return '1.1.12';
    }
    
    public function down()
    {
        return '0';
    }

    protected function is_in_admin_menu()
    {
        $menu = $this->ci->db
                ->select('id_admin_menu')
                ->where($this->where)
                ->get('admin_menu')
                ->row_array();

        return !empty($menu['id_admin_menu']);
    }

}
