Skip to content

Commit 66381af

Browse files
authored
Merge pull request #240 from jemygraw/master
fix travis build error
2 parents a1d7e51 + 07c4c70 commit 66381af

13 files changed

+269
-24
lines changed

examples/rs_batch_change_mime.php

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
require_once __DIR__ . '/../autoload.php';
3+
4+
use \Qiniu\Auth;
5+
6+
$accessKey = getenv('QINIU_ACCESS_KEY');
7+
$secretKey = getenv('QINIU_SECRET_KEY');
8+
$bucket = getenv('QINIU_TEST_BUCKET');
9+
10+
11+
$auth = new Auth($accessKey, $secretKey);
12+
$config = new \Qiniu\Config();
13+
$bucketManager = new \Qiniu\Storage\BucketManager($auth, $config);
14+
15+
//每次最多不能超过1000个
16+
$keyMimePairs = array(
17+
'qiniu.mp4' => 'video/x-mp4',
18+
'qiniu.png' => 'image/x-png',
19+
'qiniu.jpg' => 'image/x-jpg'
20+
);
21+
22+
$ops = $bucketManager->buildBatchChangeMime($bucket, $keyMimePairs);
23+
list($ret, $err) = $bucketManager->batch($ops);
24+
if ($err) {
25+
print_r($err);
26+
} else {
27+
print_r($ret);
28+
}

examples/rs_batch_change_type.php

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
require_once __DIR__ . '/../autoload.php';
3+
4+
use \Qiniu\Auth;
5+
6+
$accessKey = getenv('QINIU_ACCESS_KEY');
7+
$secretKey = getenv('QINIU_SECRET_KEY');
8+
$bucket = getenv('QINIU_TEST_BUCKET');
9+
10+
11+
$auth = new Auth($accessKey, $secretKey);
12+
$config = new \Qiniu\Config();
13+
$bucketManager = new \Qiniu\Storage\BucketManager($auth, $config);
14+
15+
//每次最多不能超过1000个
16+
$keys = array(
17+
'qiniu.mp4',
18+
'qiniu.png',
19+
'qiniu.jpg'
20+
);
21+
22+
$keyTypePairs = array();
23+
//type=0表示普通存储,type=1表示低频存储
24+
foreach ($keys as $key) {
25+
$keyTypePairs[$key] = 1;
26+
}
27+
28+
$ops = $bucketManager->buildBatchChangeType($bucket, $keyTypePairs);
29+
list($ret, $err) = $bucketManager->batch($ops);
30+
if ($err) {
31+
print_r($err);
32+
} else {
33+
print_r($ret);
34+
}

examples/rs_batch_copy.php

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
require_once __DIR__ . '/../autoload.php';
3+
4+
use \Qiniu\Auth;
5+
6+
$accessKey = getenv('QINIU_ACCESS_KEY');
7+
$secretKey = getenv('QINIU_SECRET_KEY');
8+
$bucket = getenv('QINIU_TEST_BUCKET');
9+
10+
11+
$auth = new Auth($accessKey, $secretKey);
12+
$config = new \Qiniu\Config();
13+
$bucketManager = new \Qiniu\Storage\BucketManager($auth, $config);
14+
15+
//每次最多不能超过1000个
16+
$keys = array(
17+
'qiniu.mp4',
18+
'qiniu.png',
19+
'qiniu.jpg'
20+
);
21+
22+
$keyPairs = array();
23+
foreach ($keys as $key) {
24+
$keyPairs[$key] = $key . "_copy";
25+
}
26+
27+
$srcBucket = $bucket;
28+
$destBucket = $bucket;
29+
30+
$ops = $bucketManager->buildBatchCopy($srcBucket, $keyPairs, $destBucket, true);
31+
list($ret, $err) = $bucketManager->batch($ops);
32+
if ($err) {
33+
print_r($err);
34+
} else {
35+
print_r($ret);
36+
}

examples/rs_batch_delete.php

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
require_once __DIR__ . '/../autoload.php';
3+
4+
use \Qiniu\Auth;
5+
6+
$accessKey = getenv('QINIU_ACCESS_KEY');
7+
$secretKey = getenv('QINIU_SECRET_KEY');
8+
$bucket = getenv('QINIU_TEST_BUCKET');
9+
10+
11+
$auth = new Auth($accessKey, $secretKey);
12+
$config = new \Qiniu\Config();
13+
$bucketManager = new \Qiniu\Storage\BucketManager($auth, $config);
14+
15+
//每次最多不能超过1000个
16+
$keys = array(
17+
'qiniu.mp4',
18+
'qiniu.png',
19+
'qiniu.jpg'
20+
);
21+
22+
$ops = $bucketManager->buildBatchDelete($bucket, $keys);
23+
list($ret, $err) = $bucketManager->batch($ops);
24+
if ($err) {
25+
print_r($err);
26+
} else {
27+
print_r($ret);
28+
}
+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
require_once __DIR__ . '/../autoload.php';
3+
4+
use \Qiniu\Auth;
5+
6+
$accessKey = getenv('QINIU_ACCESS_KEY');
7+
$secretKey = getenv('QINIU_SECRET_KEY');
8+
$bucket = getenv('QINIU_TEST_BUCKET');
9+
10+
11+
$auth = new Auth($accessKey, $secretKey);
12+
$config = new \Qiniu\Config();
13+
$bucketManager = new \Qiniu\Storage\BucketManager($auth, $config);
14+
15+
//每次最多不能超过1000个
16+
$keys = array(
17+
'qiniu.mp4',
18+
'qiniu.png',
19+
'qiniu.jpg'
20+
);
21+
22+
$keyDayPairs = array();
23+
//day=0表示永久存储
24+
foreach ($keys as $key) {
25+
$keyDayPairs[$key] = 0;
26+
}
27+
28+
$ops = $bucketManager->buildBatchDeleteAfterDays($bucket, $keyDayPairs);
29+
list($ret, $err) = $bucketManager->batch($ops);
30+
if ($err) {
31+
print_r($err);
32+
} else {
33+
print_r($ret);
34+
}

examples/rs_batch_move.php

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
require_once __DIR__ . '/../autoload.php';
3+
4+
use \Qiniu\Auth;
5+
6+
$accessKey = getenv('QINIU_ACCESS_KEY');
7+
$secretKey = getenv('QINIU_SECRET_KEY');
8+
$bucket = getenv('QINIU_TEST_BUCKET');
9+
10+
11+
$auth = new Auth($accessKey, $secretKey);
12+
$config = new \Qiniu\Config();
13+
$bucketManager = new \Qiniu\Storage\BucketManager($auth, $config);
14+
15+
//每次最多不能超过1000个
16+
$keys = array(
17+
'qiniu.mp4',
18+
'qiniu.png',
19+
'qiniu.jpg'
20+
);
21+
22+
$keyPairs = array();
23+
foreach ($keys as $key) {
24+
$keyPairs[$key . "_copy"] = $key . "_move";
25+
}
26+
27+
$srcBucket = $bucket;
28+
$destBucket = $bucket;
29+
30+
$ops = $bucketManager->buildBatchMove($srcBucket, $keyPairs, $destBucket, true);
31+
list($ret, $err) = $bucketManager->batch($ops);
32+
if ($err) {
33+
print_r($err);
34+
} else {
35+
print_r($ret);
36+
}

examples/rs_batch_stat.php

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
require_once __DIR__ . '/../autoload.php';
3+
4+
use \Qiniu\Auth;
5+
6+
$accessKey = getenv('QINIU_ACCESS_KEY');
7+
$secretKey = getenv('QINIU_SECRET_KEY');
8+
$bucket = getenv('QINIU_TEST_BUCKET');
9+
10+
11+
$auth = new Auth($accessKey, $secretKey);
12+
$config = new \Qiniu\Config();
13+
$bucketManager = new \Qiniu\Storage\BucketManager($auth, $config);
14+
15+
//每次最多不能超过1000个
16+
$keys = array(
17+
'qiniu.mp4',
18+
'qiniu.png',
19+
'qiniu.jpg'
20+
);
21+
22+
$ops = $bucketManager->buildBatchStat($bucket, $keys);
23+
list($ret, $err) = $bucketManager->batch($ops);
24+
if ($err) {
25+
print_r($err);
26+
} else {
27+
print_r($ret);
28+
}

examples/rs_prefetch.php

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
require_once __DIR__ . '/../autoload.php';
3+
4+
use \Qiniu\Auth;
5+
6+
$accessKey = getenv('QINIU_ACCESS_KEY');
7+
$secretKey = getenv('QINIU_SECRET_KEY');
8+
$bucket = getenv('QINIU_TEST_BUCKET');
9+
10+
$key = "qiniu.mp4";
11+
$auth = new Auth($accessKey, $secretKey);
12+
$config = new \Qiniu\Config();
13+
$bucketManager = new \Qiniu\Storage\BucketManager($auth, $config);
14+
$err = $bucketManager->prefetch($bucket, $key);
15+
if ($err) {
16+
print_r($err);
17+
}

src/Qiniu/Config.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ private function getZone($accessKey, $bucket)
129129
$this->zoneCache[$cacheId] = $zone;
130130
} else {
131131
print("from query\n");
132-
$zone = Zone::QueryZone($accessKey, $bucket);
132+
$zone = Zone::queryZone($accessKey, $bucket);
133133
$this->zoneCache[$cacheId] = $zone;
134134
}
135135
return $zone;

src/Qiniu/Storage/BucketManager.php

+13-9
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
}

src/Qiniu/Zone.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public function __construct(
3939
}
4040

4141
//华东机房
42-
public static function Zone0()
42+
public static function zone0()
4343
{
4444
$Zone_z0 = new Zone(
4545
array("up.qiniup.com", 'up-nb.qiniup.com', 'up-xs.qiniup.com'),
@@ -53,7 +53,7 @@ public static function Zone0()
5353
}
5454

5555
//华北机房
56-
public static function Zone1()
56+
public static function zone1()
5757
{
5858
$Zone_z1 = new Zone(
5959
array('up-z1.qiniup.com'),
@@ -68,7 +68,7 @@ public static function Zone1()
6868
}
6969

7070
//华南机房
71-
public static function Zone2()
71+
public static function zone2()
7272
{
7373
$Zone_z2 = new Zone(
7474
array('up-z2.qiniup.com', 'up-gz.qiniup.com', 'up-fs.qiniup.com'),
@@ -82,7 +82,7 @@ public static function Zone2()
8282
}
8383

8484
//北美机房
85-
public static function ZoneNa0()
85+
public static function zoneNa0()
8686
{
8787
//北美机房
8888
$Zone_na0 = new Zone(
@@ -99,7 +99,7 @@ public static function ZoneNa0()
9999
/*
100100
* GET /v2/query?ak=<ak>&&bucket=<bucket>
101101
**/
102-
public static function QueryZone($ak, $bucket)
102+
public static function queryZone($ak, $bucket)
103103
{
104104
$zone = new Zone();
105105
$url = Config::UC_HOST . '/v2/query' . "?ak=$ak&bucket=$bucket";

tests/Qiniu/Tests/BucketTest.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ public function testBatchCopy()
167167
$ops = BucketManager::buildBatchCopy(
168168
$this->bucketName,
169169
array($this->key => $key),
170-
$this->bucketName
170+
$this->bucketName,true
171171
);
172172
list($ret, $error) = $this->bucketManager->batch($ops);
173173
$this->assertEquals(200, $ret[0]['code']);
@@ -184,7 +184,7 @@ public function testBatchMove()
184184
$ops = BucketManager::buildBatchMove(
185185
$this->bucketName,
186186
array($key => $key2),
187-
$this->bucketName
187+
$this->bucketName,true
188188
);
189189
list($ret, $error) = $this->bucketManager->batch($ops);
190190
$this->assertEquals(200, $ret[0]['code']);
@@ -197,7 +197,7 @@ public function testBatchRename()
197197
$key = 'rename' . rand();
198198
$this->bucketManager->copy($this->bucketName, $this->key, $this->bucketName, $key);
199199
$key2 = $key . 'to';
200-
$ops = BucketManager::buildBatchRename($this->bucketName, array($key => $key2));
200+
$ops = BucketManager::buildBatchRename($this->bucketName, array($key => $key2),true);
201201
list($ret, $error) = $this->bucketManager->batch($ops);
202202
$this->assertEquals(200, $ret[0]['code']);
203203
$error = $this->bucketManager->delete($this->bucketName, $key2);

0 commit comments

Comments
 (0)