Merge branch 'MDL-54968-master' of git://github.com/marinaglancy/moodle

This commit is contained in:
Andrew Nicols 2016-07-04 10:21:06 +08:00
commit c3d8f27a95

View file

@ -149,29 +149,18 @@ function my_reset_page_for_all_users($private = MY_PAGE_PRIVATE, $pagetype = 'my
// This may take a while. Raise the execution time limit. // This may take a while. Raise the execution time limit.
core_php_time_limit::raise(); core_php_time_limit::raise();
// Find all the user pages. // Find all the user pages and all block instances in them.
$where = 'userid IS NOT NULL AND private = :private'; $sql = "SELECT bi.id
$params = array('private' => $private); FROM {my_pages} p
$pages = $DB->get_recordset_select('my_pages', $where, $params, 'id, userid'); JOIN {context} ctx ON ctx.instanceid = p.userid AND ctx.contextlevel = :usercontextlevel
$blockids = array(); JOIN {block_instances} bi ON bi.parentcontextid = ctx.id AND
bi.pagetypepattern = :pagetypepattern AND
foreach ($pages as $page) { (bi.subpagepattern IS NULL OR bi.subpagepattern = " . $DB->sql_concat("''", 'p.id') . ")
$usercontext = context_user::instance($page->userid); WHERE p.private = :private";
$params = array('private' => $private,
// Find all block instances in that page. 'usercontextlevel' => CONTEXT_USER,
$blockswhere = 'parentcontextid = :parentcontextid AND 'pagetypepattern' => $pagetype);
pagetypepattern = :pagetypepattern AND $blockids = $DB->get_fieldset_sql($sql, $params);
(subpagepattern IS NULL OR subpagepattern = :subpagepattern)';
$blockswhereparams = [
'parentcontextid' => $usercontext->id,
'pagetypepattern' => $pagetype,
'subpagepattern' => $page->id
];
if ($pageblockids = $DB->get_fieldset_select('block_instances', 'id', $blockswhere, $blockswhereparams)) {
$blockids = array_merge($blockids, $pageblockids);
}
}
$pages->close();
// Wrap the SQL queries in a transaction. // Wrap the SQL queries in a transaction.
$transaction = $DB->start_delegated_transaction(); $transaction = $DB->start_delegated_transaction();
@ -182,9 +171,7 @@ function my_reset_page_for_all_users($private = MY_PAGE_PRIVATE, $pagetype = 'my
} }
// Finally delete the pages. // Finally delete the pages.
if (!empty($pages)) { $DB->delete_records_select('my_pages', 'userid IS NOT NULL AND private = :private', ['private' => $private]);
$DB->delete_records_select('my_pages', $where, $params);
}
// We should be good to go now. // We should be good to go now.
$transaction->allow_commit(); $transaction->allow_commit();