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
299 stars 444 forks source link

Fix Open Access Notification #7186

Closed asmecher closed 1 year ago

asmecher commented 3 years ago

Past releases of OJS supported an open access notification, sent automatically (through scheduled tasks) and configured when in subscription mode through the enableOpenAccessNotification journal setting.

It checks for a user setting called openAccessNotification and only sends to users with this setting enabled.

However, at some point the ability to enable this setting was removed.

Review when this setting was removed, and fix the feature so that users can be automatically notified of submissions passing the open access threshold.

Vitaliy-1 commented 2 years ago

Saw these during email refactoring. I'm leaving the code as is for now as it's not working; among other things, it requires creating a new Mailable.

NateWr commented 1 year ago

@asmecher the last release that included this notification in the scheduled tasks list was OJS 2.4.8: https://github.com/pkp/ojs/blob/ojs-stable-2_4_8/registry/scheduledTasks.xml. Are you sure you want to restore this feature?

asmecher commented 1 year ago

There are still settings for this e.g. on the subscription policy form in OJS: image ...so the feature should either be removed or fixed. But it doesn't need to happen for 3.4, so I don't mind if this gets deferred.

NateWr commented 1 year ago

@Vitaliy-1 I've got this mostly implemented, but I'm running into an error when trying to add the unsubscribe footer to the mailable. I can't figure out what might be causing this. Have you ever run into this before? This is a low priority compared to your other 3.4 tasks, but when you clear your todo list can you look at this draft PR https://github.com/pkp/ojs/pull/3764?

It seems like the setupUnsubscribeFooter() method is not being found, even though I'm using the Unsubscribe trait. Here is the error message:

#0 lib/pkp/lib/vendor/laravel/framework/src/Illuminate/Mail/Mailable.php(1169): Illuminate\Mail\Mailable::throwBadMethodCallException()
#1 classes/mail/mailables/OpenAccessNotify.php(63): Illuminate\Mail\Mailable->__call()
#2 lib/pkp/classes/mail/Mailable.php(230): APP\mail\mailables\OpenAccessNotify->addFooter()
#3 lib/pkp/classes/mail/Mailer.php(117): PKP\mail\Mailable->setData()
#4 lib/pkp/lib/vendor/laravel/framework/src/Illuminate/Mail/MailManager.php(505): PKP\mail\Mailer->send()
#5 lib/pkp/lib/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php(337): Illuminate\Mail\MailManager->__call()
#6 jobs/notifications/OpenAccessMailUsers.php(82): Illuminate\Support\Facades\Facade::__callStatic()
#7 lib/pkp/lib/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(36): APP\jobs\notifications\OpenAccessMailUsers->handle()
#8 lib/pkp/lib/vendor/laravel/framework/src/Illuminate/Container/Util.php(41): Illuminate\Container\BoundMethod::Illuminate\Container\{closure}()
#9 lib/pkp/lib/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(93): Illuminate\Container\Util::unwrapIfClosure()
#10 lib/pkp/lib/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(37): Illuminate\Container\BoundMethod::callBoundMethod()
#11 lib/pkp/lib/vendor/laravel/framework/src/Illuminate/Container/Container.php(651): Illuminate\Container\BoundMethod::call()
#12 lib/pkp/lib/vendor/laravel/framework/src/Illuminate/Bus/Dispatcher.php(128): Illuminate\Container\Container->call()
#13 lib/pkp/lib/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(141): Illuminate\Bus\Dispatcher->Illuminate\Bus\{closure}()
#14 lib/pkp/lib/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(116): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#15 lib/pkp/lib/vendor/laravel/framework/src/Illuminate/Bus/Dispatcher.php(132): Illuminate\Pipeline\Pipeline->then()
#16 lib/pkp/lib/vendor/laravel/framework/src/Illuminate/Queue/CallQueuedHandler.php(123): Illuminate\Bus\Dispatcher->dispatchNow()
#17 lib/pkp/lib/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(141): Illuminate\Queue\CallQueuedHandler->Illuminate\Queue\{closure}()
#18 lib/pkp/lib/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(116): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#19 lib/pkp/lib/vendor/laravel/framework/src/Illuminate/Queue/CallQueuedHandler.php(125): Illuminate\Pipeline\Pipeline->then()
#20 lib/pkp/lib/vendor/laravel/framework/src/Illuminate/Queue/CallQueuedHandler.php(69): Illuminate\Queue\CallQueuedHandler->dispatchThroughMiddleware()
#21 lib/pkp/lib/vendor/laravel/framework/src/Illuminate/Queue/Jobs/Job.php(98): Illuminate\Queue\CallQueuedHandler->call()
#22 lib/pkp/lib/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(429): Illuminate\Queue\Jobs\Job->fire()
#23 lib/pkp/lib/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(379): Illuminate\Queue\Worker->process()
#24 lib/pkp/lib/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(330): Illuminate\Queue\Worker->runJob()
#25 lib/pkp/classes/core/PKPQueueProvider.php(105): Illuminate\Queue\Worker->runNextJob()
#26 lib/pkp/classes/task/ProcessQueueJobs.php(55): PKP\core\PKPQueueProvider->runJobInQueue()
#27 lib/pkp/classes/scheduledTask/ScheduledTask.php(165): PKP\task\ProcessQueueJobs->executeActions()
#28 lib/pkp/classes/cliTool/ScheduledTaskTool.php(126): PKP\scheduledTask\ScheduledTask->execute()
#29 lib/pkp/classes/cliTool/ScheduledTaskTool.php(103): PKP\cliTool\ScheduledTaskTool->executeTask()
#30 lib/pkp/classes/cliTool/ScheduledTaskTool.php(73): PKP\cliTool\ScheduledTaskTool->parseTasks()
#31 tools/runScheduledTasks.php(23): PKP\cliTool\ScheduledTaskTool->execute()
#32 {main}

The reproduction steps are a little complicated:

  1. Enable payments under Settings > Distribution > Payments.
  2. Go to the Payments page in the left-hand nav menu.
  3. Go to Subscription Policies.
  4. Enable "Open Access Options For Subscription Journals". (If you can't enable it, you need to set scheduled_tasks to On in your config.
  5. Go to Back Issues and edit a published issue.
  6. Go to the Access tab and set status to Subscription and the date to the current date.
  7. Delete any previous runs of the scheduled task with this sql command: delete from scheduled_tasks where class_name LIKE '%OpenAccessNotification%';
  8. Run the scheduled tasks: php tools/runScheduledTasks.php
Vitaliy-1 commented 1 year ago

I think there should be an error message in the failed jobs table with the failed method name, to be sure it's setupUnsubscribeFooter()

NateWr commented 1 year ago

Thanks @Vitaliy-1! That helped me track it down. Can you review this? I rearranged a few things to introduce an IssueEmailVariable, but otherwise the changes are smaller than they seem. The migration should block the email in the notification subscriptions for every user except those who subscribed in OJS 2.4.8.

PR: https://github.com/pkp/ojs/pull/3764

NateWr commented 1 year ago

@Vitaliy-1 I went ahead and merged to get this in before the locale file change this afternoon. But please do a review anyway and I can make fixes after RC1.