if (processDefinition == null || processInstance == null || !(processInstance instanceof ExecutionImpl)) return;
DbSession dbSession = EnvironmentImpl.getFromCurrent(DbSession.class);
HistoryProcessInstanceImpl historyProcessInstance = null;
long processInstanceDbid = ((ExecutionImpl)processInstance).getDbid();
historyProcessInstance = (HistoryProcessInstanceImpl)dbSession.get(HistoryProcessInstanceImpl.class, processInstanceDbid);
if (historyProcessInstance == null) return;
String oldVersion = historyProcessInstance.getProcessDefinitionId();
String newVersion = processDefinition.getId();
historyProcessInstance.setProcessDefinitionId(newVersion);
HistoryProcessInstanceMigrationImpl historyProcessInstanceMigration =
new HistoryProcessInstanceMigrationImpl(oldVersion, newVersion);
historyProcessInstance.addDetail(historyProcessInstanceMigration);
dbSession.save(historyProcessInstanceMigration);
}