Skip to content
Closed
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
3 changes: 2 additions & 1 deletion PageSnapshot.module
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ class PageSnapshot extends WireData implements Module {
}

// find values
$where = $revision_id ? "t1.id = ? AND " : "";
$where = $revision_id ? "t1.id <= ? AND " : "";
$stmt = $this->database->prepare($sql = "
SELECT t1.pages_id, t1.id AS revision, t2.fields_id, t2.property, t2.data
FROM (
Expand All @@ -258,6 +258,7 @@ class PageSnapshot extends WireData implements Module {
INNER JOIN " . VersionControl::TABLE_DATA . " AS t2
ON t2.revisions_id = t1.id AND t2.fields_id = t1.fields_id
GROUP BY t1.pages_id, t2.fields_id, t2.property
ORDER BY revision ASC
");
$input_parameters = $where ? array($revision_id) : array();
$input_parameters = array_merge($input_parameters, $page_ids);
Expand Down
57 changes: 46 additions & 11 deletions ProcessVersionControl.module
Original file line number Diff line number Diff line change
Expand Up @@ -240,11 +240,11 @@ class ProcessVersionControl extends Process implements ConfigurableModule {

// find values
$stmt = $this->database->prepare("
SELECT r.pages_id, f.name AS field_name, r.timestamp, r.users_id, r.username, d.revisions_id, d.property, d.data
SELECT r.pages_id, f.name AS field_name, r.timestamp, r.users_id, r.username, d.revisions_id, GROUP_CONCAT(d.property) AS propertylist, MIN(DISTINCT d.data)
FROM fields AS f, " . VersionControl::TABLE_REVISIONS . " AS r, " . VersionControl::TABLE_DATA . " AS d
WHERE r.pages_id IN (" . rtrim(str_repeat('?, ', count($page_ids)), ', ') . ") AND d.revisions_id = r.id AND f.id = d.fields_id
GROUP BY r.id, f.id
ORDER BY f.id, d.id DESC
ORDER BY f.id, MIN(DISTINCT d.id) DESC
");
$stmt->execute($page_ids);

Expand All @@ -265,6 +265,7 @@ class ProcessVersionControl extends Process implements ConfigurableModule {
'username' => isset($row['username']) ? $this->sanitizer->name($row['username']) : null,
'revision' => isset($row['revisions_id']) ? $row['revisions_id'] : null,
'date' => isset($row['timestamp']) ? $row['timestamp'] : null,
'propertylist' => isset($row['propertylist']) ? $row['propertylist'] : null,
'data' => isset($row['data']) ? $row['data'] : null
);
if (isset($row['users_id']) && $user = $this->users->get((int) $row['users_id'])) {
Expand Down Expand Up @@ -356,11 +357,20 @@ class ProcessVersionControl extends Process implements ConfigurableModule {
$r2 = (int) $r2;
if (!$r1 || !$r2) throw new WireException("Revisions need to be provided in following format: 123:124");

$data = array();
$propertyselect = null;
$propertywhere = null;
if ($this->input->get->property!='undefined') {
$propertyselect = ', d.property';
$propertywhere = ' AND d.property=\''.$this->input->get->property.'\'';
$data = array();

}
// find values
$stmt = $this->database->prepare("
SELECT r.id, d.data
SELECT r.id, d.data$propertyselect
FROM fields AS f, " . VersionControl::TABLE_REVISIONS . " AS r, " . VersionControl::TABLE_DATA . " AS d
WHERE r.id IN(:r1, :r2) AND d.revisions_id = r.id AND f.name = :field_name AND d.fields_id = f.id
WHERE r.id IN(:r1, :r2) AND d.revisions_id = r.id AND f.name = :field_name AND d.fields_id = f.id$propertywhere
ORDER BY r.id ASC
LIMIT 2
");
Expand All @@ -370,8 +380,9 @@ class ProcessVersionControl extends Process implements ConfigurableModule {
$stmt->execute();

// render output
$data = array();
$rowcount = 0;
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
$rowcount++;
$id = $row['id'] == $r1 ? "r1" : "r2";
if ($field->type == "FieldtypePage") {
$data[$id] = array();
Expand Down Expand Up @@ -399,6 +410,10 @@ class ProcessVersionControl extends Process implements ConfigurableModule {
echo "<textarea id='{$id}' class='revision' data-revision='{$row['id']}'>{$row['data']}</textarea>";
}
}
// if the query only returns one revision, then we add a warning for the missing rivision (r1) - this is only a tempoary solution
if ($rowcount==1) {
echo "<textarea id='r1' class='revision' data-revision='{$r1}'>" . __("Active revision not defined in this language") . "</textarea>";
}
if ($field->type == "FieldtypePage") {
// in the case of a Page field comparing strings makes little sense;
// comparing values manually yields improved results and flexibility
Expand Down Expand Up @@ -662,12 +677,32 @@ class ProcessVersionControl extends Process implements ConfigurableModule {
if ($user->id) $user_name = wirePopulateStringTags($this->user_name_format, $user);
}
if (!$user_name) $user_name = $row['username'];
$markup .= "<li><a"
. " data-revision='{$row['revision']}'"
. " data-date='{$row['date']}'"
. " href='#'>"
. "<span class='date'>{$row['date']}</span> <span class='user'>{$user_name}</span>"
. "</a></li>";
$langs = null;
if (isset($row['propertylist']) and ($row['propertylist']!='data')) {
$languages = wire('languages');
if (isset($languages)) {
$propertylist = array_flip(explode(',',$row['propertylist']));
$lids = array();
$markup .= "<li><span class='date'>{$row['date']}</span> ";
foreach ($languages as $language) {
$propertyidx = 'data'.$language->id;
$markup .= isset($propertylist[$propertyidx])
? "<a data-revision='{$row['revision']}'"
. " data-date='{$row['date']}'"
. " data-property='$propertyidx'"
. " href='#'>"
. "<span class='language'>$language->title</span></a> "
: "<span class='language'>&nbsp;</span> ";
}
$markup .= "<span class='user'>{$user_name}</span></li>";
}
} else
$markup .= "<li><a"
. " data-revision='{$row['revision']}'"
. " data-date='{$row['date']}'"
. " href='#'>"
. "<span class='date'>{$row['date']}</span> <span class='user'>{$user_name}</span>"
. "</a></li>";
}
$markup .= "</ul>";
} else {
Expand Down
20 changes: 15 additions & 5 deletions VersionControl.css
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,26 @@ textarea.version_control_filedata {
}

.field-revisions a {
margin: 0 5px;
padding: 5px 4px;
margin: 0 0px;
padding: 5px 0px;
white-space: nowrap;
font-weight: normal;
display: inline-block;
text-shadow: 0 1px 0 rgba(255,255,255,0.5);
}

.field-revisions a .user {
padding-left: 2em;
.field-revisions .user {
padding-left: 0.2em;
}

.field-revisions .date {
padding-left: 0.0em;
}

.field-revisions .language {
display: inline-block;
width: 60px;
padding-left: 0.0em;
}

.compare-revisions > a.diff-trigger::before {
Expand Down Expand Up @@ -102,7 +112,7 @@ textarea.version_control_filedata {
.field-revisions .ui-state-active {
border: 0;
cursor: default;
padding: 5px 4px;
padding: 5px 0px;
}

body.template-admin .field-revisions .ui-state-active {
Expand Down
3 changes: 2 additions & 1 deletion VersionControl.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,8 @@ $(function() {
var field = $(this).parents('.field-revisions:first').data('field');
var r1 = $(this).parents('.field-revisions:first').find('.ui-state-active').data('revision');
var r2 = $(this).data('revision');
var href = moduleConfig.processPage+'diff/?revisions='+r1+':'+r2+'&field='+field;
var property = $(this).data('property');
var href = moduleConfig.processPage+'diff/?revisions='+r1+':'+r2+'&field='+field+'&property='+property;
var label = moduleConfig.i18n.compareWithCurrent;
$(this).before('<div class="compare-revisions"><a class="diff-trigger" href="'+href+'">'+label+'</a></div>');
}
Expand Down
19 changes: 18 additions & 1 deletion VersionControl.module
Original file line number Diff line number Diff line change
Expand Up @@ -730,7 +730,24 @@ class VersionControl extends WireData implements Module, ConfigurableModule {
}
if (!count($data_array)) $data_array['0.data'] = null;
} else if ($data instanceof LanguagesPageFieldValue) {
foreach ($data->getChanges() as $key) {
// There are two cases to be considered
// 1) We read the data from the fields of a page already existing at module installation
// 2) We read the data from a field modified after the module was installed
if ($object instanceof Page) {
// 1) Page/fields already exist at time of module installation
// we need to save the corresponding value for each language installed as a reference for
// future changes
$data_keys = array();
foreach (wire('languages') as $language) {
$data_keys[] = 'data'.$language->id;
}
} else {
// 2) We need to save the new values of fields modified on the page
// The function getChanges() prefectly returns these values
$data_keys = $data->getChanges();
}
// loop over the page/field data for each of the keys found above
foreach ($data_keys as $key) {
if ($key == 'data') continue;
$data_array[$key] = $data->getLanguageValue(str_replace('data', '', $key));
}
Expand Down