Commit 24e838cf authored by Cecilia Vela Gurovic's avatar Cecilia Vela Gurovic Committed by Robert Lyon

Bug 1813987: removing layout tables from install

- removing
'usr_custom_layout'
'view_layout_rows_columns'
'view_layout'
'view_layout_columns'

behatbitneeded

Change-Id: Ic53029dfc33b6366c38750d1453cbb64fd9c317e
parent 9cf3d8eb
......@@ -700,41 +700,6 @@
<KEY NAME="foreign" TYPE="foreign" FIELDS="usr" REFTABLE="usr" REFFIELDS="id" />
</KEYS>
</TABLE>
<TABLE NAME="view_layout_columns">
<FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/>
<FIELD NAME="columns" TYPE="int" LENGTH="1" NOTNULL="true"/>
<FIELD NAME="widths" TYPE="char" LENGTH="255" NOTNULL="true"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
<KEY NAME="columnwidthuk" TYPE="unique" FIELDS="columns,widths"/>
</KEYS>
</TABLE>
<TABLE NAME="view_layout">
<FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/>
<FIELD NAME="rows" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="1"/>
<FIELD NAME="iscustom" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="0"/>
<FIELD NAME="layoutmenuorder" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
</KEYS>
</TABLE>
<TABLE NAME="view_layout_rows_columns">
<FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true" />
<FIELD NAME="viewlayout" TYPE="int" LENGTH="10" NOTNULL="true"/>
<FIELD NAME="row" TYPE="int" LENGTH="1" NOTNULL="true"/>
<FIELD NAME="columns" TYPE="int" LENGTH="10" NOTNULL="true"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
<KEY NAME="rowfk" TYPE="foreign" FIELDS="viewlayout" REFTABLE="view_layout" REFFIELDS="id"/>
<KEY NAME="columnsfk" TYPE="foreign" FIELDS="columns" REFTABLE="view_layout_columns" REFFIELDS="id"/>
</KEYS>
</TABLE>
<TABLE NAME="view_type">
<FIELDS>
<FIELD NAME="type" TYPE="char" LENGTH="50" NOTNULL="true" />
......@@ -805,21 +770,6 @@
<INDEX NAME="urliduk" UNIQUE="true" FIELDS="urlid,owner,group,institution" />
</INDEXES>
</TABLE>
<TABLE NAME="usr_custom_layout">
<FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true" />
<FIELD NAME="usr" TYPE="int" LENGTH="10" NOTNULL="false"/>
<FIELD NAME="group" TYPE="int" LENGTH="10" NOTNULL="false"/>
<FIELD NAME="institution" TYPE="char" LENGTH="255" NOTNULL="false" />
<FIELD NAME="layout" TYPE="int" LENGTH="10" NOTNULL="true"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id" />
<KEY NAME="usrfk" TYPE="foreign" FIELDS="usr" REFTABLE="usr" REFFIELDS="id"/>
<KEY NAME="groupfk" TYPE="foreign" FIELDS="group" REFTABLE="group" REFFIELDS="id" />
<KEY NAME="institutionfk" TYPE="foreign" FIELDS="institution" REFTABLE="institution" REFFIELDS="name" />
</KEYS>
</TABLE>
<TABLE NAME="view_rows_columns">
<FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true" />
......
......@@ -807,9 +807,6 @@ function core_install_lastcoredata_defaults() {
insert_record('site_content_version', $page);
}
// install the default layout options
install_view_layout_defaults();
require_once('group.php');
install_system_profile_view();
install_system_dashboard_view();
......@@ -1267,150 +1264,6 @@ function install_blocktype_extras() {
}
}
/**
* Installs all the allowed column widths for views. Used when installing core
* defaults, and also when upgrading from 1.7 to 1.8
*/
function install_view_column_widths() {
require_once('view.php');
$layout = new stdClass();
$delayinserts = array();
$x = 0;
foreach (View::$basic_column_layouts as $column => $widths) {
foreach ($widths as $width) {
// If we're upgrading, then this width may already be present
// from the conversion of an exising layout.
if (!record_exists('view_layout_columns', 'widths', $width)) {
$layout = new stdClass();
$layout->columns = $column;
$layout->widths = $width;
insert_record('view_layout_columns', $layout);
}
}
}
}
function install_view_layout_defaults() {
db_begin();
require_once('view.php');
// Make sure all the column widths are present
install_view_column_widths();
// Fetch all the existing layouts so we can check below whether each default already exists
$oldlayouts = array();
$layoutrecs = get_records_assoc('view_layout', 'iscustom', '0', '', 'id, "rows", iscustom');
if ($layoutrecs) {
foreach ($layoutrecs as $rec) {
$rows = get_records_sql_assoc(
'select vlrc.row, vlc.widths
from
{view_layout_rows_columns} vlrc
inner join {view_layout_columns} vlc
on vlrc.columns = vlc.id
where vlrc.viewlayout = ?
order by vlrc.row',
array($rec->id)
);
if (!$rows) {
// This layout has no rows. Strange, but let's just ignore it for now.
log_warn('view_layout ' . $rec->id . ' is missing its row or column width records.');
continue;
}
$allwidths = '';
foreach ($rows as $rowrec) {
$allwidths .= $rowrec->widths . '-';
}
// Drop the last comma
$allwidths = substr($allwidths, 0, -1);
$oldlayouts[$rec->id] = $allwidths;
}
}
foreach (View::$defaultlayoutoptions as $id => $rowscols) {
// Check to see whether it matches an existing record
$allwidths = '';
$numrows = 0;
foreach ($rowscols as $row => $col) {
if ($row != 'order') {
$allwidths .= $col . '-';
$numrows++;
}
}
$allwidths = substr($allwidths, 0, -1);
$found = array_search($allwidths, $oldlayouts);
if ($found !== false) {
// There's a perfect match in the DB already. Just make sure it has the right menu order
if (isset($rowscols['order'])) {
update_record(
'view_layout',
(object)array(
'id' => $found,
'layoutmenuorder'=>$rowscols['order']
)
);
}
continue;
}
// It doesn't exist yet! So, set it up.
$vlid = insert_record(
'view_layout',
(object)array(
'iscustom' => 0,
'rows' => $numrows,
'layoutmenuorder' => (isset($rowscols['order']) ? $rowscols['order'] : 0)
),
'id',
true
);
insert_record(
'usr_custom_layout',
(object)array(
'usr' => 0,
'group' => null,
'layout' => $vlid,
)
);
foreach ($rowscols as $row => $col) {
// The 'order' field indicates menu order if this layout is meant to be present
// in the default layout menu
if ($row == 'order') {
continue;
}
// Check for the ID of the column widths that match this row
$colsid = get_field('view_layout_columns', 'id', 'widths', $col);
if (!$colsid) {
// For some reason this layout_columns wasn't present yet.
// We'll just insert it, but also throw a warning
$colsid = insert_record(
'view_layout_columns',
(object) array(
'columns' => substr_count($col, ','),
'widths' => $col
),
'id',
true
);
log_warn('Default layout option ' . $id . ' uses a column set that is not present in the list of default column widths.');
}
insert_record(
'view_layout_rows_columns',
(object)array(
'viewlayout' => $vlid,
'row' => $row,
'columns' => $colsid,
)
);
}
}
db_commit();
}
/**
* Reload htmlpurifier filters from the XML configuration file.
*/
......
......@@ -294,7 +294,7 @@ class View {
}
}
if (empty(self::$layoutcolumns)) {
if (empty(self::$layoutcolumns) && db_table_exists('view_layout_columns')) {
self::$layoutcolumns = get_records_assoc('view_layout_columns', '', '', 'columns,id');
}
......@@ -587,9 +587,7 @@ class View {
// Create the view
$defaultdata = array(
'numcolumns' => 2, // Obsolete - need to leave for upgrade purposes. This can be deleted once we no longer need to support direct upgrades from 15.10 and earlier.
'numrows' => 1,
'columnsperrow' => self::default_columnsperrow(),
'template' => 0,
'type' => 'portfolio',
'title' => (array_key_exists('title', $viewdata)) ? $viewdata['title'] : self::new_title(get_string('Untitled', 'view'), (object)$viewdata),
......@@ -854,9 +852,7 @@ class View {
}
db_begin();
$creating = false;
if (empty($this->id)) {
$creating = true;
// users are only allowed one profile view
if (!$this->template && $this->type == 'profile' && record_exists('view', 'owner', $this->owner, 'type', 'profile')) {
throw new SystemException(get_string('onlonlyyoneprofileviewallowed', 'error'));
......@@ -909,25 +905,6 @@ class View {
}
}
$columnsperrowchanged = (!empty($this->oldcolumnsperrow)) ? array_udiff($this->oldcolumnsperrow, $this->columnsperrow, function($oa, $ob) {
$rows = $oa->row - $ob->row;
$columns = $oa->columns - $ob->columns;
if ($rows != 0) {
return $rows;
}
else if ($columns != 0) {
return $columns;
}
return 0;
}) : false;
if (isset($this->columnsperrow) && (!empty($columnsperrowchanged) || $creating)) {
delete_records('view_rows_columns', 'view', $this->get('id'));
foreach ($this->get_columnsperrow() as $viewrow) {
insert_record('view_rows_columns', (object)array( 'view' => $this->get('id'), 'row' => $viewrow->row, 'columns' => $viewrow->columns));
}
}
db_commit();
$this->dirty = false;
......
Markdown is supported
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