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