Skip to content

Commit f211be9

Browse files
authored
Merge pull request #381 from qiniu/features/support-deep-archive
support deep archive
2 parents ee5344f + f6a4082 commit f211be9

File tree

11 files changed

+335
-36
lines changed

11 files changed

+335
-36
lines changed

examples/bucket_lifecycleRule.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,17 @@
2121
$prefix = 'test'; // 规则策略中的前缀
2222
$delete_after_days = 80; // 用户新创建的文件将在该设定时间之后自动删除
2323
$to_line_after_days = 70; // 用户新创建的文件将在该设定的时间之后自动转为低频存储
24+
$to_archive_after_days = 72; // 用户新创建的文件将在该设定的时间之后自动转为归档存储
25+
$to_deep_archive_after_days = 74; // 用户新创建的文件将在该设定的时间之后自动转为深度归档存储
2426

2527
list($ret, $err) = $bucketManager->bucketLifecycleRule(
2628
$bucket,
2729
$name,
2830
$prefix,
2931
$delete_after_days,
30-
$to_line_after_days
32+
$to_line_after_days,
33+
$to_archive_after_days,
34+
$to_deep_archive_after_days
3135
);
3236
if ($err != null) {
3337
var_dump($err);

examples/rs_batch_change_type.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,17 @@
2525

2626
$keyTypePairs = array();
2727

28-
// type=0表示普通存储,type=1表示低频存储
28+
// key 是文件
29+
// value 是存储类型(fileType)
30+
// 0 表示普通存储
31+
// 1 表示低频存储
32+
// 2 表示归档存储
33+
// 3 表示深度归档存储
2934
foreach ($keys as $key) {
3035
$keyTypePairs[$key] = 1;
3136
}
3237

33-
$ops = $bucketManager->buildBatchChangeType($bucket, $keyTypePairs);
38+
$ops = BucketManager::buildBatchChangeType($bucket, $keyTypePairs);
3439
list($ret, $err) = $bucketManager->batch($ops);
3540
if ($err != null) {
3641
var_dump($err);

examples/rs_batch_restore_ar.php

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
require_once __DIR__ . '/../autoload.php';
3+
4+
use Qiniu\Auth;
5+
use Qiniu\Config;
6+
use Qiniu\Storage\BucketManager;
7+
8+
// 控制台获取密钥:https://portal.qiniu.com/user/key
9+
$accessKey = getenv('QINIU_ACCESS_KEY');
10+
$secretKey = getenv('QINIU_SECRET_KEY');
11+
$bucket = getenv('QINIU_TEST_BUCKET');
12+
13+
14+
$auth = new Auth($accessKey, $secretKey);
15+
$config = new Config();
16+
$bucketManager = new BucketManager($auth, $config);
17+
18+
// 批量解冻归档/深度归档文件,每次最多不能超过 1000 个
19+
20+
$keys = array(
21+
'archived_file.mp4',
22+
'deep_archived_file.png',
23+
'others.jpg'
24+
);
25+
26+
$keyTypePairs = array();
27+
28+
29+
// key 是文件
30+
// value 是解冻时间(单位:天,范围 1~7)
31+
foreach ($keys as $key) {
32+
$keyTypePairs[$key] = 1;
33+
}
34+
35+
$ops = BucketManager::buildBatchRestoreAr($bucket, $keyTypePairs);
36+
list($ret, $err) = $bucketManager->batch($ops);
37+
if ($err != null) {
38+
var_dump($err);
39+
} else {
40+
var_dump($ret);
41+
}

examples/rs_change_type.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
// 参考文档:https://developer.qiniu.com/kodo/api/3710/chtype
2222

2323
$key = "qiniu.mp4";
24-
$fileType = 1; // 0 表示标准存储;1 表示低频存储;2 表示归档存储
24+
$fileType = 1; // 0 表示标准存储;1 表示低频存储;2 表示归档存储;3 表示深度归档存储
2525

2626
list($ret, $err) = $bucketManager->changeType($bucket, $key, $fileType);
2727
if ($err != null) {

examples/rs_restore.php

Lines changed: 28 additions & 0 deletions
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+
use Qiniu\Config;
6+
use Qiniu\Storage\BucketManager;
7+
8+
// 控制台获取密钥:https://portal.qiniu.com/user/key
9+
$accessKey = getenv('QINIU_ACCESS_KEY');
10+
$secretKey = getenv('QINIU_SECRET_KEY');
11+
$bucket = getenv('QINIU_TEST_BUCKET');
12+
13+
$auth = new Auth($accessKey, $secretKey);
14+
15+
$config = new Config();
16+
$bucketManager = new BucketManager($auth, $config);
17+
18+
// 资源元信息查询
19+
// 参考文档:https://developer.qiniu.com/kodo/api/1308/stat
20+
21+
$key = "my-php-logo.png";
22+
23+
list($ret, $err) = $bucketManager->restoreAr($bucket, $key, 1);
24+
if ($err != null) {
25+
var_dump($err);
26+
} else {
27+
var_dump($ret);
28+
}

src/Qiniu/Storage/BucketManager.php

Lines changed: 55 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -203,14 +203,20 @@ public function listFilesv2(
203203
* 大于0表示多少天后删除,需大于 to_line_after_days
204204
* @param int $to_line_after_days 指定文件上传多少天后转低频存储。指定为0表示
205205
* 不转低频存储,小于0表示上传的文件立即变低频存储
206+
* @param int $to_archive_after_days 指定文件上传多少天后转归档存储。指定为0表示
207+
* 不转归档存储,小于0表示上传的文件立即变归档存储
208+
* @param int $to_deep_archive_after_days 指定文件上传多少天后转深度归档存储。指定为0表示
209+
* 不转深度归档存储,小于0表示上传的文件立即变深度归档存储
206210
* @return array
207211
*/
208212
public function bucketLifecycleRule(
209213
$bucket,
210214
$name,
211215
$prefix,
212-
$delete_after_days,
213-
$to_line_after_days
216+
$delete_after_days = null,
217+
$to_line_after_days = null,
218+
$to_archive_after_days = null,
219+
$to_deep_archive_after_days = null
214220
) {
215221
$path = '/rules/add';
216222
$params = array();
@@ -229,6 +235,12 @@ public function bucketLifecycleRule(
229235
if ($to_line_after_days) {
230236
$params['to_line_after_days'] = $to_line_after_days;
231237
}
238+
if ($to_archive_after_days) {
239+
$params['to_archive_after_days'] = $to_archive_after_days;
240+
}
241+
if ($to_deep_archive_after_days) {
242+
$params['to_deep_archive_after_days'] = $to_deep_archive_after_days;
243+
}
232244
$data = http_build_query($params);
233245
$info = $this->ucPost($path, $data);
234246
return $info;
@@ -245,14 +257,20 @@ public function bucketLifecycleRule(
245257
* 大于0表示多少天后删除,需大于 to_line_after_days
246258
* @param int $to_line_after_days 指定文件上传多少天后转低频存储。指定为0表示不
247259
* 转低频存储,小于0表示上传的文件立即变低频存储
260+
* @param int $to_archive_after_days 指定文件上传多少天后转归档存储。指定为0表示
261+
* 不转归档存储,小于0表示上传的文件立即变归档存储
262+
* @param int $to_deep_archive_after_days 指定文件上传多少天后转深度归档存储。指定为0表示
263+
* 不转深度归档存储,小于0表示上传的文件立即变深度归档存储
248264
* @return array
249265
*/
250266
public function updateBucketLifecycleRule(
251267
$bucket,
252268
$name,
253269
$prefix,
254-
$delete_after_days,
255-
$to_line_after_days
270+
$delete_after_days = null,
271+
$to_line_after_days = null,
272+
$to_archive_after_days = null,
273+
$to_deep_archive_after_days = null
256274
) {
257275
$path = '/rules/update';
258276
$params = array();
@@ -271,6 +289,12 @@ public function updateBucketLifecycleRule(
271289
if ($to_line_after_days) {
272290
$params['to_line_after_days'] = $to_line_after_days;
273291
}
292+
if ($to_archive_after_days) {
293+
$params['to_archive_after_days'] = $to_archive_after_days;
294+
}
295+
if ($to_deep_archive_after_days) {
296+
$params['to_deep_archive_after_days'] = $to_deep_archive_after_days;
297+
}
274298
$data = http_build_query($params);
275299
return $this->ucPost($path, $data);
276300
}
@@ -675,7 +699,7 @@ public function changeMime($bucket, $key, $mime)
675699
*
676700
* @param string $bucket 待操作资源所在空间
677701
* @param string $key 待操作资源文件名
678-
* @param int $fileType 0 表示标准存储;1 表示低频存储;2 表示归档存储
702+
* @param int $fileType 0 表示标准存储;1 表示低频存储;2 表示归档存储;3 表示深度归档存储
679703
*
680704
* @return array
681705
* @link https://developer.qiniu.com/kodo/api/3710/chtype
@@ -687,6 +711,23 @@ public function changeType($bucket, $key, $fileType)
687711
return $this->rsPost($path);
688712
}
689713

714+
/**
715+
* 解冻指定资源的存储类型
716+
*
717+
* @param string $bucket 待操作资源所在空间
718+
* @param string $key 待操作资源文件名
719+
* @param int $freezeAfterDays 解冻有效时长,取值范围 1~7
720+
*
721+
* @return array
722+
* @link https://developer.qiniu.com/kodo/api/6380/restore-archive
723+
*/
724+
public function restoreAr($bucket, $key, $freezeAfterDays)
725+
{
726+
$resource = \Qiniu\entry($bucket, $key);
727+
$path = '/restoreAr/' . $resource . '/freezeAfterDays/' . $freezeAfterDays;
728+
return $this->rsPost($path);
729+
}
730+
690731
/**
691732
* 修改文件的存储状态,即禁用状态和启用状态间的的互相转换
692733
*
@@ -1031,6 +1072,15 @@ public static function buildBatchChangeType($bucket, $key_type_pairs)
10311072
return $data;
10321073
}
10331074

1075+
public static function buildBatchRestoreAr($bucket, $key_restore_days_pairs)
1076+
{
1077+
$data = array();
1078+
foreach ($key_restore_days_pairs as $key => $restore_days) {
1079+
array_push($data, '/restoreAr/' . \Qiniu\entry($bucket, $key) . '/freezeAfterDays/' . $restore_days);
1080+
}
1081+
return $data;
1082+
}
1083+
10341084
private static function oneKeyBatch($operation, $bucket, $keys)
10351085
{
10361086
$data = array();

src/Qiniu/Storage/UploadManager.php

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -65,21 +65,23 @@ public function put(
6565
/**
6666
* 上传文件到七牛
6767
*
68-
* @param $upToken 上传凭证
69-
* @param $key 上传文件名
70-
* @param $filePath 上传文件的路径
71-
* @param $params 自定义变量,规格参考
72-
* http://developer.qiniu.com/docs/v6/api/overview/up/response/vars.html#xvar
73-
* @param $mime 上传数据的mimeType
74-
* @param $checkCrc 是否校验crc32
75-
* @param $version 分片上传版本 目前支持v1/v2版本 默认v1
76-
* @param $partSize 分片上传v2字段 默认大小为4MB 分片大小范围为1 MB - 1 GB
77-
* @param $resumeRecordFile 断点续传文件路径 默认为null
78-
* @return array 包含已上传文件的信息,类似:
68+
* @param string $upToken 上传凭证
69+
* @param string $key 上传文件名
70+
* @param string $filePath 上传文件的路径
71+
* @param array<string, mixed> $params 定义变量,规格参考
72+
* http://developer.qiniu.com/docs/v6/api/overview/up/response/vars.html#xvar
73+
* @param boolean $mime 上传数据的mimeType
74+
* @param string $checkCrc 是否校验crc32
75+
* @param string $resumeRecordFile 断点续传文件路径 默认为null
76+
* @param string $version 分片上传版本 目前支持v1/v2版本 默认v1
77+
* @param int $partSize 分片上传v2字段 默认大小为4MB 分片大小范围为1 MB - 1 GB
78+
*
79+
* @return array<string, mixed> 包含已上传文件的信息,类似:
7980
* [
8081
* "hash" => "<Hash string>",
8182
* "key" => "<Key string>"
8283
* ]
84+
* @throws \Exception
8385
*/
8486
public function putFile(
8587
$upToken,

0 commit comments

Comments
 (0)