智慧教务系统
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

60 lines
2.2 KiB

<?php
// +----------------------------------------------------------------------
// | Niucloud-admin 企业快速开发的多应用管理平台
// +----------------------------------------------------------------------
// | 官方网址:https://www.niucloud.com
// +----------------------------------------------------------------------
// | niucloud团队 版权所有 开源版本可自由商用
// +----------------------------------------------------------------------
// | Author: Niucloud Team
// +----------------------------------------------------------------------
namespace app\service\admin\upgrade;
use core\util\DbBackup;
/**
* 框架及插件升级恢复备份
* @package app\service\core\upgrade
*/
class RestoreService extends UpgradeService
{
/**
* 恢复代码备份
* @return true
*/
public function restoreCode() {
$backup_dir = $this->upgrade_dir .$this->upgrade_task['key'] . DIRECTORY_SEPARATOR . 'backup' . DIRECTORY_SEPARATOR . 'code' . DIRECTORY_SEPARATOR;
if (is_dir($backup_dir)) {
// 删除前端文件
// if (is_dir(public_path() . 'admin')) del_target_dir(public_path() . 'admin', true);
// if (is_dir(public_path() . 'wap')) del_target_dir(public_path() . 'wap', true);
// if (is_dir(public_path() . 'web')) del_target_dir(public_path() . 'web', true);
dir_copy($backup_dir, rtrim($this->root_path, DIRECTORY_SEPARATOR));
}
return true;
}
/**
* 恢复数据库备份
* @return true
*/
public function restoreSql() {
$backup_dir = $this->upgrade_dir .$this->upgrade_task['key'] . DIRECTORY_SEPARATOR . 'backup' . DIRECTORY_SEPARATOR . 'sql' . DIRECTORY_SEPARATOR;
if (is_dir($backup_dir)) {
$db = new DbBackup([
'path' => $backup_dir //数据库备份路径
]);
$file_list = $db->fileList();
if (!empty($file_list)) {
$db->setSqlMode();
foreach ($file_list as $file) {
$db->setFile($file)->import(0, $file['time']);
}
}
}
return true;
}
}