diff --git a/openbas-api/src/main/java/io/openbas/migration/V3_34__Add_column_trigger_now.java b/openbas-api/src/main/java/io/openbas/migration/V3_34__Add_column_trigger_now.java index 0539e4226d..ebfb2e1145 100644 --- a/openbas-api/src/main/java/io/openbas/migration/V3_34__Add_column_trigger_now.java +++ b/openbas-api/src/main/java/io/openbas/migration/V3_34__Add_column_trigger_now.java @@ -12,6 +12,6 @@ public class V3_34__Add_column_trigger_now extends BaseJavaMigration { @Override public void migrate(Context context) throws Exception { Statement select = context.getConnection().createStatement(); - select.execute("ALTER TABLE injects ADD inject_trigger_now bool default false;"); + select.execute("ALTER TABLE injects ADD inject_trigger_now_date timestamp;"); } } diff --git a/openbas-api/src/main/java/io/openbas/rest/inject/InjectApi.java b/openbas-api/src/main/java/io/openbas/rest/inject/InjectApi.java index f72e0d9809..1974bfcc66 100644 --- a/openbas-api/src/main/java/io/openbas/rest/inject/InjectApi.java +++ b/openbas-api/src/main/java/io/openbas/rest/inject/InjectApi.java @@ -360,7 +360,7 @@ public Inject updateInjectTrigger( @PathVariable String exerciseId, @PathVariable String injectId) { Inject inject = injectRepository.findById(injectId).orElseThrow(ElementNotFoundException::new); - inject.setTriggerNow(true); + inject.setTriggerNowDate(now()); inject.setUpdatedAt(now()); return injectRepository.save(inject); } diff --git a/openbas-model/src/main/java/io/openbas/database/model/Inject.java b/openbas-model/src/main/java/io/openbas/database/model/Inject.java index f4755876ce..88c3df75bc 100644 --- a/openbas-model/src/main/java/io/openbas/database/model/Inject.java +++ b/openbas-model/src/main/java/io/openbas/database/model/Inject.java @@ -80,9 +80,9 @@ public class Inject implements Base, Injection { private boolean enabled = true; @Getter - @Column(name = "inject_trigger_now") - @JsonProperty("inject_trigger_now") - private boolean triggerNow; + @Column(name = "inject_trigger_now_date") + @JsonProperty("inject_trigger_now_date") + private Instant triggerNowDate; @Getter @Column(name = "inject_content") @@ -284,10 +284,12 @@ public Instant computeInjectDate(Instant source, int speed) { @JsonProperty("inject_date") public Optional getDate() { - // If a trigger now was executed for this inject, we ignore pauses and we set inject inside of a range of execution - if (this.triggerNow) { - this.triggerNow = false; - return Optional.of(now().minusSeconds(30)); + // If a trigger now was executed for this inject linked to an exercise, we ignore pauses and we set inject inside of a range of execution + if(getExercise() != null && triggerNowDate != null ) { + Optional exerciseStartOpt = getExercise().getStart(); + if (exerciseStartOpt.isPresent() && (exerciseStartOpt.get().equals(triggerNowDate) || exerciseStartOpt.get().isBefore(triggerNowDate))) { + return Optional.of(now().minusSeconds(60)); + } } return InjectModelHelper.getDate(getExercise(), getScenario(), getDependsOn(), getDependsDuration()); }