<commit_before><?php
    /**
     * @class  autoinstallAdminController
     * @author sol (<EMAIL>)
     * @brief  autoinstall 모듈의 admin controller class
     **/

    require_once(_XE_PATH_.'modules/autoinstall/autoinstall.lib.php');

    class autoinstallAdminController extends autoinstall {

        /**
         * @brief 초기화
         **/
        function init() {
        }

        function checkFileCheckSum($file, $checksum){
            $local_checksum = md5_file(FileHandler::getRealPath($file));
            return ($local_checksum === $checksum);
        }

        function _cleanDownloaded($obj){
            FileHandler::removeDir($obj->download_path);
        }

        function procAutoinstallAdminUpdateinfo()
        {
            $oModel = &getModel('autoinstall');
            $item = $oModel->getLatestPackage();
            if($item)
            {
                $params["updatedate"] = $item->updatedate;
            }

            $params["act"] = "getResourceapiUpdate";
            $body = XmlGenerater::generate($params);
            $buff = FileHandler::getRemoteResource($this->uri, $body, 3, "POST", "application/xml");
            $xml = new XmlParser();
            $xmlDoc = $xml->parse($buff);
            $this->updateCategory($xmlDoc);
            $this->updatePackages($xmlDoc);
            $this->checkInstalled();

            $this->setMessage("success_updated");
        }

        function checkInstalled()
        {
            executeQuery("autoinstall.deleteInstalledPackage");
            $oModel =& getModel('autoinstall');
            $packages = $oModel->getPackages();
            foreach($packages as $package)
            {
                $real_path = FileHandler::getRealPath($package->path);
                if(!file_exists($real_path)) {
                    continue;
                }

                if($package->path == ".")
                {
                    $type = "core";
                    $version = __ZBXE_VERSION__; 
                }
                else
                {
                    $path_array = explode("/", $package->path);
                    $target_name = array_pop($path_array);
                    $type = substr(array_pop($path_array), 0, -1);
                    switch($type)
                    {
                        case "module":
                            case "addon":
                            case "layout":
                            case "widget":
                            $config_file = "/conf/info.xml";
                        break;
                        case "component":
                            $config_file = "/info.xml";
                        break;
                        case "skin":    
                            case "widgetstyle":
                            $config_file = "/skin.xml";
                        break;

                        default:
                        continue;
                    }
                    $xml = new XmlParser();
                    $xmlDoc = $xml->loadXmlFile($real_path.$config_file);
                    if(!$xmlDoc) continue;
                    $version = $xmlDoc->{$type}->version->body;
                }

                $args = null;
                $args->package_srl = $package->package_srl;
                $args->version = $package->version;
                $args->current_version = $version;
                if(version_compare($args->version, $args->current_version, ">"))
                {
                    $args->need_update="Y";
                }
                else
                {
                    $args->need_update="N";
                }

                $output = executeQuery("autoinstall.insertInstalledPackage", $args);
            }
        }

        function procAutoinstallAdminPackageinstall()
        {
            $package_srls = Context::get('package_srl');
            $oModel =& getModel('autoinstall');
            $packages = explode(',', $package_srls);
            $ftp_info =  Context::getFTPInfo();
            if(!$_SESSION['ftp_password'])
            {
                $ftp_password = Context::get('ftp_password');
            }
            else
            {
                $ftp_password = $_SESSION['ftp_password'];
            }

            foreach($packages as $package_srl)
            {
                $package = $oModel->getPackage($package_srl);
                if($ftp_info->sftp && $ftp_info->sftp == 'Y')
                {
                    $oModuleInstaller = new SFTPModuleInstaller($package);
                    $oModuleInstaller->setPassword($ftp_password);
                }
                else
                {
                    $oModuleInstaller = new FTPModuleInstaller($package);
                    $oModuleInstaller->setPassword($ftp_password);
                }
                $output = $oModuleInstaller->install();
                if(!$output->toBool()) return $output;
            }<commit_msg>#18634901 : add set_time_limit for installation<commit_after><?php
    /**
     * @class  autoinstallAdminController
     * @author sol (<EMAIL>)
     * @brief  autoinstall 모듈의 admin controller class
     **/

    require_once(_XE_PATH_.'modules/autoinstall/autoinstall.lib.php');

    class autoinstallAdminController extends autoinstall {

        /**
         * @brief 초기화
         **/
        function init() {
        }

        function checkFileCheckSum($file, $checksum){
            $local_checksum = md5_file(FileHandler::getRealPath($file));
            return ($local_checksum === $checksum);
        }

        function _cleanDownloaded($obj){
            FileHandler::removeDir($obj->download_path);
        }

        function procAutoinstallAdminUpdateinfo()
        {
            $oModel = &getModel('autoinstall');
            $item = $oModel->getLatestPackage();
            if($item)
            {
                $params["updatedate"] = $item->updatedate;
            }

            $params["act"] = "getResourceapiUpdate";
            $body = XmlGenerater::generate($params);
            $buff = FileHandler::getRemoteResource($this->uri, $body, 3, "POST", "application/xml");
            $xml = new XmlParser();
            $xmlDoc = $xml->parse($buff);
            $this->updateCategory($xmlDoc);
            $this->updatePackages($xmlDoc);
            $this->checkInstalled();

            $this->setMessage("success_updated");
        }

        function checkInstalled()
        {
            executeQuery("autoinstall.deleteInstalledPackage");
            $oModel =& getModel('autoinstall');
            $packages = $oModel->getPackages();
            foreach($packages as $package)
            {
                $real_path = FileHandler::getRealPath($package->path);
                if(!file_exists($real_path)) {
                    continue;
                }

                if($package->path == ".")
                {
                    $type = "core";
                    $version = __ZBXE_VERSION__; 
                }
                else
                {
                    $path_array = explode("/", $package->path);
                    $target_name = array_pop($path_array);
                    $type = substr(array_pop($path_array), 0, -1);
                    switch($type)
                    {
                        case "module":
                            case "addon":
                            case "layout":
                            case "widget":
                            $config_file = "/conf/info.xml";
                        break;
                        case "component":
                            $config_file = "/info.xml";
                        break;
                        case "skin":    
                            case "widgetstyle":
                            $config_file = "/skin.xml";
                        break;

                        default:
                        continue;
                    }
                    $xml = new XmlParser();
                    $xmlDoc = $xml->loadXmlFile($real_path.$config_file);
                    if(!$xmlDoc) continue;
                    $version = $xmlDoc->{$type}->version->body;
                }

                $args = null;
                $args->package_srl = $package->package_srl;
                $args->version = $package->version;
                $args->current_version = $version;
                if(version_compare($args->version, $args->current_version, ">"))
                {
                    $args->need_update="Y";
                }
                else
                {
                    $args->need_update="N";
                }

                $output = executeQuery("autoinstall.insertInstalledPackage", $args);
            }
        }

        function procAutoinstallAdminPackageinstall()
        {
            set_time_limit(0);
            $package_srls = Context::get('package_srl');
            $oModel =& getModel('autoinstall');
            $packages = explode(',', $package_srls);
            $ftp_info =  Context::getFTPInfo();
            if(!$_SESSION['ftp_password'])
            {
                $ftp_password = Context::get('ftp_password');
            }
            else
            {
                $ftp_password = $_SESSION['ftp_password'];
            }

            foreach($packages as $package_srl)
            {
                $package = $oModel->getPackage($package_srl);
                if($ftp_info->sftp && $ftp_info->sftp == 'Y')
                {
                    $oModuleInstaller = new SFTPModuleInstaller($package);
                    $oModuleInstaller->setPassword($ftp_password);
                }
                else
                {
                    $oModuleInstaller = new FTPModuleInstaller($package);
                    $oModuleInstaller->setPassword($ftp_password);
                }
                $output = $oModuleInstaller->install();
                if(!$output->toBool()) return $output;
            }
{'fraction_non_alphanumeric': 0.11978384869408586, 'fraction_numerical': 0.0017011908335835084, 'mean_word_length': 1.234294656829868, 'pattern_counts': {'":': 14, '<': 7, '<?xml version=': 0, '>': 73, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 28}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6434674', 'n_tokens_mistral': 2636, 'n_tokens_neox': 2391, 'n_words': 363}