<?php

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

/**
 * Upgrade Newsletter module to version 3.1.0
 *
 * @author CIEXT skeleton
 */
class Newsletter_upgrade_3_0_1 extends Abstract_upgrade
{

    public function up()
    {
        $ci = get_instance();
        $data = $ci->db->select('id_admin_menu')
                        ->where('acl_resource', 'newsletter')
                        ->where('name', 'MailChimp')
                        ->get('admin_menu')->row_array();

        if (empty($data['id_admin_menu'])) {
            $parent_info = $ci->db->select('id_admin_menu')
                            ->where('acl_resource', 'newsletter')
                            ->where('parent_id', '0')
                            ->get('admin_menu')->row_array();

            $ci->db->insert('admin_menu', [
                'name'         => 'MailChimp',
                'page'         => 'mconfig/index/newsletter/mail_chimp',
                'parent_id'    => $parent_info['id_admin_menu'],
                'view_order'   => 100,
                'acl_resource' => 'newsletter',
                'acl_action'   => 'edit_newsletter',
                'active'       => true
            ]);
        }

        return '3.1.0';
    }

    public function down()
    {
        return '3.0.1';
    }

}
