Permalink
Browse files

Merge branch 'MDL-61891-34' of git://github.com/andrewnicols/moodle i…

…nto MOODLE_34_STABLE
  • Loading branch information...
dmonllao committed Apr 23, 2018
2 parents bcefe75 + 84f092a commit 75af50bb8d8a56f017b11a0b73e20f91890e3953
Showing with 35 additions and 52 deletions.
  1. +1 −26 plagiarism/classes/privacy/provider.php
  2. +1 −26 portfolio/classes/privacy/provider.php
  3. +33 −0 privacy/classes/manager.php
@@ -66,23 +66,6 @@ public static function export_plagiarism_user_data(int $userid, \context $contex
static::call_plugin_method('export_plagiarism_user_data', [$userid, $context, $subcontext, $linkarray]);
}
/**
* Checks whether the component's provider class implements the specified interface.
* This can either be implemented directly, or by implementing a descendant (extension) of the specified interface.
*
* @param string $component the frankenstyle component name.
* @param string $interface the name of the interface we want to check.
* @return bool True if an implementation was found, false otherwise.
*/
protected static function component_implements(string $providerclass, string $interface) : bool {
if (class_exists($providerclass)) {
$rc = new \ReflectionClass($providerclass);
return $rc->implementsInterface($interface);
}
return false;
}
/**
* Deletes all user content for a context in all plagiarism plugins.
*
@@ -110,14 +93,6 @@ public static function delete_plagiarism_for_user(int $userid, \context $context
*/
protected static function call_plugin_method($methodname, $params) {
// Note: Even if plagiarism is _now_ disabled, there may be legacy data to export.
$plugins = \core_component::get_plugin_list('plagiarism');
foreach (array_keys($plugins) as $plugin) {
$component = "plagiarism_{$plugin}";
$classname = manager::get_provider_classname_for_component($component);
if (static::component_implements($classname, plagiarism_provider::class)) {
// This plagiarism plugin implements the plagiarism_provider.
component_class_callback($classname, $methodname, $params);
}
}
\core_privacy\manager::plugintype_class_callback('plagiarism', plagiarism_provider::class, $methodname, $params);
}
}
@@ -83,23 +83,6 @@ public static function delete_portfolio_for_user(int $userid, \context $context)
static::call_plugin_method('delete_portfolio_for_user', [$userid, $context]);
}
/**
* Checks whether the component's provider class implements the specified interface.
* This can either be implemented directly, or by implementing a descendant (extension) of the specified interface.
*
* @param string $providerclass the provider class name.
* @param string $interface the name of the interface we want to check.
* @return bool True if an implementation was found, false otherwise.
*/
protected static function component_implements(string $providerclass, string $interface) : bool {
if (class_exists($providerclass)) {
$rc = new \ReflectionClass($providerclass);
return $rc->implementsInterface($interface);
}
return false;
}
/**
* Internal method for looping through all of the portfolio plugins and calling a method.
*
@@ -108,14 +91,6 @@ protected static function component_implements(string $providerclass, string $in
*/
protected static function call_plugin_method($methodname, $params) {
// Note: Even if portfolio is _now_ disabled, there may be legacy data to export.
$plugins = \core_component::get_plugin_list('portfolio');
foreach (array_keys($plugins) as $plugin) {
$component = "portfolio_{$plugin}";
$classname = manager::get_provider_classname_for_component($component);
if (static::component_implements($classname, portfolio_provider::class)) {
// This portfolio plugin implements the portfolio_provider.
component_class_callback($classname, $methodname, $params);
}
}
\core_privacy\manager::plugintype_class_callback('portfolio', portfolio_provider::class, $methodname, $params);
}
}
@@ -339,4 +339,37 @@ protected function component_implements(string $component, string $interface) :
}
return false;
}
/**
* Call the named method with the specified params on any plugintype implementing the relevant interface.
*
* @param string $plugintype The plugingtype to check
* @param string $interface The interface to implement
* @param string $methodname The method to call
* @param array $params The params to call
*/
public static function plugintype_class_callback(string $plugintype, string $interface, string $methodname, array $params) {
$components = \core_component::get_plugin_list($plugintype);
foreach (array_keys($components) as $component) {
static::component_class_callback("{$plugintype}_{$component}", $interface, $methodname, $params);
}
}
/**
* Call the named method with the specified params on the supplied component if it implements the relevant interface on its provider.
*
* @param string $component The component to call
* @param string $interface The interface to implement
* @param string $methodname The method to call
* @param array $params The params to call
* @return mixed
*/
public static function component_class_callback(string $component, string $interface, string $methodname, array $params) {
$classname = static::get_provider_classname_for_component($component);
if (class_exists($classname) && is_subclass_of($classname, $interface)) {
return component_class_callback($classname, $methodname, $params);
}
return null;
}
}

0 comments on commit 75af50b

Please sign in to comment.