2

I am using a cakephp3 plugin to manage a mail queue to send newsletter (Lorenzo Cakephp Email Queue). It works fine, but I need to use a Shell method with the bake command to send the newsletter. It is not a problem with a cron job, but I would like to be able to send test mail without waiting for the cron job. I tried to call the bake command with a php exec command, but it does not work (maybe a right problem ?) but I don't have access to the server to manage the rights. But, as the method and the controller are both in cakephp, I think it's weird to do it with a console (external) bake call...

Is there a way to call a Shell method from a Controller, which would be the "cleanest" and easiest way ?

Thanks all for you help !

wyllyjon
  • 505
  • 1
  • 5
  • 20

1 Answers1

0

which would be the "cleanest" and easiest way ?

A shell should be considered similar to a controller - controllers don't call controllers.

Consider putting the cli logic in a common place and have the cli and controller action call that, not each other. The relevant cli code is a few lines of code, but it's not actually doing anything complex, just looping on the emails to be sent, and sending them one by one.

I need to use a Shell method with the bake command to send the newsletter

Note that bake is a cli, it is not "the" cli, and forms no part of the runtime usage of that plugin.

bin/cake EmailQueue.sender -h

It may not work currently, because you're using the wrong cli commands to try and run it from your controller action - though it's not a very good idea/design to do it that way anyway.

AD7six
  • 63,116
  • 12
  • 91
  • 123
  • Thanks AD7six. Indeed, I talked about "bake", but I meant "cake". Finally, I succeeded using the php 'exec' command to launch the EmailQueue.sender : exec("/bin/bash ".Configure::read('App.paths.websiteRootPath')."/cms/bin/cake EmailQueue.sender", $result); – wyllyjon Jun 06 '16 at 12:24
  • `though it's not a very good idea/design to do it that way anyway` – AD7six Jun 06 '16 at 13:26
  • This is the way the plugin is made... And I took a plugin in order not to develop it myselft – wyllyjon Jun 06 '16 at 13:55