Question

I want to use a console command from this bundle within my controller: http://knpbundles.com/dizda/CloudBackupBundle

The developer proposes cronjobs, however I want to use the command to backup my database from within my controller.

How would I do that? I am getting this error message when i simply try to register this command as a service:

You have requested a non-existent service "backupcommandservice". 

Thanks for the help!

Was it helpful?

Solution

commands don't quite work that way. Per the note on http://symfony.com/doc/current/cookbook/console/console_command.html#register-commands-in-the-service-container

registering a command as a service doesn't do much other than control location and dependency injection.

if you want to call a command: http://symfony.com/doc/current/components/console/introduction.html#calling-an-existing-command

that being said you shouldn't call commands from within a controller since you're basically asking to wait for this command to finish executing before you return a response. You'd be better off just sending a request to a queue box (for example beanstalk) and have a worker perform the job.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top