+----------------------------------------------------------
复制目录
+----------------------------------------------------------
+----------------------------------------------------------
+----------------------------------------------------------
public copyDir ( $source, $destination ) |
public function install() { define("INSTALL", true); import("Dir"); //安装目录 $path = APP_PATH . C("APP_GROUP_PATH") . DIRECTORY_SEPARATOR . $this->config['module'] . DIRECTORY_SEPARATOR . 'Install' . DIRECTORY_SEPARATOR; $Dir = new Dir(); //SQL文件 if (file_exists($path . $this->config['module'] . '.sql')) { $sql = file_get_contents($path . $this->config['module'] . '.sql'); $sql_split = $this->sql_split($sql, C("DB_PREFIX")); $db = M(''); if (is_array($sql_split)) { foreach ($sql_split as $s) { $db->execute($s); } } } //Extention,菜单添加 if (file_exists($path . 'Extention.inc.php')) { @(include $path . 'Extention.inc.php'); } //前台模板 if (file_exists($path . "Template" . DIRECTORY_SEPARATOR)) { $Dir->copyDir($path . "Template", $this->templatePath); } D("Module")->add(array("module" => $this->config['module'], "name" => $this->config['modulename'], "iscore" => 0, "version" => $this->config['version'], "description" => $this->config['introduce'], "disabled" => 1, "installdate" => date("Y-m-d"), "updatedate" => date("Y-m-d"))); return true; }
function copyDir($source, $destination) { if (is_dir($source) == false) { exit("The Source Directory Is Not Exist!"); } if (is_dir($destination) == false) { mkdir($destination, 0700); } $handle = opendir($source); while (false !== ($file = readdir($handle))) { if ($file != "." && $file != "..") { is_dir("{$source}/{$file}") ? Dir::copyDir("{$source}/{$file}", "{$destination}/{$file}") : copy("{$source}/{$file}", "{$destination}/{$file}"); } } closedir($handle); }
/** +---------------------------------------------------------- * 复制目录 +---------------------------------------------------------- * @access static +---------------------------------------------------------- * @return void +---------------------------------------------------------- */ function copyDir($source, $destination) { if (is_dir($source) == false) { $this->error = "源目录不存在!"; return false; } if (is_dir($destination) == false) { mkdir($destination, 0700); } $handle = opendir($source); while (false !== ($file = readdir($handle))) { if ($file != "." && $file != "..") { is_dir("{$source}/{$file}") ? Dir::copyDir("{$source}/{$file}", "{$destination}/{$file}") : copy("{$source}/{$file}", "{$destination}/{$file}"); } } closedir($handle); }
/** * 执行模块安装 * @param type $moduleName 模块名(目录名) * @return boolean */ public function install($moduleName = '') { defined('INSTALL') or define("INSTALL", true); if (empty($moduleName)) { if ($this->moduleName) { $moduleName = $this->moduleName; } else { $this->error = '请选择需要安装的模块!'; return false; } } //已安装模块列表 $moduleList = cache('Module'); //设置脚本最大执行时间 set_time_limit(0); if ($this->competence($moduleName) !== true) { return false; } //加载模块基本配置 $config = $this->config($moduleName); //版本检查 if ($config['adaptation']) { if (version_compare(SHUIPF_VERSION, $config['adaptation'], '>=') == false) { $this->error = '该模块要求系统最低版本为:' . $config['adaptation'] . '!'; return false; } } //依赖模块检测 if (!empty($config['depend']) && is_array($config['depend'])) { foreach ($config['depend'] as $mod) { if ('Content' == $mod) { continue; } if (!isset($moduleList[$mod])) { $this->error = "安装该模块,需要安装依赖模块 {$mod} !"; return false; } } } //检查模块是否已经安装 if ($this->isInstall($moduleName)) { $this->error = '该模块已经安装,无法重复安装!'; return false; } $model = D('Common/Module'); if (!$model->create($config, 1)) { $this->error = $model->getError() ?: '安装初始化失败!'; return false; } if ($model->add() == false) { $this->error = '安装失败!'; return false; } //执行安装脚本 if (!$this->runInstallScript($moduleName)) { $this->installRollback($moduleName); return false; } //执行数据库脚本安装 $this->runSQL($moduleName); //执行菜单项安装 if ($this->installMenu($moduleName) !== true) { $this->installRollback($moduleName); return false; } //缓存注册 if (!empty($config['cache'])) { if (D('Common/Cache')->installModuleCache($config['cache'], $config) !== true) { $this->error = D('Common/Cache')->getError(); $this->installRollback($moduleName); return false; } } $Dir = new \Dir(); //前台模板 if (file_exists($this->appPath . "{$moduleName}/Install/Template/")) { //拷贝模板到前台模板目录中去 $Dir->copyDir($this->appPath . "{$moduleName}/Install/Template/", $this->templatePath); } //静态资源文件 if (file_exists($this->appPath . "{$moduleName}/Install/Extres/")) { //拷贝模板到前台模板目录中去 $Dir->copyDir($this->appPath . "{$moduleName}/Install/Extres/", $this->extresPath . strtolower($moduleName) . '/'); } //安装行为 if (!empty($config['tags'])) { D('Common/Behavior')->moduleBehaviorInstallation($moduleName, $config['tags']); } //安装结束,最后调用安装脚本完成 $this->runInstallScriptEnd($moduleName); //更新缓存 cache('Module', NULL); return true; }
public function copyDir($source, $destination) { if (is_dir($source) == false) { exit('The Source Directory Is Not Exist!'); } if (is_dir($destination) == false) { mkdir($destination, 448); } $handle = opendir($source); while (false !== ($file = readdir($handle))) { if ($file != '.' && $file != '..') { is_dir($source . '/' . $file) ? Dir::copyDir($source . '/' . $file, $destination . '/' . $file) : copy($source . '/' . $file, $destination . '/' . $file); } } closedir($handle); }