From 484135927b012e2e997b23e686777b2f271fca93 Mon Sep 17 00:00:00 2001 From: Daniel Ziegenberg Date: Thu, 28 Mar 2024 13:47:01 +0100 Subject: [PATCH] MDL-75189 mod_data: Final deprecations after MDL-75059 Signed-off-by: Daniel Ziegenberg --- .upgradenotes/MDL-75189-2024100107115232.yml | 24 + mod/data/deprecatedlib.php | 93 +++ mod/data/lib.php | 619 ------------------- mod/data/preset_form.php | 36 -- mod/data/renderer.php | 16 +- 5 files changed, 120 insertions(+), 668 deletions(-) create mode 100644 .upgradenotes/MDL-75189-2024100107115232.yml diff --git a/.upgradenotes/MDL-75189-2024100107115232.yml b/.upgradenotes/MDL-75189-2024100107115232.yml new file mode 100644 index 00000000000..2b131f3d658 --- /dev/null +++ b/.upgradenotes/MDL-75189-2024100107115232.yml @@ -0,0 +1,24 @@ +issueNumber: MDL-75189 +notes: + mod_data: + - message: | + Final deprecation and removal of the following classes: + - data_preset_importer + - data_preset_existing_importer + - data_preset_upload_importer + - data_import_preset_zip_form + type: removed + - message: > + - Final deprecation of \mod_data_renderer::import_setting_mappings(). Please use \mod_data_renderer::importing_preset() instead. + - Final deprecation of data_print_template() function. Please use mod_data\manager::get_template and mod_data\template::parse_entries instead. + - Final deprecation of data_preset_name(). Please use preset::get_name_from_plugin() instead. + - Final deprecation of data_get_available_presets(). Please use manager::get_available_presets() instead. + - Final deprecation of data_get_available_site_presets(). Please use manager::get_available_saved_presets() instead. + - Final deprecation of data_delete_site_preset(). Please use preset::delete() instead. + - Final deprecation of is_directory_a_preset(). Please use preset::is_directory_a_preset() instead. + - Final deprecation of data_presets_save(). Please use preset::save() instead. + - Final deprecation of data_presets_generate_xml(). Please use preset::generate_preset_xml() instead. + - Final deprecation of data_presets_export(). Please use preset::export() instead. + - Final deprecation of data_user_can_delete_preset(). Please use preset::can_manage() instead. + - Final deprecation of data_view(). Please use mod_data\manager::set_module_viewed() instead. + type: removed diff --git a/mod/data/deprecatedlib.php b/mod/data/deprecatedlib.php index 4f43763bafb..a1ba882ae52 100644 --- a/mod/data/deprecatedlib.php +++ b/mod/data/deprecatedlib.php @@ -30,6 +30,99 @@ function data_get_completion_state() { throw new coding_exception(__FUNCTION__ . "() has been removed, please use the '{$completionclass}' class instead"); } +/** + * @deprecated since Moodle 4.1 MDL-75146 - please do not use this function any more. + */ +#[\core\attribute\deprecated( + 'mod_data\manager::get_template and mod_data\template::parse_entries', + since: '4.1', + mdl: 'MDL-75146', + final: true, +)] +function data_print_template(): void { + \core\deprecation::emit_deprecation_if_present(__FUNCTION__); +} + +/** + * @deprecated since Moodle 4.1 MDL-75148 - please, use the preset::get_name_from_plugin() function instead. + */ +#[\core\attribute\deprecated('mod_data\preset::get_name_from_plugin()', since: '4.1', mdl: 'MDL-75148', final: true)] +function data_preset_name(): void { + \core\deprecation::emit_deprecation_if_present(__FUNCTION__); +} + +/** + * @deprecated since Moodle 4.1 MDL-75148 - please, use the manager::get_available_presets() function instead. + */ +#[\core\attribute\deprecated('mod_data\manager::get_available_presets()', since: '4.1', mdl: 'MDL-75148', final: true)] +function data_get_available_presets(): void { + \core\deprecation::emit_deprecation_if_present(__FUNCTION__); +} + +/** + * @deprecated since Moodle 4.1 MDL-75148 - please, use the manager::get_available_saved_presets() function instead. + */ +#[\core\attribute\deprecated('mod_data\manager::get_available_saved_presets()', since: '4.1', mdl: 'MDL-75148', final: true)] +function data_get_available_site_presets(): void { + \core\deprecation::emit_deprecation_if_present(__FUNCTION__); +} + +/** + * @deprecated since Moodle 4.1 MDL-75187 - please, use the preset::delete() function instead. + */ +#[\core\attribute\deprecated('mod_data\preset::delete()', since: '4.1', mdl: 'MDL-75187', final: true)] +function data_delete_site_preset(): void { + \core\deprecation::emit_deprecation_if_present(__FUNCTION__); +} + +/** + * @deprecated since Moodle 4.1 MDL-75142 - please, use the preset::save() function instead. + */ +#[\core\attribute\deprecated('mod_data\preset::save()', since: '4.1', mdl: 'MDL-75142', final: true)] +function data_presets_save(): void { + \core\deprecation::emit_deprecation_if_present(__FUNCTION__); +} + +/** + * @deprecated since Moodle 4.1 MDL-75142 - please, use the protected preset::generate_preset_xml() function instead. + */ +#[\core\attribute\deprecated('mod_data\preset::generate_preset_xml()', since: '4.1', mdl: 'MDL-75142', final: true)] +function data_presets_generate_xml(): void { + \core\deprecation::emit_deprecation_if_present(__FUNCTION__); +} + +/** + * @deprecated since Moodle 4.1 MDL-75142 - please, use the preset::export() function instead. + */ +#[\core\attribute\deprecated('mod_data\preset::export()', since: '4.1', mdl: 'MDL-75142', final: true)] +function data_presets_export(): void { + \core\deprecation::emit_deprecation_if_present(__FUNCTION__); +} + +/** + * @deprecated since Moodle 4.1 MDL-75187 - please, use the preset::can_manage() function instead. + */ +#[\core\attribute\deprecated('mod_data\preset::can_manage()', since: '4.1', mdl: 'MDL-75187', final: true)] +function data_user_can_delete_preset(): void { + \core\deprecation::emit_deprecation_if_present(__FUNCTION__); +} + +/** + * @deprecated since Moodle 4.1 MDL-75146 - please do not use this function any more. + */ +#[\core\attribute\deprecated('mod_data\manager::set_module_viewed', since: '4.1', mdl: 'MDL-75146', final: true)] +function data_view(): void { + \core\deprecation::emit_deprecation_if_present(__FUNCTION__); +} + +/** + * @deprecated since Moodle 4.1 MDL-75148 - please, use the preset::is_directory_a_preset() function instead. + */ +#[\core\attribute\deprecated('mod_data\preset::is_directory_a_preset()', since: '4.1', mdl: 'MDL-75148', final: true)] +function is_directory_a_preset(): void { + \core\deprecation::emit_deprecation_if_present(__FUNCTION__); +} + /** * @deprecated since Moodle 4.3. * @global object diff --git a/mod/data/lib.php b/mod/data/lib.php index 1aa3027e7fc..9557843ba91 100644 --- a/mod/data/lib.php +++ b/mod/data/lib.php @@ -21,7 +21,6 @@ */ use mod_data\manager; -use mod_data\preset; defined('MOODLE_INTERNAL') || die(); @@ -1537,42 +1536,6 @@ function data_grade_item_delete($data) { } // junk functions -/** - * takes a list of records, the current data, a search string, - * and mode to display prints the translated template - * - * @deprecated since Moodle 4.1 MDL-75146 - please do not use this function any more. - * @todo MDL-75189 Final deprecation in Moodle 4.5. - * @param string $templatename the template name - * @param array $records the entries records - * @param stdClass $data the database instance object - * @param string $search the current search term - * @param int $page page number for pagination - * @param bool $return if the result should be returned (true) or printed (false) - * @param moodle_url|null $jumpurl a moodle_url by which to jump back to the record list (can be null) - * @return mixed string with all parsed entries or nothing if $return is false - */ -function data_print_template($templatename, $records, $data, $search='', $page=0, $return=false, ?moodle_url $jumpurl=null) { - debugging( - 'data_print_template is deprecated. Use mod_data\\manager::get_template and mod_data\\template::parse_entries instead', - DEBUG_DEVELOPER - ); - - $options = [ - 'search' => $search, - 'page' => $page, - ]; - if ($jumpurl) { - $options['baseurl'] = $jumpurl; - } - $manager = manager::create_from_instance($data); - $parser = $manager->get_template($templatename, $options); - $content = $parser->parse_entries($records); - if ($return) { - return $content; - } - echo $content; -} /** * Return rating related permissions @@ -2215,88 +2178,6 @@ function data_convert_to_roles($data, $teacherroles=array(), $studentroles=array return true; } -/** - * Returns the best name to show for a preset - * - * @param string $shortname - * @param string $path - * @return string - * @deprecated since Moodle 4.1 MDL-75148 - please, use the preset::get_name_from_plugin() function instead. - * @todo MDL-75189 This will be deleted in Moodle 4.5. - * @see preset::get_name_from_plugin() - */ -function data_preset_name($shortname, $path) { - debugging('data_preset_name() is deprecated. Please use preset::get_name_from_plugin() instead.', DEBUG_DEVELOPER); - - return preset::get_name_from_plugin($shortname); -} - -/** - * Returns an array of all the available presets. - * - * @return array - * @deprecated since Moodle 4.1 MDL-75148 - please, use the manager::get_available_presets() function instead. - * @todo MDL-75189 This will be deleted in Moodle 4.5. - * @see manager::get_available_presets() - */ -function data_get_available_presets($context) { - debugging('data_get_available_presets() is deprecated. Please use manager::get_available_presets() instead.', DEBUG_DEVELOPER); - - $cm = get_coursemodule_from_id('', $context->instanceid, 0, false, MUST_EXIST); - $manager = manager::create_from_coursemodule($cm); - return $manager->get_available_presets(); -} - -/** - * Gets an array of all of the presets that users have saved to the site. - * - * @param stdClass $context The context that we are looking from. - * @param array $presets - * @return array An array of presets - * @deprecated since Moodle 4.1 MDL-75148 - please, use the manager::get_available_saved_presets() function instead. - * @todo MDL-75189 This will be deleted in Moodle 4.5. - * @see manager::get_available_saved_presets() - */ -function data_get_available_site_presets($context, array $presets=array()) { - debugging( - 'data_get_available_site_presets() is deprecated. Please use manager::get_available_saved_presets() instead.', - DEBUG_DEVELOPER - ); - - $cm = get_coursemodule_from_id('', $context->instanceid, 0, false, MUST_EXIST); - $manager = manager::create_from_coursemodule($cm); - $savedpresets = $manager->get_available_saved_presets(); - return array_merge($presets, $savedpresets); -} - -/** - * Deletes a saved preset. - * - * @param string $name - * @return bool - * @deprecated since Moodle 4.1 MDL-75187 - please, use the preset::delete() function instead. - * @todo MDL-75189 This will be deleted in Moodle 4.5. - * @see preset::delete() - */ -function data_delete_site_preset($name) { - debugging('data_delete_site_preset() is deprecated. Please use preset::delete() instead.', DEBUG_DEVELOPER); - - $fs = get_file_storage(); - - $files = $fs->get_directory_files(DATA_PRESET_CONTEXT, DATA_PRESET_COMPONENT, DATA_PRESET_FILEAREA, 0, '/'.$name.'/'); - if (!empty($files)) { - foreach ($files as $file) { - $file->delete(); - } - } - - $dir = $fs->get_file(DATA_PRESET_CONTEXT, DATA_PRESET_COMPONENT, DATA_PRESET_FILEAREA, 0, '/'.$name.'/', '.'); - if (!empty($dir)) { - $dir->delete(); - } - return true; -} - /** * Prints the heads for a page * @@ -2428,376 +2309,6 @@ function data_in_readonly_period($data) { return true; } -/** - * Check if the files in a directory are the expected for a preset. - * - * @return bool Wheter the defined $directory has or not all the expected preset files. - * - * @deprecated since Moodle 4.1 MDL-75148 - please, use the preset::is_directory_a_preset() function instead. - * @todo MDL-75189 This will be deleted in Moodle 4.5. - * @see manager::is_directory_a_preset() - */ -function is_directory_a_preset($directory) { - debugging('is_directory_a_preset() is deprecated. Please use preset::is_directory_a_preset() instead.', DEBUG_DEVELOPER); - - return preset::is_directory_a_preset($directory); -} - -/** - * Abstract class used for data preset importers - * - * @deprecated since Moodle 4.1 MDL-75140 - please do not use this class any more. - * @todo MDL-75189 Final deprecation in Moodle 4.5. - */ -abstract class data_preset_importer { - - protected $course; - protected $cm; - protected $module; - protected $directory; - - /** - * Constructor - * - * @param stdClass $course - * @param stdClass $cm - * @param stdClass $module - * @param string $directory - */ - public function __construct($course, $cm, $module, $directory) { - debugging( - 'data_preset_importer is deprecated. Please use mod\\data\\local\\importer\\preset_importer instead', - DEBUG_DEVELOPER - ); - - $this->course = $course; - $this->cm = $cm; - $this->module = $module; - $this->directory = $directory; - } - - /** - * Returns the name of the directory the preset is located in - * @return string - */ - public function get_directory() { - return basename($this->directory); - } - - /** - * Retreive the contents of a file. That file may either be in a conventional directory of the Moodle file storage - * @param file_storage $filestorage. should be null if using a conventional directory - * @param stored_file $fileobj the directory to look in. null if using a conventional directory - * @param string $dir the directory to look in. null if using the Moodle file storage - * @param string $filename the name of the file we want - * @return string the contents of the file or null if the file doesn't exist. - */ - public function data_preset_get_file_contents(&$filestorage, &$fileobj, $dir, $filename) { - if(empty($filestorage) || empty($fileobj)) { - if (substr($dir, -1)!='/') { - $dir .= '/'; - } - if (file_exists($dir.$filename)) { - return file_get_contents($dir.$filename); - } else { - return null; - } - } else { - if ($filestorage->file_exists(DATA_PRESET_CONTEXT, DATA_PRESET_COMPONENT, DATA_PRESET_FILEAREA, 0, $fileobj->get_filepath(), $filename)) { - $file = $filestorage->get_file(DATA_PRESET_CONTEXT, DATA_PRESET_COMPONENT, DATA_PRESET_FILEAREA, 0, $fileobj->get_filepath(), $filename); - return $file->get_content(); - } else { - return null; - } - } - - } - /** - * Gets the preset settings - * @global moodle_database $DB - * @return stdClass - */ - public function get_preset_settings() { - global $DB, $CFG; - require_once($CFG->libdir.'/xmlize.php'); - - $fs = $fileobj = null; - if (!preset::is_directory_a_preset($this->directory)) { - //maybe the user requested a preset stored in the Moodle file storage - - $fs = get_file_storage(); - $files = $fs->get_area_files(DATA_PRESET_CONTEXT, DATA_PRESET_COMPONENT, DATA_PRESET_FILEAREA); - - //preset name to find will be the final element of the directory - $explodeddirectory = explode('/', $this->directory); - $presettofind = end($explodeddirectory); - - //now go through the available files available and see if we can find it - foreach ($files as $file) { - if (($file->is_directory() && $file->get_filepath()=='/') || !$file->is_directory()) { - continue; - } - $presetname = trim($file->get_filepath(), '/'); - if ($presetname==$presettofind) { - $this->directory = $presetname; - $fileobj = $file; - } - } - - if (empty($fileobj)) { - throw new \moodle_exception('invalidpreset', 'data', '', $this->directory); - } - } - - $allowed_settings = array( - 'intro', - 'comments', - 'requiredentries', - 'requiredentriestoview', - 'maxentries', - 'rssarticles', - 'approval', - 'defaultsortdir', - 'defaultsort'); - - $result = new stdClass; - $result->settings = new stdClass; - $result->importfields = array(); - $result->currentfields = $DB->get_records('data_fields', array('dataid'=>$this->module->id)); - if (!$result->currentfields) { - $result->currentfields = array(); - } - - - /* Grab XML */ - $presetxml = $this->data_preset_get_file_contents($fs, $fileobj, $this->directory,'preset.xml'); - $parsedxml = xmlize($presetxml, 0); - - /* First, do settings. Put in user friendly array. */ - $settingsarray = $parsedxml['preset']['#']['settings'][0]['#']; - $result->settings = new StdClass(); - foreach ($settingsarray as $setting => $value) { - if (!is_array($value) || !in_array($setting, $allowed_settings)) { - // unsupported setting - continue; - } - $result->settings->$setting = $value[0]['#']; - } - - /* Now work out fields to user friendly array */ - $fieldsarray = $parsedxml['preset']['#']['field']; - foreach ($fieldsarray as $field) { - if (!is_array($field)) { - continue; - } - $f = new StdClass(); - foreach ($field['#'] as $param => $value) { - if (!is_array($value)) { - continue; - } - $f->$param = $value[0]['#']; - } - $f->dataid = $this->module->id; - $f->type = clean_param($f->type, PARAM_ALPHA); - $result->importfields[] = $f; - } - /* Now add the HTML templates to the settings array so we can update d */ - $result->settings->singletemplate = $this->data_preset_get_file_contents($fs, $fileobj,$this->directory,"singletemplate.html"); - $result->settings->listtemplate = $this->data_preset_get_file_contents($fs, $fileobj,$this->directory,"listtemplate.html"); - $result->settings->listtemplateheader = $this->data_preset_get_file_contents($fs, $fileobj,$this->directory,"listtemplateheader.html"); - $result->settings->listtemplatefooter = $this->data_preset_get_file_contents($fs, $fileobj,$this->directory,"listtemplatefooter.html"); - $result->settings->addtemplate = $this->data_preset_get_file_contents($fs, $fileobj,$this->directory,"addtemplate.html"); - $result->settings->rsstemplate = $this->data_preset_get_file_contents($fs, $fileobj,$this->directory,"rsstemplate.html"); - $result->settings->rsstitletemplate = $this->data_preset_get_file_contents($fs, $fileobj,$this->directory,"rsstitletemplate.html"); - $result->settings->csstemplate = $this->data_preset_get_file_contents($fs, $fileobj,$this->directory,"csstemplate.css"); - $result->settings->jstemplate = $this->data_preset_get_file_contents($fs, $fileobj,$this->directory,"jstemplate.js"); - $result->settings->asearchtemplate = $this->data_preset_get_file_contents($fs, $fileobj,$this->directory,"asearchtemplate.html"); - - $result->settings->instance = $this->module->id; - return $result; - } - - /** - * Import the preset into the given database module - * @return bool - */ - function import($overwritesettings) { - global $DB, $CFG, $OUTPUT; - - $params = $this->get_preset_settings(); - $settings = $params->settings; - $newfields = $params->importfields; - $currentfields = $params->currentfields; - $preservedfields = array(); - - /* Maps fields and makes new ones */ - if (!empty($newfields)) { - /* We require an injective mapping, and need to know what to protect */ - foreach ($newfields as $nid => $newfield) { - $cid = optional_param("field_$nid", -1, PARAM_INT); - if ($cid == -1) { - continue; - } - if (array_key_exists($cid, $preservedfields)){ - throw new \moodle_exception('notinjectivemap', 'data'); - } - else $preservedfields[$cid] = true; - } - $missingfieldtypes = []; - foreach ($newfields as $nid => $newfield) { - $cid = optional_param("field_$nid", -1, PARAM_INT); - - /* A mapping. Just need to change field params. Data kept. */ - if ($cid != -1 and isset($currentfields[$cid])) { - $fieldobject = data_get_field_from_id($currentfields[$cid]->id, $this->module); - foreach ($newfield as $param => $value) { - if ($param != "id") { - $fieldobject->field->$param = $value; - } - } - unset($fieldobject->field->similarfield); - $fieldobject->update_field(); - unset($fieldobject); - } else { - /* Make a new field */ - $filepath = "field/$newfield->type/field.class.php"; - if (!file_exists($filepath)) { - $missingfieldtypes[] = $newfield->name; - continue; - } - include_once($filepath); - - if (!isset($newfield->description)) { - $newfield->description = ''; - } - $classname = 'data_field_'.$newfield->type; - $fieldclass = new $classname($newfield, $this->module); - $fieldclass->insert_field(); - unset($fieldclass); - } - } - if (!empty($missingfieldtypes)) { - echo $OUTPUT->notification(get_string('missingfieldtypeimport', 'data') . html_writer::alist($missingfieldtypes)); - } - } - - /* Get rid of all old unused data */ - foreach ($currentfields as $cid => $currentfield) { - if (!array_key_exists($cid, $preservedfields)) { - /* Data not used anymore so wipe! */ - echo "Deleting field $currentfield->name
"; - - // Delete all information related to fields. - $todelete = data_get_field_from_id($currentfield->id, $this->module); - $todelete->delete_field(); - } - } - - // handle special settings here - if (!empty($settings->defaultsort)) { - if (is_numeric($settings->defaultsort)) { - // old broken value - $settings->defaultsort = 0; - } else { - $settings->defaultsort = (int)$DB->get_field('data_fields', 'id', array('dataid'=>$this->module->id, 'name'=>$settings->defaultsort)); - } - } else { - $settings->defaultsort = 0; - } - - // do we want to overwrite all current database settings? - if ($overwritesettings) { - // all supported settings - $overwrite = array_keys((array)$settings); - } else { - // only templates and sorting - $overwrite = array('singletemplate', 'listtemplate', 'listtemplateheader', 'listtemplatefooter', - 'addtemplate', 'rsstemplate', 'rsstitletemplate', 'csstemplate', 'jstemplate', - 'asearchtemplate', 'defaultsortdir', 'defaultsort'); - } - - // now overwrite current data settings - foreach ($this->module as $prop=>$unused) { - if (in_array($prop, $overwrite)) { - $this->module->$prop = $settings->$prop; - } - } - - data_update_instance($this->module); - - return $this->cleanup(); - } - - /** - * Any clean up routines should go here - * @return bool - */ - public function cleanup() { - return true; - } -} - -/** - * Data preset importer for uploaded presets - * - * @deprecated since Moodle 4.1 MDL-75140 - please do not use this class any more. - * @todo MDL-75189 Final deprecation in Moodle 4.5. - */ -class data_preset_upload_importer extends data_preset_importer { - public function __construct($course, $cm, $module, $filepath) { - global $USER; - - debugging( - 'data_preset_upload_importer is deprecated. Please use mod\\data\\local\\importer\\preset_upload_importer instead', - DEBUG_DEVELOPER - ); - - if (is_file($filepath)) { - $fp = get_file_packer(); - if ($fp->extract_to_pathname($filepath, $filepath.'_extracted')) { - fulldelete($filepath); - } - $filepath .= '_extracted'; - } - parent::__construct($course, $cm, $module, $filepath); - } - - public function cleanup() { - return fulldelete($this->directory); - } -} - -/** - * Data preset importer for existing presets - * - * @deprecated since Moodle 4.1 MDL-75140 - please do not use this class any more. - * @todo MDL-75189 Final deprecation in Moodle 4.5. - */ -class data_preset_existing_importer extends data_preset_importer { - protected $userid; - public function __construct($course, $cm, $module, $fullname) { - global $USER; - - debugging( - 'data_preset_existing_importer is deprecated. Please use mod\\data\\local\\importer\\preset_existing_importer instead', - DEBUG_DEVELOPER - ); - - list($userid, $shortname) = explode('/', $fullname, 2); - $context = context_module::instance($cm->id); - if ($userid && ($userid != $USER->id) && !has_capability('mod/data:manageuserpresets', $context) && !has_capability('mod/data:viewalluserpresets', $context)) { - throw new coding_exception('Invalid preset provided'); - } - - $this->userid = $userid; - $filepath = data_preset_path($course, $userid, $shortname); - parent::__construct($course, $cm, $module, $filepath); - } - public function get_userid() { - return $this->userid; - } -} - /** * @global object * @global object @@ -3392,71 +2903,6 @@ function data_extend_settings_navigation(settings_navigation $settings, navigati } } -/** - * Save the database configuration as a preset. - * - * @param stdClass $course The course the database module belongs to. - * @param stdClass $cm The course module record - * @param stdClass $data The database record - * @param string $path - * @return bool - * @deprecated since Moodle 4.1 MDL-75142 - please, use the preset::save() function instead. - * @todo MDL-75189 This will be deleted in Moodle 4.5. - * @see preset::save() - */ -function data_presets_save($course, $cm, $data, $path) { - debugging('data_presets_save() is deprecated. Please use preset::save() instead.', DEBUG_DEVELOPER); - - $manager = manager::create_from_instance($data); - $preset = preset::create_from_instance($manager, $path); - return $preset->save(); -} - -/** - * Generates the XML for the database module provided - * - * @global moodle_database $DB - * @param stdClass $course The course the database module belongs to. - * @param stdClass $cm The course module record - * @param stdClass $data The database record - * @return string The XML for the preset - * @deprecated since Moodle 4.1 MDL-75142 - please, use the protected preset::generate_preset_xml() function instead. - * @todo MDL-75189 This will be deleted in Moodle 4.5. - * @see preset::generate_preset_xml() - */ -function data_presets_generate_xml($course, $cm, $data) { - debugging( - 'data_presets_generate_xml() is deprecated. Please use the protected preset::generate_preset_xml() instead.', - DEBUG_DEVELOPER - ); - - $manager = manager::create_from_instance($data); - $preset = preset::create_from_instance($manager, $data->name); - $reflection = new \ReflectionClass(preset::class); - $method = $reflection->getMethod('generate_preset_xml'); - return $method->invokeArgs($preset, []); -} - -/** - * Export current fields and presets. - * - * @param stdClass $course The course the database module belongs to. - * @param stdClass $cm The course module record - * @param stdClass $data The database record - * @param bool $tostorage - * @return string the full path to the exported preset file. - * @deprecated since Moodle 4.1 MDL-75142 - please, use the preset::export() function instead. - * @todo MDL-75189 This will be deleted in Moodle 4.5. - * @see preset::export() - */ -function data_presets_export($course, $cm, $data, $tostorage=false) { - debugging('data_presets_export() is deprecated. Please use preset::export() instead.', DEBUG_DEVELOPER); - - $manager = manager::create_from_instance($data); - $preset = preset::create_from_instance($manager, $data->name); - return $preset->export(); -} - /** * Running addtional permission check on plugin, for example, plugins * may have switch to turn on/off comments option, this callback will @@ -3791,39 +3237,6 @@ function data_get_advanced_search_sql($sort, $data, $recordids, $selectdata, $so return $sqlselect; } -/** - * Checks to see if the user has permission to delete the preset. - * @param stdClass $context Context object. - * @param stdClass $preset The preset object that we are checking for deletion. - * @return bool Returns true if the user can delete, otherwise false. - * @deprecated since Moodle 4.1 MDL-75187 - please, use the preset::can_manage() function instead. - * @todo MDL-75189 This will be deleted in Moodle 4.5. - * @see preset::can_manage() - */ -function data_user_can_delete_preset($context, $preset) { - global $USER; - - debugging('data_user_can_delete_preset() is deprecated. Please use manager::can_manage() instead.', DEBUG_DEVELOPER); - - if ($context->contextlevel == CONTEXT_MODULE && isset($preset->name)) { - $cm = get_coursemodule_from_id('', $context->instanceid, 0, false, MUST_EXIST); - $manager = manager::create_from_coursemodule($cm); - $todelete = preset::create_from_instance($manager, $preset->name); - return $todelete->can_manage(); - } - - if (has_capability('mod/data:manageuserpresets', $context)) { - return true; - } else { - $candelete = false; - $userid = $preset instanceof preset ? $preset->get_userid() : $preset->userid; - if ($userid == $USER->id) { - $candelete = true; - } - return $candelete; - } -} - /** * Delete a record entry. * @@ -4087,38 +3500,6 @@ function data_update_completion_state($data, $course, $cm) { } } -/** - * Mark the activity completed (if required) and trigger the course_module_viewed event. - * - * @deprecated since Moodle 4.1 MDL-75146 - please do not use this function any more. - * @todo MDL-75189 Final deprecation in Moodle 4.5. - * @param stdClass $data data object - * @param stdClass $course course object - * @param stdClass $cm course module object - * @param stdClass $context context object - * @since Moodle 3.3 - */ -function data_view($data, $course, $cm, $context) { - global $CFG; - debugging('data_view is deprecated. Use mod_data\\manager::set_module_viewed instead', DEBUG_DEVELOPER); - require_once($CFG->libdir . '/completionlib.php'); - - // Trigger course_module_viewed event. - $params = array( - 'context' => $context, - 'objectid' => $data->id - ); - - $event = \mod_data\event\course_module_viewed::create($params); - $event->add_record_snapshot('course_modules', $cm); - $event->add_record_snapshot('course', $course); - $event->add_record_snapshot('data', $data); - $event->trigger(); - - // Completion. - $completion = new completion_info($course); - $completion->set_module_viewed($cm); -} /** * Get the list of deprecated icons. diff --git a/mod/data/preset_form.php b/mod/data/preset_form.php index 1140f1ddacf..a8ac05f01a1 100644 --- a/mod/data/preset_form.php +++ b/mod/data/preset_form.php @@ -46,42 +46,6 @@ class data_existing_preset_form extends moodleform { } } -/** - * Import preset class - * - * - * @package mod_data - * @deprecated since 4.1 This is deprecated since MDL-75188, please use the dynamic_form - * form (\mod_data\form\import_presets) - * @todo MDL-75189 This will be deleted in Moodle 4.5. - */ -class data_import_preset_zip_form extends moodleform { - /** - * Form definition - * - * @return void - * @throws coding_exception - */ - public function definition() { - $this->_form->addElement('header', 'uploadpreset', get_string('fromfile', 'data')); - $this->_form->addHelpButton('uploadpreset', 'fromfile', 'data'); - - $this->_form->addElement('hidden', 'd'); - $this->_form->setType('d', PARAM_INT); - $this->_form->addElement('hidden', 'mode', 'import'); - $this->_form->setType('mode', PARAM_ALPHANUM); - $this->_form->addElement('hidden', 'action', 'importzip'); - $this->_form->setType('action', PARAM_ALPHANUM); - $this->_form->addElement('filepicker', 'importfile', get_string('chooseorupload', 'data')); - $this->_form->addRule('importfile', null, 'required'); - $buttons = [ - $this->_form->createElement('submit', 'submitbutton', get_string('save')), - $this->_form->createElement('cancel'), - ]; - $this->_form->addGroup($buttons, 'buttonar', '', [' '], false); - } -} - class data_export_form extends moodleform { public function definition() { $this->_form->addElement('header', 'exportheading', get_string('exportaszip', 'data')); diff --git a/mod/data/renderer.php b/mod/data/renderer.php index 80e029c256f..911db1df2c1 100644 --- a/mod/data/renderer.php +++ b/mod/data/renderer.php @@ -22,7 +22,6 @@ * @package mod_data */ -use mod_data\local\importer\preset_existing_importer; use mod_data\manager; defined('MOODLE_INTERNAL') || die(); @@ -30,20 +29,11 @@ defined('MOODLE_INTERNAL') || die(); class mod_data_renderer extends plugin_renderer_base { /** - * Rendering setting and mapping page to import a preset. - * - * @param stdClass $datamodule Database module to import to. - * @param data_preset_importer $importer Importer instance to use for the importing. - * @return string * @deprecated since Moodle 4.1 MDL-75140 - please do not use this class any more. - * @todo MDL-75189 Final deprecation in Moodle 4.5. */ - public function import_setting_mappings($datamodule, data_preset_importer $importer) { - debugging('import_setting_mappings is deprecated. Please use importing_preset instead', DEBUG_DEVELOPER); - - $manager = \mod_data\manager::create_from_coursemodule($datamodule); - $fullname = $importer->get_directory(); - return $this->importing_preset($datamodule, new preset_existing_importer($manager, $fullname)); + #[\core\attribute\deprecated('mod_data_renderer::importing_preset()', since: '4.1', mdl: 'MDL-75140', final: true)] + public function import_setting_mappings(): void { + \core\deprecation::emit_deprecation_if_present([self::class, __FUNCTION__]); } /**