1313 * @brief Manage callback functions to register works in Thoth
1414 */
1515
16+ use ThothApi \Exception \QueryException ;
17+
1618import ('plugins.generic.thoth.classes.facades.ThothService ' );
1719import ('plugins.generic.thoth.classes.ThothValidator ' );
1820
@@ -51,12 +53,14 @@ public function addThothField($hookName, $form)
5153 $ errors = [];
5254
5355 try {
54- $ thothClient = $ this ->plugin ->getThothClient ($ submission ->getData ('contextId ' ));
55- $ publishers = $ thothClient ->linkedPublishers ();
56+ $ thothClient = ThothContainer::getInstance ()->get ('client ' );
57+ $ thothAccountDetails = $ thothClient ->accountDetails ();
58+ $ publishers = $ thothAccountDetails ['resourceAccess ' ]['linkedPublishers ' ];
59+
5660 $ imprints = $ thothClient ->imprints (['publishers ' => array_column ($ publishers , 'publisherId ' )]);
57- } catch (ThothException $ e ) {
61+ } catch (QueryException $ e ) {
5862 $ errors [] = __ ('plugins.generic.thoth.connectionError ' );
59- error_log ($ e ->getMessage ());
63+ error_log (' Failed to send the request to Thoth: ' . $ e ->getMessage ());
6064 }
6165
6266 if (empty ($ errors )) {
@@ -83,8 +87,8 @@ public function addThothField($hookName, $form)
8387 $ imprintOptions = [];
8488 foreach ($ imprints as $ imprint ) {
8589 $ imprintOptions [] = [
86- 'value ' => $ imprint[ ' imprintId ' ] ,
87- 'label ' => $ imprint[ ' imprintName ' ]
90+ 'value ' => $ imprint-> getImprintId () ,
91+ 'label ' => $ imprint-> getImprintName ()
8892 ];
8993 }
9094
@@ -102,7 +106,7 @@ public function addThothField($hookName, $form)
102106 'required ' => true ,
103107 'showWhen ' => 'registerConfirmation ' ,
104108 'groupId ' => 'default ' ,
105- 'value ' => $ imprints [0 ]['imprintId ' ] ?? null
109+ 'value ' => $ imprintOptions [0 ]['value ' ] ?? null
106110 ]));
107111
108112 return false ;
@@ -187,11 +191,10 @@ public function registerWork($submission, $imprint)
187191 }
188192
189193 try {
190- $ thothClient = $ this ->plugin ->getThothClient ($ submissionContext ->getId ());
191- $ thothBook = ThothService::work ()->registerBook ($ thothClient , $ submission , $ imprint );
194+ $ thothBook = ThothService::work ()->registerBook ($ submission , $ imprint );
192195 $ submission = Services::get ('submission ' )->edit (
193196 $ submission ,
194- ['thothWorkId ' => $ thothBook ->getId ()],
197+ ['thothWorkId ' => $ thothBook ->getWorkId ()],
195198 $ request
196199 );
197200
@@ -201,14 +204,14 @@ public function registerWork($submission, $imprint)
201204 NOTIFICATION_TYPE_SUCCESS ,
202205 'plugins.generic.thoth.register.success '
203206 );
204- } catch (ThothException $ e ) {
205- error_log ($ e ->getMessage ());
207+ } catch (QueryException $ e ) {
208+ error_log (' Failed to send the request to Thoth: ' . $ e ->getMessage ());
206209 ThothNotification::notify (
207210 $ request ,
208211 $ submission ,
209212 NOTIFICATION_TYPE_ERROR ,
210213 'plugins.generic.thoth.register.error ' ,
211- $ e ->getError ()
214+ $ e ->getMessage ()
212215 );
213216 }
214217 }
0 commit comments