Use Joomla Framework via CLI Topic is solved

General questions relating to Joomla! 3.x.

Moderator: General Support Moderators

Forum rules
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting.
Forum Post Assistant - If you are serious about wanting help, you should use this tool to help you post.
Windows Defender SmartScreen Issues <-- please read this if using Windows 10
Post Reply
MichDam
Joomla! Fledgling
Joomla! Fledgling
Posts: 2
Joined: Wed Apr 14, 2021 5:05 pm

Use Joomla Framework via CLI

Post by MichDam » Wed Apr 14, 2021 5:19 pm

Hello there,

since I am getting more and more frustrated, I want to place my question down here:

Scenario:
- Joomla! CMS 3.9

My task is to write a scheduler, which is executing parts of our business logic at a certain time. The call into the Joomla-Project is done via CRON (CLI), which is calling my scheduler class, which then checks tasks from a config file and executes them, based on the specified time within the config.

My issue is to find out, how can I initialize or bootstrap the Joomla Framework, so I can interact with Joomla components such the database component or Joomla's internal consts or registering namespaces with Joomla and so on.

I have often heared, that Joomla is not very CLI friendly - maybe one of you guys has an idea or a way to initialize and access the Joomla Framework?

Thank you very much in advance!


Michele

User avatar
pe7er
Joomla! Master
Joomla! Master
Posts: 23064
Joined: Thu Aug 18, 2005 8:55 pm
Location: Nijmegen, Netherlands
Contact:

Re: Use Joomla Framework via CLI

Post by pe7er » Wed Apr 14, 2021 8:17 pm

MichDam wrote:
Wed Apr 14, 2021 5:19 pm
My issue is to find out, how can I initialize or bootstrap the Joomla Framework, so I can interact with Joomla components such the database component or Joomla's internal consts or registering namespaces with Joomla and so on.

I have often heared, that Joomla is not very CLI friendly - maybe one of you guys has an idea or a way to initialize and access the Joomla Framework?
Welcome to Joomla forum!

I don't know who is telling you that Joomla is not CLI friendly. I haven't heard that before and don't agree.

Two examples that load the framework in a CLI PHP script before doing something:
https://gist.github.com/renekreijveld/8823105
https://gist.github.com/pe7er/47bf1020b ... a80d1fdccd

Note that Joomla CLI scripts use the PHP CLI instance (version + modules) that can differ from the PHP instance that is used by the webserver.

PS: The future Joomla 4 has some very interesting CLI scipts included in the core that you can use to create users etc.
Kind Regards,
Peter Martin, Global Moderator
https://db8.nl - Joomla specialist, Nijmegen, Nederland
The best website: https://the-best-website.com

MichDam
Joomla! Fledgling
Joomla! Fledgling
Posts: 2
Joined: Wed Apr 14, 2021 5:05 pm

Re: Use Joomla Framework via CLI

Post by MichDam » Wed Apr 21, 2021 1:53 pm

pe7er wrote:
Wed Apr 14, 2021 8:17 pm
MichDam wrote:
Wed Apr 14, 2021 5:19 pm
My issue is to find out, how can I initialize or bootstrap the Joomla Framework, so I can interact with Joomla components such the database component or Joomla's internal consts or registering namespaces with Joomla and so on.

I have often heared, that Joomla is not very CLI friendly - maybe one of you guys has an idea or a way to initialize and access the Joomla Framework?
Welcome to Joomla forum!

I don't know who is telling you that Joomla is not CLI friendly. I haven't heard that before and don't agree.

Two examples that load the framework in a CLI PHP script before doing something:
https://gist.github.com/renekreijveld/8823105
https://gist.github.com/pe7er/47bf1020b ... a80d1fdccd

Note that Joomla CLI scripts use the PHP CLI instance (version + modules) that can differ from the PHP instance that is used by the webserver.

PS: The future Joomla 4 has some very interesting CLI scipts included in the core that you can use to create users etc.
Thank you Peter,

you and your provided links were a great help! I will officially take back my statement about Joomla CLI capabilities. :)

Greetings from Germany and stay healthy!


Michele

User avatar
pe7er
Joomla! Master
Joomla! Master
Posts: 23064
Joined: Thu Aug 18, 2005 8:55 pm
Location: Nijmegen, Netherlands
Contact:

Re: Use Joomla Framework via CLI

Post by pe7er » Wed Apr 21, 2021 3:00 pm

Thanks for your feedback. Good to hear that the links were helpful!
Kind Regards,
Peter Martin, Global Moderator
https://db8.nl - Joomla specialist, Nijmegen, Nederland
The best website: https://the-best-website.com


Post Reply

Return to “General Questions/New to Joomla! 3.x”