Reindex the change after forcing patchset as draft
Changing the status of a patchset or a change requires the change to be
reindexed.
Change-Id: Ibf8e0b67f693fb996b0a628919b531a4828dd071
diff --git a/src/main/java/com/googlesource/gerrit/plugins/forcedraft/ForceDraft.java b/src/main/java/com/googlesource/gerrit/plugins/forcedraft/ForceDraft.java
index 88ac0d4..f0407db 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/forcedraft/ForceDraft.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/forcedraft/ForceDraft.java
@@ -22,6 +22,7 @@
import com.google.gerrit.reviewdb.client.PatchSet;
import com.google.gerrit.reviewdb.server.ReviewDb;
import com.google.gerrit.server.config.GerritServerConfig;
+import com.google.gerrit.server.index.ChangeIndexer;
import com.google.gerrit.sshd.CommandMetaData;
import com.google.gerrit.sshd.SshCommand;
import com.google.gerrit.common.data.GlobalCapability;
@@ -30,6 +31,8 @@
import com.google.inject.Inject;
import com.google.inject.Provider;
+import java.io.IOException;
+
@RequiresCapability(value = GlobalCapability.ADMINISTRATE_SERVER, scope = CapabilityScope.CORE)
@CommandMetaData(name = "force-draft", description = "changes patch set to draft")
public class ForceDraft extends SshCommand {
@@ -54,6 +57,9 @@
@Inject
private @GerritServerConfig Config config;
+ @Inject
+ private ChangeIndexer changeIndexer;
+
@Argument(index = 0, required = true, metaVar = "{CHANGE,PATCHSET}",
usage = "<change, patch set> to be changed to draft")
private void addPatchSetId(final String token) {
@@ -213,14 +219,15 @@
/**
* Updates PatchSet and, if applicable, parent Change.
*
- * @throws OrmException
+ * @throws OrmException if an error occur while updating the change in the DB.
+ * @throws IOException if an error occur while indexing the change.
*/
- private void updatePatchSet() throws OrmException {
+ private void updatePatchSet() throws OrmException, IOException {
Change.Status changeStatus = parentChange.getStatus();
switch (changeStatus) {
case NEW:
setPatchSetAsDraft();
- updateChange();
+ changeIndexer.index(dbProvider.get(), updateChange());
break;
default:
sendUserInfo("Unable to set patch set as draft, change is "