This piece of code produces 'Application Instantiation Error' error in CLI Application:
$model = JModelItem::getInstance('extension', 'ItemModel', array('ignore_request' => true));
$model->save($data); // $data is array containing 'tags' key - array of new tags.
A quick look through source code (/libraries/cms/ucm/content.php) gives us:
// In JUcmContent::__construct
$input = JFactory::getApplication()->input; //This line produces the error.
// $input variable is used only in the next line
$this->alias = isset($alias) ? $alias : $input->get('option') . '.' . $input->get('view');
This code can be rewritten to isolate JFactory::getApplication() call as follows:
if (isset($alias))
{
$this->alias = $alias;
}
else
{
$input = JFactory::getApplication()->input;
$this->alias = $input->get('option') . '.' . $input->get('view');
}
List of files affected:
/libraries/cms/helper/tags.php (line 677)
/libraries/cms/ucm/type.php (line 88)
/libraries/cms/ucm/content.php (line 46)
/libraries/cms/ucm/base.php (line 45)
Labels |
Added:
?
|
Thank you for quick reply. That solved my problem, but it seems a little bit tricky. Official documentation says JFactory::getApplication() returns JApplicationCms instance.
Status | New | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2015-03-19 17:34:10 |
It's valid but at the same time isn't. There's a pretty hard coupling in the code to JFactory, so the CLI application should be setting itself to
JFactory::$application
if it is a JApplicationCli instance. At least for this specific problem, that should resolve things as all application objects have an input attribute.