Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
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 @@ -361,8 +361,24 @@ public static function processLookupFields($object, ContentType $typesTable)
$sourceColumn = $lookup->sourceColumn ?? false;
$sourceValue = $object->$sourceColumn->value ?? false;

if ($sourceColumn && $sourceValue && ($lookupValue = static::getLookupValue($lookup, $sourceValue))) {
$object->$sourceColumn->value = $lookupValue;
if (!\is_array($sourceValue)) {
if ($sourceColumn && $sourceValue && ($lookupValue = static::getLookupValue($lookup, $sourceValue))) {
$object->$sourceColumn->value = $lookupValue;
}

continue;
}

if (\is_array($sourceValue)) {
$result = [];

foreach ($sourceValue as $key => $subValue) {
if ($sourceColumn && $subValue && ($lookupValue = static::getLookupValue($lookup, $subValue))) {
$result[$key] = $lookupValue;
}

$object->$sourceColumn->value = $result;
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use Joomla\CMS\Table\ContentHistory;
use Joomla\CMS\Table\ContentType;
use Joomla\CMS\Table\Table;
use Joomla\CMS\Versioning\VersionableModelInterface;
use Joomla\Database\ParameterType;
use Joomla\Database\QueryInterface;

Expand Down Expand Up @@ -377,13 +378,27 @@ protected function getSha1Hash()
{
$result = false;
$item_id = Factory::getApplication()->getInput()->getCmd('item_id', '');
$typeAlias = explode('.', $item_id);
Table::addIncludePath(JPATH_ADMINISTRATOR . '/components/' . $typeAlias[0] . '/tables');

[$extension, $type, $id] = explode('.', $item_id);

$app = Factory::getApplication();

$model = $app->bootComponent($extension)->getMVCFactory()->createModel($type, 'Administrator');

if ($model instanceof VersionableModelInterface) {
$item = $model->getItem($id);
$result = $model->getSha1($item);

return $result;
}

// Legacy code for history concept before 6.0.0, deprecated 6.0.0 will be removed with 8.0.0
Table::addIncludePath(JPATH_ADMINISTRATOR . '/components/' . $extension . '/tables');
$typeTable = $this->getTable('ContentType');
$typeTable->load(['type_alias' => $typeAlias[0] . '.' . $typeAlias[1]]);
$typeTable->load(['type_alias' => $extension . '.' . $type]);
$contentTable = $typeTable->getContentTable();

if ($contentTable && $contentTable->load($typeAlias[2])) {
if ($contentTable && $contentTable->load($id)) {
$helper = new CMSHelper();

$dataObject = $helper->getDataObject($contentTable);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@
</thead>
<tbody>
<?php foreach ($object1 as $name => $value1) : ?>
<?php if (isset($value1['value']) && isset($object2[$name]['value'])) : ?>
<?php $value2 = $object2[$name]['value']; ?>
<?php if (isset($value1['value']) && isset($object2[$name]['value']) && ($value1['value'] !== $object2[$name]['value'])) : ?>
<?php $value2 = $object2[$name]; ?>
<?php
if (is_array($value1)) : ?>
<?php if (is_array($value1['value'])) : ?>
Expand All @@ -57,38 +57,37 @@
</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 $keys = array_unique(array_merge(array_keys($value1['value']), array_keys($value2['value']))); ?>
<?php endif; ?>
<?php foreach ($keys as $key) : ?>
<tr>
<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 if (isset($value1['value'][$key]) && isset($value2['value'][$key]) && $value1['value'][$key] === $value2['value'][$key]) :?>
<?php continue; ?>
<?php endif;?>
<tr>
<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 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(' | ', $value2['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 endif; ?>
<td class="diff">&nbsp;</td>
</tr>
<?php endforeach; ?>
<?php else : ?>
<tr>
Expand All @@ -99,7 +98,7 @@
<?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; ?>
<?php $currentvalue2 = is_array($value2['value']) ? json_encode($value2['value']) : $value2['value']; ?>
<td class="changed"><?php
echo htmlspecialchars($currentvalue2, ENT_COMPAT, 'UTF-8'); ?></td>
<td class="diff">&nbsp;</td>
Expand Down
3 changes: 1 addition & 2 deletions administrator/components/com_tags/src/Model/TagModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
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 @@ -29,7 +28,7 @@
*
* @since 3.1
*/
class TagModel extends AdminModel implements VersionableModelInterface
class TagModel extends AdminModel
{
use VersionableModelTrait;

Expand Down
25 changes: 1 addition & 24 deletions libraries/src/MVC/Model/AdminModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
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 @@ -1465,12 +1464,11 @@ public function save($data)
// Merge table data and data so that we write all data to the history
$tableData = ArrayHelper::fromObject($table);

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

// 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);
}

Expand Down Expand Up @@ -1761,25 +1759,4 @@ 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 6.0.0
*/
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;
}
}
12 changes: 12 additions & 0 deletions libraries/src/Versioning/VersionableModelInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,16 @@ interface VersionableModelInterface
* @since 6.0.0
*/
public function loadHistory(int $historyId);

/**
* 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__
*/
public function saveHistory(array $data, string $context);
}
Loading
Loading