Commit 1fc9e895 authored by Eloy Lafuente's avatar Eloy Lafuente
Browse files

MDL-32709 book: replace some deprecated stuff. Some pending yet, blame $PAGE

parent 98cef39d
......@@ -141,7 +141,7 @@ function xmldb_book_upgrade($oldversion) {
upgrade_set_timeout(360); // set up timeout, may also abort execution
$pbar->update($i, $count, "Migrating book files - $i/$count.");
$context = get_context_instance(CONTEXT_MODULE, $book->cmid);
$context = context_module::instance($book->cmid);
mod_book_migrate_moddata_dir_to_legacy($book, $context, '/');
......
......@@ -46,7 +46,6 @@ function mod_book_migrate_moddata_dir_to_legacy($book, $context, $path) {
}
$fs = get_file_storage();
$textlib = textlib_get_instance();
$items = new DirectoryIterator($fulldir);
foreach ($items as $item) {
......@@ -77,7 +76,7 @@ function mod_book_migrate_moddata_dir_to_legacy($book, $context, $path) {
continue;
}
if ($textlib->strlen($filepath) > 255) {
if (textlib::strlen($filepath) > 255) {
echo $OUTPUT->notification(" File path longer than 255 chars, skipping: ".$fulldir.$item->getFilename());
unset($item); // release file handle
continue;
......@@ -115,7 +114,7 @@ function mod_book_migrate_all_areas() {
foreach($rsbooks as $book) {
upgrade_set_timeout(360); // set up timeout, may also abort execution
$cm = get_coursemodule_from_instance('book', $book->id);
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
$context = context_module::instance($cm->id);
mod_book_migrate_area($book, 'intro', 'book', $book->course, $context, 'mod_book', 'intro', 0);
$rschapters = $DB->get_recordset('book_chapters', array('bookid'=>$book->id));
......@@ -147,7 +146,7 @@ function mod_book_migrate_area($record, $field, $table, $courseid, $context, $co
foreach(array(get_site()->id, $courseid) as $cid) {
$matches = null;
$ooldcontext = get_context_instance(CONTEXT_COURSE, $cid);
$ooldcontext = context_course::instance($cid);
if (preg_match_all("|$CFG->wwwroot/file.php(\?file=)?/$cid(/[^\s'\"&\?#]+)|", $record->$field, $matches)) {
$file_record = array('contextid'=>$context->id, 'component'=>$component, 'filearea'=>$filearea, 'itemid'=>$itemid);
foreach ($matches[2] as $i=>$filepath) {
......
......@@ -36,7 +36,7 @@ $book = $DB->get_record('book', array('id'=>$cm->instance), '*', MUST_EXIST);
require_login($course, false, $cm);
require_sesskey();
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
$context = context_module::instance($cm->id);
require_capability('mod/book:edit', $context);
$PAGE->set_url('/mod/book/delete.php', array('id'=>$id, 'chapterid'=>$chapterid));
......
......@@ -37,7 +37,7 @@ $book = $DB->get_record('book', array('id'=>$cm->instance), '*', MUST_EXIST);
require_login($course, false, $cm);
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
$context = context_module::instance($cm->id);
require_capability('mod/book:edit', $context);
$PAGE->set_url('/mod/book/edit.php', array('cmid'=>$cmid, 'id'=>$chapterid, 'pagenum'=>$pagenum, 'subchapter'=>$subchapter));
......
......@@ -75,7 +75,7 @@ if ($usesections) {
$modinfo = get_fast_modinfo($course);
$currentsection = '';
foreach ($books as $book) {
$cm = $modinfo->cms[$book->coursemodule];
$cm = $modinfo->get_cm($book->coursemodule);
if ($usesections) {
$printsection = '';
if ($book->section !== $currentsection) {
......
......@@ -221,7 +221,7 @@ function book_get_toc($chapters, $chapter, $book, $cm, $edit) {
$ns = 0; // Subchapter number
$first = 1;
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
$context = context_module::instance($cm->id);
switch ($book->numbering) {
case BOOK_NUM_NONE:
......
......@@ -37,7 +37,7 @@ $book = $DB->get_record('book', array('id'=>$cm->instance), '*', MUST_EXIST);
require_login($course, false, $cm);
require_sesskey();
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
$context = context_module::instance($cm->id);
require_capability('mod/book:edit', $context);
$chapter = $DB->get_record('book_chapters', array('id'=>$chapterid, 'bookid'=>$book->id), '*', MUST_EXIST);
......
......@@ -35,7 +35,7 @@ $book = $DB->get_record('book', array('id'=>$cm->instance), '*', MUST_EXIST);
require_login($course, false, $cm);
require_sesskey();
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
$context = context_module::instance($cm->id);
require_capability('mod/book:edit', $context);
$PAGE->set_url('/mod/book/show.php', array('id'=>$id, 'chapterid'=>$chapterid));
......
......@@ -40,7 +40,7 @@ $PAGE->set_url('/mod/book/tool/exportimscp/index.php', array('id'=>$id));
require_login($course, false, $cm);
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
$context = context_module::instance($cm->id);
require_capability('mod/book:read', $context);
require_capability('booktool/exportimscp:export', $context);
......
......@@ -159,7 +159,7 @@ function booktool_exportimscp_prepare_files($book, $context) {
// Update prevlevel
$prevlevel = $currlevel;
// Calculate the number of spaces (for visual xml-text formating)
// Calculate the number of spaces (for visual xml-text formatting)
$currspaces = substr(' ', 0, $currlevel * 2);
$chaptertitle = format_string($chapter->title, true, array('context'=>$context));
......
......@@ -64,7 +64,7 @@ class booktool_importhtml_form extends moodleform {
return $errors;
}
$usercontext = get_context_instance(CONTEXT_USER, $USER->id);
$usercontext = context_user::instance($USER->id);
$fs = get_file_storage();
if (!$files = $fs->get_area_files($usercontext->id, 'user', 'draft', $data['importfile'], 'id', false)) {
......
......@@ -35,7 +35,7 @@ $book = $DB->get_record('book', array('id'=>$cm->instance), '*', MUST_EXIST);
require_login($course, false, $cm);
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
$context = context_module::instance($cm->id);
require_capability('booktool/importhtml:import', $context);
$PAGE->set_url('/mod/book/tool/importhtml/index.php', array('id'=>$id, 'chapterid'=>$chapterid));
......@@ -73,7 +73,7 @@ if ($mform->is_cancelled()) {
// this is a bloody hack - children do not try this at home!
$fs = get_file_storage();
$draftid = file_get_submitted_draft_itemid('importfile');
if (!$files = $fs->get_area_files(get_context_instance(CONTEXT_USER, $USER->id)->id, 'user', 'draft', $draftid, 'id DESC', false)) {
if (!$files = $fs->get_area_files(context_user::instance($USER->id)->id, 'user', 'draft', $draftid, 'id DESC', false)) {
redirect($PAGE->url);
}
$file = reset($files);
......
......@@ -215,7 +215,7 @@ function toolbook_importhtml_fix_encoding($html) {
$head = $matches[1];
if (preg_match('/charset=([^"]+)/is', $head, $matches)) {
$enc = $matches[1];
return textlib_get_instance()->convert($html, $enc, 'utf-8');
return textlib::convert($html, $enc, 'utf-8');
}
}
return iconv('UTF-8', 'UTF-8//IGNORE', $html);
......@@ -299,9 +299,9 @@ function toolbook_importhtml_get_chapter_files($package, $type) {
}
}
// TODO: natural dir sorting would be nice here...
textlib_get_instance()->asort($tophtmlfiles);
textlib_get_instance()->asort($subhtmlfiles);
textlib_get_instance()->asort($topdirs);
textlib::asort($tophtmlfiles);
textlib::asort($subhtmlfiles);
textlib::asort($topdirs);
$chapterfiles = array();
......@@ -313,7 +313,7 @@ function toolbook_importhtml_get_chapter_files($package, $type) {
if (empty($htmlfiles)) {
continue;
}
textlib_get_instance()->asort($htmlfiles);
textlib::asort($htmlfiles);
if (isset($htmlfiles[$dir.'/index.html'])) {
$htmlfile = $htmlfiles[$dir.'/index.html'];
} else if (isset($htmlfiles[$dir.'/index.htm'])) {
......
......@@ -38,7 +38,7 @@ $book = $DB->get_record('book', array('id'=>$cm->instance), '*', MUST_EXIST);
require_course_login($course, true, $cm);
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
$context = context_module::instance($cm->id);
require_capability('mod/book:read', $context);
require_capability('booktool/print:print', $context);
......
......@@ -39,7 +39,7 @@ function booktool_print_get_toc($chapters, $book, $cm) {
$first = true;
$titles = array();
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
$context = context_module::instance($cm->id);
$toc = ''; // Representation of toc (HTML).
......
......@@ -47,7 +47,7 @@ if ($id) {
require_course_login($course, true, $cm);
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
$context = context_module::instance($cm->id);
require_capability('mod/book:read', $context);
$allowedit = has_capability('mod/book:edit', $context);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment