Skip to content

Commit e1693bd

Browse files
bembelimenwilsonge
authored andcommitted
[4.0] Feature/New Publishing Workflow (#20381)
Thanks @bembelimen @Didldu-Florian @puneet0191 @priiish @brianteeman and @chmst
1 parent d6435d2 commit e1693bd

File tree

110 files changed

+10496
-332
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

110 files changed

+10496
-332
lines changed
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
--
2+
-- Table structure for table `#__workflows`
3+
--
4+
5+
CREATE TABLE IF NOT EXISTS `#__workflows` (
6+
`id` int(10) NOT NULL AUTO_INCREMENT,
7+
`asset_id` int(10) DEFAULT 0,
8+
`published` tinyint(1) NOT NULL DEFAULT 0,
9+
`title` varchar(255) NOT NULL,
10+
`description` text NOT NULL DEFAULT '',
11+
`extension` varchar(255) NOT NULL,
12+
`default` tinyint(1) NOT NULL DEFAULT 0,
13+
`ordering` int(11) NOT NULL DEFAULT 0,
14+
`created` datetime NOT NULL DEFAULT NOW(),
15+
`created_by` int(10) NOT NULL DEFAULT 0,
16+
`modified` datetime NOT NULL DEFAULT NOW(),
17+
`modified_by` int(10) NOT NULL DEFAULT 0,
18+
PRIMARY KEY (`id`),
19+
KEY `asset_id` (`asset_id`),
20+
KEY `title` (`title`(191)),
21+
KEY `extension` (`extension`(191)),
22+
KEY `default` (`default`),
23+
KEY `created` (`created`),
24+
KEY `created_by` (`created_by`),
25+
KEY `modified` (`modified`),
26+
KEY `modified_by` (`modified_by`)
27+
) ENGINE=InnoDB COLLATE=utf8mb4_unicode_ci;
28+
29+
--
30+
-- Dumping data for table `#__workflows`
31+
--
32+
33+
INSERT INTO `#__workflows` (`id`, `asset_id`, `published`, `title`, `description`, `extension`, `default`, `ordering`, `created`, `created_by`, `modified`, `modified_by`) VALUES
34+
(1, 0, 1, 'Joomla! Default', '', 'com_content', 1, 1, NOW(), 0, '0000-00-00 00:00:00', 0);
35+
36+
--
37+
-- Table structure for table `#__workflow_associations`
38+
--
39+
40+
CREATE TABLE IF NOT EXISTS `#__workflow_associations` (
41+
`item_id` int(10) NOT NULL DEFAULT 0 COMMENT 'Extension table id value',
42+
`state_id` int(10) NOT NULL COMMENT 'Foreign Key to #__workflow_states.id',
43+
`extension` varchar(100) NOT NULL,
44+
PRIMARY KEY (`item_id`, `state_id`, `extension`),
45+
KEY `idx_item_id` (`item_id`),
46+
KEY `idx_state_id` (`state_id`),
47+
KEY `idx_extension` (`extension`(100))
48+
) ENGINE=InnoDB COLLATE=utf8mb4_unicode_ci;
49+
50+
--
51+
-- Table structure for table `#__workflow_states`
52+
--
53+
54+
CREATE TABLE IF NOT EXISTS `#__workflow_states` (
55+
`id` int(10) NOT NULL AUTO_INCREMENT,
56+
`asset_id` int(10) DEFAULT 0,
57+
`ordering` int(11) NOT NULL DEFAULT 0,
58+
`workflow_id` int(10) NOT NULL,
59+
`published` tinyint(1) NOT NULL DEFAULT 0,
60+
`title` varchar(255) NOT NULL,
61+
`description` text NOT NULL DEFAULT '',
62+
`condition` enum('0','1','-2') NOT NULL,
63+
`default` tinyint(1) NOT NULL DEFAULT 0,
64+
PRIMARY KEY (`id`),
65+
KEY `workflow_id` (`workflow_id`),
66+
KEY `title` (`title`(191)),
67+
KEY `asset_id` (`asset_id`),
68+
KEY `default` (`default`)
69+
) ENGINE=InnoDB DEFAULT COLLATE=utf8mb4_unicode_ci;
70+
71+
--
72+
-- Dumping data for table `#__workflow_states`
73+
--
74+
75+
INSERT INTO `#__workflow_states` (`id`, `asset_id`, `ordering`, `workflow_id`, `published`, `title`, `description`, `condition`, `default`) VALUES
76+
(1, 0, 1, 1, 1, 'Unpublished', '', '0', 0),
77+
(2, 0, 2, 1, 1, 'Published', '', '1', 1),
78+
(3, 0, 3, 1, 1, 'Trashed', '', '-2', 0),
79+
(4, 0, 4, 1, 1, 'Archived', '', '1', 0);
80+
81+
--
82+
-- Table structure for table `#__workflow_transitions`
83+
--
84+
85+
CREATE TABLE IF NOT EXISTS `#__workflow_transitions` (
86+
`id` int(10) NOT NULL AUTO_INCREMENT,
87+
`asset_id` int(10) DEFAULT 0,
88+
`ordering` int(11) NOT NULL DEFAULT 0,
89+
`workflow_id` int(10) NOT NULL,
90+
`published` tinyint(1) NOT NULL DEFAULT 0,
91+
`title` varchar(255) NOT NULL,
92+
`description` text NOT NULL DEFAULT '',
93+
`from_state_id` int(10) NOT NULL,
94+
`to_state_id` int(10) NOT NULL,
95+
PRIMARY KEY (`id`),
96+
KEY `title` (`title`(191)),
97+
KEY `asset_id` (`asset_id`),
98+
KEY `from_state_id` (`from_state_id`),
99+
KEY `to_state_id` (`to_state_id`),
100+
KEY `workflow_id` (`workflow_id`)
101+
) ENGINE=InnoDB DEFAULT COLLATE=utf8mb4_unicode_ci;
102+
103+
--
104+
-- Dumping data for table `#__workflow_transitions`
105+
--
106+
107+
INSERT INTO `#__workflow_transitions` (`id`, `asset_id`, `published`, `ordering`, `workflow_id`, `title`, `description`, `from_state_id`, `to_state_id`) VALUES
108+
(1, 0, 1, 1, 1, 'Unpublish', '', -1, 1),
109+
(2, 0, 1, 2, 1, 'Publish', '', -1, 2),
110+
(3, 0, 1, 3, 1, 'Trash', '', -1, 3),
111+
(4, 0, 1, 4, 1, 'Archive', '', -1, 4);
112+
113+
--
114+
-- Creating extension entry
115+
--
116+
117+
INSERT INTO `#__extensions` (`extension_id`, `package_id`, `name`, `type`, `element`, `folder`, `client_id`, `enabled`, `access`, `protected`, `manifest_cache`, `params`, `checked_out`, `checked_out_time`, `ordering`, `state`, `namespace`) VALUES
118+
(35, 0, 'com_workflow', 'component', 'com_workflow', '', 1, 1, 0, 0, '', '{}', 0, '0000-00-00 00:00:00', 0, 0, 'Joomla\\Component\\Workflow');
119+
120+
--
121+
-- Creating Associations for existing content
122+
--
123+
INSERT INTO `#__workflow_associations` (`item_id`, `state_id`, `extension`)
124+
SELECT `id`, CASE WHEN `state` = -2 THEN 3 WHEN `state` = 0 THEN 1 WHEN `state` = 2 THEN 4 ELSE 2 END, 'com_content' FROM `#__content`;

administrator/components/com_categories/Model/CategoryModel.php

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -422,30 +422,39 @@ protected function preprocessForm(\JForm $form, $data, $group = 'content')
422422
}
423423
}
424424

425-
// Try to find the component helper.
426-
$eName = str_replace('com_', '', $component);
427-
$path = Path::clean(JPATH_ADMINISTRATOR . "/components/$component/helpers/category.php");
425+
$componentInterface = Factory::getApplication()->bootComponent($component);
428426

429-
if (file_exists($path))
427+
if ($componentInterface instanceof CategoriesServiceInterface)
430428
{
431-
$cName = ucfirst($eName) . ucfirst($section) . 'HelperCategory';
432-
433-
\JLoader::register($cName, $path);
429+
$componentInterface->prepareForm($form, $data);
430+
}
431+
else
432+
{
433+
// Try to find the component helper.
434+
$eName = str_replace('com_', '', $component);
435+
$path = Path::clean(JPATH_ADMINISTRATOR . "/components/$component/helpers/category.php");
434436

435-
if (class_exists($cName) && is_callable(array($cName, 'onPrepareForm')))
437+
if (file_exists($path))
436438
{
437-
$lang->load($component, JPATH_BASE, null, false, false)
438-
|| $lang->load($component, JPATH_BASE . '/components/' . $component, null, false, false)
439-
|| $lang->load($component, JPATH_BASE, $lang->getDefault(), false, false)
440-
|| $lang->load($component, JPATH_BASE . '/components/' . $component, $lang->getDefault(), false, false);
441-
call_user_func_array(array($cName, 'onPrepareForm'), array(&$form));
442-
443-
// Check for an error.
444-
if ($form instanceof \Exception)
445-
{
446-
$this->setError($form->getMessage());
439+
$cName = ucfirst($eName) . ucfirst($section) . 'HelperCategory';
447440

448-
return false;
441+
\JLoader::register($cName, $path);
442+
443+
if (class_exists($cName) && is_callable(array($cName, 'onPrepareForm')))
444+
{
445+
$lang->load($component, JPATH_BASE, null, false, false)
446+
|| $lang->load($component, JPATH_BASE . '/components/' . $component, null, false, false)
447+
|| $lang->load($component, JPATH_BASE, $lang->getDefault(), false, false)
448+
|| $lang->load($component, JPATH_BASE . '/components/' . $component, $lang->getDefault(), false, false);
449+
call_user_func_array(array($cName, 'onPrepareForm'), array(&$form));
450+
451+
// Check for an error.
452+
if ($form instanceof \Exception)
453+
{
454+
$this->setError($form->getMessage());
455+
456+
return false;
457+
}
449458
}
450459
}
451460
}

administrator/components/com_content/Extension/ContentComponent.php

Lines changed: 70 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,12 @@
1919
use Joomla\CMS\Extension\BootableExtensionInterface;
2020
use Joomla\CMS\Extension\MVCComponent;
2121
use Joomla\CMS\Fields\FieldsServiceInterface;
22+
use Joomla\CMS\Form\Form;
2223
use Joomla\CMS\HTML\HTMLRegistryAwareTrait;
24+
use Joomla\CMS\MVC\Factory\MVCFactoryServiceTrait;
25+
use Joomla\CMS\MVC\Factory\MVCFactoryServiceInterface;
26+
use Joomla\CMS\Workflow\WorkflowServiceInterface;
27+
use Joomla\Component\Content\Administrator\Helper\ContentHelper;
2328
use Joomla\Component\Content\Administrator\Service\HTML\AdministratorService;
2429
use Joomla\Component\Content\Administrator\Service\HTML\Icon;
2530
use Psr\Container\ContainerInterface;
@@ -29,10 +34,11 @@
2934
/**
3035
* Component class for com_content
3136
*
32-
* @since 4.0.0
37+
* @since __DEPLOY_VERSION__
3338
*/
3439
class ContentComponent extends MVCComponent implements
35-
BootableExtensionInterface, CategoriesServiceInterface, FieldsServiceInterface, AssociationServiceInterface
40+
BootableExtensionInterface, MVCFactoryServiceInterface, CategoriesServiceInterface, FieldsServiceInterface,
41+
AssociationServiceInterface, WorkflowServiceInterface
3642
{
3743
use CategoriesServiceTrait;
3844
use AssociationServiceTrait;
@@ -49,7 +55,7 @@ class ContentComponent extends MVCComponent implements
4955
*
5056
* @return void
5157
*
52-
* @since 4.0.0
58+
* @since __DEPLOY_VERSION__
5359
*/
5460
public function boot(ContainerInterface $container)
5561
{
@@ -69,7 +75,7 @@ public function boot(ContainerInterface $container)
6975
*
7076
* @return string|null The new section
7177
*
72-
* @since 4.0.0
78+
* @since __DEPLOY_VERSION__
7379
*/
7480
public function validateSection($section, $item = null)
7581
{
@@ -102,7 +108,7 @@ public function validateSection($section, $item = null)
102108
*
103109
* @return array
104110
*
105-
* @since 4.0.0
111+
* @since __DEPLOY_VERSION__
106112
*/
107113
public function getContexts(): array
108114
{
@@ -123,10 +129,68 @@ public function getContexts(): array
123129
*
124130
* @return string|null
125131
*
126-
* @since 4.0.0
132+
* @since __DEPLOY_VERSION__
127133
*/
128134
protected function getTableNameForSection(string $section = null)
129135
{
130136
return '#__content';
131137
}
138+
139+
/**
140+
* Method to filter transitions by given id of state.
141+
*
142+
* @param array $transitions The Transitions to filter
143+
* @param int $pk Id of the state
144+
*
145+
* @return array
146+
*
147+
* @since __DEPLOY_VERSION__
148+
*/
149+
public function filterTransitions($transitions, $pk): array
150+
{
151+
return ContentHelper::filterTransitions($transitions, $pk);
152+
}
153+
154+
/**
155+
* Adds Count Items for Category Manager.
156+
*
157+
* @param \stdClass[] $items The category objects
158+
* @param string $section The section
159+
*
160+
* @return void
161+
*
162+
* @since __DEPLOY_VERSION__
163+
*/
164+
public function countItems(array $items, string $section)
165+
{
166+
return ContentHelper::countItems($items);
167+
}
168+
169+
/**
170+
* Prepares the category form
171+
*
172+
* @param Form $form The form to prepare
173+
* @param array|object $data The form data
174+
*
175+
* @return void
176+
*/
177+
public function prepareForm(Form $form, $data)
178+
{
179+
ContentHelper::onPrepareForm($form, $data);
180+
}
181+
182+
/**
183+
* Method to change state of multiple ids
184+
*
185+
* @param array $pks Array of IDs
186+
* @param int $condition Condition of the workflow state
187+
*
188+
* @return boolean
189+
*
190+
* @since __DEPLOY_VERSION__
191+
*/
192+
public static function updateContentState($pks, $condition): bool
193+
{
194+
return ContentHelper::updateContentState($pks, $condition);
195+
}
132196
}

0 commit comments

Comments
 (0)