|
|
@ -4,6 +4,8 @@ namespace app\admin\command; |
|
|
|
|
|
|
|
|
|
|
|
use app\admin\model\AuthRule; |
|
|
|
use app\admin\model\AuthRule; |
|
|
|
use app\admin\model\User; |
|
|
|
use app\admin\model\User; |
|
|
|
|
|
|
|
use app\common\model\Attachment; |
|
|
|
|
|
|
|
use OSS\OssClient; |
|
|
|
use ReflectionClass; |
|
|
|
use ReflectionClass; |
|
|
|
use ReflectionMethod; |
|
|
|
use ReflectionMethod; |
|
|
|
use think\Cache; |
|
|
|
use think\Cache; |
|
|
@ -32,8 +34,40 @@ class UserLevel extends Command |
|
|
|
|
|
|
|
|
|
|
|
protected function execute(Input $input, Output $output) |
|
|
|
protected function execute(Input $input, Output $output) |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
$config = get_addon_config('alioss'); |
|
|
|
|
|
|
|
if ($config['uploadmode'] != 'server') { |
|
|
|
|
|
|
|
throw new Exception("无需执行该操作"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (!$config['accessKeyId'] || !$config['accessKeySecret']) { |
|
|
|
|
|
|
|
throw new Exception("请先配置好阿里云OSS"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (!class_exists('\OSS\OssClient')) { |
|
|
|
|
|
|
|
throw new Exception("请安装composer require symfony/polyfill-php72"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$oss = new OssClient($config['accessKeyId'], $config['accessKeySecret'], $config['endpoint']); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$attachments = Attachment::where('storage', 'local') |
|
|
|
|
|
|
|
->where('createtime', '>', '1711610369')->select(); |
|
|
|
|
|
|
|
$i = 1; |
|
|
|
|
|
|
|
foreach ($attachments as $attachment) { |
|
|
|
|
|
|
|
$filePath = ROOT_PATH . 'public' . $attachment->url; |
|
|
|
|
|
|
|
// var_dump($filePath); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
echo $filePath.PHP_EOL; |
|
|
|
|
|
|
|
$ret = $oss->uploadFile($config['bucket'], ltrim($attachment->url, "/"), $filePath); |
|
|
|
|
|
|
|
var_dump($ret); |
|
|
|
|
|
|
|
sleep(1); |
|
|
|
|
|
|
|
$i++; |
|
|
|
|
|
|
|
//成功不做任何操作 |
|
|
|
|
|
|
|
} catch (\Exception $e) { |
|
|
|
|
|
|
|
\think\Log::write($e->getMessage()); |
|
|
|
|
|
|
|
throw new Exception($e->getMessage()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
$output->info("同步成功 {$i}条数据"); |
|
|
|
|
|
|
|
|
|
|
|
$output->info("Build Successed!"); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|