Sébastien,

I've run into some issues with batch files and I've managed to iron
out most wrinkles, so here are my notes:

Symfony offers a front controller for batch files.  Make sure Symfony
is up to date, then check your factories.yml and make sure you have:

cli:
  controller:
    class: sfConsoleController
  request:
    class: sfConsoleRequest
  response:
    class: sfConsoleResponse

To use these classes, in your batch file you must have:

define('SF_ENVIRONMENT', 'cli');

Do you really need security enabled for batch files?  Probably not, so
in your settings.yml put:

cli:
  .settings:
    use_security: off

Now when you want to call an action, don't use
sfContext::getInstance()->getController()->forward('myModule',
'myAction');  Instead use:

sfContext::getInstance()->getController()->dispatch('myModule',
'myAction');

You can also send the action request parameters:

sfContext::getInstance()->getController()->dispatch('myModule',
'myAction', array('param'=>'test'));

As suggested by others, you should refactor your code, but you can
still keep it in modules with actions, instead of static class
methods.  In this case a layout won't be required, so in your myModule
view.yml you will need:

all:
  has_layout: off

In my testing, I have discovered that http headers are still sent by
the rendering filter, but the method doesn't exist in the
sfConsoleClass (as it shouldn't).  There are several ways around
this.  I opted to extend the sfConsoleResponse class, add the missing
sendHttpHeaders() method, but it will do nothing:

class MysfConsoleResponse extends sfConsoleResponse
{

  /**
   * This method does nothing so that http headers are not sent while
in cli
   * mode
   */
  public function sendHttpHeaders()     {
        //do nothing since we're in a console, not a browser
  }
}

In your factories.yml, replace the sfConsoleResponse class with your
newly created MysfConsoleResponse class.

Hope this helps,

Kris

BTW, first post :-)

On Sep 10, 5:35 am, Sébastien CAS <[EMAIL PROTECTED]> wrote:
> Hi all,
>
> I've created a batch file to send daily emails to my users.
>
> So I call an action in my batch file like that:
>
> sfContext::getInstance()->getController()->forward('myModule', 'myAction');
>
> But this action is secured and requires "admin" credential.
>
> So:
>
> sfContext::getInstance()->getUser()->setAuthenticated(true);
>
> sfContext::getInstance()->getUser()->addCredential('admin');
>
> But the credential 'admin' is not applied and I have not the permissions to
> access this action.
>
> How to call an action which is secured in a batch file?
>
> Sébastien Cas


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"symfony users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/symfony-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to