pkp / pkp-lib

The library used by PKP's applications OJS, OMP and OPS, open source software for scholarly publishing.
https://pkp.sfu.ca
GNU General Public License v3.0
306 stars 445 forks source link

Unable to add new email template to a mailable #8585

Closed Vitaliy-1 closed 1 year ago

Vitaliy-1 commented 1 year ago

Describe the bug In a new Mailables UI, when trying to add a new email template to any mailable receiving a fatal error:

Type: TypeError
Message: PKP\emailTemplate\Repository::PKP\emailTemplate\{closure}(): Argument #1 ($mailable) must be of type array, string given, called in /Users/vitalii/Documents/development/ojs-main/ojs/lib/pkp/lib/vendor/laravel/framework/src/Illuminate/Collections/Arr.php on line 201
File: /Users/vitalii/Documents/development/ojs-main/ojs/lib/pkp/classes/emailTemplate/Repository.php
Line: 119
Trace: #0 /Users/vitalii/Documents/development/ojs-main/ojs/lib/pkp/lib/vendor/laravel/framework/src/Illuminate/Collections/Arr.php(201): PKP\emailTemplate\Repository->PKP\emailTemplate\{closure}('PKP\\mail\\mailab...', 0)
#1 /Users/vitalii/Documents/development/ojs-main/ojs/lib/pkp/lib/vendor/laravel/framework/src/Illuminate/Collections/Collection.php(385): Illuminate\Support\Arr::first(Array, Object(Closure), Object(stdClass))
#2 /Users/vitalii/Documents/development/ojs-main/ojs/lib/pkp/lib/vendor/laravel/framework/src/Illuminate/Collections/Collection.php(177): Illuminate\Support\Collection->first(Object(Closure), Object(stdClass))
#3 /Users/vitalii/Documents/development/ojs-main/ojs/lib/pkp/classes/emailTemplate/Repository.php(119): Illuminate\Support\Collection->contains(Object(Closure))
#4 /Users/vitalii/Documents/development/ojs-main/ojs/lib/pkp/lib/vendor/laravel/framework/src/Illuminate/Validation/Validator.php(384): PKP\emailTemplate\Repository->PKP\emailTemplate\{closure}(Object(Illuminate\Validation\Validator))
#5 /Users/vitalii/Documents/development/ojs-main/ojs/lib/pkp/lib/vendor/laravel/framework/src/Illuminate/Validation/Validator.php(433): Illuminate\Validation\Validator->Illuminate\Validation\{closure}()
#6 /Users/vitalii/Documents/development/ojs-main/ojs/lib/pkp/lib/vendor/laravel/framework/src/Illuminate/Validation/Validator.php(446): Illuminate\Validation\Validator->passes()
#7 /Users/vitalii/Documents/development/ojs-main/ojs/lib/pkp/classes/emailTemplate/Repository.php(130): Illuminate\Validation\Validator->fails()
#8 /Users/vitalii/Documents/development/ojs-main/ojs/lib/pkp/api/v1/emailTemplates/PKPEmailTemplateHandler.php(184): PKP\emailTemplate\Repository->validate(NULL, Array, Object(APP\journal\Journal))
#9 [internal function]: PKP\API\v1\emailTemplates\PKPEmailTemplateHandler->add(Object(Slim\Http\Request), Object(PKP\core\APIResponse), Array)
#10 /Users/vitalii/Documents/development/ojs-main/ojs/lib/pkp/lib/vendor/slim/slim/Slim/Handlers/Strategies/RequestResponse.php(40): call_user_func(Array, Object(Slim\Http\Request), Object(PKP\core\APIResponse), Array)
#11 /Users/vitalii/Documents/development/ojs-main/ojs/lib/pkp/lib/vendor/slim/slim/Slim/Route.php(281): Slim\Handlers\Strategies\RequestResponse->__invoke(Array, Object(Slim\Http\Request), Object(PKP\core\APIResponse), Array)
#12 /Users/vitalii/Documents/development/ojs-main/ojs/lib/pkp/lib/vendor/slim/slim/Slim/MiddlewareAwareTrait.php(117): Slim\Route->__invoke(Object(Slim\Http\Request), Object(PKP\core\APIResponse))
#13 /Users/vitalii/Documents/development/ojs-main/ojs/lib/pkp/lib/vendor/slim/slim/Slim/Route.php(268): Slim\Route->callMiddlewareStack(Object(Slim\Http\Request), Object(PKP\core\APIResponse))
#14 /Users/vitalii/Documents/development/ojs-main/ojs/lib/pkp/lib/vendor/slim/slim/Slim/App.php(503): Slim\Route->run(Object(Slim\Http\Request), Object(PKP\core\APIResponse))
#15 /Users/vitalii/Documents/development/ojs-main/ojs/lib/pkp/classes/security/authorization/internal/ApiAuthorizationMiddleware.php(87): Slim\App->__invoke(Object(Slim\Http\Request), Object(PKP\core\APIResponse))
#16 [internal function]: PKP\security\authorization\internal\ApiAuthorizationMiddleware->__invoke(Object(Slim\Http\Request), Object(PKP\core\APIResponse), Object(Slim\App))
#17 /Users/vitalii/Documents/development/ojs-main/ojs/lib/pkp/lib/vendor/slim/slim/Slim/DeferredCallable.php(57): call_user_func_array(Object(PKP\security\authorization\internal\ApiAuthorizationMiddleware), Array)
#18 [internal function]: Slim\DeferredCallable->__invoke(Object(Slim\Http\Request), Object(PKP\core\APIResponse), Object(Slim\App))
#19 /Users/vitalii/Documents/development/ojs-main/ojs/lib/pkp/lib/vendor/slim/slim/Slim/MiddlewareAwareTrait.php(70): call_user_func(Object(Slim\DeferredCallable), Object(Slim\Http\Request), Object(PKP\core\APIResponse), Object(Slim\App))
#20 /Users/vitalii/Documents/development/ojs-main/ojs/lib/pkp/classes/security/authorization/internal/ApiCsrfMiddleware.php(54): Slim\App->Slim\{closure}(Object(Slim\Http\Request), Object(PKP\core\APIResponse))
#21 [internal function]: PKP\security\authorization\internal\ApiCsrfMiddleware->__invoke(Object(Slim\Http\Request), Object(PKP\core\APIResponse), Object(Closure))
#22 /Users/vitalii/Documents/development/ojs-main/ojs/lib/pkp/lib/vendor/slim/slim/Slim/DeferredCallable.php(57): call_user_func_array(Object(PKP\security\authorization\internal\ApiCsrfMiddleware), Array)
#23 [internal function]: Slim\DeferredCallable->__invoke(Object(Slim\Http\Request), Object(PKP\core\APIResponse), Object(Closure))
#24 /Users/vitalii/Documents/development/ojs-main/ojs/lib/pkp/lib/vendor/slim/slim/Slim/MiddlewareAwareTrait.php(70): call_user_func(Object(Slim\DeferredCallable), Object(Slim\Http\Request), Object(PKP\core\APIResponse), Object(Closure))
#25 /Users/vitalii/Documents/development/ojs-main/ojs/lib/pkp/classes/security/authorization/internal/ApiTokenDecodingMiddleware.php(141): Slim\App->Slim\{closure}(Object(Slim\Http\Request), Object(PKP\core\APIResponse))
#26 [internal function]: PKP\security\authorization\internal\ApiTokenDecodingMiddleware->__invoke(Object(Slim\Http\Request), Object(PKP\core\APIResponse), Object(Closure))
#27 /Users/vitalii/Documents/development/ojs-main/ojs/lib/pkp/lib/vendor/slim/slim/Slim/DeferredCallable.php(57): call_user_func_array(Object(PKP\security\authorization\internal\ApiTokenDecodingMiddleware), Array)
#28 [internal function]: Slim\DeferredCallable->__invoke(Object(Slim\Http\Request), Object(PKP\core\APIResponse), Object(Closure))
#29 /Users/vitalii/Documents/development/ojs-main/ojs/lib/pkp/lib/vendor/slim/slim/Slim/MiddlewareAwareTrait.php(70): call_user_func(Object(Slim\DeferredCallable), Object(Slim\Http\Request), Object(PKP\core\APIResponse), Object(Closure))
#30 /Users/vitalii/Documents/development/ojs-main/ojs/lib/pkp/classes/handler/APIHandler.php(78): Slim\App->Slim\{closure}(Object(Slim\Http\Request), Object(PKP\core\APIResponse))
#31 [internal function]: PKP\handler\APIHandler->PKP\handler\{closure}(Object(Slim\Http\Request), Object(PKP\core\APIResponse), Object(Closure))
#32 /Users/vitalii/Documents/development/ojs-main/ojs/lib/pkp/lib/vendor/slim/slim/Slim/DeferredCallable.php(57): call_user_func_array(Object(Closure), Array)
#33 [internal function]: Slim\DeferredCallable->__invoke(Object(Slim\Http\Request), Object(PKP\core\APIResponse), Object(Closure))
#34 /Users/vitalii/Documents/development/ojs-main/ojs/lib/pkp/lib/vendor/slim/slim/Slim/MiddlewareAwareTrait.php(70): call_user_func(Object(Slim\DeferredCallable), Object(Slim\Http\Request), Object(PKP\core\APIResponse), Object(Closure))
#35 /Users/vitalii/Documents/development/ojs-main/ojs/lib/pkp/classes/handler/APIHandler.php(137): Slim\App->Slim\{closure}(Object(Slim\Http\Request), Object(PKP\core\APIResponse))
#36 [internal function]: PKP\handler\APIHandler->PKP\handler\{closure}(Object(Slim\Http\Request), Object(PKP\core\APIResponse), Object(Closure))
#37 /Users/vitalii/Documents/development/ojs-main/ojs/lib/pkp/lib/vendor/slim/slim/Slim/DeferredCallable.php(57): call_user_func_array(Object(Closure), Array)
#38 [internal function]: Slim\DeferredCallable->__invoke(Object(Slim\Http\Request), Object(PKP\core\APIResponse), Object(Closure))
#39 /Users/vitalii/Documents/development/ojs-main/ojs/lib/pkp/lib/vendor/slim/slim/Slim/MiddlewareAwareTrait.php(70): call_user_func(Object(Slim\DeferredCallable), Object(Slim\Http\Request), Object(PKP\core\APIResponse), Object(Closure))
#40 /Users/vitalii/Documents/development/ojs-main/ojs/lib/pkp/classes/handler/APIHandler.php(142): Slim\App->Slim\{closure}(Object(Slim\Http\Request), Object(PKP\core\APIResponse))
#41 [internal function]: PKP\handler\APIHandler->PKP\handler\{closure}(Object(Slim\Http\Request), Object(PKP\core\APIResponse), Object(Closure))
#42 /Users/vitalii/Documents/development/ojs-main/ojs/lib/pkp/lib/vendor/slim/slim/Slim/DeferredCallable.php(57): call_user_func_array(Object(Closure), Array)
#43 [internal function]: Slim\DeferredCallable->__invoke(Object(Slim\Http\Request), Object(PKP\core\APIResponse), Object(Closure))
#44 /Users/vitalii/Documents/development/ojs-main/ojs/lib/pkp/lib/vendor/slim/slim/Slim/MiddlewareAwareTrait.php(70): call_user_func(Object(Slim\DeferredCallable), Object(Slim\Http\Request), Object(PKP\core\APIResponse), Object(Closure))
#45 /Users/vitalii/Documents/development/ojs-main/ojs/lib/pkp/lib/vendor/slim/slim/Slim/MiddlewareAwareTrait.php(117): Slim\App->Slim\{closure}(Object(Slim\Http\Request), Object(PKP\core\APIResponse))
#46 /Users/vitalii/Documents/development/ojs-main/ojs/lib/pkp/lib/vendor/slim/slim/Slim/App.php(392): Slim\App->callMiddlewareStack(Object(Slim\Http\Request), Object(PKP\core\APIResponse))
#47 /Users/vitalii/Documents/development/ojs-main/ojs/lib/pkp/classes/handler/APIHandler.php(134): Slim\App->process(Object(Slim\Http\Request), Object(PKP\core\APIResponse))
#48 [internal function]: PKP\handler\APIHandler->PKP\handler\{closure}(Object(Slim\Http\Request), Object(PKP\core\APIResponse), Object(Closure))
#49 /Users/vitalii/Documents/development/ojs-main/ojs/lib/pkp/lib/vendor/slim/slim/Slim/DeferredCallable.php(57): call_user_func_array(Object(Closure), Array)
#50 [internal function]: Slim\DeferredCallable->__invoke(Object(Slim\Http\Request), Object(PKP\core\APIResponse), Object(Closure))
#51 /Users/vitalii/Documents/development/ojs-main/ojs/lib/pkp/lib/vendor/slim/slim/Slim/MiddlewareAwareTrait.php(70): call_user_func(Object(Slim\DeferredCallable), Object(Slim\Http\Request), Object(PKP\core\APIResponse), Object(Closure))
#52 /Users/vitalii/Documents/development/ojs-main/ojs/lib/pkp/classes/handler/APIHandler.php(142): Slim\App->Slim\{closure}(Object(Slim\Http\Request), Object(PKP\core\APIResponse))
#53 [internal function]: PKP\handler\APIHandler->PKP\handler\{closure}(Object(Slim\Http\Request), Object(PKP\core\APIResponse), Object(Closure))
#54 /Users/vitalii/Documents/development/ojs-main/ojs/lib/pkp/lib/vendor/slim/slim/Slim/DeferredCallable.php(57): call_user_func_array(Object(Closure), Array)
#55 [internal function]: Slim\DeferredCallable->__invoke(Object(Slim\Http\Request), Object(PKP\core\APIResponse), Object(Closure))
#56 /Users/vitalii/Documents/development/ojs-main/ojs/lib/pkp/lib/vendor/slim/slim/Slim/MiddlewareAwareTrait.php(70): call_user_func(Object(Slim\DeferredCallable), Object(Slim\Http\Request), Object(PKP\core\APIResponse), Object(Closure))
#57 /Users/vitalii/Documents/development/ojs-main/ojs/lib/pkp/lib/vendor/slim/slim/Slim/MiddlewareAwareTrait.php(117): Slim\App->Slim\{closure}(Object(Slim\Http\Request), Object(PKP\core\APIResponse))
#58 /Users/vitalii/Documents/development/ojs-main/ojs/lib/pkp/lib/vendor/slim/slim/Slim/App.php(392): Slim\App->callMiddlewareStack(Object(Slim\Http\Request), Object(PKP\core\APIResponse))
#59 /Users/vitalii/Documents/development/ojs-main/ojs/lib/pkp/lib/vendor/slim/slim/Slim/App.php(297): Slim\App->process(Object(Slim\Http\Request), Object(PKP\core\APIResponse))
#60 /Users/vitalii/Documents/development/ojs-main/ojs/lib/pkp/classes/core/APIRouter.php(127): Slim\App->run()
#61 /Users/vitalii/Documents/development/ojs-main/ojs/lib/pkp/classes/core/Dispatcher.php(163): PKP\core\APIRouter->route(Object(APP\core\Request))
#62 /Users/vitalii/Documents/development/ojs-main/ojs/lib/pkp/classes/core/PKPApplication.php(379): PKP\core\Dispatcher->dispatch(Object(APP\core\Request))
#63 /Users/vitalii/Documents/development/ojs-main/ojs/index.php(21): PKP\core\PKPApplication->execute()
#64 {main}

To Reproduce Steps to reproduce the behavior:

  1. Go to Workflow settings -> emails
  2. Click on add and edit templates link
  3. Click on Edit any mailable, e.g., Discussion (Copyediting)
  4. Click on Add Template
  5. Fill the edit template form and click save
  6. See the error

What application are you using? OJS main branch

Additional information emailTemplate

NateWr commented 1 year ago

One step missing in your repro steps: after step 3, do you add a new template or edit an existing one? Can you add that in and I'll take a look soon?

Vitaliy-1 commented 1 year ago

Sorry, it's add a new template

NateWr commented 1 year ago

I committed the fix directly to main: https://github.com/pkp/pkp-lib/commit/4a259627f14a980a86eeab020e55ed801e15b60b.