When you are working in the adminhtml backend of your module, this code returns the username of the currently logged in user:


What value would the above code return, when the magento cron is executing one of my controller method in my custom module? Will it say "cron" or something equivalent? Or will it be empty?


I haven't actually tested it but I don't believe it will return anything - you don't start an admin session running a cron job, unless part of the functionality of the cron job is to log an admin user in. Also worth noting is that the store scope when running a cron job is admin, unless you set it otherwise or use store emulation.

  • is there anything I can use to determine if in cron? like environment variables? etc... – Latheesan Oct 16 '14 at 11:30
  • If you need to run the same job via admin and via cron and need to determine a difference between the two, I would suggest doing something like set a registry value when the job runs via one method but not the other. Through admin it's probably going to be kicked off via a controller but from cron it will start at a model so you could say set a registry value in the controller and then check if this value exists wherever you need to. – Jonathan Hussey Oct 16 '14 at 11:47

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.