Skip to content

[4][CLI] - reuse of code from CMS #34840

@alikon

Description

@alikon

Steps to reproduce the issue

try to reuse code from CLI, for example notify superuser

// Push a notification to the site's super users
/** @var MessageModel $messageModel */
$messageModel = $this->app->bootComponent('com_messages')->getMVCFactory()->createModel('Message', 'Administrator');

//.... do something

$_SERVER['HTTP_HOST'] = 'fake.url';
$username= 'fakeuser';

// Load com_message's language
$language = Factory::getLanguage();
$language->load('com_messages', JPATH_ADMINISTRATOR, 'en-GB', false, true);
$language->load('com_messages', JPATH_ADMINISTRATOR, null, true);

$messageModel->notifySuperUsers(
	Text::_('PLG_SYSTEM_PRIVACYCONSENT_NOTIFICATION_USER_PRIVACY_EXPIRED_SUBJECT'),
	Text::sprintf('PLG_SYSTEM_PRIVACYCONSENT_NOTIFICATION_USER_PRIVACY_EXPIRED_MESSAGE', $username)
);

Expected result

able to call $messageModel->notifySuperUsers from CLI

Actual result

image

System information (as much as possible)

j4

Additional comments

as a quick dirty fix
i've just added this method to ConsoleApplication.php https://github.com/joomla/joomla-cms/blob/4.0-dev/libraries/src/Application/ConsoleApplication.php

	public static function getRouter($name = null, array $options = array())
	{
		$app = Factory::getApplication();

		if (!isset($name))
		{
			$name = $app->getName();
		}

		$options['mode'] = $app->get('sef');

		return Router::getInstance($name, $options);
	}

is there a better way ?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions