mirror of
https://github.com/moodle/moodle.git
synced 2025-04-21 00:12:56 +02:00
Merge branch 'MDL-53425-master-delete-by-chunks' of git://github.com/junpataleta/moodle
This commit is contained in:
commit
485de12199
@ -2073,21 +2073,31 @@ function blocks_delete_instance($instance, $nolongerused = false, $skipblockstab
|
||||
function blocks_delete_instances($instanceids) {
|
||||
global $DB;
|
||||
|
||||
$instances = $DB->get_recordset_list('block_instances', 'id', $instanceids);
|
||||
foreach ($instances as $instance) {
|
||||
blocks_delete_instance($instance, false, true);
|
||||
$limit = 1000;
|
||||
$count = count($instanceids);
|
||||
$chunks = [$instanceids];
|
||||
if ($count > $limit) {
|
||||
$chunks = array_chunk($instanceids, $limit);
|
||||
}
|
||||
$instances->close();
|
||||
|
||||
$DB->delete_records_list('block_positions', 'blockinstanceid', $instanceids);
|
||||
$DB->delete_records_list('block_instances', 'id', $instanceids);
|
||||
// Perform deletion for each chunk.
|
||||
foreach ($chunks as $chunk) {
|
||||
$instances = $DB->get_recordset_list('block_instances', 'id', $chunk);
|
||||
foreach ($instances as $instance) {
|
||||
blocks_delete_instance($instance, false, true);
|
||||
}
|
||||
$instances->close();
|
||||
|
||||
$preferences = array();
|
||||
foreach ($instanceids as $instanceid) {
|
||||
$preferences[] = 'block' . $instanceid . 'hidden';
|
||||
$preferences[] = 'docked_block_instance_' . $instanceid;
|
||||
$DB->delete_records_list('block_positions', 'blockinstanceid', $chunk);
|
||||
$DB->delete_records_list('block_instances', 'id', $chunk);
|
||||
|
||||
$preferences = array();
|
||||
foreach ($chunk as $instanceid) {
|
||||
$preferences[] = 'block' . $instanceid . 'hidden';
|
||||
$preferences[] = 'docked_block_instance_' . $instanceid;
|
||||
}
|
||||
$DB->delete_records_list('user_preferences', 'name', $preferences);
|
||||
}
|
||||
$DB->delete_records_list('user_preferences', 'name', $preferences);
|
||||
}
|
||||
|
||||
/**
|
||||
|
24
my/lib.php
24
my/lib.php
@ -150,22 +150,23 @@ function my_reset_page_for_all_users($private = MY_PAGE_PRIVATE, $pagetype = 'my
|
||||
$where = 'userid IS NOT NULL AND private = :private';
|
||||
$params = array('private' => $private);
|
||||
$pages = $DB->get_recordset_select('my_pages', $where, $params, 'id, userid');
|
||||
$pageids = array();
|
||||
$blockids = array();
|
||||
|
||||
foreach ($pages as $page) {
|
||||
$pageids[] = $page->id;
|
||||
$usercontext = context_user::instance($page->userid);
|
||||
|
||||
// Find all block instances in that page.
|
||||
$blocks = $DB->get_recordset('block_instances', array('parentcontextid' => $usercontext->id,
|
||||
'pagetypepattern' => $pagetype), '', 'id, subpagepattern');
|
||||
foreach ($blocks as $block) {
|
||||
if (is_null($block->subpagepattern) || $block->subpagepattern == $page->id) {
|
||||
$blockids[] = $block->id;
|
||||
}
|
||||
$blockswhere = 'parentcontextid = :parentcontextid AND
|
||||
pagetypepattern = :pagetypepattern AND
|
||||
(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);
|
||||
}
|
||||
$blocks->close();
|
||||
}
|
||||
$pages->close();
|
||||
|
||||
@ -178,9 +179,8 @@ function my_reset_page_for_all_users($private = MY_PAGE_PRIVATE, $pagetype = 'my
|
||||
}
|
||||
|
||||
// Finally delete the pages.
|
||||
if (!empty($pageids)) {
|
||||
list($insql, $inparams) = $DB->get_in_or_equal($pageids);
|
||||
$DB->delete_records_select('my_pages', "id $insql", $pageids);
|
||||
if (!empty($pages)) {
|
||||
$DB->delete_records_select('my_pages', $where, $params);
|
||||
}
|
||||
|
||||
// We should be good to go now.
|
||||
|
Loading…
x
Reference in New Issue
Block a user