/** * 保存记录 * @param type $model */ protected static function saveInternal($attributes) { if ($attributes) { foreach ($attributes as $key => $value) { $cmodel = Config::findOne(['`key`' => $key]); if (!$cmodel) { $cmodel = new Config(); $cmodel->key = $key; $cmodel->value = $value ? $value : ''; $cmodel->save(); } else { if ($cmodel->value != $value) { $cmodel->value = $value ? $value : ''; $cmodel->save(); } } if ($key == 'site_language') { //写入语言的配置文件 $configFile = LsYii::getWebPath('/common/config/main-local.php'); FileHelper::writeConfig($configFile, ['language' => $value]); } if ($key == 'datetime_timezone') { //写入时间的配置文件 $configFile = LsYii::getWebPath('/common/config/main-local.php'); FileHelper::writeConfig($configFile, ['timezone' => $value]); } } } return true; }
public function loadActiveModules($isAdmin) { $moduleManager = $this->modularityService; $this->activeModules = $moduleManager->getActiveModules($isAdmin); // \source\helpers\VarDumper::dump($this->activeModules);die; $module = $isAdmin ? "admin\\AdminModule" : "home\\HomeModule"; foreach ($this->activeModules as $m) { $moduleId = $m['id']; $moduleDir = $m['dir']; $ModuleClassName = $m['dirClass']; $this->setModule($moduleId, ['class' => 'source\\modules\\' . $moduleDir . '\\' . $module]); $serviceFile = LsYii::getAlias('@source') . '\\modules\\' . $moduleDir . '\\' . $ModuleClassName . 'Service.php'; if (FileHelper::exist($serviceFile)) { $serviceClass = 'source\\modules\\' . $moduleDir . '\\' . $ModuleClassName . 'Service'; $serviceInstance = new $serviceClass(); $this->set($serviceInstance->getServiceId(), $serviceInstance); } } }
public function loadAllModules() { if ($this->allModules !== null) { return $this->allModules; } $this->allModules = []; $moduleRootPath = LsYii::getAlias('@source') . '/modules'; if ($moduleRootDir = dir($moduleRootPath)) { while (($moduleFolder = $moduleRootDir->read()) !== false) { $currentModuleDir = $moduleRootPath . '/' . $moduleFolder; if (preg_match('|^\\.+$|', $moduleFolder) || !is_dir($currentModuleDir)) { continue; } $moduleClassName = ucwords($moduleFolder); if (FileHelper::exist($currentModuleDir . '/' . $moduleClassName . 'Info.php')) { $class = 'source\\modules\\' . $moduleFolder . '\\' . $moduleClassName . 'Info'; } else { continue; } $instance = null; try { $instance = new $class(); if (empty($instance->id)) { $instance->id = $moduleFolder; } if (empty($instance->name)) { $instance->name = $moduleFolder; } } catch (Exception $ex) { $instance = null; } if ($instance !== null) { $hasAdmin = FileHelper::exist($currentModuleDir . '/admin/AdminModule.php') ? true : false; $hasHome = FileHelper::exist($currentModuleDir . '/home/HomeModule.php') ? true : false; $this->allModules[$instance->id] = ['id' => $instance->id, 'dir' => $moduleFolder, 'dirClass' => $moduleClassName, 'class' => $class, 'instance' => $instance, 'canInstall' => true, 'canUninstall' => true, 'hasAdmin' => $hasAdmin, 'hasHome' => $hasHome, 'canActiveAdmin' => false, 'canActiveHome' => false]; } } } return $this->allModules; }
/** * 服务器环境检测 * @return type */ private function getEnvData() { $isWritable = [['系统临时文件(data/runtime)', true, FileHelper::canWrite(LsYii::getAlias('@data/runtime')), '系统核心', '必须可读写'], ['附件上传目录(data/attachment)', false, FileHelper::canWrite(LsYii::getAlias('@data/attachment')), '附件上传', '若无附件上传可不用写权限'], ['数据备份目录(data/backup)', false, FileHelper::canWrite(LsYii::getAlias('@data/backup')), '数据库备份', '若不备份数据库可不用写权限'], ['配置文件目录(common/config)', false, FileHelper::canWrite(LsYii::getAlias('@common/config')), '安装程序', '若手动安装系统写可不用写权限'], ['公共资源文件(webroot/assets)', true, FileHelper::canWrite(LsYii::getAlias('@webroot/assets')), '系统核心', '必须可读写']]; $requirements = array(['PHP版本', true, version_compare(PHP_VERSION, "5.4.0", ">="), '系统核心', 'PHP 5.4.0 或更高版本是必须的.'], ['$_SERVER 服务器变量', true, 'ok' === ($message = Utility::checkServerVar()), '系统核心', $message], ['Reflection 扩展模块', true, class_exists('Reflection', false), '系统核心', ''], ['PCRE 扩展模块', true, extension_loaded("pcre"), '系统核心', ''], ['SPL 扩展模块', true, extension_loaded("SPL"), '系统核心', ''], ['PDO 扩展模块', true, extension_loaded('pdo'), '所有和使用PDO数据库连接相关的类', ''], ['PDO MySQL 扩展模块', true, extension_loaded('pdo_mysql'), 'MySql数据库', '使用MySql数据库必须支持'], ['OpenSSL 扩展模块', true, extension_loaded('openssl'), 'Security', '加密和解密方法'], ['GD 扩展模块', false, 'ok' === ($message = Utility::checkCaptchaSupport()), 'CaptchaAction', $message]); $requireResult = 1; foreach ($requirements as $i => $requirement) { if ($requirement[1] && !$requirement[2]) { $requireResult = 0; } else { if ($requireResult > 0 && !$requirement[1] && !$requirement[2]) { $requireResult = -1; } } if ($requirement[4] === '') { $requirements[$i][4] = ' '; } } $writeableResult = 1; foreach ($isWritable as $k => $val) { if ($val[1] && !$val[2]) { $writeableResult = 0; } else { if ($requireResult > 0 && !$val[1] && !$val[2]) { $writeableResult = -1; } } if ($val[4] === '') { $isWritable[$i][4] = ' '; } } $data = ['isWritable' => $isWritable, 'writeableResult' => $writeableResult, 'requireResult' => $requireResult, 'requirements' => $requirements]; return $data; }