How to delete draft reviews in a batch?
Asked by Blazej Kroll:

I have over 1000 reviews in draft. I need to clean the reviews database in some smart way. How to delete reviews from Crucible??

Is it possible form GUI or do I have to do it on a database?

HOW?

Thanks in advance,

Blazej


Answers:
author: LeonardoL
body: Hi Blazej,

In this case you could delete review using crucible's [REST API](http://docs.atlassian.com/fisheye-crucible/2.1.0/wadl/crucible.html). Here's an example using [curl](http://curl.haxx.se/) command line you can try:

curl -u \<username\>:\<password\> http://localhost:8060/fisheye/rest-service/reviews-v1/\<reviewID\> -X DELETE -H "Content-Type:application/xml"

```
Replace the username, password, host url, reviewID accordingly. You can consult more information about reviews structure at crucible's database inside table cru_review. Also this procedure deletes one review so you can create a script to run it against more that one review to automati the process.
```

```
 
```

Also this procedure delete one review so you can create a script to run

it against more that one review to automati the process.

```
 
```

```
Cheers,
```

```
Leonardo.
```

```
 
```

comments: author: Blazej Kroll
body: Hi Leonardo,

Thanks for your answer. I tested the REST API method you mentioned. However, it seems that all the reviews must be put in **Abandoned** **state** beforehand. (which was quite an astonishing discovery...)

* I go the following error while trying to delete a drafted code review:

```
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><error><code>IllegalArgument</code><message>The review PermId:CR-5113 in the Draft is not deletable.</message><stacktrace>java.lang.IllegalArgumentException: The review PermId:CR-5113 in the Draft is not deletable.        at com.atlassian.crucible.spi.impl.DefaultReviewService.deleteReview(DefaultReviewService.java:1679)at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)	...</stacktrace></error>
```

* I also tried the following method:  
  **`/rest-service/reviews-v1/{id}/transition``?action:deleteReview`**

The description I took from [here](http://docs.atlassian.com/fisheye-crucible/2.1.0/wadl/crucible.html#d2e936 "here") **is inconsitent** with way this option should be executed:

` /rest-service/reviews-v1/{id}/transition``?``action=``action:deleteReview`

I think you should correct the description [here](http://docs.atlassian.com/fisheye-crucible/2.1.0/wadl/crucible.html#d2e936 "here").

I found the proper way of doing it here:

* **<https://confluence.atlassian.com/plugins/viewsource/viewpagesrc.action?pageId=168461519>**

```
curl -k -u login:pass http://myCrucibleHost/rest-service/reviews-v1/CR-5113/transition?action=action:deleteReview -X POST -H "Content-Type:application/xml"
```

Performing the aciton **both ways** on **an abandoned review works fine**:

curl -k -u login:pass <http://myCrucibleHost/rest-service/reviews-v1/CR-4894> -X DELETE -H "Content-Type:application/xml"

* Why you need to change a review to abandoned in order to delete it?
* What is happening when a review is in an abandoned state?
* I plan to transform all my drafts (which I want to remove) to abandoned reviews - is there anything I should look for/worry about?

Best regards,

Blazej


author: Blazej Kroll
body: Hi Leonardo,

I am still having issues with this.

As I am trying to change the state of a review to abandoned with:

```
curl -k -u user:pass "http://myCrucibleHost/rest-service/reviews-v1/CR-2197/transition?action=action:abandonReview" -X POST -H "Content-Type:application/xml"            <?xml version="1.0" encoding="UTF-8" standalone="yes"?><error><code>Authorization</code><message>Crucible unauthorised action.</message><stacktrace>com.atlassian.crucible.spi.services.AuthorizationException: Crucible unauthorised action.        at com.cenqua.crucible.model.managers.impl.DefaultReviewManager.changeState(DefaultReviewManager.java:967)        at com.atlassian.crucible.spi.impl.DefaultReviewService$27.doInTransaction(DefaultReviewService.java:1703)        at com.atlassian.crucible.spi.impl.DefaultReviewService$27.doInTransaction(DefaultReviewService.java:1694)        at com.atlassian.fisheye.spi.impl.DefaultTxTemplate.execute(DefaultTxTemplate.java:123)        at sun.reflect.GeneratedMethodAccessor1236.invoke(Unknown Source)        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)        at java.lang.reflect.Method.invoke(Unknown Source)
```

I am using administrator rights and still get this error.

**How to be able to abandon a review??**


author: Bob Swift (personal)
body: Try the Crucible CLI (see other answer) and use **-v** to see what it is doing under the covers. I remember it being a royal pain for doing something one would think as being simple.


author: LeonardoL
body: Hi Blazej,

Here's some ideas that could help you:

1. Take a look into [this](http://forums.atlassian.com/thread.jspa?messageID=257324196) and see a workaround which actually worked.

2. Make sure your users have permission to ABANDON reviews inside Crucible ADMIN at Permission Scheme and then try again.

3. Try to summarize and then delete:

```
curl -v -d "" -u youruser:pwd -H "Content-Type: application/xml" http://myCrucible/crucible/rest-service/reviews-v1/CR-2197/transition?action=action:summarizeReviewcurl -v -d "" -u youruser:pwd -H "Content-Type: application/xml" http://myCrucible/crucible/rest-service/reviews-v1/CR-2197/transition?action=action:closeReview
```


author: Bob Swift (personal)
body: [deleteReview](https://bobswift.atlassian.net/wiki/display/crucli/Documentation#Documentation-deleteReview) action from the [Crucible Command Line Interface](https://bobswift.atlassian.net/wiki/display/crucli) can be used in combination with [runFromSql](https://bobswift.atlassian.net/wiki/display/crucli/Documentation#Documentation-runFromSql) to select the reviews you want to remove from the Crucible database. The deleteReview action makes sure the review is in the appropriate state to delete before running the delete (under the covers, the delete is done using the rest api like in Leonardo's answer).


author: Malik
body: <https://confluence.atlassian.com/display/FISHKB/Deleting+hung+reviews+manually>


author: LeonardoL
body: Hi Blazej,

It's possible to delete reviews from GUI. Please refer to [this article](https://confluence.atlassian.com/display/CRUCIBLE/Deleting+a+review) to know how. I hope this can help you.

Cheers,

Leonardo.

comments: author: Blazej Kroll
body: Hi Leonardo,

<br />

Thanks for quick answer - I knew about that option, however I'd like to make a massive delete of over one thousand reviews in draft mode. I really don't like to do it on a one-by-one basis.

How to delete all draft reviews with single operation? sql query? script?

Regards,

Blazej