When a Console Command tries to insert an article, the Workflow throws an error.
TypeError: Joomla\CMS\Workflow\Workflow::__construct(): Argument #2 ($app) must be of type ?Joomla\CMS\Application\CMSApplication, Joomla\CMS\Application\ConsoleApplication given, called in /app/www/libraries/src/MVC/Model/WorkflowBehaviorTrait.php on line 90
The Joomla\CMS\Workflow \Workflow
assumes it will receive a CMSApplication
(child of WebApplication
). When called from a Console Command, the application is a Joomla\CMS\Application\ConsoleApplication
. So, the error is thrown.
Console Commands must be able to use the Joomla Workflow
TypeError: Joomla\CMS\Workflow\Workflow::__construct(): Argument #2 ($app) must be of type ?Joomla\CMS\Application\CMSApplication, Joomla\CMS\Application\ConsoleApplication given, called in /app/www/libraries/src/MVC/Model/WorkflowBehaviorTrait.php on line 90
Joomla 4.3.1
Labels |
Added:
No Code Attached Yet
|
Labels |
Added:
bug
|
The console command is part of a system; I can't publish it here.
You can reproduce the issue in any console command by instantiating an article model:
$app = \Joomla\CMS\Factory::getApplication();
$mvcFactory = $app->bootComponent('com_content')->getMVCFactory();
$articleModel = $mvcFactory->createModel('Article', 'Administrator', ['ignore_request' => true]);
When it creates the ArticleModel
, it executes the $this->setUpWorkflow('com_content.article');
and $this->workflow = new Workflow($extension, Factory::getApplication(), $db);
(libraries/src/MVC/Model/WorkflowBehaviorTrait.php, line 90)
I have the same problem with my console plugin to bulk import articles to joomla. Any workaround to create articles from console plugin?
The restrictive argument type in the Workflow constructor causes the error when it receives the whole App. The only possible workaround is patching the Workflow constructor to change the argument type.
Same problem.
I think that, in addition to correcting the argument type, we also need to remove class initialization if Workflow is disabled.
There is no need to connect something that will not be used.
if (!Factory::getApplication()->isClient('cli')) {
$this->setUpWorkflow('com_content.article');
}
The way that workflow is coded is such that even when it is disabled records are created in the workflow tables for the article status. This is so that you can enable workflows at a later date if you wish.
The way that workflow is coded is such that even when it is disabled records are created in the workflow tables for the article status. This is so that you can enable workflows at a later date if you wish.
I saw this and it is also very bad.
The more Joins, the more unstable the indexes.
As a result, disabling Workflow does not actually disable it.
not saying its good or bad - just saying what it is
My observations:
My preliminary conclusions:
Please correct me if I'm wrong or if you have other obeservations or conclusions.
@HermanPeeren To fix the issue, your proposal is the right approach.
Looking into a long-term solution, the problem is that the hexagonal CMS architecture needs to be more widely adopted in the core development practice.
At any time, a developer can create a feature or a bug fix that does not follow the separation between the layers. Similar issues will appear repeatedly if the practice is not enforced (automatically or manually).
@HermanPeeren is right because \Joomla\CMS\Workflow\Workflow only use $app for bootComponent. But bootComponent is method define in CMSApplicationInterface. You not need CMSApplication.
I checkt with this change. It works.
Why leave Joomla broken 1+ year if we know fix? I do not understand why wait.
@leeroy1821 Please submit a pull request. Thanks.
Status | New | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2024-11-03 08:57:04 |
Closed_By | ⇒ | richard67 |
can yuo please post your console command script for testing ?