Index: backup/moodle2/restore_stepslib.php =================================================================== --- backup/moodle2/restore_stepslib.php (revision 1.44) +++ backup/moodle2/restore_stepslib.php (revision ) @@ -1593,7 +1593,7 @@ } public function process_block($data) { - global $DB; + global $DB, $CFG; $data = (object)$data; // Handy $oldcontextid = $data->contextid; @@ -1605,16 +1605,31 @@ throw new restore_step_exception('restore_block_missing_parent_ctx', $data->parentcontextid); } + // get instance of block object, we need to query it + $data->blockname = clean_param($data->blockname, PARAM_SAFEDIR); + $blockfile = $CFG->dirroot.'/blocks/'.$data->blockname.'/block_'.$data->blockname.'.php'; + if (!file_exists($blockfile)) { + return false; + } + include_once($blockfile); + $classname = 'block_'.$data->blockname; + if (!class_exists($classname)) { + return false; + } + $blockobject = new $classname(); + + //TODO: it would be nice to use standard plugin supports instead of this instance_allow_multiple() // If there is already one block of that type in the parent context // and the block is not multiple, stop processing + if (!$blockobject->instance_allow_multiple()) { - if ($DB->record_exists_sql("SELECT bi.id - FROM {block_instances} bi - JOIN {block} b ON b.name = bi.blockname - WHERE bi.parentcontextid = ? + if ($DB->record_exists_sql("SELECT bi.id + FROM {block_instances} bi + JOIN {block} b ON b.name = bi.blockname + WHERE bi.parentcontextid = ? - AND bi.blockname = ? - AND b.multiple = 0", array($data->parentcontextid, $data->blockname))) { + AND bi.blockname = ?", array($data->parentcontextid, $data->blockname))) { - return false; - } + return false; + } + } // If there is already one block of that type in the parent context // with the same showincontexts, pagetypepattern, subpagepattern, defaultregion and configdata