<?php
/**
* 2023 Anvanto
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
*
*  @author    Anvanto <anvantoco@gmail.com>
*  @copyright 2023 Anvanto
*  @license   http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
*/

if (!defined('_PS_VERSION_')) {
    exit;
}

function upgrade_module_2_4_7($object)
{
    @unlink(_PS_MODULE_DIR_ . 'an_theme/cfg/hooks.php');
    
    $cssGeneratorFile = _PS_MODULE_DIR_ . 'an_theme/views/templates/hook/css_generator.tpl';
    $newCssGeneratorPath = _PS_THEME_DIR_ . 'modules/an_theme';
    if (!Tools::file_exists_no_cache($newCssGeneratorPath)){
        mkdir($newCssGeneratorPath, 0777, true);
        if (Tools::file_exists_no_cache($newCssGeneratorPath)){
            Tools::copy(_PS_MODULE_DIR_ . 'an_theme/index.php', $newCssGeneratorPath . '/index.php');
            if (Tools::copy($cssGeneratorFile, $newCssGeneratorPath . '/css_generator.tpl')){
                @unlink($cssGeneratorFile);
                return true;
            }
        }
    } else if (Tools::file_exists_no_cache($newCssGeneratorPath . '/css_generator.tpl')){
        return true;
    }
    
    return false;
}