Skip to content

Commit fd5a85c

Browse files
authored
object lifecycle archive ir (#423)
1 parent 9ee81f0 commit fd5a85c

File tree

5 files changed

+84
-38
lines changed

5 files changed

+84
-38
lines changed

examples/bucket_lifecycleRule.php

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

@@ -31,7 +32,8 @@
3132
$delete_after_days,
3233
$to_line_after_days,
3334
$to_archive_after_days,
34-
$to_deep_archive_after_days
35+
$to_deep_archive_after_days,
36+
$to_archive_ir_after_days
3537
);
3638
if ($err != null) {
3739
var_dump($err);

examples/rs_batch_change_type.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
// 1 表示低频存储
3232
// 2 表示归档存储
3333
// 3 表示深度归档存储
34+
// 4 表示归档直读存储
3435
foreach ($keys as $key) {
3536
$keyTypePairs[$key] = 1;
3637
}

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 表示归档存储;3 表示深度归档存储
24+
$fileType = 1; // 0 表示标准存储;1 表示低频存储;2 表示归档存储;3 表示深度归档存储;4 表示归档直读存储;
2525

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

src/Qiniu/Storage/BucketManager.php

Lines changed: 65 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -215,18 +215,23 @@ public function listFilesv2(
215215
/**
216216
* 增加bucket生命规则
217217
*
218-
* @param string $bucket 空间名
219-
* @param string $name 规则名称 bucket 内唯一,长度小于50,不能为空,只能为
220-
* 字母、数字、下划线
221-
* @param string $prefix 同一个 bucket 里面前缀不能重复
222-
* @param int $delete_after_days 指定上传文件多少天后删除,指定为0表示不删除,
223-
* 大于0表示多少天后删除,需大于 to_line_after_days
224-
* @param int $to_line_after_days 指定文件上传多少天后转低频存储。指定为0表示
225-
* 不转低频存储,小于0表示上传的文件立即变低频存储
226-
* @param int $to_archive_after_days 指定文件上传多少天后转归档存储。指定为0表示
227-
* 不转归档存储,小于0表示上传的文件立即变归档存储
228-
* @param int $to_deep_archive_after_days 指定文件上传多少天后转深度归档存储。指定为0表示
229-
* 不转深度归档存储,小于0表示上传的文件立即变深度归档存储
218+
* @param string $bucket
219+
* 空间名
220+
* @param string $name
221+
* 规则名称 bucket 内唯一,长度小于50,不能为空,只能为字母、数字、下划线
222+
* @param string $prefix
223+
* 同一个 bucket 里面前缀不能重复
224+
* @param int $delete_after_days
225+
* 指定上传文件多少天后删除,指定为0表示不删除,大于0表示多少天后删除。
226+
* 需大于 to_line_after_days
227+
* @param int $to_line_after_days
228+
* 指定文件上传多少天后转低频存储。指定为0表示不转低频存储
229+
* @param int $to_archive_ir_after_days
230+
* 指定文件上传多少天后转归档直读。指定为0表示不转归档直读
231+
* @param int $to_archive_after_days
232+
* 指定文件上传多少天后转归档存储。指定为0表示不转归档存储
233+
* @param int $to_deep_archive_after_days
234+
* 指定文件上传多少天后转深度归档存储。指定为0表示不转深度归档存储
230235
* @return array
231236
*/
232237
public function bucketLifecycleRule(
@@ -236,7 +241,8 @@ public function bucketLifecycleRule(
236241
$delete_after_days = null,
237242
$to_line_after_days = null,
238243
$to_archive_after_days = null,
239-
$to_deep_archive_after_days = null
244+
$to_deep_archive_after_days = null,
245+
$to_archive_ir_after_days = null
240246
) {
241247
$path = '/rules/add';
242248
$params = array();
@@ -255,6 +261,9 @@ public function bucketLifecycleRule(
255261
if ($to_line_after_days) {
256262
$params['to_line_after_days'] = $to_line_after_days;
257263
}
264+
if ($to_archive_ir_after_days) {
265+
$params['to_archive_ir_after_days'] = $to_archive_ir_after_days;
266+
}
258267
if ($to_archive_after_days) {
259268
$params['to_archive_after_days'] = $to_archive_after_days;
260269
}
@@ -269,18 +278,23 @@ public function bucketLifecycleRule(
269278
/**
270279
* 更新bucket生命规则
271280
*
272-
* @param string $bucket 空间名
273-
* @param string $name 规则名称 bucket 内唯一,长度小于50,不能为空,只能为字母、
274-
* 数字、下划线
275-
* @param string $prefix 同一个 bucket 里面前缀不能重复
276-
* @param int $delete_after_days 指定上传文件多少天后删除,指定为0表示不删除,
277-
* 大于0表示多少天后删除,需大于 to_line_after_days
278-
* @param int $to_line_after_days 指定文件上传多少天后转低频存储。指定为0表示不
279-
* 转低频存储,小于0表示上传的文件立即变低频存储
280-
* @param int $to_archive_after_days 指定文件上传多少天后转归档存储。指定为0表示
281-
* 不转归档存储,小于0表示上传的文件立即变归档存储
282-
* @param int $to_deep_archive_after_days 指定文件上传多少天后转深度归档存储。指定为0表示
283-
* 不转深度归档存储,小于0表示上传的文件立即变深度归档存储
281+
* @param string $bucket
282+
* 空间名
283+
* @param string $name
284+
* 规则名称 bucket 内唯一,长度小于50,不能为空,只能为字母、数字、下划线
285+
* @param string $prefix
286+
* 同一个 bucket 里面前缀不能重复
287+
* @param int $delete_after_days
288+
* 指定上传文件多少天后删除,指定为0表示不删除,大于0表示多少天后删除
289+
* 需大于 to_line_after_days
290+
* @param int $to_line_after_days
291+
* 指定文件上传多少天后转低频存储。指定为0表示不转低频存储
292+
* @param int $to_archive_ir_after_days
293+
* 指定文件上传多少天后转归档只读。指定为0表示不转归档只读
294+
* @param int $to_archive_after_days
295+
* 指定文件上传多少天后转归档存储。指定为0表示不转归档存储
296+
* @param int $to_deep_archive_after_days
297+
* 指定文件上传多少天后转深度归档存储。指定为0表示不转深度归档存储
284298
* @return array
285299
*/
286300
public function updateBucketLifecycleRule(
@@ -290,7 +304,8 @@ public function updateBucketLifecycleRule(
290304
$delete_after_days = null,
291305
$to_line_after_days = null,
292306
$to_archive_after_days = null,
293-
$to_deep_archive_after_days = null
307+
$to_deep_archive_after_days = null,
308+
$to_archive_ir_after_days = null
294309
) {
295310
$path = '/rules/update';
296311
$params = array();
@@ -309,6 +324,9 @@ public function updateBucketLifecycleRule(
309324
if ($to_line_after_days) {
310325
$params['to_line_after_days'] = $to_line_after_days;
311326
}
327+
if ($to_archive_ir_after_days) {
328+
$params['to_archive_ir_after_days'] = $to_archive_ir_after_days;
329+
}
312330
if ($to_archive_after_days) {
313331
$params['to_archive_after_days'] = $to_archive_after_days;
314332
}
@@ -724,6 +742,7 @@ public function changeMime($bucket, $key, $mime)
724742
* 1 表示低频存储;
725743
* 2 表示归档存储;
726744
* 3 表示深度归档存储;
745+
* 4 表示归档直读存储;
727746
*
728747
* @return array
729748
* @link https://developer.qiniu.com/kodo/api/3710/chtype
@@ -811,7 +830,7 @@ public function fetch($url, $bucket, $key = null)
811830
* @param string $callbackbody 回调Body
812831
* @param string $callbackbodytype 回调Body内容类型,默认为"application/x-www-form-urlencoded"
813832
* @param string $callbackhost 回调时使用的Host
814-
* @param int $file_type 存储文件类型 0:标准存储(默认),1:低频存储,2:归档存储
833+
* @param int $file_type 存储文件类型 0:标准存储(默认),1:低频存储,2:归档存储,3:深度归档存储,4:归档直读存储
815834
* @param bool $ignore_same_key 如果空间中已经存在同名文件则放弃本次抓取
816835
* @return array
817836
* @link https://developer.qiniu.com/kodo/api/4097/asynch-fetch
@@ -952,6 +971,9 @@ public function deleteAfterDays($bucket, $key, $days)
952971
* @param int $to_line_after_days 多少天后将文件转为低频存储。
953972
* -1 表示取消已设置的转低频存储的生命周期规则;
954973
* 0 表示不修改转低频生命周期规则。
974+
* @param int $to_archive_ir_after_days 多少天后转为归档直读存储。
975+
* -1 表示取消已设置的转归档直读存储的生命周期规则;
976+
* 0 表示不修改转归档直读生命周期规则。
955977
* @param int $to_archive_after_days 多少天后将文件转为归档存储。
956978
* -1 表示取消已设置的转归档存储的生命周期规则;
957979
* 0 表示不修改转归档生命周期规则。
@@ -969,7 +991,8 @@ public function setObjectLifecycle(
969991
$to_line_after_days = 0,
970992
$to_archive_after_days = 0,
971993
$to_deep_archive_after_days = 0,
972-
$delete_after_days = 0
994+
$delete_after_days = 0,
995+
$to_archive_ir_after_days = 0
973996
) {
974997
return $this->setObjectLifecycleWithCond(
975998
$bucket,
@@ -978,7 +1001,8 @@ public function setObjectLifecycle(
9781001
$to_line_after_days,
9791002
$to_archive_after_days,
9801003
$to_deep_archive_after_days,
981-
$delete_after_days
1004+
$delete_after_days,
1005+
$to_archive_ir_after_days
9821006
);
9831007
}
9841008

@@ -990,6 +1014,9 @@ public function setObjectLifecycle(
9901014
* @param int $to_line_after_days 多少天后将文件转为低频存储。
9911015
* 设置为 -1 表示取消已设置的转低频存储的生命周期规则;
9921016
* 0 表示不修改转低频生命周期规则。
1017+
* @param int $to_archive_ir_after_days 多少天后将文件转为归档直读存储。
1018+
* 设置为 -1 表示取消已设置的转归档直读存储的生命周期规则;
1019+
* 0 表示不修改转归档直读生命周期规则。
9931020
* @param int $to_archive_after_days 多少天后将文件转为归档存储。
9941021
* -1 表示取消已设置的转归档存储的生命周期规则;
9951022
* 0 表示不修改转归档生命周期规则。
@@ -1010,11 +1037,13 @@ public function setObjectLifecycleWithCond(
10101037
$to_line_after_days = 0,
10111038
$to_archive_after_days = 0,
10121039
$to_deep_archive_after_days = 0,
1013-
$delete_after_days = 0
1040+
$delete_after_days = 0,
1041+
$to_archive_ir_after_days = 0
10141042
) {
10151043
$encodedEntry = \Qiniu\entry($bucket, $key);
10161044
$path = '/lifecycle/' . $encodedEntry .
10171045
'/toIAAfterDays/' . $to_line_after_days .
1046+
'/toArchiveIRAfterDays/' . $to_archive_ir_after_days .
10181047
'/toArchiveAfterDays/' . $to_archive_after_days .
10191048
'/toDeepArchiveAfterDays/' . $to_deep_archive_after_days .
10201049
'/deleteAfterDays/' . $delete_after_days;
@@ -1182,6 +1211,9 @@ public static function buildBatchDeleteAfterDays($bucket, $key_day_pairs)
11821211
* @param int $to_line_after_days 多少天后将文件转为低频存储。
11831212
* -1 表示取消已设置的转低频存储的生命周期规则;
11841213
* 0 表示不修改转低频生命周期规则。
1214+
* @param int $to_archive_ir_after_days 多少天后将文件转为归档直读。
1215+
* -1 表示取消已设置的转归档只读的生命周期规则;
1216+
* 0 表示不修改转归档只读周期规则。
11851217
* @param int $to_archive_after_days 多少天后将文件转为归档存储。
11861218
* -1 表示取消已设置的转归档存储的生命周期规则;
11871219
* 0 表示不修改转归档生命周期规则。
@@ -1200,13 +1232,15 @@ public static function buildBatchSetObjectLifecycle(
12001232
$to_line_after_days,
12011233
$to_archive_after_days,
12021234
$to_deep_archive_after_days,
1203-
$delete_after_days
1235+
$delete_after_days,
1236+
$to_archive_ir_after_days = 0
12041237
) {
12051238
$result = array();
12061239
foreach ($keys as $key) {
12071240
$encodedEntry = \Qiniu\entry($bucket, $key);
12081241
$op = '/lifecycle/' . $encodedEntry .
12091242
'/toIAAfterDays/' . $to_line_after_days .
1243+
'/toArchiveIRAfterDays/' . $to_archive_ir_after_days .
12101244
'/toArchiveAfterDays/' . $to_archive_after_days .
12111245
'/toDeepArchiveAfterDays/' . $to_deep_archive_after_days .
12121246
'/deleteAfterDays/' . $delete_after_days;

tests/Qiniu/Tests/BucketTest.php

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,8 @@ public function testBucketLifecycleRule()
172172
80,
173173
70,
174174
72,
175-
74
175+
74,
176+
71
176177
);
177178
$this->assertNull($error);
178179
$this->assertNotNull($ret);
@@ -192,6 +193,7 @@ public function testBucketLifecycleRule()
192193
$this->assertEquals(self::$bucketLifeRulePrefix, $rule["prefix"]);
193194
$this->assertEquals(80, $rule["delete_after_days"]);
194195
$this->assertEquals(70, $rule["to_line_after_days"]);
196+
//$this->assertEquals(71, $rule["to_archive_ir_after_days"]);
195197
$this->assertEquals(72, $rule["to_archive_after_days"]);
196198
$this->assertEquals(74, $rule["to_deep_archive_after_days"]);
197199

@@ -203,7 +205,8 @@ public function testBucketLifecycleRule()
203205
90,
204206
75,
205207
80,
206-
85
208+
85,
209+
78
207210
);
208211
$this->assertNull($error);
209212
$this->assertNotNull($ret);
@@ -223,6 +226,7 @@ public function testBucketLifecycleRule()
223226
$this->assertEquals('update-' . self::$bucketLifeRulePrefix, $rule["prefix"]);
224227
$this->assertEquals(90, $rule["delete_after_days"]);
225228
$this->assertEquals(75, $rule["to_line_after_days"]);
229+
//$this->assertEquals(78, $rule["to_archive_ir_after_days"]);
226230
$this->assertEquals(80, $rule["to_archive_after_days"]);
227231
$this->assertEquals(85, $rule["to_deep_archive_after_days"]);
228232

@@ -549,13 +553,15 @@ public function testSetObjectLifecycle()
549553
10,
550554
20,
551555
30,
552-
40
556+
40,
557+
15
553558
);
554559
$this->assertNull($err);
555560

556561
list($ret, $error) = self::$bucketManager->stat(self::$bucketName, $key);
557562
$this->assertNull($error);
558563
$this->assertNotNull($ret['transitionToIA']);
564+
//$this->assertNotNull($ret['transitionToArchiveIR']);
559565
$this->assertNotNull($ret['transitionToARCHIVE']);
560566
$this->assertNotNull($ret['transitionToDeepArchive']);
561567
$this->assertNotNull($ret['expiration']);
@@ -580,13 +586,15 @@ public function testSetObjectLifecycleWithCond()
580586
10,
581587
20,
582588
30,
583-
40
589+
40,
590+
15
584591
);
585592
$this->assertNull($err);
586593

587594
list($ret, $error) = self::$bucketManager->stat(self::$bucketName, $key);
588595
$this->assertNull($error);
589596
$this->assertNotNull($ret['transitionToIA']);
597+
//$this->assertNotNull($ret['transitionToArchiveIR']);
590598
$this->assertNotNull($ret['transitionToARCHIVE']);
591599
$this->assertNotNull($ret['transitionToDeepArchive']);
592600
$this->assertNotNull($ret['expiration']);
@@ -602,7 +610,8 @@ public function testBatchSetObjectLifecycle()
602610
10,
603611
20,
604612
30,
605-
40
613+
40,
614+
15
606615
);
607616
list($ret, $err) = self::$bucketManager->batch($ops);
608617
$this->assertNull($err);

0 commit comments

Comments
 (0)