<?php

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

/**
 * Upgrade user module to version 3.0.8
 *
 * @author CIEXT skeleton
 */
class User_upgrade_1_3_0 extends Abstract_upgrade
{

    protected $mod_cnf  = 'application/modules/user/config/config.php';
    protected $incl_str = 'vendor/ciext/user/config/config.php';

    public function up()
    {
        if (!$this->include_in_file()) {
            file_put_contents($this->mod_cnf, str_replace('<?php', '<?php include_once \'' . $this->incl_str . '\';', file_get_contents($this->mod_cnf)));
        }

        return ($this->include_in_file()) ? '3.0.8' : $this->down();
    }

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

    protected function include_in_file()
    {
        if (file_exists($this->mod_cnf)) {
            $data = file_get_contents($this->mod_cnf);
            return (strpos($data, $this->incl_str) !== false);
        } else {
            return true;
        }
    }

}
