<?php

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

/**
 * Upgrade ciext module to version 3.3.1
 *
 * @author Igor Ratsun
 */
class Ciext_upgrade_3_2_3 extends Abstract_upgrade
{

    public function up()
    {
        $file = APPPATH . 'config' . DIRECTORY_SEPARATOR . 'ciext.php';
        if (!file_exists($file)) {
            return $this->down();
        }

        if (!$this->check_content($file)) {
            $data = file_get_contents($file);
            file_put_contents($file, str_replace('\'adapter\' => \'file\'', '\'adapter\' => (ENVIRONMENT !== \'production\') ? \'dummy\' : \'file\'', $data));
        }

        return $this->check_content($file) ? '3.3.1' : $this->down();
    }

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

    protected function check_content($file = '')
    {
        return (strpos(file_get_contents($file), '\'adapter\' => (ENVIRONMENT !== \'production\') ? \'dummy\' : \'file\'') !== false);
    }

}
