6
0
Fork 0

OssCopyCommand

base
panliang 2022-07-29 15:11:11 +08:00
parent 000b13a075
commit 865b36bcd6
1 changed files with 21 additions and 21 deletions

View File

@ -85,23 +85,27 @@ class OssCopy extends Command
{ {
$data = []; $data = [];
foreach($attributes as $key) { foreach($attributes as $key) {
$item = $model->$key; try {
if (!$item) { $item = $model->$key;
continue; if (!$item) {
} continue;
// 数组
if (is_array($item)) {
$values = [];
foreach($item as $value) {
array_push($values, $this->copy($value));
} }
$data[$key] = $values; // 数组
} if (is_array($item)) {
// 富文本 $values = [];
else if (preg_match('/^\<.+\>$/i', $item)) { foreach($item as $value) {
$data[$key] = $this->parseEditorImage($item); array_push($values, $this->copy($value));
} else { }
$data[$key] = $this->copy($item); $data[$key] = $values;
}
// 富文本
else if (preg_match('/^\<.+\>$/i', $item)) {
$data[$key] = $this->parseEditorImage($item);
} else {
$data[$key] = $this->copy($item);
}
} catch (OssException $e) {
$this->error('key: ' . $key . ', value: ' . $item . ', id: ' . $model->id);
} }
} }
if (count($data) > 0) { if (count($data) > 0) {
@ -120,11 +124,7 @@ class OssCopy extends Command
if (Str::startsWith($url, $baseUrl)) { if (Str::startsWith($url, $baseUrl)) {
$path = substr($url, strlen($baseUrl)); $path = substr($url, strlen($baseUrl));
$bucket = 'jiqu-library'; $bucket = 'jiqu-library';
try { $client->copyObject($oldBucket, $path, $bucket, $path);
$client->copyObject($oldBucket, $path, $bucket, $path);
} catch (OssException $e) {
$this->error('地址:' . $url);
}
return $newUrl . $path; return $newUrl . $path;
} }