Skip to content

Commit 75af50b

Browse files
author
David Monllao
committed
Merge branch 'MDL-61891-34' of git://github.com/andrewnicols/moodle into MOODLE_34_STABLE
2 parents bcefe75 + 84f092a commit 75af50b

File tree

3 files changed

+35
-52
lines changed

3 files changed

+35
-52
lines changed

plagiarism/classes/privacy/provider.php

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -66,23 +66,6 @@ public static function export_plagiarism_user_data(int $userid, \context $contex
6666
static::call_plugin_method('export_plagiarism_user_data', [$userid, $context, $subcontext, $linkarray]);
6767
}
6868

69-
/**
70-
* Checks whether the component's provider class implements the specified interface.
71-
* This can either be implemented directly, or by implementing a descendant (extension) of the specified interface.
72-
*
73-
* @param string $component the frankenstyle component name.
74-
* @param string $interface the name of the interface we want to check.
75-
* @return bool True if an implementation was found, false otherwise.
76-
*/
77-
protected static function component_implements(string $providerclass, string $interface) : bool {
78-
if (class_exists($providerclass)) {
79-
$rc = new \ReflectionClass($providerclass);
80-
return $rc->implementsInterface($interface);
81-
}
82-
83-
return false;
84-
}
85-
8669
/**
8770
* Deletes all user content for a context in all plagiarism plugins.
8871
*
@@ -110,14 +93,6 @@ public static function delete_plagiarism_for_user(int $userid, \context $context
11093
*/
11194
protected static function call_plugin_method($methodname, $params) {
11295
// Note: Even if plagiarism is _now_ disabled, there may be legacy data to export.
113-
$plugins = \core_component::get_plugin_list('plagiarism');
114-
foreach (array_keys($plugins) as $plugin) {
115-
$component = "plagiarism_{$plugin}";
116-
$classname = manager::get_provider_classname_for_component($component);
117-
if (static::component_implements($classname, plagiarism_provider::class)) {
118-
// This plagiarism plugin implements the plagiarism_provider.
119-
component_class_callback($classname, $methodname, $params);
120-
}
121-
}
96+
\core_privacy\manager::plugintype_class_callback('plagiarism', plagiarism_provider::class, $methodname, $params);
12297
}
12398
}

portfolio/classes/privacy/provider.php

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -83,23 +83,6 @@ public static function delete_portfolio_for_user(int $userid, \context $context)
8383
static::call_plugin_method('delete_portfolio_for_user', [$userid, $context]);
8484
}
8585

86-
/**
87-
* Checks whether the component's provider class implements the specified interface.
88-
* This can either be implemented directly, or by implementing a descendant (extension) of the specified interface.
89-
*
90-
* @param string $providerclass the provider class name.
91-
* @param string $interface the name of the interface we want to check.
92-
* @return bool True if an implementation was found, false otherwise.
93-
*/
94-
protected static function component_implements(string $providerclass, string $interface) : bool {
95-
if (class_exists($providerclass)) {
96-
$rc = new \ReflectionClass($providerclass);
97-
return $rc->implementsInterface($interface);
98-
}
99-
100-
return false;
101-
}
102-
10386
/**
10487
* Internal method for looping through all of the portfolio plugins and calling a method.
10588
*
@@ -108,14 +91,6 @@ protected static function component_implements(string $providerclass, string $in
10891
*/
10992
protected static function call_plugin_method($methodname, $params) {
11093
// Note: Even if portfolio is _now_ disabled, there may be legacy data to export.
111-
$plugins = \core_component::get_plugin_list('portfolio');
112-
foreach (array_keys($plugins) as $plugin) {
113-
$component = "portfolio_{$plugin}";
114-
$classname = manager::get_provider_classname_for_component($component);
115-
if (static::component_implements($classname, portfolio_provider::class)) {
116-
// This portfolio plugin implements the portfolio_provider.
117-
component_class_callback($classname, $methodname, $params);
118-
}
119-
}
94+
\core_privacy\manager::plugintype_class_callback('portfolio', portfolio_provider::class, $methodname, $params);
12095
}
12196
}

privacy/classes/manager.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,4 +339,37 @@ protected function component_implements(string $component, string $interface) :
339339
}
340340
return false;
341341
}
342+
343+
/**
344+
* Call the named method with the specified params on any plugintype implementing the relevant interface.
345+
*
346+
* @param string $plugintype The plugingtype to check
347+
* @param string $interface The interface to implement
348+
* @param string $methodname The method to call
349+
* @param array $params The params to call
350+
*/
351+
public static function plugintype_class_callback(string $plugintype, string $interface, string $methodname, array $params) {
352+
$components = \core_component::get_plugin_list($plugintype);
353+
foreach (array_keys($components) as $component) {
354+
static::component_class_callback("{$plugintype}_{$component}", $interface, $methodname, $params);
355+
}
356+
}
357+
358+
/**
359+
* Call the named method with the specified params on the supplied component if it implements the relevant interface on its provider.
360+
*
361+
* @param string $component The component to call
362+
* @param string $interface The interface to implement
363+
* @param string $methodname The method to call
364+
* @param array $params The params to call
365+
* @return mixed
366+
*/
367+
public static function component_class_callback(string $component, string $interface, string $methodname, array $params) {
368+
$classname = static::get_provider_classname_for_component($component);
369+
if (class_exists($classname) && is_subclass_of($classname, $interface)) {
370+
return component_class_callback($classname, $methodname, $params);
371+
}
372+
373+
return null;
374+
}
342375
}

0 commit comments

Comments
 (0)