Skip to content

Commit

Permalink
Show the version conflict message on a separate page (see #809).
Browse files Browse the repository at this point in the history
  • Loading branch information
leofeyer committed May 19, 2017
1 parent b659d4d commit fbee6c7
Show file tree
Hide file tree
Showing 6 changed files with 142 additions and 10 deletions.
26 changes: 21 additions & 5 deletions src/Resources/contao/classes/Versions.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,22 @@ class Versions extends \Controller
*
* @param string $strTable
* @param integer $intPid
*
* @throws \InvalidArgumentException
*/
public function __construct($strTable, $intPid)
{
$this->import('Database');
parent::__construct();

$this->loadDataContainer($strTable);

if (!isset($GLOBALS['TL_DCA'][$strTable])) {
throw new \InvalidArgumentException(sprintf('"%s" is not a valid table', StringUtil::specialchars($strTable)));
}

$this->strTable = $strTable;
$this->intPid = $intPid;
$this->intPid = (int) $intPid;
}


Expand Down Expand Up @@ -318,8 +326,6 @@ public function restore($intVersion)
// Unset fields that do not exist (see #5219)
$data = array_intersect_key($data, $arrFields);

$this->loadDataContainer($this->strTable);

// Reset fields added after storing the version to their default value (see #7755)
foreach (array_diff_key($arrFields, $data) as $k=>$v)
{
Expand Down Expand Up @@ -378,8 +384,14 @@ public function restore($intVersion)

/**
* Compare versions
*
* @param bool $blnReturnBuffer
*
* @return string
*
* @throws ResponseException
*/
public function compare()
public function compare($blnReturnBuffer=false)
{
$strBuffer = '';
$arrVersions = array();
Expand Down Expand Up @@ -454,7 +466,6 @@ public function compare()
if ($intTo > 0 && $intFrom > 0)
{
\System::loadLanguageFile($this->strTable);
$this->loadDataContainer($this->strTable);

// Get the order fields
$objDcaExtractor = \DcaExtractor::getInstance($this->strTable);
Expand Down Expand Up @@ -541,6 +552,11 @@ public function compare()
$strBuffer = '<p>'.$GLOBALS['TL_LANG']['MSC']['identicalVersions'].'</p>';
}

if ($blnReturnBuffer)
{
return $strBuffer;
}

/** @var BackendTemplate|object $objTemplate */
$objTemplate = new \BackendTemplate('be_diff');

Expand Down
19 changes: 17 additions & 2 deletions src/Resources/contao/drivers/DC_Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

use Contao\CoreBundle\Exception\AccessDeniedException;
use Contao\CoreBundle\Exception\InternalServerErrorException;
use Contao\CoreBundle\Exception\ResponseException;
use Patchwork\Utf8;
use Symfony\Component\HttpFoundation\Session\Attribute\AttributeBagInterface;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
Expand Down Expand Up @@ -2212,8 +2213,22 @@ public function edit($intId=null, $ajaxId=null)
// Show a warning if the record has been saved by another user (see #8412)
if ($intLatestVersion !== null && isset($_POST['VERSION_NUMBER']) && $intLatestVersion > \Input::post('VERSION_NUMBER'))
{
\Message::addError(sprintf($GLOBALS['TL_LANG']['ERR']['versionWarning'], $intLatestVersion, \Input::post('VERSION_NUMBER')));
$this->reload();
/** @var BackendTemplate|object $objTemplate */
$objTemplate = new \BackendTemplate('be_conflict');

$objTemplate->language = $GLOBALS['TL_LANGUAGE'];
$objTemplate->title = StringUtil::specialchars($GLOBALS['TL_LANG']['MSC']['versionConflict']);
$objTemplate->theme = \Backend::getTheme();
$objTemplate->charset = \Config::get('characterSet');
$objTemplate->base = \Environment::get('base');
$objTemplate->h1 = $GLOBALS['TL_LANG']['MSC']['versionConflict'];
$objTemplate->explain1 = sprintf($GLOBALS['TL_LANG']['MSC']['versionConflict1'], $intLatestVersion, \Input::post('VERSION_NUMBER'));
$objTemplate->explain2 = sprintf($GLOBALS['TL_LANG']['MSC']['versionConflict2'], $intLatestVersion + 1, $intLatestVersion);
$objTemplate->diff = $objVersions->compare(true);
$objTemplate->href = \Environment::get('request');
$objTemplate->button = $GLOBALS['TL_LANG']['MSC']['continue'];

throw new ResponseException($objTemplate->getResponse());
}

// Redirect
Expand Down
12 changes: 9 additions & 3 deletions src/Resources/contao/languages/en/default.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,6 @@
<trans-unit id="ERR.invalidFieldName">
<source>Please enter only the following characters: A-Z0-9[]_-</source>
</trans-unit>
<trans-unit id="ERR.versionWarning">
<source>Another user has created version %s while you were editing version %s of this record.</source>
</trans-unit>
<trans-unit id="SEC.question1">
<source>Please add %d and %d.</source>
</trans-unit>
Expand Down Expand Up @@ -1688,6 +1685,15 @@ This e-mail has been generated by Contao. You can not reply to it directly.
<trans-unit id="MSC.invalidTokenUrl">
<source>Invalid token</source>
</trans-unit>
<trans-unit id="MSC.versionConflict">
<source>Version conflict</source>
</trans-unit>
<trans-unit id="MSC.versionConflict1">
<source>Another user has created version %s while you were editing version %s of this record.</source>
</trans-unit>
<trans-unit id="MSC.versionConflict2">
<source>Your changes have been now been saved as version %s and have potentially overwritten the changes of version %s, therefore please compare the versions below:</source>
</trans-unit>
<trans-unit id="MSC.dragItemsHint">
<source>Drag the items to re-order them</source>
</trans-unit>
Expand Down
39 changes: 39 additions & 0 deletions src/Resources/contao/templates/backend/be_conflict.html5
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<!DOCTYPE html>
<html lang="<?= $this->language ?>">
<head>

<meta charset="<?= $this->charset ?>">
<title><?= $this->title ?> - Contao Open Source CMS</title>
<base href="<?= $this->base ?>">
<meta name="generator" content="Contao Open Source CMS">
<meta name="viewport" content="width=device-width,initial-scale=1.0,shrink-to-fit=no">
<meta name="referrer" content="origin">

<link rel="stylesheet" href="<?= TL_ASSETS_URL ?>system/themes/<?= $this->theme ?>/fonts.css">
<link rel="stylesheet" href="<?= TL_ASSETS_URL ?>system/themes/<?= $this->theme ?>/basic.css">
<link rel="stylesheet" href="<?= TL_ASSETS_URL ?>system/themes/<?= $this->theme ?>/diff.css">
<link rel="stylesheet" href="<?= TL_ASSETS_URL ?>system/themes/<?= $this->theme ?>/conflict.css">
<?= $this->stylesheets ?>

<script><?= $this->getLocaleString() ?></script>
<script src="<?= TL_ASSETS_URL ?>assets/mootools/js/mootools.min.js"></script>
<script src="<?= TL_ASSETS_URL ?>bundles/contaocore/mootao.min.js"></script>
<script src="<?= TL_ASSETS_URL ?>bundles/contaocore/core.min.js"></script>
<script><?= $this->getDateString() ?></script>
<?= $this->javascripts ?>

</head>
<body class="<?= $this->ua ?>">

<div id="container" class="cf">
<div id="main">
<h1><?= $this->h1 ?></h1>
<p><?= $this->explain1 ?></p>
<p><?= $this->explain2 ?></p>
<div id="diff"><?= $this->diff ?></div>
<p><a href="<?= $this->href ?>" class="tl_submit"><?= $this->button ?></a></p>
</div>
</div>

</body>
</html>
2 changes: 2 additions & 0 deletions src/Resources/contao/themes/flexible/conflict.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

54 changes: 54 additions & 0 deletions src/Resources/contao/themes/flexible/src/conflict.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/**
* Contao Open Source CMS
*
* Copyright (c) 2005-2017 Leo Feyer
*
* @license LGPL-3.0+
*/

/* Body */
body {
background:#eaeaea url("icons/stop.svg") center 3em no-repeat;
}

/* Container */
#container {
width:640px;
margin:14em auto 0;
background:#fff;
}
#main {
padding-bottom:6px;
}

/* Elements */
h1 {
padding:14px 18px 12px;
line-height:22px;
border-bottom:1px solid #ddd;
}
p {
line-height:1.3;
}
p a {
vertical-align:middle;
}
#diff {
margin:18px 0;
}
#diff,#main > p {
padding-left:18px;
padding-right:18px;
}
#main > p:first-of-type {
margin:18px 0 9px;
}

/* Handheld */
@media (max-width:767px) {
#container {
width:auto;
margin-left:10px;
margin-right:10px;
}
}

0 comments on commit fbee6c7

Please sign in to comment.