7K Views

Using Symfony Console Commands

Updated 18 November 2019

Facebook Linkedin

Symfony Console Commands

It can be used in a Symfony console application or in a web application. In symfony, Symfony Console component allows us to create commands.

It is basically used to perform such tasks which takes quite a long time, as from user point of view, once a user perform a batch job, expects the response asap. Also, it avoids Response Timeout.

Lets take an example:

Suppose, you want to remove a user from multiple tasks (say 5- 10 tasks) assigned to him. For this, we need to remove the user from task table as set user_id = null. It takes no time to update such small amount of rows. But what if we need to update 1000+ rows, that will take quite a long time for sure. In such scenario, we use Symfony Console Command, which updates the 1000+ rows in background and giving user response during execution.

Calling Command From Controller

This calls ‘uvdesk:ticket:unassign-discharged-agent 12345‘ command where 12345 is supposed user id.

 

Command

Commands are defined in classes extending Command. 

In below code, configure() is used to set name, description and argument passed to the command (say user_id) which is further used in execute() where main logic is implemented.

intialize() method is executed before the execute() method. Its main purpose is to initialise variables used in the rest of the command methods.

The above code executes in background untill it removes user_id from given 1000+ rows but success response is given earlier to the user.

I’ve explored this while contributing to Symfony based project UVdesk, there are a lot more things to learn and you could also contribute to an enterprise-level open source helpdesk.

Thanks for reading me. I hope this blog would help you with a better understanding of the Symfony Console Command. Please share your reviews on this, which will support me to write more.

Until next time. 👋

 

Category(s) Symfony UVdesk
. . .

Leave a Comment

Your email address will not be published. Required fields are marked*


2 comments

  • David
    Good morning.
    I have installed uvdesk in my shared hosting.
    How do I access the console?
    • Himani Gupta (Moderator)
      Hello there
      Hope you are doing great!!
      In order to run a community skeleton helpdesk you must have access for terminal, else you can create the SSH to run the commands.
      Thank you