Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
alikon opened this issue Jul 19, 2021 · 1 comment
Closed

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

alikon opened this issue Jul 19, 2021 · 1 comment

Comments

@alikon
Copy link
Contributor

alikon commented Jul 19, 2021

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 ?

@alikon
Copy link
Contributor Author

alikon commented Dec 17, 2021

fixed with #36332

@alikon alikon closed this as completed Dec 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants