22
22
use APP \notification \Notification ;
23
23
use APP \notification \NotificationManager ;
24
24
use APP \submission \Submission ;
25
+ use Carbon \Carbon ;
25
26
use Illuminate \Support \Facades \Mail ;
26
27
use PKP \context \Context ;
27
28
use PKP \db \DAORegistry ;
32
33
use PKP \notification \PKPNotification ;
33
34
use PKP \submission \reviewRound \ReviewRound ;
34
35
use PKP \submission \reviewRound \ReviewRoundDAO ;
36
+ use PKP \security \Role ;
35
37
use PKP \user \User ;
36
38
use PKP \workflow \WorkflowStageDAO ;
37
39
@@ -53,14 +55,24 @@ public function __construct(int $editorId, int $contextId)
53
55
*/
54
56
public function handle (): void
55
57
{
56
- if (!$ this ->isSubscribed ()) {
57
- return ;
58
- }
59
-
60
58
/** @var Context $context */
61
59
$ context = Services::get ('context ' )->get ($ this ->contextId );
62
60
$ editor = Repo::user ()->get ($ this ->editorId );
63
61
62
+ // Context or user was removed since job was created, or the user was disabled
63
+ if (!$ context || !$ editor ) {
64
+ return ;
65
+ }
66
+
67
+ // If the user has been removed form manager or editor role since the job was created
68
+ if (!$ editor ->hasRole ([Role::ROLE_ID_MANAGER , Role::ROLE_ID_SUB_EDITOR ], $ context ->getId ())) {
69
+ return ;
70
+ }
71
+
72
+ if (!$ this ->isSubscribed ()) {
73
+ return ;
74
+ }
75
+
64
76
// Don't use the request locale because this job is
65
77
// run during a scheduled task
66
78
$ requestLocale = Locale::getLocale ();
@@ -88,34 +100,45 @@ public function handle(): void
88
100
}
89
101
90
102
if (in_array ($ submission ->getData ('stageId ' ), [WORKFLOW_STAGE_ID_INTERNAL_REVIEW , WORKFLOW_STAGE_ID_EXTERNAL_REVIEW ])) {
91
- /** @var ReviewRoundDAO $reviewRoundDao */
92
- $ reviewRoundDao = DAORegistry::getDAO ('ReviewRoundDAO ' );
103
+ $ reviewRoundDao = DAORegistry::getDAO ('ReviewRoundDAO ' ); /** @var ReviewRoundDAO $reviewRoundDao */
93
104
$ reviewRound = $ reviewRoundDao ->getLastReviewRoundBySubmissionId ($ submission ->getId (), $ submission ->getData ('stageId ' ));
105
+ $ status = $ reviewRound ->determineStatus ();
94
106
95
- if ($ reviewRound -> getStatus () === ReviewRound::REVIEW_ROUND_STATUS_PENDING_REVIEWERS ) {
107
+ if ($ status === ReviewRound::REVIEW_ROUND_STATUS_PENDING_REVIEWERS ) {
96
108
$ outstanding [$ submissionId ] = __ ('editor.submission.roundStatus.pendingReviewers ' );
97
109
continue ;
98
110
}
99
111
100
- if ($ reviewRound ->getStatus () === ReviewRound::REVIEW_ROUND_STATUS_REVIEWS_COMPLETED ) {
112
+ if ($ status === ReviewRound::REVIEW_ROUND_STATUS_PENDING_REVIEWS ) {
113
+ $ outstanding [$ submissionId ] = __ ('editor.submission.roundStatus.pendingReviews ' );
114
+ continue ;
115
+ }
116
+
117
+ if ($ status === ReviewRound::REVIEW_ROUND_STATUS_REVIEWS_READY ) {
118
+ $ outstanding [$ submissionId ] = __ ('editor.submission.roundStatus.reviewsReady ' );
119
+ continue ;
120
+ }
121
+
122
+ if ($ status === ReviewRound::REVIEW_ROUND_STATUS_REVIEWS_COMPLETED ) {
101
123
$ outstanding [$ submissionId ] = __ ('editor.submission.roundStatus.reviewsCompleted ' );
102
124
continue ;
103
125
}
104
126
105
- if ($ reviewRound -> getStatus () === ReviewRound::REVIEW_ROUND_STATUS_REVIEWS_OVERDUE ) {
127
+ if ($ status === ReviewRound::REVIEW_ROUND_STATUS_REVIEWS_OVERDUE ) {
106
128
$ outstanding [$ submissionId ] = __ ('editor.submission.roundStatus.reviewOverdue ' );
107
129
continue ;
108
130
}
109
131
110
- if ($ reviewRound -> getStatus () === ReviewRound::REVIEW_ROUND_STATUS_REVISIONS_SUBMITTED ) {
132
+ if ($ status === ReviewRound::REVIEW_ROUND_STATUS_REVISIONS_SUBMITTED ) {
111
133
$ outstanding [$ submissionId ] = __ ('editor.submission.roundStatus.revisionsSubmitted ' );
112
134
continue ;
113
135
}
114
136
}
115
137
116
138
if (in_array ($ submission ->getData ('stageId ' ), [WORKFLOW_STAGE_ID_EDITING , WORKFLOW_STAGE_ID_PRODUCTION ])) {
117
- $ lastActivityTimestamp = strtotime ($ submission ->getData ('dateLastActivity ' ));
118
- if ($ lastActivityTimestamp < strtotime ('-30 days ' )) {
139
+ $ lastActivityTimestamp = Carbon::parse ($ submission ->getData ('dateLastActivity ' ))->endOfDay ();
140
+ $ comparingTimestamp = Carbon::today ()->endOfDay ()->subDays (30 );
141
+ if ($ comparingTimestamp ->gt ($ lastActivityTimestamp )) {
119
142
/** @var WorkflowStageDAO $workflowStageDao */
120
143
$ workflowStageDao = DAORegistry::getDAO ('WorkflowStageDAO ' );
121
144
$ outstanding [$ submissionId ] = __ (
@@ -137,11 +160,6 @@ public function handle(): void
137
160
return ;
138
161
}
139
162
140
- // Context or user was removed since job was created, or the user was disabled
141
- if (!$ context || !$ editor ) {
142
- return ;
143
- }
144
-
145
163
$ notificationManager = new NotificationManager ();
146
164
$ notification = $ notificationManager ->createNotification (
147
165
Application::get ()->getRequest (),
@@ -168,13 +186,18 @@ public function handle(): void
168
186
}
169
187
170
188
/**
171
- * Is this editor subscribed to this email?
189
+ * Is this editor subscribed to this email notification type ?
172
190
*/
173
191
protected function isSubscribed (): bool
174
192
{
175
193
/** @var NotificationSubscriptionSettingsDAO $notificationSubscriptionSettingsDao */
176
194
$ notificationSubscriptionSettingsDao = DAORegistry::getDAO ('NotificationSubscriptionSettingsDAO ' );
177
- $ blockedEmails = $ notificationSubscriptionSettingsDao ->getNotificationSubscriptionSettings ('blocked_emailed_notification ' , $ this ->editorId , $ this ->contextId );
195
+ $ blockedEmails = $ notificationSubscriptionSettingsDao ->getNotificationSubscriptionSettings (
196
+ NotificationSubscriptionSettingsDAO::BLOCKED_EMAIL_NOTIFICATION_KEY ,
197
+ $ this ->editorId ,
198
+ $ this ->contextId
199
+ );
200
+
178
201
return !in_array (Notification::NOTIFICATION_TYPE_EDITORIAL_REMINDER , $ blockedEmails );
179
202
}
180
203
0 commit comments