Skip to content

Commit

Permalink
Merge pull request #240 from jemygraw/master
Browse files Browse the repository at this point in the history
fix travis build error
  • Loading branch information
jemygraw authored Aug 22, 2017
2 parents a1d7e51 + 07c4c70 commit 66381af
Show file tree
Hide file tree
Showing 13 changed files with 269 additions and 24 deletions.
28 changes: 28 additions & 0 deletions examples/rs_batch_change_mime.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php
require_once __DIR__ . '/../autoload.php';

use \Qiniu\Auth;

$accessKey = getenv('QINIU_ACCESS_KEY');
$secretKey = getenv('QINIU_SECRET_KEY');
$bucket = getenv('QINIU_TEST_BUCKET');


$auth = new Auth($accessKey, $secretKey);
$config = new \Qiniu\Config();
$bucketManager = new \Qiniu\Storage\BucketManager($auth, $config);

//每次最多不能超过1000个
$keyMimePairs = array(
'qiniu.mp4' => 'video/x-mp4',
'qiniu.png' => 'image/x-png',
'qiniu.jpg' => 'image/x-jpg'
);

$ops = $bucketManager->buildBatchChangeMime($bucket, $keyMimePairs);
list($ret, $err) = $bucketManager->batch($ops);
if ($err) {
print_r($err);
} else {
print_r($ret);
}
34 changes: 34 additions & 0 deletions examples/rs_batch_change_type.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php
require_once __DIR__ . '/../autoload.php';

use \Qiniu\Auth;

$accessKey = getenv('QINIU_ACCESS_KEY');
$secretKey = getenv('QINIU_SECRET_KEY');
$bucket = getenv('QINIU_TEST_BUCKET');


$auth = new Auth($accessKey, $secretKey);
$config = new \Qiniu\Config();
$bucketManager = new \Qiniu\Storage\BucketManager($auth, $config);

//每次最多不能超过1000个
$keys = array(
'qiniu.mp4',
'qiniu.png',
'qiniu.jpg'
);

$keyTypePairs = array();
//type=0表示普通存储,type=1表示低频存储
foreach ($keys as $key) {
$keyTypePairs[$key] = 1;
}

$ops = $bucketManager->buildBatchChangeType($bucket, $keyTypePairs);
list($ret, $err) = $bucketManager->batch($ops);
if ($err) {
print_r($err);
} else {
print_r($ret);
}
36 changes: 36 additions & 0 deletions examples/rs_batch_copy.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php
require_once __DIR__ . '/../autoload.php';

use \Qiniu\Auth;

$accessKey = getenv('QINIU_ACCESS_KEY');
$secretKey = getenv('QINIU_SECRET_KEY');
$bucket = getenv('QINIU_TEST_BUCKET');


$auth = new Auth($accessKey, $secretKey);
$config = new \Qiniu\Config();
$bucketManager = new \Qiniu\Storage\BucketManager($auth, $config);

//每次最多不能超过1000个
$keys = array(
'qiniu.mp4',
'qiniu.png',
'qiniu.jpg'
);

$keyPairs = array();
foreach ($keys as $key) {
$keyPairs[$key] = $key . "_copy";
}

$srcBucket = $bucket;
$destBucket = $bucket;

$ops = $bucketManager->buildBatchCopy($srcBucket, $keyPairs, $destBucket, true);
list($ret, $err) = $bucketManager->batch($ops);
if ($err) {
print_r($err);
} else {
print_r($ret);
}
28 changes: 28 additions & 0 deletions examples/rs_batch_delete.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php
require_once __DIR__ . '/../autoload.php';

use \Qiniu\Auth;

$accessKey = getenv('QINIU_ACCESS_KEY');
$secretKey = getenv('QINIU_SECRET_KEY');
$bucket = getenv('QINIU_TEST_BUCKET');


$auth = new Auth($accessKey, $secretKey);
$config = new \Qiniu\Config();
$bucketManager = new \Qiniu\Storage\BucketManager($auth, $config);

//每次最多不能超过1000个
$keys = array(
'qiniu.mp4',
'qiniu.png',
'qiniu.jpg'
);

$ops = $bucketManager->buildBatchDelete($bucket, $keys);
list($ret, $err) = $bucketManager->batch($ops);
if ($err) {
print_r($err);
} else {
print_r($ret);
}
34 changes: 34 additions & 0 deletions examples/rs_batch_delete_after_days.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php
require_once __DIR__ . '/../autoload.php';

use \Qiniu\Auth;

$accessKey = getenv('QINIU_ACCESS_KEY');
$secretKey = getenv('QINIU_SECRET_KEY');
$bucket = getenv('QINIU_TEST_BUCKET');


$auth = new Auth($accessKey, $secretKey);
$config = new \Qiniu\Config();
$bucketManager = new \Qiniu\Storage\BucketManager($auth, $config);

//每次最多不能超过1000个
$keys = array(
'qiniu.mp4',
'qiniu.png',
'qiniu.jpg'
);

$keyDayPairs = array();
//day=0表示永久存储
foreach ($keys as $key) {
$keyDayPairs[$key] = 0;
}

$ops = $bucketManager->buildBatchDeleteAfterDays($bucket, $keyDayPairs);
list($ret, $err) = $bucketManager->batch($ops);
if ($err) {
print_r($err);
} else {
print_r($ret);
}
36 changes: 36 additions & 0 deletions examples/rs_batch_move.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php
require_once __DIR__ . '/../autoload.php';

use \Qiniu\Auth;

$accessKey = getenv('QINIU_ACCESS_KEY');
$secretKey = getenv('QINIU_SECRET_KEY');
$bucket = getenv('QINIU_TEST_BUCKET');


$auth = new Auth($accessKey, $secretKey);
$config = new \Qiniu\Config();
$bucketManager = new \Qiniu\Storage\BucketManager($auth, $config);

//每次最多不能超过1000个
$keys = array(
'qiniu.mp4',
'qiniu.png',
'qiniu.jpg'
);

$keyPairs = array();
foreach ($keys as $key) {
$keyPairs[$key . "_copy"] = $key . "_move";
}

$srcBucket = $bucket;
$destBucket = $bucket;

$ops = $bucketManager->buildBatchMove($srcBucket, $keyPairs, $destBucket, true);
list($ret, $err) = $bucketManager->batch($ops);
if ($err) {
print_r($err);
} else {
print_r($ret);
}
28 changes: 28 additions & 0 deletions examples/rs_batch_stat.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php
require_once __DIR__ . '/../autoload.php';

use \Qiniu\Auth;

$accessKey = getenv('QINIU_ACCESS_KEY');
$secretKey = getenv('QINIU_SECRET_KEY');
$bucket = getenv('QINIU_TEST_BUCKET');


$auth = new Auth($accessKey, $secretKey);
$config = new \Qiniu\Config();
$bucketManager = new \Qiniu\Storage\BucketManager($auth, $config);

//每次最多不能超过1000个
$keys = array(
'qiniu.mp4',
'qiniu.png',
'qiniu.jpg'
);

$ops = $bucketManager->buildBatchStat($bucket, $keys);
list($ret, $err) = $bucketManager->batch($ops);
if ($err) {
print_r($err);
} else {
print_r($ret);
}
17 changes: 17 additions & 0 deletions examples/rs_prefetch.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php
require_once __DIR__ . '/../autoload.php';

use \Qiniu\Auth;

$accessKey = getenv('QINIU_ACCESS_KEY');
$secretKey = getenv('QINIU_SECRET_KEY');
$bucket = getenv('QINIU_TEST_BUCKET');

$key = "qiniu.mp4";
$auth = new Auth($accessKey, $secretKey);
$config = new \Qiniu\Config();
$bucketManager = new \Qiniu\Storage\BucketManager($auth, $config);
$err = $bucketManager->prefetch($bucket, $key);
if ($err) {
print_r($err);
}
2 changes: 1 addition & 1 deletion src/Qiniu/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ private function getZone($accessKey, $bucket)
$this->zoneCache[$cacheId] = $zone;
} else {
print("from query\n");
$zone = Zone::QueryZone($accessKey, $bucket);
$zone = Zone::queryZone($accessKey, $bucket);
$this->zoneCache[$cacheId] = $zone;
}
return $zone;
Expand Down
22 changes: 13 additions & 9 deletions src/Qiniu/Storage/BucketManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ private function rsGet($path)
$url = $this->getRsHost() . $path;
return $this->get($url);
}

private function get($url)
{
$headers = $this->auth->authorization($url);
Expand All @@ -390,21 +390,21 @@ private function post($url, $body)
return array($r, null);
}

public static function buildBatchCopy($source_bucket, $key_pairs, $target_bucket)
public static function buildBatchCopy($source_bucket, $key_pairs, $target_bucket, $force)
{
return self::twoKeyBatch('/copy', $source_bucket, $key_pairs, $target_bucket);
return self::twoKeyBatch('/copy', $source_bucket, $key_pairs, $target_bucket, $force);
}


public static function buildBatchRename($bucket, $key_pairs)
public static function buildBatchRename($bucket, $key_pairs, $force)
{
return self::buildBatchMove($bucket, $key_pairs, $bucket);
return self::buildBatchMove($bucket, $key_pairs, $bucket, $force);
}


public static function buildBatchMove($source_bucket, $key_pairs, $target_bucket)
public static function buildBatchMove($source_bucket, $key_pairs, $target_bucket, $force)
{
return self::twoKeyBatch('/move', $source_bucket, $key_pairs, $target_bucket);
return self::twoKeyBatch('/move', $source_bucket, $key_pairs, $target_bucket, $force);
}


Expand Down Expand Up @@ -455,16 +455,20 @@ private static function oneKeyBatch($operation, $bucket, $keys)
return $data;
}

private static function twoKeyBatch($operation, $source_bucket, $key_pairs, $target_bucket)
private static function twoKeyBatch($operation, $source_bucket, $key_pairs, $target_bucket, $force)
{
if ($target_bucket === null) {
$target_bucket = $source_bucket;
}
$data = array();
$forceOp = "false";
if ($force) {
$forceOp = "true";
}
foreach ($key_pairs as $from_key => $to_key) {
$from = \Qiniu\entry($source_bucket, $from_key);
$to = \Qiniu\entry($target_bucket, $to_key);
array_push($data, $operation . '/' . $from . '/' . $to);
array_push($data, $operation . '/' . $from . '/' . $to . "/force/" . $forceOp);
}
return $data;
}
Expand Down
10 changes: 5 additions & 5 deletions src/Qiniu/Zone.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function __construct(
}

//华东机房
public static function Zone0()
public static function zone0()
{
$Zone_z0 = new Zone(
array("up.qiniup.com", 'up-nb.qiniup.com', 'up-xs.qiniup.com'),
Expand All @@ -53,7 +53,7 @@ public static function Zone0()
}

//华北机房
public static function Zone1()
public static function zone1()
{
$Zone_z1 = new Zone(
array('up-z1.qiniup.com'),
Expand All @@ -68,7 +68,7 @@ public static function Zone1()
}

//华南机房
public static function Zone2()
public static function zone2()
{
$Zone_z2 = new Zone(
array('up-z2.qiniup.com', 'up-gz.qiniup.com', 'up-fs.qiniup.com'),
Expand All @@ -82,7 +82,7 @@ public static function Zone2()
}

//北美机房
public static function ZoneNa0()
public static function zoneNa0()
{
//北美机房
$Zone_na0 = new Zone(
Expand All @@ -99,7 +99,7 @@ public static function ZoneNa0()
/*
* GET /v2/query?ak=<ak>&&bucket=<bucket>
**/
public static function QueryZone($ak, $bucket)
public static function queryZone($ak, $bucket)
{
$zone = new Zone();
$url = Config::UC_HOST . '/v2/query' . "?ak=$ak&bucket=$bucket";
Expand Down
6 changes: 3 additions & 3 deletions tests/Qiniu/Tests/BucketTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ public function testBatchCopy()
$ops = BucketManager::buildBatchCopy(
$this->bucketName,
array($this->key => $key),
$this->bucketName
$this->bucketName,true
);
list($ret, $error) = $this->bucketManager->batch($ops);
$this->assertEquals(200, $ret[0]['code']);
Expand All @@ -184,7 +184,7 @@ public function testBatchMove()
$ops = BucketManager::buildBatchMove(
$this->bucketName,
array($key => $key2),
$this->bucketName
$this->bucketName,true
);
list($ret, $error) = $this->bucketManager->batch($ops);
$this->assertEquals(200, $ret[0]['code']);
Expand All @@ -197,7 +197,7 @@ public function testBatchRename()
$key = 'rename' . rand();
$this->bucketManager->copy($this->bucketName, $this->key, $this->bucketName, $key);
$key2 = $key . 'to';
$ops = BucketManager::buildBatchRename($this->bucketName, array($key => $key2));
$ops = BucketManager::buildBatchRename($this->bucketName, array($key => $key2),true);
list($ret, $error) = $this->bucketManager->batch($ops);
$this->assertEquals(200, $ret[0]['code']);
$error = $this->bucketManager->delete($this->bucketName, $key2);
Expand Down
Loading

0 comments on commit 66381af

Please sign in to comment.