Skip to content

Commit 2cecb29

Browse files
authored
Add option to reset last notification time (#136)
* Add option to reset last notification time #122 * Renamed debug options to testing options
1 parent ed5b62b commit 2cecb29

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

modules/localgov_workflows_notifications/src/Form/LocalgovWorkflowsNotificationsSettingsForm.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,23 @@ public function buildForm(array $form, FormStateInterface $form_state): array {
7979
'#default_value' => $this->config('localgov_workflows_notifications.settings')->get('email_frequency') ?? 1,
8080
];
8181

82+
$form['test_options'] = [
83+
'#type' => 'details',
84+
'#title' => $this->t('Testing options'),
85+
'#open' => FALSE,
86+
];
87+
$form['test_options']['reset_help'] = [
88+
'#type' => 'item',
89+
'#markup' => $this->t('<p>Last run time: @time</p><p>Resetting the last run time will force notifications to be sent for all content needing review. This is useful when testing email notifications.</p>', [
90+
'@time' => $this->timer->getLastRun() ? date('F j Y, g:ia', $this->timer->getLastRun()) : $this->t('Never'),
91+
]),
92+
];
93+
$form['test_options']['reset_last_run'] = [
94+
'#type' => 'submit',
95+
'#value' => $this->t('Rest last run time'),
96+
'#submit' => ['::resetLastRun'],
97+
];
98+
8299
return parent::buildForm($form, $form_state);
83100
}
84101

@@ -102,4 +119,11 @@ public function submitForm(array &$form, FormStateInterface $form_state): void {
102119
parent::submitForm($form, $form_state);
103120
}
104121

122+
/**
123+
* Reset last run time submit handler.
124+
*/
125+
public function resetLastRun(array &$form, FormStateInterface $form_state): void {
126+
$this->timer->reset();
127+
}
128+
105129
}

modules/localgov_workflows_notifications/src/NotificationTimer.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,13 @@ public function getLastRun(): ?int {
4949
return $this->state->get(self::LAST_RUN);
5050
}
5151

52+
/**
53+
* {@inheritdoc}
54+
*/
55+
public function reset(): void {
56+
$this->state->set(self::LAST_RUN, 0);
57+
}
58+
5259
/**
5360
* {@inheritdoc}
5461
*/

modules/localgov_workflows_notifications/src/NotificationTimerInterface.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ interface NotificationTimerInterface {
2222
*/
2323
public function getLastRun(): ?int;
2424

25+
/**
26+
* Reset the notification timer.
27+
*/
28+
public function reset(): void;
29+
2530
/**
2631
* Update the notification timer.
2732
*/

0 commit comments

Comments
 (0)