Closed anibalsanchez closed 5 days ago
can yuo please post your console command script for testing ?
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.
@Quy I made PR: https://github.com/joomla/joomla-cms/pull/44397 Thank you!
Closing as having a pull request. Please test #44397 . Thanks in advance.
Steps to reproduce the issue
When a Console Command tries to insert an article, the Workflow throws an error.
The
Joomla\CMS\Workflow \Workflow
assumes it will receive aCMSApplication
(child ofWebApplication
). When called from a Console Command, the application is aJoomla\CMS\Application\ConsoleApplication
. So, the error is thrown.Expected result
Console Commands must be able to use the Joomla Workflow
Actual result
System information (as much as possible)
Joomla 4.3.1
Additional comments