Skip to content

Commit

Permalink
MDL-61913 restore: Protect against blocks that aren't being created
Browse files Browse the repository at this point in the history
  • Loading branch information
ericmerrill authored and stronk7 committed Apr 10, 2018
1 parent 6643410 commit 815c44c
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
8 changes: 6 additions & 2 deletions backup/moodle2/restore_stepslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -5662,8 +5662,12 @@ class restore_block_search_index extends restore_execution_step {
* When this step is executed, we add the block context to the queue for reindexing.
*/
protected function define_execution() {
$context = \context_block::instance($this->task->get_blockid());
\core_search\manager::request_index($context);
// A block in the restore list may be skipped because a duplicate is detected.
// In this case, there is no new blockid (or context) to get.
if (!empty($this->task->get_blockid())) {
$context = \context_block::instance($this->task->get_blockid());
\core_search\manager::request_index($context);
}
}
}

Expand Down
40 changes: 40 additions & 0 deletions backup/moodle2/tests/behat/import_multiple_times.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
@core @core_backup
Feature: Import course's content's twice
In order to import content from a course more than one
As a teacher
I need to confirm that errors will not happen

Background:
Given the following config values are set as admin:
| enableglobalsearch | 1 |
And the following "courses" exist:
| fullname | shortname | category |
| Course 1 | C1 | 0 |
| Course 2 | C2 | 0 |
And the following "users" exist:
| username | firstname | lastname | email |
| teacher1 | Teacher | 1 | teacher1@example.com |
And the following "course enrolments" exist:
| user | course | role |
| teacher1 | C1 | editingteacher |
| teacher1 | C2 | editingteacher |
And the following "blocks" exist:
| blockname | contextlevel | reference | pagetypepattern | defaultregion |
| online_users | Course | C1 | course-view-* | site-post |
And the following "activities" exist:
| activity | name | course | idnumber |
| quiz | Test quiz | C1 | quiz1 |
And I log in as "teacher1"

Scenario: Import course's contents to another course
Given I am on "Course 2" course homepage with editing mode on
And I should not see "Online users"
And I should not see "Test quiz"
And I import "Course 1" course into "Course 2" course using this options:
And I am on "Course 2" course homepage
And I should see "Online users"
And I should see "Test quiz"
When I import "Course 1" course into "Course 2" course using this options:
And I am on "Course 2" course homepage
Then I should see "Online users"
And I should see "Test quiz"

0 comments on commit 815c44c

Please sign in to comment.