Skip to content

Commit 1e09868

Browse files
authored
Merge branch '6.0-dev' into 60-admin-menuitem-filter-featured
2 parents 3a4d7d1 + 56a0940 commit 1e09868

File tree

35 files changed

+290
-154
lines changed

35 files changed

+290
-154
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
-- Update content types for lookup tags
2+
3+
UPDATE `#__content_types`
4+
SET `content_history_options` = JSON_ARRAY_APPEND(
5+
`content_history_options`,
6+
'$.displayLookup',
7+
JSON_OBJECT(
8+
'sourceColumn', 'tags',
9+
'targetTable', '#__tags',
10+
'targetColumn', 'id',
11+
'displayColumn', 'title'
12+
)
13+
)
14+
WHERE `type_alias` IN (
15+
'com_content.article',
16+
'com_contact.contact',
17+
'com_newsfeeds.newsfeed',
18+
'com_content.category',
19+
'com_contact.category',
20+
'com_newsfeeds.category',
21+
'com_banners.category',
22+
'com_users.category'
23+
)
24+
AND NOT JSON_CONTAINS(
25+
JSON_EXTRACT(`content_history_options`, '$.displayLookup'),
26+
JSON_OBJECT(
27+
'sourceColumn', 'tags',
28+
'targetTable', '#__tags',
29+
'targetColumn', 'id',
30+
'displayColumn', 'title'
31+
)
32+
);
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
ALTER TABLE `#__history`
2+
ADD COLUMN `is_current` TINYINT NOT NULL DEFAULT 0 /** CAN FAIL **/;
3+
ALTER TABLE `#__history`
4+
ADD COLUMN `is_legacy` TINYINT NOT NULL DEFAULT 0 /** CAN FAIL **/;
5+
UPDATE `#__history` SET `is_legacy` = 1;
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
-- Update content types for lookup tags
2+
3+
UPDATE "#__content_types"
4+
SET "content_history_options" = jsonb_set(
5+
"content_history_options"::jsonb,
6+
'{displayLookup}',
7+
"content_history_options"::jsonb->'displayLookup' ||
8+
jsonb_build_object(
9+
'sourceColumn', 'tags',
10+
'targetTable', '#__tags',
11+
'targetColumn', 'id',
12+
'displayColumn', 'title'
13+
)
14+
)
15+
WHERE "type_alias" IN (
16+
'com_content.article',
17+
'com_contact.contact',
18+
'com_newsfeeds.newsfeed',
19+
'com_content.category',
20+
'com_contact.category',
21+
'com_newsfeeds.category',
22+
'com_banners.category',
23+
'com_users.category'
24+
)
25+
AND NOT EXISTS (
26+
SELECT * FROM jsonb_array_elements("content_history_options"::jsonb->'displayLookup')
27+
WHERE value = jsonb_build_object(
28+
'sourceColumn', 'tags',
29+
'targetTable', '#__tags',
30+
'targetColumn', 'id',
31+
'displayColumn', 'title'
32+
)
33+
);
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
-- Remove wrong unique constraint from "#__ucm_content" table
2+
ALTER TABLE "#__ucm_content" DROP CONSTRAINT "#__ucm_content_idx_type_alias_item_id" /** CAN FAIL **/;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
ALTER TABLE "#__history"
2+
ADD COLUMN "is_current" SMALLINT NOT NULL DEFAULT 0 /** CAN FAIL **/;
3+
ALTER TABLE "#__history"
4+
ADD COLUMN "is_legacy" SMALLINT NOT NULL DEFAULT 0 /** CAN FAIL **/;
5+
UPDATE "#__history" SET "is_legacy" = 1;

administrator/components/com_banners/src/Table/BannerTable.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
use Joomla\CMS\Factory;
1616
use Joomla\CMS\Language\Text;
1717
use Joomla\CMS\Table\Table;
18-
use Joomla\CMS\Versioning\VersionableTableInterface;
1918
use Joomla\Database\DatabaseInterface;
2019
use Joomla\Database\ParameterType;
2120
use Joomla\Event\DispatcherInterface;
@@ -31,7 +30,7 @@
3130
*
3231
* @since 1.5
3332
*/
34-
class BannerTable extends Table implements VersionableTableInterface
33+
class BannerTable extends Table
3534
{
3635
/**
3736
* Indicates that columns fully support the NULL value in the database

administrator/components/com_categories/src/Model/CategoryModel.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -710,6 +710,12 @@ public function save($data)
710710

711711
$this->setState($this->getName() . '.id', $table->id);
712712

713+
/**
714+
* Save the version history. We need to call saveHistory method manually because category model does not
715+
* call parent::save()
716+
*/
717+
$this->saveHistory($data, $this->typeAlias);
718+
713719
if (Factory::getApplication()->getInput()->get('task') == 'editAssociations') {
714720
return $this->redirectToAssociations($data);
715721
}

administrator/components/com_contact/src/Table/ContactTable.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
use Joomla\CMS\Tag\TaggableTableTrait;
2121
use Joomla\CMS\User\CurrentUserInterface;
2222
use Joomla\CMS\User\CurrentUserTrait;
23-
use Joomla\CMS\Versioning\VersionableTableInterface;
2423
use Joomla\Database\DatabaseInterface;
2524
use Joomla\Event\DispatcherInterface;
2625
use Joomla\String\StringHelper;
@@ -34,7 +33,7 @@
3433
*
3534
* @since 1.0
3635
*/
37-
class ContactTable extends Table implements VersionableTableInterface, TaggableTableInterface, CurrentUserInterface
36+
class ContactTable extends Table implements TaggableTableInterface, CurrentUserInterface
3837
{
3938
use TaggableTableTrait;
4039
use CurrentUserTrait;

administrator/components/com_contenthistory/src/Model/HistoryModel.php

Lines changed: 15 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
use Joomla\CMS\Access\Exception\NotAllowed;
1414
use Joomla\CMS\Component\ComponentHelper;
1515
use Joomla\CMS\Factory;
16-
use Joomla\CMS\Form\Form;
1716
use Joomla\CMS\Helper\CMSHelper;
1817
use Joomla\CMS\Language\Text;
1918
use Joomla\CMS\Log\Log;
@@ -22,7 +21,6 @@
2221
use Joomla\CMS\Table\ContentHistory;
2322
use Joomla\CMS\Table\ContentType;
2423
use Joomla\CMS\Table\Table;
25-
use Joomla\CMS\Versioning\VersionableModelInterface;
2624
use Joomla\Database\ParameterType;
2725
use Joomla\Database\QueryInterface;
2826

@@ -307,7 +305,6 @@ protected function populateState($ordering = 'h.save_date', $direction = 'DESC')
307305
$itemId = $input->get('item_id', '', 'string');
308306

309307
$this->setState('item_id', $itemId);
310-
$this->setState('sha1_hash', $this->getSha1Hash());
311308

312309
// Load the parameters.
313310
$params = ComponentHelper::getParams('com_contenthistory');
@@ -345,6 +342,7 @@ protected function getListQuery()
345342
$db->quoteName('h.sha1_hash'),
346343
$db->quoteName('h.version_data'),
347344
$db->quoteName('h.keep_forever'),
345+
$db->quoteName('h.is_current'),
348346
]
349347
)
350348
)
@@ -375,47 +373,27 @@ protected function getListQuery()
375373
*
376374
* @since 3.2
377375
*/
378-
protected function getSha1Hash()
376+
public function getSha1Hash()
379377
{
380-
$result = false;
381-
$item_id = Factory::getApplication()->getInput()->getCmd('item_id', '');
382-
383-
[$extension, $type, $id] = explode('.', $item_id);
384-
385-
$app = Factory::getApplication();
386-
387-
$model = $app->bootComponent($extension)->getMVCFactory()->createModel($type, 'Administrator');
388-
389-
if ($model instanceof VersionableModelInterface) {
390-
$path = JPATH_BASE . '/components/' . $extension;
391-
392-
Form::addFormPath($path . '/forms');
393-
Form::addFormPath($path . '/models/forms');
394-
Form::addFieldPath($path . '/models/fields');
395-
Form::addFormPath($path . '/model/form');
396-
Form::addFieldPath($path . '/model/field');
397-
398-
// This is needed to make sure the model has called populateState
399-
$tmp = $model->getState();
400-
401-
// Now we can set the article.id and it is not overwritten later by populateState
402-
$model->setState('article.id', $id);
403-
404-
$item = $model->getItem();
405-
$form = $model->getForm();
378+
/**
379+
* From Joomla 6, we use is_current field to determine the current version, so no need to calculate sha1 hash
380+
* if there is already a current version
381+
*/
406382

407-
$cf = $form->getData()->get('com_fields', null);
383+
$items = $this->getItems();
408384

409-
if (!empty($cf)) {
410-
$item->com_fields = $cf;
385+
foreach ($items as $item) {
386+
if ($item->is_current == 1) {
387+
return $item->sha1_hash;
411388
}
412-
413-
$result = $model->getSha1($item);
414-
415-
return $result;
416389
}
417390

418391
// Legacy code for history concept before 6.0.0, deprecated 6.0.0 will be removed with 8.0.0
392+
$result = false;
393+
$item_id = $this->state->get('item_id', '');
394+
395+
[$extension, $type, $id] = explode('.', $item_id);
396+
419397
Table::addIncludePath(JPATH_ADMINISTRATOR . '/components/' . $extension . '/tables');
420398
$typeTable = $this->getTable('ContentType');
421399
$typeTable->load(['type_alias' => $extension . '.' . $type]);

administrator/components/com_contenthistory/src/View/History/HtmlView.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,13 @@ class HtmlView extends BaseHtmlView
5959
*/
6060
protected $toolbar;
6161

62+
/**
63+
* The SHA1 hash of the current version of the item being viewed
64+
*
65+
* @var string
66+
*/
67+
protected $currentVersionHash;
68+
6269
/**
6370
* Method to display the view.
6471
*
@@ -74,9 +81,10 @@ public function display($tpl = null)
7481
$model = $this->getModel();
7582
$model->setUseExceptions(true);
7683

77-
$this->state = $model->getState();
78-
$this->items = $model->getItems();
79-
$this->pagination = $model->getPagination();
84+
$this->state = $model->getState();
85+
$this->items = $model->getItems();
86+
$this->pagination = $model->getPagination();
87+
$this->currentVersionHash = $model->getSha1Hash();
8088

8189
$this->toolbar = $this->addToolbar();
8290

0 commit comments

Comments
 (0)