Commit 5af4dea0 authored by Robert Lyon's avatar Robert Lyon Committed by Aaron Wells

Bug 1515929: Changing the insert of usr custom layouts

Rewrite to use ensure_record_exists instead of re-inventing
the wheel.

behatnotneeded: Covered by existing tests

Change-Id: Id57be0e00f14ab65dd40b4ef13f696e72f608d46
Signed-off-by: Robert Lyon's avatarRobert Lyon <robertl@catalyst.net.nz>
parent ac365767
......@@ -2919,39 +2919,17 @@ function xmldb_core_upgrade($oldversion=0) {
$views = get_records_array('view', 'layout', $groupcustomlayout->layout, '', 'owner, "group", institution');
if ($views != false) {
foreach ($views as $view) {
if (isset($view->owner)) {
// view owned by individual
$recordexists = get_record('usr_custom_layout', 'usr', $view->owner, 'layout', $groupcustomlayout->layout);
if (!$recordexists) {
// add new record into usr_custom_layout table
$customlayout = new stdClass();
$customlayout->usr = $view->owner;
$customlayout->layout = $groupcustomlayout->layout;
insert_record('usr_custom_layout', $customlayout, 'id');
}
}
else if (isset($view->group)) {
// view owned by group
$recordexists = get_record('usr_custom_layout', 'group', $view->group, 'layout', $groupcustomlayout->layout);
if (!$recordexists) {
// add new record into usr_custom_layout table
$customlayout = new stdClass();
$customlayout->group = $view->group;
$customlayout->layout = $groupcustomlayout->layout;
insert_record('usr_custom_layout', $customlayout, 'id');
}
}
else if (isset($view->institution)) {
// view owned by group
$recordexists = get_record('usr_custom_layout', 'institution', $view->institution, 'layout', $groupcustomlayout->layout);
if (!$recordexists) {
// add new record into usr_custom_layout table
$customlayout = new stdClass();
$customlayout->institution = $view->institution;
$customlayout->layout = $groupcustomlayout->layout;
insert_record('usr_custom_layout', $customlayout, 'id');
}
}
$group = $view->group;
$institution = $view->institution;
$owner = (!empty($institution) || !empty($group)) ? null : $view->owner;
$data = (object) array(
'usr' => $owner,
'group' => $group,
'institution' => $institution,
'layout' => $groupcustomlayout->layout,
);
$where = clone $data;
ensure_record_exists('usr_custom_layout', $where, $data);
}
}
// now remove this custom layout
......
......@@ -411,26 +411,17 @@ class View {
$customlayout = get_record('view_layout', 'id', $template->get('layout'), 'iscustom', 1);
if ($customlayout !== false) {
// is the owner of the copy going to be a group or institution or not?
$owner = $view->owner;
$group = $view->group;
$institution = $view->institution;
$haslayout = false;
if (!empty($group)) {
$owner = null;
$haslayout = get_record('usr_custom_layout', 'layout', $template->get('layout'), 'group', $group);
}
if (!empty($institution)) {
$owner = null;
$haslayout = get_record('usr_custom_layout', 'layout', $template->get('layout'), 'institution', $institution);
}
else if (isset($owner)) {
$haslayout = get_record('usr_custom_layout', 'layout', $template->get('layout'), 'usr', $owner);
}
if (!$haslayout) {
$newcustomlayout = insert_record('usr_custom_layout', (object) array('usr' => $owner, 'group' => $group, 'institution' => $institution, 'layout' => $template->get('layout')) );
}
$owner = (!empty($institution) || !empty($group)) ? null : $view->owner;
$data = (object) array(
'usr' => $owner,
'group' => $group,
'institution' => $institution,
'layout' => $template->get('layout'),
);
$where = clone $data;
ensure_record_exists('usr_custom_layout', $where, $data);
}
}
......@@ -1179,19 +1170,15 @@ class View {
throw new SystemException("View::addcustomlayout: Couldn't create new layout record.");
}
if (isset($owner)) {
$newcustomlayout = insert_record('usr_custom_layout', (object) array('usr' => $owner, 'group' => null, 'institution' => null, 'layout' => $newlayoutid));
}
else if (isset($group)) {
$newcustomlayout = insert_record('usr_custom_layout', (object) array('usr' => null, 'group' => $group, 'institution' => null, 'layout' => $newlayoutid));
}
else if (isset($institution)) {
$newcustomlayout = insert_record('usr_custom_layout', (object) array('usr' => null, 'group' => null, 'institution' => $institution, 'layout' => $newlayoutid));
}
if (!$newcustomlayout) {
db_rollback();
throw new SystemException("View::addcustomlayout: Couldn't create new usr custom layout record.");
}
$owner = (!empty($institution) || !empty($group)) ? null : $owner;
$data = (object) array(
'usr' => $owner,
'group' => $group,
'institution' => $institution,
'layout' => $newlayoutid,
);
$where = clone $data;
ensure_record_exists('usr_custom_layout', $where, $data);
for ($i=0; $i<$numrows; $i++) {
if (array_key_exists(($i+1), $rowscols)) {
......
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