Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
b2ac1ce
RFC extend versioning
rdeutz May 22, 2025
02e48ba
cs fix
rdeutz May 22, 2025
385e025
cs fix 2
rdeutz May 22, 2025
3d832a5
Update libraries/src/MVC/Model/VersionableModelInterface.php
rdeutz May 22, 2025
dc5e7a1
Update libraries/src/Versioning/VersionableModelTrait.php
rdeutz May 22, 2025
eb8533b
Merge branch '6.0-dev' into versions
rdeutz May 22, 2025
3eac007
Merge branch '6.0-dev' into versions
rdeutz Jun 12, 2025
59d76b1
Merge branch '6.0-dev' into versions
rdeutz Jun 25, 2025
c7734b3
Merge remote-tracking branch 'Joomla-main-repo/6.0-dev' into versions
RobertDeutz Jul 29, 2025
47d49b4
Merge branch '6.0-dev' into versions
rdeutz Aug 2, 2025
372ab96
same change for other models
RobertDeutz Aug 3, 2025
35e01da
cs
RobertDeutz Aug 3, 2025
8495392
fix json decode for history
RobertDeutz Aug 4, 2025
028805a
Merge branch '6.0-dev' into versions
rdeutz Aug 6, 2025
4604ba3
Merge branch '6.0-dev' into versions
richard67 Aug 11, 2025
326f17c
fix testing
RobertDeutz Aug 14, 2025
3ed25f8
fixed compare view
RobertDeutz Aug 14, 2025
2f6e8f6
added a missing Language Tag
RobertDeutz Aug 14, 2025
38175ba
Better readability
RobertDeutz Aug 14, 2025
1fff98f
cs fix1
RobertDeutz Aug 14, 2025
541f78e
Merge branch '6.0-dev' into versions
rdeutz Aug 14, 2025
352e76a
missed a case
RobertDeutz Aug 14, 2025
0ac8205
cs fix2
RobertDeutz Aug 14, 2025
db93c16
check if the model supports versions
RobertDeutz Aug 14, 2025
4d88384
cs fix3
RobertDeutz Aug 14, 2025
5d68b82
show old data better
RobertDeutz Aug 14, 2025
feab254
changes made based on code review
RobertDeutz Aug 15, 2025
960f246
moving the interface file, thank you IDE for nothing
RobertDeutz Aug 15, 2025
9dea69b
missed one place
RobertDeutz Aug 15, 2025
c027b4d
moved it back, I don’t want the trait in adminModel
RobertDeutz Aug 16, 2025
c567d36
fix version note
RobertDeutz Aug 16, 2025
38000a1
cs fix
RobertDeutz Aug 16, 2025
3ed378a
Merge branch '6.0-dev' into versions
richard67 Aug 16, 2025
239db54
Apply suggestion from code review
richard67 Aug 17, 2025
8728cd0
Merge branch '6.0-dev' into versions
richard67 Aug 17, 2025
4a424ce
Fix PHPCS
richard67 Aug 17, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Joomla\CMS\MVC\Model\AdminModel;
use Joomla\CMS\Table\Table;
use Joomla\CMS\Table\TableInterface;
use Joomla\CMS\Versioning\VersionableModelInterface;
use Joomla\CMS\Versioning\VersionableModelTrait;
use Joomla\Component\Categories\Administrator\Helper\CategoriesHelper;
use Joomla\Database\ParameterType;
Expand All @@ -29,7 +30,7 @@
*
* @since 1.6
*/
class BannerModel extends AdminModel
class BannerModel extends AdminModel implements VersionableModelInterface
{
use VersionableModelTrait;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Joomla\CMS\Factory;
use Joomla\CMS\MVC\Model\AdminModel;
use Joomla\CMS\Table\Table;
use Joomla\CMS\Versioning\VersionableModelInterface;
use Joomla\CMS\Versioning\VersionableModelTrait;

// phpcs:disable PSR1.Files.SideEffects
Expand All @@ -24,7 +25,7 @@
*
* @since 1.6
*/
class ClientModel extends AdminModel
class ClientModel extends AdminModel implements VersionableModelInterface
{
use VersionableModelTrait;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
use Joomla\CMS\Plugin\PluginHelper;
use Joomla\CMS\Table\Category;
use Joomla\CMS\UCM\UCMType;
use Joomla\CMS\Versioning\VersionableModelInterface;
use Joomla\CMS\Versioning\VersionableModelTrait;
use Joomla\Component\Categories\Administrator\Helper\CategoriesHelper;
use Joomla\Database\ParameterType;
Expand All @@ -43,7 +44,7 @@
*
* @since 1.6
*/
class CategoryModel extends AdminModel
class CategoryModel extends AdminModel implements VersionableModelInterface
{
use VersionableModelTrait;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Joomla\CMS\Language\Text;
use Joomla\CMS\MVC\Model\AdminModel;
use Joomla\CMS\String\PunycodeHelper;
use Joomla\CMS\Versioning\VersionableModelInterface;
use Joomla\CMS\Versioning\VersionableModelTrait;
use Joomla\Component\Categories\Administrator\Helper\CategoriesHelper;
use Joomla\Database\ParameterType;
Expand All @@ -33,7 +34,7 @@
*
* @since 1.6
*/
class ContactModel extends AdminModel
class ContactModel extends AdminModel implements VersionableModelInterface
{
use VersionableModelTrait;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
use Joomla\CMS\Table\TableInterface;
use Joomla\CMS\Tag\TaggableTableInterface;
use Joomla\CMS\UCM\UCMType;
use Joomla\CMS\Versioning\VersionableModelInterface;
use Joomla\CMS\Versioning\VersionableModelTrait;
use Joomla\CMS\Workflow\Workflow;
use Joomla\Component\Categories\Administrator\Helper\CategoriesHelper;
Expand All @@ -49,7 +50,7 @@
* @since 1.6
*/

class ArticleModel extends AdminModel implements WorkflowModelInterface
class ArticleModel extends AdminModel implements WorkflowModelInterface, VersionableModelInterface
{
use WorkflowBehaviorTrait;
use VersionableModelTrait;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Joomla\Filesystem\File;
use Joomla\Filesystem\Folder;
use Joomla\Filesystem\Path;
use Joomla\Utilities\ArrayHelper;

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

if (\is_object($object)) {
foreach ($object as $name => $value) {
if (!\is_null($value) && $subObject = json_decode($value)) {
$object->$name = $subObject;
if (!\is_null($value)) {
if (\is_object($value)) {
$object->$name = ArrayHelper::fromObject($value);
continue;
}

if (str_starts_with($value, '{')) {
$object->$name = json_decode($value);
continue;
}

$object->$name = $value;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,16 @@

use Joomla\CMS\Language\Text;
use Joomla\CMS\Session\Session;
use Joomla\Utilities\ArrayHelper;

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

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

$version2 = $this->items[0];
$version1 = $this->items[1];
$object1 = $version1->data;
$object2 = $version2->data;
$object1 = ArrayHelper::fromObject($version1->data);
$object2 = ArrayHelper::fromObject($version2->data);

/** @var Joomla\CMS\WebAsset\WebAssetManager $wa */
$wa = $this->getDocument()->getWebAssetManager();
Expand All @@ -43,40 +44,70 @@
</tr>
</thead>
<tbody>
<?php foreach ($object1 as $name => $value) : ?>
<?php if (isset($value->value) && isset($object2->$name->value) && $value->value != $object2->$name->value) : ?>
<?php if (is_object($value->value)) : ?>
<tr>
<td colspan="4">
<strong><?php echo $value->label; ?></strong>
</td>
</tr>
<?php foreach ($value->value as $subName => $subValue) : ?>
<?php $newSubValue = $object2->$name->value->$subName->value ?? ''; ?>
<?php if ($subValue->value || $newSubValue) : ?>
<?php if ($subValue->value != $newSubValue) : ?>
<?php foreach ($object1 as $name => $value1) : ?>
<?php if (isset($value1['value']) && isset($object2[$name]['value'])) : ?>
<?php $value2 = $object2[$name]['value']; ?>
<?php
if (is_array($value1)) : ?>
<?php if (is_array($value1['value'])) : ?>
<tr>
<td colspan="4">
<strong><?php echo $value1['label']; ?></strong>
</td>
</tr>
<?php $keys = array_keys($value1['value']); ?>
<?php if (isset($value2['value']) && is_array($value2['value'])) :?>
<?php $keys = array_merge(array_keys($value1['value']), array_keys($value2['value'])); ?>
<?php endif; ?>
<?php foreach ($keys as $key) : ?>
<tr>
<th scope="row"><em>&nbsp;&nbsp;<?php echo $subValue->label; ?></em></th>
<td class="original"><?php echo htmlspecialchars($subValue->value, ENT_COMPAT, 'UTF-8'); ?></td>
<td class="changed" ><?php echo htmlspecialchars($newSubValue, ENT_COMPAT, 'UTF-8'); ?></td>
<td></td>
<td class="original">
<?php if (isset($value1['value'][$key])) : ?>
<?php $currentvalue1 = $value1['value'][$key]; ?>
<?php if (is_array($value1['value'][$key])) : ?>
<?php $currentvalue1 = implode(' | ', $value1['value'][$key]); ?>
<?php echo htmlspecialchars($key . ': ' . $currentvalue1, ENT_COMPAT, 'UTF-8'); ?>
<?php else : ?>
<?php echo htmlspecialchars($key . ': ' . $currentvalue1, ENT_COMPAT, 'UTF-8'); ?>
<?php endif;?>
<?php else : ?>
<?php echo Text::_('JUNDEFINED');?>
<?php endif; ?>
</td>
<td class="changed">
<?php if (isset($value2['value'][$key])) : ?>
<?php $currentvalue2 = $value2['value'][$key]; ?>
<?php if (is_array($value2['value'][$key])) : ?>
<?php $currentvalue2 = implode(' | ', $value1['value'][$key]); ?>
<?php echo htmlspecialchars($key . ': ' . $currentvalue2, ENT_COMPAT, 'UTF-8'); ?>
<?php else : ?>
<?php echo htmlspecialchars($key . ': ' . $currentvalue2, ENT_COMPAT, 'UTF-8'); ?>
<?php endif;?>
<?php else : ?>
<?php echo Text::_('JUNDEFINED');?>
<?php endif; ?>
<td class="diff">&nbsp;</td>
</tr>
<?php endif; ?>
<?php endforeach; ?>
<?php else : ?>
<tr>
<th scope="row">
<?php
echo $value1['label']; ?>
</th>
<?php $currentvalue1 = is_array($value1['value']) ? json_encode($value1['value']) : $value1['value']; ?>
<td class="original"><?php
echo htmlspecialchars($currentvalue1); ?></td>
<?php $currentvalue2 = is_array($value2) ? json_encode($value2) : $value2; ?>
<td class="changed"><?php
echo htmlspecialchars($currentvalue2, ENT_COMPAT, 'UTF-8'); ?></td>
<td class="diff">&nbsp;</td>
</tr>
<?php endif; ?>
<?php endforeach; ?>
<?php else : ?>
<tr>
<th scope="row">
<?php echo $value->label; ?>
</th>
<td class="original"><?php echo htmlspecialchars($value->value); ?></td>
<?php $object2->$name->value = is_object($object2->$name->value) ? json_encode($object2->$name->value) : $object2->$name->value; ?>
<td class="changed"><?php echo htmlspecialchars($object2->$name->value, ENT_COMPAT, 'UTF-8'); ?></td>
<td class="diff">&nbsp;</td>
</tr>
<?php endif; ?>
<?php endif; ?>
<?php endif; ?>
<?php endforeach; ?>
<?php endforeach; ?>
</tbody>
</table>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,27 @@
<?php $subValue->value = (\is_object($subValue->value) || \is_array($subValue->value)) ? \json_encode($subValue->value, \JSON_UNESCAPED_UNICODE) : $subValue->value; ?>
<tr>
<th scope="row"><em>&nbsp;&nbsp;<?php echo $subValue->label; ?></em></th>
<td><?php echo $subValue->value; ?></td>
<td>
<?php if (\is_array($subValue->value)) : ?>
<?php echo json_decode($subValue->value); ?>
<?php else : ?>
<?php echo $subValue->value; ?>
<?php endif; ?>
</td>
</tr>
<?php endif; ?>

<?php endforeach; ?>
<?php else : ?>
<tr>
<th scope="row"><?php echo $value->label; ?></th>
<td><?php echo $value->value; ?></td>
<td>
<?php if (\is_array($value->value)) : ?>
<?php echo json_encode($value->value); ?>
<?php else : ?>
<?php echo $value->value; ?>
<?php endif; ?>
</td>
</tr>
<?php endif; ?>
<?php endforeach; ?>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Joomla\CMS\Language\Associations;
use Joomla\CMS\Language\LanguageHelper;
use Joomla\CMS\MVC\Model\AdminModel;
use Joomla\CMS\Versioning\VersionableModelInterface;
use Joomla\CMS\Versioning\VersionableModelTrait;
use Joomla\Component\Categories\Administrator\Helper\CategoriesHelper;
use Joomla\Registry\Registry;
Expand All @@ -30,7 +31,7 @@
*
* @since 1.6
*/
class NewsfeedModel extends AdminModel
class NewsfeedModel extends AdminModel implements VersionableModelInterface
{
use VersionableModelTrait;

Expand Down
3 changes: 2 additions & 1 deletion administrator/components/com_tags/src/Model/TagModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Joomla\CMS\Factory;
use Joomla\CMS\MVC\Model\AdminModel;
use Joomla\CMS\Plugin\PluginHelper;
use Joomla\CMS\Versioning\VersionableModelInterface;
use Joomla\CMS\Versioning\VersionableModelTrait;
use Joomla\Registry\Registry;
use Joomla\String\StringHelper;
Expand All @@ -28,7 +29,7 @@
*
* @since 3.1
*/
class TagModel extends AdminModel
class TagModel extends AdminModel implements VersionableModelInterface
{
use VersionableModelTrait;

Expand Down
3 changes: 2 additions & 1 deletion administrator/components/com_users/src/Model/NoteModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Joomla\CMS\Factory;
use Joomla\CMS\MVC\Model\AdminModel;
use Joomla\CMS\Plugin\PluginHelper;
use Joomla\CMS\Versioning\VersionableModelInterface;
use Joomla\CMS\Versioning\VersionableModelTrait;

// phpcs:disable PSR1.Files.SideEffects
Expand All @@ -24,7 +25,7 @@
*
* @since 2.5
*/
class NoteModel extends AdminModel
class NoteModel extends AdminModel implements VersionableModelInterface
{
use VersionableModelTrait;

Expand Down
1 change: 1 addition & 0 deletions administrator/language/en-GB/joomla.ini
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ JFIELD_PLG_SEARCH_SEARCHLIMIT_LABEL="Search Limit"
JFIELD_PUBLISHED_DESC="Set publication status."
JFIELD_READMORE_DESC="Add a custom text instead of Read More."
JFIELD_READMORE_LABEL="Read More Text"
JFIELD_RULES_LABEL="Group Permissions"
JFIELD_SPACER_LABEL="<span style=\"width:auto\"><hr></span>"
JFIELD_TITLE_DESC="Title"
JFIELD_VERSION_HISTORY_DESC="This button allows you to open a window to view older versions of this item."
Expand Down
36 changes: 36 additions & 0 deletions libraries/src/MVC/Model/AdminModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
use Joomla\CMS\Table\TableInterface;
use Joomla\CMS\Tag\TaggableTableInterface;
use Joomla\CMS\UCM\UCMType;
use Joomla\CMS\Versioning\VersionableModelInterface;
use Joomla\CMS\Versioning\Versioning;
use Joomla\Database\ParameterType;
use Joomla\Registry\Registry;
use Joomla\String\StringHelper;
Expand Down Expand Up @@ -1443,6 +1445,19 @@ public function save($data)
}
}

if ($this instanceof VersionableModelInterface) {
// Merge table data and data so that we write all data to the history
$tableData = ArrayHelper::fromObject($table);

$historyData = array_merge($tableData, $data);

// We have to set the key for new items, would be always 0 otherwise
$historyData[$key] = $this->getState($this->getName() . '.id');


$this->saveHistory($historyData, $context);
}

if ($app->getInput()->get('task') == 'editAssociations') {
return $this->redirectToAssociations($data);
}
Expand Down Expand Up @@ -1730,4 +1745,25 @@ protected function redirectToAssociations($data)

return true;
}

/**
* Method to save the history.
*
* @param array $data The form data.
* @param string $context The model context.
*
* @return boolean True on success, False on error.
*
* @since __DEPLOY_VERSION__
*/
protected function saveHistory(array $data, string $context)
{
$id = $this->getState($this->getName() . '.id');

$versionNote = \array_key_exists('version_note', $data) ? $data['version_note'] : '';

$result = Versioning::store($context, $id, ArrayHelper::toObject($data), $versionNote);

return $result;
}
}
Loading
Loading