public function testBatchDeleteMoveCopy() { $key2 = 'testOp2' . getTid(); $key3 = 'testOp3' . getTid(); $key4 = 'testOp4' . getTid(); $e1 = new Qiniu_RS_EntryPath($this->bucket, $this->key); $e2 = new Qiniu_RS_EntryPath($this->bucket, $key2); $e3 = new Qiniu_RS_EntryPath($this->bucket, $key3); $e4 = new Qiniu_RS_EntryPath($this->bucket, $key4); Qiniu_RS_BatchDelete($this->client, array($e2, $e3, $e4)); $entryPairs = array(new Qiniu_RS_EntryPathPair($e1, $e2), new Qiniu_RS_EntryPathPair($e1, $e3)); list($ret, $err) = Qiniu_RS_BatchCopy($this->client, $entryPairs); $this->assertNull($err); $this->assertEquals($ret[0]['code'], 200); $this->assertEquals($ret[1]['code'], 200); list($ret, $err) = Qiniu_RS_BatchMove($this->client, array(new Qiniu_RS_EntryPathPair($e2, $e4))); $this->assertNull($err); $this->assertEquals($ret[0]['code'], 200); list($ret, $err) = Qiniu_RS_BatchDelete($this->client, array($e3, $e4)); $this->assertNull($err); $this->assertEquals($ret[0]['code'], 200); $this->assertEquals($ret[1]['code'], 200); Qiniu_RS_BatchDelete($this->client, array($e2, $e3, $e4)); }
/** * Delete a directory * 七牛无目录概念. 目前实现方案是.列举指定目录资源.批量删除 * @param $dirname * @return bool */ public function deleteDir($dirname) { $item = $this->listDirContents($dirname); $enties = array_map(function ($file) { return new \Qiniu_RS_EntryPath($this->bucket, $file['key']); }, $item); list($ret, $err) = Qiniu_RS_BatchDelete($this->getClient(), $enties); return $err === null; }
public function batchMove() { $keys = func_get_args(); if (func_num_args() <= 0) { return array(); } $entries = array(); foreach ($keys as $i => $key) { if (isset($key['old']) and !empty($key['old']) and isset($key['new']) and !empty($key['new'])) { $key['old'] = new \Qiniu_RS_EntryPath($this->bucket, $key['old']); $key['new'] = new \Qiniu_RS_EntryPath($this->bucket, $key['new']); $entries[$i] = new \Qiniu_RS_EntryPathPair($key['old'], $key['new']); } else { $entries[$i] = new \Qiniu_RS_EntryPathPair(new \Qiniu_RS_EntryPath($this->bucket, 'empty'), new \Qiniu_RS_EntryPath($this->bucket, 'empty')); } } list($ret, $err) = Qiniu_RS_BatchDelete($client, $entries); if ($err !== null) { $ret['code'] = $err->Code; return $ret; } else { return $ret; } }
var_dump($ret); } # @endgist # @gist batch_copy $entryPairs = array(new Qiniu_RS_EntryPathPair($e1, $e2), new Qiniu_RS_EntryPathPair($e1, $e3)); list($ret, $err) = Qiniu_RS_BatchCopy($client, $entryPairs); echo "\n\n====> Qiniu_RS_BatchCopy result: \n"; if ($err !== null) { var_dump($err); } else { var_dump($ret); } # @endgist # @gist batch_delete $entries = array($e1, $e2); list($ret, $err) = Qiniu_RS_BatchDelete($client, $entries); echo "\n\n====> Qiniu_RS_BatchDelete result: \n"; if ($err !== null) { var_dump($err); } else { var_dump($ret); } # @endgist # @gist batch_move $entryPairs = array(new Qiniu_RS_EntryPathPair($e3, $e1)); list($ret, $err) = Qiniu_RS_BatchMove($client, $entryPairs); echo "\n\n====> Qiniu_RS_BatchMove result: \n"; if ($err !== null) { var_dump($err); } else { var_dump($ret);
public function deleteFolder(&$client, $path, $limit = '100', $marker = '') { static $objects = array(); $arr = self::parsePath($path); //echo( $path.'---------'); list($commonPrefixes, $iterms, $markerOut, $err) = Qiniu_RSF_ListPrefix($client, $arr['bucket'], $arr['object'], $marker, '', $limit); if ($err != null) { if ($err === Qiniu_RSF_EOF) { $data['items'] = $iterms; } else { runlog('qiniu_log', $err->Code . ':' . $err->Err); return array('error' => $err->Code . ':' . $err->Err); } } else { $data['items'] = $iterms; } if ($data['items']) { $icos = $data['items']; } $value = array(); $entries = array(); foreach ($icos as $key => $value) { if (is_array($value)) { $entries[] = new Qiniu_RS_EntryPath($arr['bucket'], $value['key']); //Qiniu_RS_Delete($client, $arr['bucket'],$value['key']); } else { $entries[] = new Qiniu_RS_EntryPath($arr['bucket'], $value); //Qiniu_RS_Delete($client, $arr['bucket'],$value); } } Qiniu_RS_BatchDelete($client, $entries); if ($markerOut) { self::deleteFolder($client, $path, 100, $markerOut); } return true; }