Merge branch 'stable-2.12' into stable-2.13
* stable-2.12:
Reindex the change after forcing patchset as draft
Change-Id: I94bd63c01056beb056f5ff8885071936b7619d24
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 fe8991c..1554c58 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.change.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,13 +219,14 @@
/**
* 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();
if (changeStatus == Change.Status.NEW) {
setPatchSetAsDraft();
- updateChange();
+ changeIndexer.index(dbProvider.get(), updateChange());
} else {
sendUserInfo("Unable to set patch set as draft, change is "
+ getStatusName(changeStatus));