Skip to content

Commit 76a1e40

Browse files
committed
add force mode for batch move and copy
1 parent 91bf7a4 commit 76a1e40

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

src/Qiniu/Storage/BucketManager.php

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ private function rsGet($path)
368368
$url = $this->getRsHost() . $path;
369369
return $this->get($url);
370370
}
371-
371+
372372
private function get($url)
373373
{
374374
$headers = $this->auth->authorization($url);
@@ -390,21 +390,21 @@ private function post($url, $body)
390390
return array($r, null);
391391
}
392392

393-
public static function buildBatchCopy($source_bucket, $key_pairs, $target_bucket)
393+
public static function buildBatchCopy($source_bucket, $key_pairs, $target_bucket, $force)
394394
{
395-
return self::twoKeyBatch('/copy', $source_bucket, $key_pairs, $target_bucket);
395+
return self::twoKeyBatch('/copy', $source_bucket, $key_pairs, $target_bucket, $force);
396396
}
397397

398398

399-
public static function buildBatchRename($bucket, $key_pairs)
399+
public static function buildBatchRename($bucket, $key_pairs, $force)
400400
{
401-
return self::buildBatchMove($bucket, $key_pairs, $bucket);
401+
return self::buildBatchMove($bucket, $key_pairs, $bucket, $force);
402402
}
403403

404404

405-
public static function buildBatchMove($source_bucket, $key_pairs, $target_bucket)
405+
public static function buildBatchMove($source_bucket, $key_pairs, $target_bucket, $force)
406406
{
407-
return self::twoKeyBatch('/move', $source_bucket, $key_pairs, $target_bucket);
407+
return self::twoKeyBatch('/move', $source_bucket, $key_pairs, $target_bucket, $force);
408408
}
409409

410410

@@ -455,16 +455,20 @@ private static function oneKeyBatch($operation, $bucket, $keys)
455455
return $data;
456456
}
457457

458-
private static function twoKeyBatch($operation, $source_bucket, $key_pairs, $target_bucket)
458+
private static function twoKeyBatch($operation, $source_bucket, $key_pairs, $target_bucket, $force)
459459
{
460460
if ($target_bucket === null) {
461461
$target_bucket = $source_bucket;
462462
}
463463
$data = array();
464+
$forceOp = "false";
465+
if ($force) {
466+
$forceOp = "true";
467+
}
464468
foreach ($key_pairs as $from_key => $to_key) {
465469
$from = \Qiniu\entry($source_bucket, $from_key);
466470
$to = \Qiniu\entry($target_bucket, $to_key);
467-
array_push($data, $operation . '/' . $from . '/' . $to);
471+
array_push($data, $operation . '/' . $from . '/' . $to . "/force/" . $forceOp);
468472
}
469473
return $data;
470474
}

0 commit comments

Comments
 (0)