Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
moodle
moodle
Commits
8fef061d
Commit
8fef061d
authored
Mar 01, 2016
by
Marina Glancy
Browse files
MDL-53292 core: deprecate callback delete_course
parent
a0a63678
Changes
11
Hide whitespace changes
Inline
Side-by-side
course/format/README.txt
View file @
8fef061d
...
...
@@ -139,8 +139,3 @@ Optional file (styles)
If this file exists it will be included in the CSS Moodle generates.
Optional delete course hook
---------------------------
* in your yourformat/lib.php add function format_yourformat_delete_course($courseid)
\ No newline at end of file
course/format/upgrade.txt
View file @
8fef061d
...
...
@@ -2,6 +2,9 @@ This files describes API changes for course formats
Overview of this plugin type at http://docs.moodle.org/dev/Course_formats
=== 3.2 ===
* Callback delete_course is deprecated and should be replaced with observer for event \core\event\course_content_deleted
=== 3.1 ===
* Course format may use the inplace_editable template to allow quick editing of section names, see
https://docs.moodle.org/dev/Inplace_editable and MDL-51802 for example implementation.
...
...
lib/moodlelib.php
View file @
8fef061d
...
...
@@ -4798,6 +4798,9 @@ function remove_course_contents($courseid, $showfeedback = true, array $options
echo
$OUTPUT
->
notification
(
$strdeleted
.
get_string
(
'type_block_plural'
,
'plugin'
),
'notifysuccess'
);
}
// Get the list of all modules that are properly installed.
$allmodules
=
$DB
->
get_records_menu
(
'modules'
,
array
(),
''
,
'name, id'
);
// Delete every instance of every module,
// this has to be done before deleting of course level stuff.
$locations
=
core_component
::
get_plugin_list
(
'mod'
);
...
...
@@ -4805,30 +4808,36 @@ function remove_course_contents($courseid, $showfeedback = true, array $options
if
(
$modname
===
'NEWMODULE'
)
{
continue
;
}
if
(
$module
=
$DB
->
get_record
(
'modules'
,
array
(
'name'
=>
$modname
)))
{
if
(
array_key_exists
(
$modname
,
$allmodules
))
{
$sql
=
"SELECT cm.*, m.id AS modinstance, m.name, '
$modname
' AS modname
FROM
{
".$modname."
}
m
LEFT JOIN
{
course_modules
}
cm ON cm.instance = m.id AND cm.module = :moduleid
WHERE m.course = :courseid"
;
$instances
=
$DB
->
get_records_sql
(
$sql
,
array
(
'courseid'
=>
$course
->
id
,
'modulename'
=>
$modname
,
'moduleid'
=>
$allmodules
[
$modname
]));
include_once
(
"
$moddir
/lib.php"
);
// Shows php warning only if plugin defective.
$moddelete
=
$modname
.
'_delete_instance'
;
// Delete everything connected to an instance.
$moddeletecourse
=
$modname
.
'_delete_course'
;
// Delete other stray stuff (uncommon).
if
(
$instances
=
$DB
->
get_records
(
$modname
,
array
(
'course'
=>
$course
->
id
))
)
{
foreach
(
$instances
as
$
instance
)
{
if
(
$cm
=
get_coursemodule_from_instance
(
$modname
,
$instance
->
id
,
$course
->
id
)
)
{
if
(
$instances
)
{
foreach
(
$instances
as
$
cm
)
{
if
(
$cm
->
id
)
{
// Delete activity context questions and question categories.
question_delete_activity
(
$cm
,
$showfeedback
);
// Notify the competency subsystem.
\
core_competency\api
::
hook_course_module_deleted
(
$cm
);
}
if
(
function_exists
(
$moddelete
))
{
// This purges all module data in related tables, extra user prefs, settings, etc.
$moddelete
(
$instance
->
id
);
$moddelete
(
$
cm
->
mod
instance
);
}
else
{
// NOTE: we should not allow installation of modules with missing delete support!
debugging
(
"Defective module '
$modname
' detected when deleting course contents: missing function
$moddelete
()!"
);
$DB
->
delete_records
(
$modname
,
array
(
'id'
=>
$instance
->
id
));
$DB
->
delete_records
(
$modname
,
array
(
'id'
=>
$
cm
->
mod
instance
));
}
if
(
$cm
)
{
if
(
$cm
->
id
)
{
// Delete cm and its context - orphaned contexts are purged in cron in case of any race condition.
context_helper
::
delete_instance
(
CONTEXT_MODULE
,
$cm
->
id
);
$DB
->
delete_records
(
'course_modules'
,
array
(
'id'
=>
$cm
->
id
));
...
...
@@ -4836,7 +4845,9 @@ function remove_course_contents($courseid, $showfeedback = true, array $options
}
}
if
(
function_exists
(
$moddeletecourse
))
{
// Execute ptional course cleanup callback.
// Execute optional course cleanup callback. Deprecated since Moodle 3.2. TODO MDL-53297 remove in 3.6.
debugging
(
"Callback delete_course is deprecated. Function
$moddeletecourse
should be converted "
.
'to observer of event \core\event\course_content_deleted'
,
DEBUG_DEVELOPER
);
$moddeletecourse
(
$course
,
$showfeedback
);
}
if
(
$instances
and
$showfeedback
)
{
...
...
@@ -4856,12 +4867,13 @@ function remove_course_contents($courseid, $showfeedback = true, array $options
'coursemoduleid IN (SELECT id from {course_modules} WHERE course=?)'
,
array
(
$courseid
));
// Remove course-module data.
// Remove course-module data
that has not been removed in modules' _delete_instance callbacks
.
$cms
=
$DB
->
get_records
(
'course_modules'
,
array
(
'course'
=>
$course
->
id
));
$allmodulesbyid
=
array_flip
(
$allmodules
);
foreach
(
$cms
as
$cm
)
{
if
(
$module
=
$DB
->
get_record
(
'modules'
,
array
(
'id'
=>
$cm
->
module
)
))
{
if
(
array_key_exists
(
$cm
->
module
,
$all
module
sbyid
))
{
try
{
$DB
->
delete_records
(
$module
->
name
,
array
(
'id'
=>
$cm
->
instance
));
$DB
->
delete_records
(
$
all
module
sbyid
[
$cm
->
module
]
,
array
(
'id'
=>
$cm
->
instance
));
}
catch
(
Exception
$e
)
{
// Ignore weird or missing table problems.
}
...
...
@@ -4874,17 +4886,19 @@ function remove_course_contents($courseid, $showfeedback = true, array $options
echo
$OUTPUT
->
notification
(
$strdeleted
.
get_string
(
'type_mod_plural'
,
'plugin'
),
'notifysuccess'
);
}
// Cleanup the rest of plugins.
// Cleanup the rest of plugins.
Deprecated since Moodle 3.2. TODO MDL-53297 remove in 3.6.
$cleanuplugintypes
=
array
(
'report'
,
'coursereport'
,
'format'
);
$callbacks
=
get_plugins_with_function
(
'delete_course'
,
'lib.php'
);
foreach
(
$cleanuplugintypes
as
$type
)
{
if
(
!
empty
(
$callbacks
[
$type
]))
{
foreach
(
$callbacks
[
$type
]
as
$pluginfunction
)
{
debugging
(
"Callback delete_course is deprecated. Function
$pluginfunction
should be converted "
.
'to observer of event \core\event\course_content_deleted'
,
DEBUG_DEVELOPER
);
$pluginfunction
(
$course
->
id
,
$showfeedback
);
}
}
if
(
$showfeedback
)
{
echo
$OUTPUT
->
notification
(
$strdeleted
.
get_string
(
'type_'
.
$type
.
'_plural'
,
'plugin'
),
'notifysuccess'
);
if
(
$showfeedback
)
{
echo
$OUTPUT
->
notification
(
$strdeleted
.
get_string
(
'type_'
.
$type
.
'_plural'
,
'plugin'
),
'notifysuccess'
);
}
}
}
...
...
mod/feedback/classes/observer.php
0 → 100644
View file @
8fef061d
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Event observers supported by this module
*
* @package mod_feedback
* @copyright 2016 Marina Glancy
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined
(
'MOODLE_INTERNAL'
)
||
die
();
/**
* Event observers supported by this module
*
* @package mod_feedback
* @copyright 2016 Marina Glancy
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class
mod_feedback_observer
{
/**
* Observer for the even course_content_deleted - delete all course templates.
*
* @param \core\event\course_content_deleted $event
*/
public
static
function
course_content_deleted
(
\
core\event\course_content_deleted
$event
)
{
global
$DB
;
// Delete all templates of given course.
$DB
->
delete_records
(
'feedback_template'
,
array
(
'course'
=>
$event
->
objectid
));
}
}
mod/feedback/db/events.php
0 → 100644
View file @
8fef061d
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Feedback event handler definition.
*
* @package mod_feedback
* @category event
* @copyright 2016 Marina Glancy
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
// List of observers.
$observers
=
array
(
array
(
'eventname'
=>
'\core\event\course_content_deleted'
,
'callback'
=>
'mod_feedback_observer::course_content_deleted'
,
),
);
mod/feedback/lib.php
View file @
8fef061d
...
...
@@ -312,21 +312,6 @@ function feedback_delete_instance($id) {
return
$DB
->
delete_records
(
"feedback"
,
array
(
"id"
=>
$id
));
}
/**
* this is called after deleting all instances if the course will be deleted.
* only templates have to be deleted
*
* @global object
* @param object $course
* @return boolean
*/
function
feedback_delete_course
(
$course
)
{
global
$DB
;
//delete all templates of given course
return
$DB
->
delete_records
(
'feedback_template'
,
array
(
'course'
=>
$course
->
id
));
}
/**
* Return a small object with summary information about what a
* user has done with a given particular instance of this module
...
...
mod/feedback/tests/events_test.php
View file @
8fef061d
...
...
@@ -329,5 +329,18 @@ class mod_feedback_events_testcase extends advanced_testcase {
$this
->
assertContains
(
"The 'anonymous' value must be set in other."
,
$e
->
getMessage
());
}
}
/**
* Test that event observer is executed on course deletion and the templates are removed.
*/
public
function
test_delete_course
()
{
global
$DB
;
$this
->
resetAfterTest
();
feedback_save_as_template
(
$this
->
eventfeedback
,
'my template'
,
0
);
$courseid
=
$this
->
eventcourse
->
id
;
$this
->
assertNotEmpty
(
$DB
->
get_records
(
'feedback_template'
,
array
(
'course'
=>
$courseid
)));
delete_course
(
$this
->
eventcourse
,
false
);
$this
->
assertEmpty
(
$DB
->
get_records
(
'feedback_template'
,
array
(
'course'
=>
$courseid
)));
}
}
mod/feedback/version.php
View file @
8fef061d
...
...
@@ -24,7 +24,7 @@
defined
(
'MOODLE_INTERNAL'
)
||
die
();
$plugin
->
version
=
20160
52
300
;
// The current module version (Date: YYYYMMDDXX)
$plugin
->
version
=
20160
61
300
;
// The current module version (Date: YYYYMMDDXX)
$plugin
->
requires
=
2016051900
;
// Requires this Moodle version
$plugin
->
component
=
'mod_feedback'
;
// Full name of the plugin (used for diagnostics)
$plugin
->
cron
=
0
;
...
...
mod/lesson/lib.php
View file @
8fef061d
...
...
@@ -274,19 +274,6 @@ function lesson_delete_instance($id) {
return
$lesson
->
delete
();
}
/**
* Given a course object, this function will clean up anything that
* would be leftover after all the instances were deleted
*
* @global object
* @param object $course an object representing the course that is being deleted
* @param boolean $feedback to specify if the process must output a summary of its work
* @return boolean
*/
function
lesson_delete_course
(
$course
,
$feedback
=
true
)
{
return
true
;
}
/**
* Return a small object with summary information about what a
* user has done with a given particular instance of this module
...
...
mod/upgrade.txt
View file @
8fef061d
This files describes API changes in /mod/* - activity modules,
information provided here is intended especially for developers.
=== 3.2 ===
* Callback delete_course is deprecated and should be replaced with observer for event \core\event\course_content_deleted
=== 3.1 ===
* Old /mod/MODULENAME/pix/icon.gif and enrol/paypal/pix/icon.gif GIF icons have been removed. Please use pix_icon
...
...
report/upgrade.txt
View file @
8fef061d
This files describes API changes in /report/* - plugins,
information provided here is intended especially for developers.
=== 3.2 ===
* Callback delete_course is deprecated and should be replaced with observer for event \core\event\course_content_deleted
=== 2.7 ===
* How to migrate reports accessing table 'log':
http://docs.moodle.org/dev/Migrating_log_access_in_reports
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment