Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RTM] Warn if another user has edited a record #809

Merged
merged 4 commits into from
May 5, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Contao core bundle change log

### DEV


* Warn if another user has edited a record when saving it (see #809).
* Optimize the element preview height (see #810).
* Use the file meta data by default when adding an image (see #807).
* Use the kernel.project_dir parameter (see #758).
Expand All @@ -21,5 +22,5 @@
* Add the contao.image.target_dir parameter (see #684).
* Match the security firewall based on the request scope (see #677).
* Add the contao.web_dir parameter (see contao/installation-bundle#40).
* Look up the form class and allow to choose the type (see contao/core#8527).
* Look up the form class and allow to choose the type (see contao/core#8527).
* Auto-select the active page in the quick navigation/link module (see contao/core#8587).
3 changes: 1 addition & 2 deletions src/Resources/contao/classes/Maintenance.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,13 @@ public function run()

if ($isLocked)
{
$objTemplate->class= 'tl_confirm';
$objTemplate->class= 'tl_error';
$objTemplate->explain = $GLOBALS['TL_LANG']['MSC']['maintenanceEnabled'];
$objTemplate->submit = $GLOBALS['TL_LANG']['tl_maintenance']['maintenanceDisable'];
}
else
{
$objTemplate->class= 'tl_info';
$objTemplate->explain = $GLOBALS['TL_LANG']['MSC']['maintenanceDisabled'];
$objTemplate->submit = $GLOBALS['TL_LANG']['tl_maintenance']['maintenanceEnable'];
}

Expand Down
20 changes: 20 additions & 0 deletions src/Resources/contao/classes/Versions.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,26 @@ public function setUserId($intUserId)
}


/**
* Returns the latest version
*
* @return integer|null
*/
public function getLatestVersion()
{
if (!$GLOBALS['TL_DCA'][$this->strTable]['config']['enableVersioning'])
{
return null;
}

$objVersion = $this->Database->prepare("SELECT MAX(version) AS version FROM tl_version WHERE fromTable=? AND pid=?")
->limit(1)
->execute($this->strTable, $this->intPid);

return (int) $objVersion->version;
}


/**
* Create the initial version of a record
*/
Expand Down
18 changes: 17 additions & 1 deletion src/Resources/contao/drivers/DC_Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -2098,6 +2098,15 @@ public function edit($intId=null, $ajaxId=null)
</div>
</form>';

$strVersionField = '';

// Store the current version number (see #8412)
if (($intLatestVersion = $objVersions->getLatestVersion()) !== null)
{
$strVersionField = '
<input type="hidden" name="VERSION_NUMBER" value="'.$intLatestVersion.'">';
}

// Begin the form (-> DO NOT CHANGE THIS ORDER -> this way the onsubmit attribute of the form can be changed by a field)
$return = $version . '
<div id="tl_buttons">' . (\Input::get('nb') ? '&nbsp;' : '
Expand All @@ -2107,7 +2116,7 @@ public function edit($intId=null, $ajaxId=null)
<form action="'.ampersand(\Environment::get('request'), true).'" id="'.$this->strTable.'" class="tl_form" method="post" enctype="' . ($this->blnUploadable ? 'multipart/form-data' : 'application/x-www-form-urlencoded') . '"'.(!empty($this->onsubmit) ? ' onsubmit="'.implode(' ', $this->onsubmit).'"' : '').'>
<div class="tl_formbody_edit">
<input type="hidden" name="FORM_SUBMIT" value="'.$this->strTable.'">
<input type="hidden" name="REQUEST_TOKEN" value="'.REQUEST_TOKEN.'">
<input type="hidden" name="REQUEST_TOKEN" value="'.REQUEST_TOKEN.'">'.$strVersionField.'
<input type="hidden" name="FORM_FIELDS[]" value="'.\StringUtil::specialchars($this->strPalette).'">'.($this->noReload ? '

<p class="tl_error">'.$GLOBALS['TL_LANG']['ERR']['general'].'</p>' : '').$return;
Expand Down Expand Up @@ -2172,6 +2181,13 @@ public function edit($intId=null, $ajaxId=null)
->execute(time(), $this->intId);
}

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

// Redirect
if (isset($_POST['saveNclose']))
{
Expand Down
6 changes: 3 additions & 3 deletions src/Resources/contao/languages/en/default.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,9 @@
<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 @@ -1268,9 +1271,6 @@ This e-mail has been generated by Contao. You can not reply to it directly.
<trans-unit id="MSC.maintenanceEnabled">
<source>The maintenance mode is currently enabled.</source>
</trans-unit>
<trans-unit id="MSC.maintenanceDisabled">
<source>The maintenance mode is currently disabled.</source>
</trans-unit>
<trans-unit id="MSC.wordWrap">
<source>Word wrap</source>
</trans-unit>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@
<div class="tl_formbody_edit">
<input type="hidden" name="FORM_SUBMIT" value="tl_maintenance_mode">
<input type="hidden" name="REQUEST_TOKEN" value="<?= REQUEST_TOKEN ?>">
<div class="tl_tbox">
<p class="<?= $this->class ?>"><?= $this->explain ?></p>
</div>
<?php if ($this->explain): ?>
<div class="tl_message">
<p class="<?= $this->class ?>"><?= $this->explain ?></p>
</div>
<?php endif; ?>
</div>
<div class="tl_submit_container">
<button type="submit" name="maintenance" class="tl_submit"><?= $this->submit ?></button>
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/contao/themes/flexible/main.css

Large diffs are not rendered by default.

28 changes: 18 additions & 10 deletions src/Resources/contao/themes/flexible/src/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -197,29 +197,29 @@ h2.sub_headline {
color:#589b0e;
}
.tl_message {
margin:18px 18px 0;
margin:18px 0 0;
}
.tl_gerror {
margin:12px 9px 6px;
margin:12px;
padding:3px 0 3px 22px;
background:url("icons/error.svg") no-repeat left center;
}
.tl_error,.tl_confirm,.tl_info,.tl_new {
margin:0 0 1px;
padding:3px 6px 3px 22px;
padding:12px 18px 12px 37px;
line-height:1.2;
}
.tl_error {
background:url("icons/error.svg") no-repeat left center;
background:#faebeb url("icons/error.svg") no-repeat 16px center;
}
.tl_confirm {
background:url("icons/ok.svg") no-repeat left center;
background:#eefcde url("icons/ok.svg") no-repeat 16px center;
}
.tl_info {
background:url("icons/show.svg") no-repeat left center;
background:#e9f0f7 url("icons/show.svg") no-repeat 16px center;
}
.tl_new {
background:url("icons/featured.svg") no-repeat left center;
background:#fbf2e5 url("icons/featured.svg") no-repeat 16px center;
}
.tl_gerror,.tl_gerror a,.tl_error,.tl_error a {
color:#c33;
Expand Down Expand Up @@ -392,6 +392,9 @@ input[type=search]::-webkit-search-decoration {
.maintenance_inactive .tl_tbox {
padding:6px 2% 14px;
}
.maintenance_inactive .tl_message {
margin-top:0;
}
.maintenance_inactive h2.sub_headline {
margin:18px 2% 3px;
}
Expand All @@ -400,11 +403,11 @@ input[type=search]::-webkit-search-decoration {
padding:0 2% 24px;
border:0;
}
#tl_maintenance_mode .tl_tbox {
padding-top:4px;
#tl_maintenance_mode .tl_message {
margin-bottom:12px;
}
#tl_maintenance_index .tl_tbox {
margin-top:-13px;
margin-top:-12px;
}

/* Picker search */
Expand Down Expand Up @@ -882,6 +885,11 @@ ul.sgallery li {
#tl_messages p:not([class]) {
margin-top:6px;
}
#tl_messages .tl_error,#tl_messages .tl_confirm,#tl_messages .tl_info,#tl_messages .tl_new {
padding:3px 6px 3px 21px;
background-color:transparent;
background-position:left center;
}
#tl_shortcuts p a {
text-decoration:underline;
}
Expand Down