@@ -926,6 +926,74 @@ public function deleteAfterDays($bucket, $key, $days)
926
926
return $ this ->rsPost ($ bucket , $ path );
927
927
}
928
928
929
+ /**
930
+ * 更新 object 生命周期
931
+ *
932
+ * @param string $bucket 空间名
933
+ * @param string $key 目标资源
934
+ * @param int $to_line_after_days 多少天后将文件转为低频存储,设置为 -1 表示取消已设置的转低频存储的生命周期规则, 0 表示不修改转低频生命周期规则。
935
+ * @param int $to_archive_after_days 多少天后将文件转为归档存储,设置为 -1 表示取消已设置的转归档存储的生命周期规则, 0 表示不修改转归档生命周期规则。
936
+ * @param int $to_deep_archive_after_days 多少天后将文件转为深度归档存储,设置为 -1 表示取消已设置的转深度归档存储的生命周期规则, 0 表示不修改转深度归档生命周期规则。
937
+ * @param int $delete_after_days 多少天后将文件删除,设置为 -1 表示取消已设置的删除存储的生命周期规则, 0 表示不修改删除存储的生命周期规则。
938
+ * @return array
939
+ */
940
+ public function setObjectLifecycle (
941
+ $ bucket ,
942
+ $ key ,
943
+ $ to_line_after_days = 0 ,
944
+ $ to_archive_after_days = 0 ,
945
+ $ to_deep_archive_after_days = 0 ,
946
+ $ delete_after_days = 0
947
+ ) {
948
+ return $ this ->setObjectLifecycleWithCond (
949
+ $ bucket ,
950
+ $ key ,
951
+ null ,
952
+ $ to_line_after_days ,
953
+ $ to_archive_after_days ,
954
+ $ to_deep_archive_after_days ,
955
+ $ delete_after_days
956
+ );
957
+ }
958
+
959
+ /**
960
+ * 更新 object 生命周期
961
+ *
962
+ * @param string $bucket 空间名
963
+ * @param string $key 目标资源
964
+ * @param int $to_line_after_days 多少天后将文件转为低频存储,设置为 -1 表示取消已设置的转低频存储的生命周期规则, 0 表示不修改转低频生命周期规则。
965
+ * @param int $to_archive_after_days 多少天后将文件转为归档存储,设置为 -1 表示取消已设置的转归档存储的生命周期规则, 0 表示不修改转归档生命周期规则。
966
+ * @param int $to_deep_archive_after_days 多少天后将文件转为深度归档存储,设置为 -1 表示取消已设置的转深度归档存储的生命周期规则, 0 表示不修改转深度归档生命周期规则。
967
+ * @param int $delete_after_days 多少天后将文件删除,设置为 -1 表示取消已设置的删除存储的生命周期规则, 0 表示不修改删除存储的生命周期规则。
968
+ * @param array<string, mixed> $cond 匹配条件,只有条件匹配才会设置成功,目前支持:hash、mime、fsize、putTime
969
+ * @return array
970
+ */
971
+ public function setObjectLifecycleWithCond (
972
+ $ bucket ,
973
+ $ key ,
974
+ $ cond = null ,
975
+ $ to_line_after_days = 0 ,
976
+ $ to_archive_after_days = 0 ,
977
+ $ to_deep_archive_after_days = 0 ,
978
+ $ delete_after_days = 0
979
+ ) {
980
+ $ encodedEntry = \Qiniu \entry ($ bucket , $ key );
981
+ $ path = '/lifecycle/ ' . $ encodedEntry .
982
+ '/toIAAfterDays/ ' . $ to_line_after_days .
983
+ '/toArchiveAfterDays/ ' . $ to_archive_after_days .
984
+ '/toDeepArchiveAfterDays/ ' . $ to_deep_archive_after_days .
985
+ '/deleteAfterDays/ ' . $ delete_after_days ;
986
+ if ($ cond != null ) {
987
+ $ condStrArr = array ();
988
+ foreach ($ cond as $ key => $ value ) {
989
+ array_push ($ condStrArr , $ key . '= ' . $ value );
990
+ }
991
+ $ condStr = implode ('& ' , $ condStrArr );
992
+ $ path .= '/cond ' . \Qiniu \base64_urlSafeEncode ($ condStr );
993
+ }
994
+ return $ this ->rsPost ($ bucket , $ path );
995
+ }
996
+
929
997
private function getUcHost ()
930
998
{
931
999
$ scheme = "http:// " ;
@@ -1062,6 +1130,37 @@ public static function buildBatchDeleteAfterDays($bucket, $key_day_pairs)
1062
1130
return $ data ;
1063
1131
}
1064
1132
1133
+ /**
1134
+ * @param string $bucket 空间名
1135
+ * @param array<string> $keys 目标资源
1136
+ * @param int $to_line_after_days 多少天后将文件转为低频存储,设置为 -1 表示取消已设置的转低频存储的生命周期规则, 0 表示不修改转低频生命周期规则。
1137
+ * @param int $to_archive_after_days 多少天后将文件转为归档存储,设置为 -1 表示取消已设置的转归档存储的生命周期规则, 0 表示不修改转归档生命周期规则。
1138
+ * @param int $to_deep_archive_after_days 多少天后将文件转为深度归档存储,设置为 -1 表示取消已设置的转深度归档存储的生命周期规则, 0 表示不修改转深度归档生命周期规则。
1139
+ * @param int $delete_after_days 多少天后将文件删除,设置为 -1 表示取消已设置的删除存储的生命周期规则, 0 表示不修改删除存储的生命周期规则。
1140
+ *
1141
+ * @retrun array<string>
1142
+ */
1143
+ public static function buildBatchSetObjectLifecycle (
1144
+ $ bucket ,
1145
+ $ keys ,
1146
+ $ to_line_after_days ,
1147
+ $ to_archive_after_days ,
1148
+ $ to_deep_archive_after_days ,
1149
+ $ delete_after_days
1150
+ ) {
1151
+ $ result = array ();
1152
+ foreach ($ keys as $ key ) {
1153
+ $ encodedEntry = \Qiniu \entry ($ bucket , $ key );
1154
+ $ op = '/lifecycle/ ' . $ encodedEntry .
1155
+ '/toIAAfterDays/ ' . $ to_line_after_days .
1156
+ '/toArchiveAfterDays/ ' . $ to_archive_after_days .
1157
+ '/toDeepArchiveAfterDays/ ' . $ to_deep_archive_after_days .
1158
+ '/deleteAfterDays/ ' . $ delete_after_days ;
1159
+ array_push ($ result , $ op );
1160
+ }
1161
+ return $ result ;
1162
+ }
1163
+
1065
1164
public static function buildBatchChangeMime ($ bucket , $ key_mime_pairs )
1066
1165
{
1067
1166
$ data = array ();
0 commit comments