Skip to content

Commit adb79e9

Browse files
authored
[6.0] Extend versioning, save releated information in history table and restore historical data (#45515)
* RFC extend versioning * cs fix * cs fix 2 * Update libraries/src/MVC/Model/VersionableModelInterface.php Co-authored-by: Brian Teeman <[email protected]> * Update libraries/src/Versioning/VersionableModelTrait.php Co-authored-by: Brian Teeman <[email protected]> * same change for other models * cs * fix json decode for history * fix testing * fixed compare view * added a missing Language Tag * Better readability * cs fix1 * missed a case * cs fix2 * check if the model supports versions * cs fix3 * show old data better * changes made based on code review * moving the interface file, thank you IDE for nothing * missed one place * moved it back, I don’t want the trait in adminModel * fix version note * cs fix * Apply suggestion from code review Co-authored-by: Martina Scholz <[email protected]> * Fix PHPCS
1 parent 39be764 commit adb79e9

File tree

17 files changed

+288
-91
lines changed

17 files changed

+288
-91
lines changed

administrator/components/com_banners/src/Model/BannerModel.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Joomla\CMS\MVC\Model\AdminModel;
1717
use Joomla\CMS\Table\Table;
1818
use Joomla\CMS\Table\TableInterface;
19+
use Joomla\CMS\Versioning\VersionableModelInterface;
1920
use Joomla\CMS\Versioning\VersionableModelTrait;
2021
use Joomla\Component\Categories\Administrator\Helper\CategoriesHelper;
2122
use Joomla\Database\ParameterType;
@@ -29,7 +30,7 @@
2930
*
3031
* @since 1.6
3132
*/
32-
class BannerModel extends AdminModel
33+
class BannerModel extends AdminModel implements VersionableModelInterface
3334
{
3435
use VersionableModelTrait;
3536

administrator/components/com_banners/src/Model/ClientModel.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use Joomla\CMS\Factory;
1414
use Joomla\CMS\MVC\Model\AdminModel;
1515
use Joomla\CMS\Table\Table;
16+
use Joomla\CMS\Versioning\VersionableModelInterface;
1617
use Joomla\CMS\Versioning\VersionableModelTrait;
1718

1819
// phpcs:disable PSR1.Files.SideEffects
@@ -24,7 +25,7 @@
2425
*
2526
* @since 1.6
2627
*/
27-
class ClientModel extends AdminModel
28+
class ClientModel extends AdminModel implements VersionableModelInterface
2829
{
2930
use VersionableModelTrait;
3031

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
use Joomla\CMS\Plugin\PluginHelper;
2727
use Joomla\CMS\Table\Category;
2828
use Joomla\CMS\UCM\UCMType;
29+
use Joomla\CMS\Versioning\VersionableModelInterface;
2930
use Joomla\CMS\Versioning\VersionableModelTrait;
3031
use Joomla\Component\Categories\Administrator\Helper\CategoriesHelper;
3132
use Joomla\Database\ParameterType;
@@ -43,7 +44,7 @@
4344
*
4445
* @since 1.6
4546
*/
46-
class CategoryModel extends AdminModel
47+
class CategoryModel extends AdminModel implements VersionableModelInterface
4748
{
4849
use VersionableModelTrait;
4950

administrator/components/com_contact/src/Model/ContactModel.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Joomla\CMS\Language\Text;
1919
use Joomla\CMS\MVC\Model\AdminModel;
2020
use Joomla\CMS\String\PunycodeHelper;
21+
use Joomla\CMS\Versioning\VersionableModelInterface;
2122
use Joomla\CMS\Versioning\VersionableModelTrait;
2223
use Joomla\Component\Categories\Administrator\Helper\CategoriesHelper;
2324
use Joomla\Database\ParameterType;
@@ -33,7 +34,7 @@
3334
*
3435
* @since 1.6
3536
*/
36-
class ContactModel extends AdminModel
37+
class ContactModel extends AdminModel implements VersionableModelInterface
3738
{
3839
use VersionableModelTrait;
3940

administrator/components/com_content/src/Model/ArticleModel.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
use Joomla\CMS\Table\TableInterface;
3030
use Joomla\CMS\Tag\TaggableTableInterface;
3131
use Joomla\CMS\UCM\UCMType;
32+
use Joomla\CMS\Versioning\VersionableModelInterface;
3233
use Joomla\CMS\Versioning\VersionableModelTrait;
3334
use Joomla\CMS\Workflow\Workflow;
3435
use Joomla\Component\Categories\Administrator\Helper\CategoriesHelper;
@@ -49,7 +50,7 @@
4950
* @since 1.6
5051
*/
5152

52-
class ArticleModel extends AdminModel implements WorkflowModelInterface
53+
class ArticleModel extends AdminModel implements WorkflowModelInterface, VersionableModelInterface
5354
{
5455
use WorkflowBehaviorTrait;
5556
use VersionableModelTrait;

administrator/components/com_contenthistory/src/Helper/ContenthistoryHelper.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Joomla\Filesystem\File;
1919
use Joomla\Filesystem\Folder;
2020
use Joomla\Filesystem\Path;
21+
use Joomla\Utilities\ArrayHelper;
2122

2223
// phpcs:disable PSR1.Files.SideEffects
2324
\defined('_JEXEC') or die;
@@ -75,8 +76,18 @@ public static function decodeFields($jsonString)
7576

7677
if (\is_object($object)) {
7778
foreach ($object as $name => $value) {
78-
if (!\is_null($value) && $subObject = json_decode($value)) {
79-
$object->$name = $subObject;
79+
if (!\is_null($value)) {
80+
if (\is_object($value)) {
81+
$object->$name = ArrayHelper::fromObject($value);
82+
continue;
83+
}
84+
85+
if (str_starts_with($value, '{')) {
86+
$object->$name = json_decode($value);
87+
continue;
88+
}
89+
90+
$object->$name = $value;
8091
}
8192
}
8293
}

administrator/components/com_contenthistory/tmpl/compare/compare.php

Lines changed: 62 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,16 @@
1212

1313
use Joomla\CMS\Language\Text;
1414
use Joomla\CMS\Session\Session;
15+
use Joomla\Utilities\ArrayHelper;
1516

1617
/** @var \Joomla\Component\Contenthistory\Administrator\View\Compare\HtmlView $this */
1718

1819
Session::checkToken('get') or die(Text::_('JINVALID_TOKEN'));
1920

2021
$version2 = $this->items[0];
2122
$version1 = $this->items[1];
22-
$object1 = $version1->data;
23-
$object2 = $version2->data;
23+
$object1 = ArrayHelper::fromObject($version1->data);
24+
$object2 = ArrayHelper::fromObject($version2->data);
2425

2526
/** @var Joomla\CMS\WebAsset\WebAssetManager $wa */
2627
$wa = $this->getDocument()->getWebAssetManager();
@@ -43,40 +44,70 @@
4344
</tr>
4445
</thead>
4546
<tbody>
46-
<?php foreach ($object1 as $name => $value) : ?>
47-
<?php if (isset($value->value) && isset($object2->$name->value) && $value->value != $object2->$name->value) : ?>
48-
<?php if (is_object($value->value)) : ?>
49-
<tr>
50-
<td colspan="4">
51-
<strong><?php echo $value->label; ?></strong>
52-
</td>
53-
</tr>
54-
<?php foreach ($value->value as $subName => $subValue) : ?>
55-
<?php $newSubValue = $object2->$name->value->$subName->value ?? ''; ?>
56-
<?php if ($subValue->value || $newSubValue) : ?>
57-
<?php if ($subValue->value != $newSubValue) : ?>
47+
<?php foreach ($object1 as $name => $value1) : ?>
48+
<?php if (isset($value1['value']) && isset($object2[$name]['value'])) : ?>
49+
<?php $value2 = $object2[$name]['value']; ?>
50+
<?php
51+
if (is_array($value1)) : ?>
52+
<?php if (is_array($value1['value'])) : ?>
53+
<tr>
54+
<td colspan="4">
55+
<strong><?php echo $value1['label']; ?></strong>
56+
</td>
57+
</tr>
58+
<?php $keys = array_keys($value1['value']); ?>
59+
<?php if (isset($value2['value']) && is_array($value2['value'])) :?>
60+
<?php $keys = array_merge(array_keys($value1['value']), array_keys($value2['value'])); ?>
61+
<?php endif; ?>
62+
<?php foreach ($keys as $key) : ?>
5863
<tr>
59-
<th scope="row"><em>&nbsp;&nbsp;<?php echo $subValue->label; ?></em></th>
60-
<td class="original"><?php echo htmlspecialchars($subValue->value, ENT_COMPAT, 'UTF-8'); ?></td>
61-
<td class="changed" ><?php echo htmlspecialchars($newSubValue, ENT_COMPAT, 'UTF-8'); ?></td>
64+
<td></td>
65+
<td class="original">
66+
<?php if (isset($value1['value'][$key])) : ?>
67+
<?php $currentvalue1 = $value1['value'][$key]; ?>
68+
<?php if (is_array($value1['value'][$key])) : ?>
69+
<?php $currentvalue1 = implode(' | ', $value1['value'][$key]); ?>
70+
<?php echo htmlspecialchars($key . ': ' . $currentvalue1, ENT_COMPAT, 'UTF-8'); ?>
71+
<?php else : ?>
72+
<?php echo htmlspecialchars($key . ': ' . $currentvalue1, ENT_COMPAT, 'UTF-8'); ?>
73+
<?php endif;?>
74+
<?php else : ?>
75+
<?php echo Text::_('JUNDEFINED');?>
76+
<?php endif; ?>
77+
</td>
78+
<td class="changed">
79+
<?php if (isset($value2['value'][$key])) : ?>
80+
<?php $currentvalue2 = $value2['value'][$key]; ?>
81+
<?php if (is_array($value2['value'][$key])) : ?>
82+
<?php $currentvalue2 = implode(' | ', $value1['value'][$key]); ?>
83+
<?php echo htmlspecialchars($key . ': ' . $currentvalue2, ENT_COMPAT, 'UTF-8'); ?>
84+
<?php else : ?>
85+
<?php echo htmlspecialchars($key . ': ' . $currentvalue2, ENT_COMPAT, 'UTF-8'); ?>
86+
<?php endif;?>
87+
<?php else : ?>
88+
<?php echo Text::_('JUNDEFINED');?>
89+
<?php endif; ?>
6290
<td class="diff">&nbsp;</td>
6391
</tr>
64-
<?php endif; ?>
92+
<?php endforeach; ?>
93+
<?php else : ?>
94+
<tr>
95+
<th scope="row">
96+
<?php
97+
echo $value1['label']; ?>
98+
</th>
99+
<?php $currentvalue1 = is_array($value1['value']) ? json_encode($value1['value']) : $value1['value']; ?>
100+
<td class="original"><?php
101+
echo htmlspecialchars($currentvalue1); ?></td>
102+
<?php $currentvalue2 = is_array($value2) ? json_encode($value2) : $value2; ?>
103+
<td class="changed"><?php
104+
echo htmlspecialchars($currentvalue2, ENT_COMPAT, 'UTF-8'); ?></td>
105+
<td class="diff">&nbsp;</td>
106+
</tr>
65107
<?php endif; ?>
66-
<?php endforeach; ?>
67-
<?php else : ?>
68-
<tr>
69-
<th scope="row">
70-
<?php echo $value->label; ?>
71-
</th>
72-
<td class="original"><?php echo htmlspecialchars($value->value); ?></td>
73-
<?php $object2->$name->value = is_object($object2->$name->value) ? json_encode($object2->$name->value) : $object2->$name->value; ?>
74-
<td class="changed"><?php echo htmlspecialchars($object2->$name->value, ENT_COMPAT, 'UTF-8'); ?></td>
75-
<td class="diff">&nbsp;</td>
76-
</tr>
108+
<?php endif; ?>
77109
<?php endif; ?>
78-
<?php endif; ?>
79-
<?php endforeach; ?>
110+
<?php endforeach; ?>
80111
</tbody>
81112
</table>
82113
</div>

administrator/components/com_contenthistory/tmpl/preview/preview.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,27 @@
5151
<?php $subValue->value = (\is_object($subValue->value) || \is_array($subValue->value)) ? \json_encode($subValue->value, \JSON_UNESCAPED_UNICODE) : $subValue->value; ?>
5252
<tr>
5353
<th scope="row"><em>&nbsp;&nbsp;<?php echo $subValue->label; ?></em></th>
54-
<td><?php echo $subValue->value; ?></td>
54+
<td>
55+
<?php if (\is_array($subValue->value)) : ?>
56+
<?php echo json_decode($subValue->value); ?>
57+
<?php else : ?>
58+
<?php echo $subValue->value; ?>
59+
<?php endif; ?>
60+
</td>
5561
</tr>
5662
<?php endif; ?>
63+
5764
<?php endforeach; ?>
5865
<?php else : ?>
5966
<tr>
6067
<th scope="row"><?php echo $value->label; ?></th>
61-
<td><?php echo $value->value; ?></td>
68+
<td>
69+
<?php if (\is_array($value->value)) : ?>
70+
<?php echo json_encode($value->value); ?>
71+
<?php else : ?>
72+
<?php echo $value->value; ?>
73+
<?php endif; ?>
74+
</td>
6275
</tr>
6376
<?php endif; ?>
6477
<?php endforeach; ?>

administrator/components/com_newsfeeds/src/Model/NewsfeedModel.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Joomla\CMS\Language\Associations;
1818
use Joomla\CMS\Language\LanguageHelper;
1919
use Joomla\CMS\MVC\Model\AdminModel;
20+
use Joomla\CMS\Versioning\VersionableModelInterface;
2021
use Joomla\CMS\Versioning\VersionableModelTrait;
2122
use Joomla\Component\Categories\Administrator\Helper\CategoriesHelper;
2223
use Joomla\Registry\Registry;
@@ -30,7 +31,7 @@
3031
*
3132
* @since 1.6
3233
*/
33-
class NewsfeedModel extends AdminModel
34+
class NewsfeedModel extends AdminModel implements VersionableModelInterface
3435
{
3536
use VersionableModelTrait;
3637

administrator/components/com_tags/src/Model/TagModel.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Joomla\CMS\Factory;
1616
use Joomla\CMS\MVC\Model\AdminModel;
1717
use Joomla\CMS\Plugin\PluginHelper;
18+
use Joomla\CMS\Versioning\VersionableModelInterface;
1819
use Joomla\CMS\Versioning\VersionableModelTrait;
1920
use Joomla\Registry\Registry;
2021
use Joomla\String\StringHelper;
@@ -28,7 +29,7 @@
2829
*
2930
* @since 3.1
3031
*/
31-
class TagModel extends AdminModel
32+
class TagModel extends AdminModel implements VersionableModelInterface
3233
{
3334
use VersionableModelTrait;
3435

0 commit comments

Comments
 (0)