1

I have a CLI function that runs daily and a key part of its processing uses a Plugin to create a connection with an external source to retrieve data and it works fine when the Access Level on the Plugin is Public, or Guest, but not when it is Registered or above.

However the same Plugin is used by other parts of the website for the user to initiate the connection and it should not be visible to the public so it runs with an Access Level of Registered. And this is the conflict, it can't be both Public and Registered.

I think the solution is to make the CLI appear to be running as a logged in user or at least appear to be Registered so that the required Plugin is loaded but I haven't been able to find any examples or suggestions about how to achieve this.

Alternatively I wondered if there was a way to force a specific plugin to be loaded in the Dispatcher for my CLI.

Anyone seen something similar or can suggest how I might be able to get the Plugin to be loaded in my CLI environment?

It currently runs in Joomla 3 but I am preparing things to migrate to Joomla 4 so if there is an easier solution Joomla 4, like the new Scheduling feature, I might be able to delay fixing it until then.

2

There was a discussion a few years ago about that current access level implementation for plugins should be removed. Instead each plugin should handle authorization inside its code. As most important things in Joomla do, this discussion went nowhere. But you can implement access checks in your plugin anyways. This would be at a small performance cost since the plugin would be instantiated for all users.

2

The pure Joomla 4 cli plugins use a new architecture. There are several articles and a worked example available via the J4 Tutorials page: https://docs.joomla.org/JDOC:Joomla_4_Tutorials_Project

It may be worth your while having separate plugins for Web and Cli access. It can be tricky to set up - but I now have a plugin with related code doing 10 different jobs depending on the arguments passed in the cli command line.

2
  • Thanks for the comment. I am looking to develop my CLI's in the new Joomla 4 structure once I have moved from Joomla 3 and for now just do a work around for this particular issue.
    – Irata
    Nov 14 '21 at 21:28
  • @user wow, a member for almost 6 years and only just posting answers in 2021. Thank you for your courage to contribute. Please take the tour to get your Informed badge.
    – mickmackusa
    Nov 14 '21 at 23:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.