Commit e95ebc66 authored by Robert Lyon's avatar Robert Lyon
Browse files

Bug 1626805: Allow the view constructor to fix missing layout info



Sometimes in MySql if many users are copying a page at once the
view_rows_columns information can get deleted.

As we can work out what the values should have been from other tables
we can regenerate it and add it back in.

If the view doesn't have a layout set it hasn't changed from when
first been made so we can make it the same as view type's template

To test: see bug report

behatnotneeded

Change-Id: I81c8e33dc1bc4121c1df97e1acbc981ad969271c
Signed-off-by: Robert Lyon's avatarRobert Lyon <robertl@catalyst.net.nz>
parent 72498ad7
......@@ -314,6 +314,48 @@ class View {
// set only for existing views - _create provides default value
if (empty($this->columnsperrow)) {
$this->columnsperrow = get_records_assoc('view_rows_columns', 'view', $this->get('id'), 'row', 'row, columns');
if (empty($this->columnsperrow)) {
// if we are missing the info for some reason we will give the page it's layout back
// this can happen in MySQL when many users are copying the same page
if ($this->layout) {
if ($rowscols = get_records_sql_array("
SELECT vlrc.row, vlc.columns
FROM {view_layout_rows_columns} vlrc
JOIN {view_layout_columns} vlc ON vlc.id = vlrc.columns
WHERE viewlayout = ?", array($this->layout))) {
$default = array();
foreach ($rowscols as $row) {
insert_record('view_rows_columns', (object) array(
'view' => $this->get('id'),
'row' => $row->row, 'columns' => $row->columns));
$default[$row->row] = $row;
}
}
}
else if ($rowscols = get_records_sql_array("
SELECT vrc.row, vrc.columns
FROM {view} v
JOIN {view_rows_columns} vrc ON vrc.view = v.id
WHERE v.template = ?
AND v.type = ?", array(self::SITE_TEMPLATE, $this->type))) {
// Layout not specified so use the view type default layout
$default = array();
foreach ($rowscols as $row) {
insert_record('view_rows_columns', (object) array(
'view' => $this->get('id'),
'row' => $row->row, 'columns' => $row->columns));
$default[$row->row] = $row;
}
}
else {
// Layout not known so make it 1 row / 3 cols
insert_record('view_rows_columns', (object) array(
'view' => $this->get('id'),
'row' => 1, 'columns' => 3));
$default = self::default_columnsperrow();
}
$this->columnsperrow = $default;
}
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment