<?php
defined('JPATH_BASE') or die;


//for Joomla 6
use Joomla\CMS\Factory;
use Joomla\CMS\Uri\Uri;
use Joomla\CMS\Form\FormField;

if (version_compare(JVERSION, "6.0.0", "ge")) {
    if (!class_exists('JFactory')) class_alias('Joomla\CMS\Factory', 'JFactory');
    if (!class_exists('JURI')) class_alias('Joomla\CMS\Uri\Uri', 'JURI');
    if (!class_exists('JFormField')) class_alias('Joomla\CMS\Form\FormField', 'JFormField');
} 

class os_basetemplateInstallerScript{

    function postflight($type, $parent) {
                if ( $type == 'install' ) {
                    $db = JFactory::getDbo();
                    $stdParams = trim(file_get_contents(__DIR__.'/admin/default_DB.txt'));

                    if(!empty($stdParams)){
                        $stdParamsToDb = addslashes($stdParams);
                        $query = "UPDATE #__template_styles SET params = '".$stdParamsToDb."' WHERE template = '".$this->getTemplateName()."'";
                        $db->setQuery($query);
                        $result = $db->execute();
                    }

                    return true;
                }
    }

    function getTemplateName(){
            $xml = simplexml_load_file(__DIR__.'/templateDetails.xml');
            $templateName = $xml->name->__toString();
            return $templateName;
        }

}


 ?>
