Skip to content

Commit 201fd1b

Browse files
committed
Fix CollectionManager->dropCollection method
Change-Id: I936a06fc2093548b99737d86d356c1927c8ca783 Reviewed-on: http://review.couchbase.org/121629 Tested-by: Build Bot <[email protected]> Reviewed-by: Sergey Avseyev <[email protected]>
1 parent bd80da7 commit 201fd1b

File tree

2 files changed

+43
-2
lines changed

2 files changed

+43
-2
lines changed

integration/CollectionManager.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,11 @@
3131
$scope = $bucket->collections()->getScope($scope_name);
3232
printf("Scope \"%s\" has %d collections\n", $scope_name, count($scope->collections()));
3333

34-
$start = microtime(true);
3534
$collection = new \Couchbase\CollectionSpec();
3635
$collection->setScopeName($scope_name);
3736
$collection->setName('users');
37+
38+
$start = microtime(true);
3839
$bucket->collections()->createCollection($collection);
3940
printf("Collection \"%s\" on scope \"%s\" has been created in %fus\n",
4041
$collection->name(), $collection->scopeName(), microtime(true)-$start);
@@ -44,3 +45,14 @@
4445
foreach ($scope->collections() as $collection) {
4546
printf(" * \"%s\"\n", $collection->name());
4647
}
48+
49+
$start = microtime(true);
50+
$bucket->collections()->dropCollection($collection);
51+
printf("Collection \"%s\" on scope \"%s\" has been dropped in %fus\n",
52+
$collection->name(), $collection->scopeName(), microtime(true)-$start);
53+
54+
$scope = $bucket->collections()->getScope($scope_name);
55+
printf("Scope \"%s\" has %d collections\n", $scope_name, count($scope->collections()));
56+
foreach ($scope->collections() as $collection) {
57+
printf(" * \"%s\"\n", $collection->name());
58+
}

src/couchbase/managers/collection_manager.c

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,36 @@ PHP_METHOD(CollectionManager, createCollection)
260260
efree(path);
261261
}
262262

263-
PHP_METHOD(CollectionManager, dropCollection) {}
263+
PHP_METHOD(CollectionManager, dropCollection)
264+
{
265+
266+
pcbc_bucket_t *bucket = NULL;
267+
zval *prop, val, *collection, *name, *scope_name, val1, val2;
268+
char *path;
269+
size_t path_len;
270+
271+
int rv = zend_parse_parameters_throw(ZEND_NUM_ARGS() TSRMLS_CC, "O", &collection, pcbc_collection_spec_ce);
272+
if (rv == FAILURE) {
273+
RETURN_NULL();
274+
}
275+
prop = zend_read_property(pcbc_collection_manager_ce, getThis(), ZEND_STRL("bucket"), 0, &val);
276+
bucket = Z_BUCKET_OBJ_P(prop);
277+
278+
name = zend_read_property(pcbc_collection_spec_ce, collection, ZEND_STRL("name"), 0, &val1);
279+
scope_name = zend_read_property(pcbc_collection_spec_ce, collection, ZEND_STRL("scope_name"), 0, &val2);
280+
if (name == NULL || Z_TYPE_P(name) != IS_STRING || scope_name == NULL || Z_TYPE_P(scope_name) != IS_STRING) {
281+
RETURN_NULL();
282+
}
283+
284+
lcb_CMDHTTP *cmd;
285+
lcb_cmdhttp_create(&cmd, LCB_HTTP_TYPE_MANAGEMENT);
286+
lcb_cmdhttp_method(cmd, LCB_HTTP_METHOD_DELETE);
287+
path_len = spprintf(&path, 0, "/pools/default/buckets/%s/collections/%.*s/%.*s", bucket->conn->bucketname,
288+
(int)Z_STRLEN_P(scope_name), Z_STRVAL_P(scope_name), (int)Z_STRLEN_P(name), Z_STRVAL_P(name));
289+
lcb_cmdhttp_path(cmd, path, path_len);
290+
pcbc_http_request(return_value, bucket->conn->lcb, cmd, 1, NULL, NULL, NULL TSRMLS_CC);
291+
efree(path);
292+
}
264293

265294
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(ai_CollectionManager_getScope, 0, 1, \\Couchbase\\ScopeSpec, 0)
266295
ZEND_ARG_TYPE_INFO(0, name, IS_STRING, 0)

0 commit comments

Comments
 (0)