<?php

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

/**
 * Upgrade Filemanager module to version 3.10.0
 *
 * @author CIEXT skeleton
 */
class Filemanager_upgrade_0 extends \Ciext\Migration\AbstractUpgrade
{

    public function up()
    {
        if (!$this->is_table_exist('media')) {
            $ci = &get_instance();
            $ci->db->query('CREATE TABLE IF NOT EXISTS `media` ( 
`id_media` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(255) CHARACTER SET utf8,
`type` varchar(255) CHARACTER SET utf8,
`size` varchar(255) CHARACTER SET utf8,
`is_image` tinyint(1),
`image_type` varchar(255) CHARACTER SET utf8,
`created` DATETIME,
PRIMARY KEY (`id_media`) 
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;');

            $ckconf = FCPATH . 'assets/plugins/ckeditor/config.js';
            @file_put_contents($ckconf, str_replace([
                '/assets/plugins/kcfinder/browse.php?type=files',
                '/assets/plugins/kcfinder/browse.php?type=images',
                '/assets/plugins/kcfinder/browse.php?type=flash',
                '/assets/plugins/kcfinder/upload.php',
            ], ['', '', '', '/ajax/filemanager/filemanager_admin/upload',
            ], file_get_contents($ckconf)));
        }

        return '3.10.0';
    }

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

}
