Skip to content

Commit

Permalink
MDL-49306 blocks: Copy instance data when copying block instances
Browse files Browse the repository at this point in the history
  • Loading branch information
Nathan Lewis authored and Dave Cooper committed Apr 8, 2015
1 parent d8727a4 commit ad5c323
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
9 changes: 9 additions & 0 deletions blocks/moodleblock.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,15 @@ function instance_create() {
return true;
}

/**
* Copy any block-specific data when copying to a new block instance.
* @param int $fromid the id number of the block instance to copy from
* @return boolean
*/
public function instance_copy($fromid) {
return true;
}

/**
* Delete everything related to this instance if you have been using persistent storage other than the configdata field.
* @return boolean
Expand Down
2 changes: 2 additions & 0 deletions blocks/upgrade.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ information provided here is intended especially for developers.

* The obsolete method preferred_width() was removed (it was not doing anything)
* Deprecated block_base::config_save as is not called anywhere and should not be used.
* Added instance_copy() function to the block_base class. This function allows for block
specific data to be copied when a block is copied.

=== 2.8 ===

Expand Down
6 changes: 6 additions & 0 deletions my/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,17 @@ function my_copy_page($userid, $private=MY_PAGE_PRIVATE, $pagetype='my-index') {
'pagetypepattern' => $pagetype,
'subpagepattern' => $systempage->id));
foreach ($blockinstances as $instance) {
$originalid = $instance->id;
unset($instance->id);
$instance->parentcontextid = $usercontext->id;
$instance->subpagepattern = $page->id;
$instance->id = $DB->insert_record('block_instances', $instance);
$blockcontext = context_block::instance($instance->id); // Just creates the context record
$block = block_instance($instance->blockname, $instance);
if (!$block->instance_copy($originalid)) {
debugging("Unable to copy block-specific data for original block instance: $originalid
to new block instance: $instance->id", DEBUG_DEVELOPER);
}
}

// FIXME: block position overrides should be merged in with block instance
Expand Down

0 comments on commit ad5c323

Please sign in to comment.