1

I'm having trouble getting the elements service working correctly in a consolecommand. The same code works as expected in a controller, so I expect there is either a bug, or some extra config I'm missing.

<?php
namespace Craft;

class ShoppingCommand extends BaseCommand {

    public function actionListOrders() {
        $c = craft()->elements->getCriteria(ElementType::Entry);
        //$c->locale = craft()->i18n->getPrimarySiteLocale();
        $c->section = 'orders';
        $c->limit = 5;
        foreach($c as $o) {
            print $o->orderId . ": " . $o->title . ", " . $o->price . "\n";
        }
    }
}

running this results in the following

$ ./app/etc/console/yiic shopping listorders
: blah,

running the same action with a Controller in the webapp results in the expected output:

10: blah, 123

Anyone have any ideas if it's possible to get around this? For now I can just build my functionality into a controller, but it would be much more convenient if I could run it from the command line like this.

Also, there is another issue with this relating to the locale. Originally I needed to use the commented out line above because my site's default locale was en where as the consolecommands default to en_us and without forcing the locale my queries were not returning any results at all. I changed my default locale to en_us to test whether the other issue was something to do with the locales as well, but it didn't make a difference.

Cheers

-Tristan

0

There was a bug in Craft where custom fields weren't being loaded when using the ElementsService in the context of a console command.

Just fixed it for the next (post 2.2.2598) release.

Am I'm not sure I'm following the locale issue. Can you post that as a separate question with some more clarification?

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.