Entry not saving through command line I'm trying to create a command line function, in my plugin, to import some data into entries. The problem is that the Craft\EntriesService-&gt;saveEntry() method seems to call the Craft\TemplatesService-&gt;renderObjectTemplate() method which uses the SERVER_NAMEconstant. Obviously there is no SERVER_NAME because the application is being run from the command line. 

Is there a way to manually set this, or can this be bypassed in any other way?

I will include my stack trace here as well:

PHP Error[8]: Undefined index: SERVER_NAME in file myproject/craft/app/framework/web/CHttpRequest.php at line 352
0 myproject/craft/app/etc/console/ConsoleApp.php(252): Craft\ConsoleApp-&gt;handleError()
1 myproject/craft/app/framework/web/CHttpRequest.php(352): Craft\ConsoleApp-&gt;handleError()
2 myproject/craft/app/services/ConfigService.php(420): Craft\HttpRequestService-&gt;getHostInfo()
3 myproject/craft/app/helpers/UrlHelper.php(422): Craft\ConfigService-&gt;usePathInfo()
4 myproject/craft/app/helpers/UrlHelper.php(196): _getUrl()
5 myproject/craft/app/etc/templating/twigextensions/CraftTwigExtension.php(493): getUrl()
6 myproject/craft/app/vendor/twig/twig/lib/Twig/Environment.php(1276): Craft\CraftTwigExtension-&gt;getGlobals()
7 myproject/craft/app/vendor/twig/twig/lib/Twig/Environment.php(1200): Craft\TwigEnvironment-&gt;initGlobals()
8 myproject/craft/app/vendor/twig/twig/lib/Twig/Environment.php(1217): Craft\TwigEnvironment-&gt;getGlobals()
9 myproject/craft/app/vendor/twig/twig/lib/Twig/Template.php(355): Craft\TwigEnvironment-&gt;mergeGlobals()
10 myproject/craft/app/vendor/twig/twig/lib/Twig/Template.php(366): __TwigTemplate_5f77fd774cac1595e134b05c66db80e7998372598504ff29b7e2487f820a3d8c-&gt;display()
11 myproject/craft/app/services/TemplatesService.php(336): __TwigTemplate_5f77fd774cac1595e134b05c66db80e7998372598504ff29b7e2487f820a3d8c-&gt;render()
12 myproject/craft/app/services/EntriesService.php(157): Craft\TemplatesService-&gt;renderObjectTemplate()
13 myproject/craft/plugins/myplugin/services/Myproject_SomeService.php(312): Craft\EntriesService-&gt;saveEntry()
14 myproject/craft/plugins/myplugin/services/Myproject_SomeService.php(280): Craft\Myproject_SomeService-&gt;update()
15 myproject/craft/plugins/myplugin/consolecommands/ImportEmployeeCommand.php(24): Craft\Myproject_SomeService-&gt;createOrUpdate()
16 unknown(0): Craft\ImportCommand-&gt;actionImport()
17 myproject/craft/app/framework/console/CConsoleCommand.php(172): ReflectionMethod-&gt;invokeArgs()
18 myproject/craft/app/framework/console/CConsoleCommandRunner.php(71): Craft\ImportCommand-&gt;run()
19 myproject/craft/app/framework/console/CConsoleApplication.php(92): Craft\ConsoleCommandRunner-&gt;run()
20 myproject/craft/app/framework/base/CApplication.php(185): Craft\ConsoleApp-&gt;processRequest()
21 myproject/craft/app/etc/console/yiic.php(81): Craft\ConsoleApp-&gt;run()
22 myproject/craft/app/etc/console/yiic(4): require_once()
I'm assuming you're using a multi-environment config.  From wherever your plugin is bootstrapping yiic, you need to manually set the CRAFT_ENVIRONMENT PHP constant to the environment you want yiic to load in the config files.