21
21
use APP \orcid \OrcidReview ;
22
22
use Carbon \Carbon ;
23
23
use GuzzleHttp \Exception \ClientException ;
24
+ use Illuminate \Contracts \Queue \ShouldBeUnique ;
24
25
use PKP \config \Config ;
25
26
use PKP \jobs \BaseJob ;
27
+ use PKP \jobs \orcid \SendUpdateScopeMail ;
28
+ use PKP \orcid \enums \OrcidDepositType ;
26
29
use PKP \orcid \OrcidManager ;
27
30
use PKP \submission \reviewAssignment \ReviewAssignment ;
28
31
29
- class DepositOrcidReview extends BaseJob
32
+ class DepositOrcidReview extends BaseJob implements ShouldBeUnique
30
33
{
31
34
public function __construct (
32
35
private int $ reviewAssignmentId
@@ -45,7 +48,7 @@ public function handle(): void
45
48
}
46
49
47
50
if (!in_array ($ reviewAssignment ->getStatus (), ReviewAssignment::REVIEW_COMPLETE_STATUSES )) {
48
- $ this -> fail ( ' Review assignment was not completed. ' ) ;
51
+ return ;
49
52
}
50
53
51
54
$ submission = Repo::submission ()->get ($ reviewAssignment ->getSubmissionId ());
@@ -56,7 +59,7 @@ public function handle(): void
56
59
$ this ->fail ('Application is set to sandbox mode and will not interact with the ORCID service ' );
57
60
}
58
61
59
- if (OrcidManager::isEnabled ($ context )) {
62
+ if (! OrcidManager::isEnabled ($ context )) {
60
63
return ;
61
64
}
62
65
@@ -71,6 +74,13 @@ public function handle(): void
71
74
$ reviewer = Repo::user ()->get ($ reviewAssignment ->getData ('reviewerId ' ));
72
75
73
76
if ($ reviewer ->getOrcid () && $ reviewer ->getData ('orcidAccessToken ' )) {
77
+ // Check user scope, if public API, stop here and request member scope
78
+ if ($ reviewer ->getData ('orcidAccessScope ' ) !== OrcidManager::ORCID_API_SCOPE_MEMBER ) {
79
+ // Request member scope and retry deposit
80
+ dispatch (new SendUpdateScopeMail ($ reviewer , $ context ->getId (), $ this ->reviewAssignmentId , OrcidDepositType::REVIEW ));
81
+ return ;
82
+ }
83
+
74
84
$ orcidAccessExpiresOn = Carbon::parse ($ reviewer ->getData ('orcidAccessExpiresOn ' ));
75
85
if ($ orcidAccessExpiresOn ->isFuture ()) {
76
86
# Extract only the ORCID from the stored ORCID uri
@@ -121,12 +131,17 @@ public function handle(): void
121
131
OrcidManager::logError ("Unexpected status {$ httpStatus } response, body: " . json_encode ($ responseHeaders ));
122
132
}
123
133
} catch (ClientException $ exception ) {
124
- $ reason = $ exception ->getResponse ()->getBody ();
134
+ $ reason = $ exception ->getResponse ()->getBody ()-> getContents () ;
125
135
OrcidManager::logError ("Publication fail: {$ reason }" );
126
136
127
137
$ this ->fail ($ exception );
128
138
}
129
139
}
130
140
}
131
141
}
142
+
143
+ public function uniqueId (): string
144
+ {
145
+ return (string ) $ this ->reviewAssignmentId ;
146
+ }
132
147
}
0 commit comments