TIP: Use Markdown or, <pre> for multi line code blocks / <code> for inline code.
These forums are read-only and for archival purposes only!
Please join our new forums at discourse.kohanaframework.org
Sessions and CLI
  • Greetings,

    I was wondering if anyone out there has some thoughts on using sessions in Minion tasks (KO 3.3). Is this a good practice? I have an Abstract ORM model which looks into Session::instance()->get('admin') data. When creating / updating an ORM object, application stores in the database the user_id of the admin so I know who created/modified a given object. That's all nice and cool when using the admin interface via browser. I have few Minion tasks which also operate on some ORM models, but in such case the admin user id won't exist. How should I go about that? Is it good idea to look inside the session in the ORM model? Should I maybe set the current user somewhere else? Any thoughts would be greatly appreciated.

    Thanks, Z

  • Sounds like a perfect example when your code is coupled too much. Your ORM code should never have any knowledge about sessions. That's implementation stuff of your actual application. Keep your models clean so they're not tight to your www logic/app, so you can re-use them in any environment.

    Fast workaround: check if the session exists, store the info. If it does not exist, do not store.

  • Thanks mauserrifle - I ended up removing Session::instance() calls in models and added a special "session" array which is only initialized in the abstract controller (that way it's only set in the non "cli" sapi interface). Thanks!

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion