5

I'm trying to get a basic console command for my plugin to run but not having much luck. I have created a folder called consolecommands inside my plugin directory and have created a file called AcmeNotificationsCommand.php.

In this file I have:

namespace Craft;

class AcmeNotificationsCommand extends BaseCommand
{
    public function actionHello()
    {
        echo "hello";
        return 0;
    }   
}

From the console I am running /Users/dave/acme/craft/app/framework/yiic acmenotifications hello

But yiic comes back and says:

The following commands are available:
- migrate
- shell

So I guess it's not picking up my new console command. What am I missing?

Update:

It occurred to me that maybe I was running the wrong yiic file since I could not see the Querygen command that is in the app/consolecommands directory as expected.

So instead I tried running /Users/dave/acme/craft/app/etc/console/yiic to see what commands were available and I got the following error:

0 /Users/dave/code/acme/craft/app/Craft.php(397): CComponent->__call('getTranslatedBr...', Array)
1 /Users/dave/code/acme/craft/app/Craft.php(397): Craft\ConsoleApp->getTranslatedBrowserLanguage()
2 /Users/dave/code/acme/craft/app/etc/db/DbConnection.php(57): Craft\Craft::t('Craft can???t c...')
3 /Users/dave/code/acme/craft/app/framework/base/CModule.php(387): Craft\DbConnection->init()
4 /Users/dave/code/acme/craft/app/etc/behaviors/AppBehavior.php(41): CModule->getComponent('db')
5 [internal function]: Craft\AppBehavior->isInstalled()
6 /Users/dave/code/acme/craft/app/framework/base/CComponent.php(261): call_user_func_array(Array, Array)
7 /Users/dave/code/acme/craft/app/services/PluginsService.php(89): CComponent->__call('isInstalled', Array)
8 /Users/dave/code/acme/craft/app/services/PluginsService.php(89): Craft\ConsoleApp->isInstalled()
9 /Users/dave/code/acme/craft/app/etc/console/ConsoleApp.php(53): Craft\PluginsService->loadPlugins()
10 /Users/dave/code/acme/craft/app/framework/base/CApplication.php(165): Craft\ConsoleApp->init()
11 /Users/dave/code/acme/craft/app/framework/YiiBase.php(121): CApplication->__construct('/Users/dave/cod...')
12 /Users/dave/code/acme/craft/app/etc/console/yiic.php(76): YiiBase::createApplication('Craft\ConsoleAp...', '/Users/dave/cod...')
13 /Users/dave/code/acme/craft/app/etc/console/yiic(4): require_once('/Users/dave/cod...')
14 {main}%

I also noticed a similar error when looking at the databaseimportexport plugin. Not sure if this is a bug or whether I am still doing something wrong?

  • You should be running the one in craft/app/etc/console. Not sure what the error is about, though. Can you send a database dump over to support@buildwithcraft.com? – Brad Bell Jul 26 '14 at 15:37
  • I had a similar error when trying to use the console to generate a migration script and it lead to finding out that when called from the command line console the db.php in the config folder had to have any entry added for 'console' which is where I had to define the database, user and password as well as unixSocket entry to point to the location of the mysql.sock file used by MAMP in my case. It was the MAMP – StevenHill Dec 9 '16 at 16:41
1

Sounds like you haven't enabled the plugin from Settings->Plugins.

Once you do that, yiic will register your plugin's custom command.

| improve this answer | |
  • I have uninstalled and re installed the plugin but sill no joy. – Dave Coggins Jul 26 '14 at 6:51
  • I've been hunting around trying to find a craft plugin that uses a custom command to try and work out what i'm doing wrong but can't seem to find one. Do you know of any? – Dave Coggins Jul 26 '14 at 7:52
  • I've got one locally you can test with... email support@buildwithcraft.com. – Brad Bell Jul 26 '14 at 15:38
  • anyone else troubleshooting needs a reference, I found the twittercraft plugin handy: github.com/brammittendorff/twittercraft/tree/master/… – nullvariable Jan 4 '17 at 18:13

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.