Skip to content

Commit

Permalink
MDL-76583 core: Update uses of external_* classes
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewnicols committed Jan 18, 2023
1 parent 3e19209 commit a3cc26f
Show file tree
Hide file tree
Showing 382 changed files with 4,052 additions and 4,428 deletions.
14 changes: 5 additions & 9 deletions admin/tool/analytics/classes/external.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,11 @@

namespace tool_analytics;

defined('MOODLE_INTERNAL') || die();

require_once("$CFG->libdir/externallib.php");

use external_api;
use external_function_parameters;
use external_value;
use external_single_structure;
use external_multiple_structure;
use core_external\external_api;
use core_external\external_function_parameters;
use core_external\external_value;
use core_external\external_single_structure;
use core_external\external_multiple_structure;

/**
* This is the external API for this component.
Expand Down
30 changes: 19 additions & 11 deletions admin/tool/behat/classes/external/get_entity_generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,22 @@

namespace tool_behat\external;

use core_external\external_api;
use core_external\external_function_parameters;
use core_external\external_multiple_structure;
use core_external\external_single_structure;
use core_external\external_value;

defined('MOODLE_INTERNAL') || die();

require_once($CFG->libdir . '/externallib.php');
// Ensure we can load Behat and Facebook namespaces in behat libraries.
require_once($CFG->dirroot . '/vendor/autoload.php');
require_once($CFG->libdir . '/tests/behat/behat_data_generators.php');

/**
* External function for getting properties of entity generators.
*/
class get_entity_generator extends \external_api {
class get_entity_generator extends external_api {

/**
* Define parameters for external function.
Expand All @@ -42,11 +50,11 @@ class get_entity_generator extends \external_api {
* behat_data_generators::parse_entity_type, which validates the format of the parameter and throws an exception if it is not
* correct.
*
* @return \external_function_parameters
* @return external_function_parameters
*/
public static function execute_parameters(): \external_function_parameters {
return new \external_function_parameters([
'entitytype' => new \external_value(PARAM_RAW, 'Entity type that can be created by a generator.'),
public static function execute_parameters(): external_function_parameters {
return new external_function_parameters([
'entitytype' => new external_value(PARAM_RAW, 'Entity type that can be created by a generator.'),
]);
}

Expand Down Expand Up @@ -78,12 +86,12 @@ public static function execute(string $entitytype): array {
*
* Return required fields
*
* @return \external_single_structure
* @return external_single_structure
*/
public static function execute_returns(): \external_single_structure {
return new \external_single_structure([
'required' => new \external_multiple_structure(
new \external_value(PARAM_TEXT, 'Required field'),
public static function execute_returns(): external_single_structure {
return new external_single_structure([
'required' => new external_multiple_structure(
new external_value(PARAM_TEXT, 'Required field'),
'Required fields',
VALUE_OPTIONAL
),
Expand Down
38 changes: 16 additions & 22 deletions admin/tool/dataprivacy/classes/external.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,30 +21,24 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace tool_dataprivacy;

defined('MOODLE_INTERNAL') || die();

require_once("$CFG->libdir/externallib.php");
require_once($CFG->dirroot . '/' . $CFG->admin . '/tool/dataprivacy/lib.php');

use coding_exception;
use context_helper;
use context_system;
use context_user;
use core\invalid_persistent_exception;
use core\notification;
use core_user;
use dml_exception;
use external_api;
use external_description;
use external_function_parameters;
use external_multiple_structure;
use external_single_structure;
use external_value;
use external_warnings;
use invalid_parameter_exception;
use core_external\external_api;
use core_external\external_function_parameters;
use core_external\external_multiple_structure;
use core_external\external_single_structure;
use core_external\external_value;
use core_external\external_warnings;
use moodle_exception;
use required_capability_exception;
use restricted_context_exception;
use tool_dataprivacy\external\category_exporter;
use tool_dataprivacy\external\data_request_exporter;
use tool_dataprivacy\external\purpose_exporter;
Expand Down Expand Up @@ -136,7 +130,7 @@ public static function cancel_data_request($requestid) {
* Parameter description for cancel_data_request().
*
* @since Moodle 3.5
* @return external_description
* @return \core_external\external_description
*/
public static function cancel_data_request_returns() {
return new external_single_structure([
Expand Down Expand Up @@ -228,7 +222,7 @@ public static function contact_dpo($message) {
* Parameter description for contact_dpo().
*
* @since Moodle 3.5
* @return external_description
* @return \core_external\external_description
*/
public static function contact_dpo_returns() {
return new external_single_structure([
Expand Down Expand Up @@ -293,7 +287,7 @@ public static function mark_complete($requestid) {
* Parameter description for mark_complete().
*
* @since Moodle 3.5.2
* @return external_description
* @return \core_external\external_description
*/
public static function mark_complete_returns() {
return new external_single_structure([
Expand Down Expand Up @@ -355,7 +349,7 @@ public static function get_data_request($requestid) {
* Parameter description for get_data_request().
*
* @since Moodle 3.5
* @return external_description
* @return \core_external\external_description
*/
public static function get_data_request_returns() {
return new external_single_structure([
Expand Down Expand Up @@ -427,7 +421,7 @@ public static function approve_data_request($requestid) {
* Parameter description for approve_data_request().
*
* @since Moodle 3.5
* @return external_description
* @return \core_external\external_description
*/
public static function approve_data_request_returns() {
return new external_single_structure([
Expand Down Expand Up @@ -506,7 +500,7 @@ public static function bulk_approve_data_requests($requestids) {
* Parameter description for bulk_approve_data_requests().
*
* @since Moodle 3.5
* @return external_description
* @return \core_external\external_description
*/
public static function bulk_approve_data_requests_returns() {
return new external_single_structure([
Expand Down Expand Up @@ -578,7 +572,7 @@ public static function deny_data_request($requestid) {
* Parameter description for deny_data_request().
*
* @since Moodle 3.5
* @return external_description
* @return \core_external\external_description
*/
public static function deny_data_request_returns() {
return new external_single_structure([
Expand Down Expand Up @@ -657,7 +651,7 @@ public static function bulk_deny_data_requests($requestids) {
* Parameter description for bulk_deny_data_requests().
*
* @since Moodle 3.5
* @return external_description
* @return \core_external\external_description
*/
public static function bulk_deny_data_requests_returns() {
return new external_single_structure([
Expand Down Expand Up @@ -740,7 +734,7 @@ public static function get_users($query) {
* Parameter description for get_users().
*
* @since Moodle 3.5
* @return external_description
* @return \core_external\external_description
* @throws coding_exception
*/
public static function get_users_returns() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,9 @@
namespace tool_dataprivacy\external;
defined('MOODLE_INTERNAL') || die();

use coding_exception;
use core\external\persistent_exporter;
use core_user;
use core_user\external\user_summary_exporter;
use dml_exception;
use moodle_exception;
use renderer_base;
use tool_dataprivacy\api;
use tool_dataprivacy\data_request;
Expand Down
2 changes: 0 additions & 2 deletions admin/tool/dataprivacy/classes/external/purpose_exporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@
namespace tool_dataprivacy\external;
defined('MOODLE_INTERNAL') || die();

use coding_exception;
use core\external\persistent_exporter;
use Exception;
use renderer_base;
use tool_dataprivacy\context_instance;
use tool_dataprivacy\purpose;
Expand Down
37 changes: 19 additions & 18 deletions admin/tool/dataprivacy/tests/external/external_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

namespace tool_dataprivacy\external;

use core_external\external_api;
use externallib_advanced_testcase;
use tool_dataprivacy\api;
use tool_dataprivacy\context_instance;
Expand Down Expand Up @@ -123,7 +124,7 @@ public function test_approve_data_request() {
$this->setAdminUser();
api::update_request_status($datarequest->get('id'), api::DATAREQUEST_STATUS_AWAITING_APPROVAL);
$result = external::approve_data_request($datarequest->get('id'));
$return = (object) \external_api::clean_returnvalue(external::approve_data_request_returns(), $result);
$return = (object) external_api::clean_returnvalue(external::approve_data_request_returns(), $result);
$this->assertTrue($return->result);
$this->assertEmpty($return->warnings);
}
Expand All @@ -139,7 +140,7 @@ public function test_approve_data_request_non_existent() {

$result = external::approve_data_request(1);

$return = (object) \external_api::clean_returnvalue(external::approve_data_request_returns(), $result);
$return = (object) external_api::clean_returnvalue(external::approve_data_request_returns(), $result);
$this->assertFalse($return->result);
$this->assertCount(1, $return->warnings);
$warning = reset($return->warnings);
Expand All @@ -165,7 +166,7 @@ public function test_cancel_data_request_other_user() {
$this->setUser($otheruser);

$result = external::cancel_data_request($datarequest->get('id'));
$return = (object) \external_api::clean_returnvalue(external::approve_data_request_returns(), $result);
$return = (object) external_api::clean_returnvalue(external::approve_data_request_returns(), $result);
$this->assertFalse($return->result);
$this->assertCount(1, $return->warnings);
$warning = reset($return->warnings);
Expand Down Expand Up @@ -194,7 +195,7 @@ public function test_cancel_data_request_other_user_as_requester() {
$datarequest = api::create_data_request($otheruser->id, api::DATAREQUEST_TYPE_EXPORT, $comment);

$result = external::cancel_data_request($datarequest->get('id'));
$return = (object) \external_api::clean_returnvalue(external::approve_data_request_returns(), $result);
$return = (object) external_api::clean_returnvalue(external::approve_data_request_returns(), $result);
$this->assertTrue($return->result);
$this->assertEmpty($return->warnings);
}
Expand Down Expand Up @@ -250,7 +251,7 @@ public function test_cancel_data_request_other_user_as_child() {
$datarequest = api::create_data_request($otheruser->id, api::DATAREQUEST_TYPE_EXPORT, $comment);

$result = external::cancel_data_request($datarequest->get('id'));
$return = (object) \external_api::clean_returnvalue(external::approve_data_request_returns(), $result);
$return = (object) external_api::clean_returnvalue(external::approve_data_request_returns(), $result);
$this->assertTrue($return->result);
$this->assertEmpty($return->warnings);
}
Expand All @@ -273,7 +274,7 @@ public function test_cancel_data_request() {
$this->setUser($requester);
$result = external::cancel_data_request($datarequest->get('id'));

$return = (object) \external_api::clean_returnvalue(external::approve_data_request_returns(), $result);
$return = (object) external_api::clean_returnvalue(external::approve_data_request_returns(), $result);
$this->assertTrue($return->result);
$this->assertEmpty($return->warnings);
}
Expand All @@ -290,7 +291,7 @@ public function test_contact_dpo() {
$this->setUser($user);
$message = 'Hello world!';
$result = external::contact_dpo($message);
$return = (object) \external_api::clean_returnvalue(external::contact_dpo_returns(), $result);
$return = (object) external_api::clean_returnvalue(external::contact_dpo_returns(), $result);
$this->assertTrue($return->result);
$this->assertEmpty($return->warnings);
}
Expand Down Expand Up @@ -385,7 +386,7 @@ public function test_deny_data_request() {
$this->setAdminUser();
api::update_request_status($datarequest->get('id'), api::DATAREQUEST_STATUS_AWAITING_APPROVAL);
$result = external::approve_data_request($datarequest->get('id'));
$return = (object) \external_api::clean_returnvalue(external::deny_data_request_returns(), $result);
$return = (object) external_api::clean_returnvalue(external::deny_data_request_returns(), $result);
$this->assertTrue($return->result);
$this->assertEmpty($return->warnings);
}
Expand All @@ -400,7 +401,7 @@ public function test_deny_data_request_non_existent() {
$this->setAdminUser();
$result = external::deny_data_request(1);

$return = (object) \external_api::clean_returnvalue(external::deny_data_request_returns(), $result);
$return = (object) external_api::clean_returnvalue(external::deny_data_request_returns(), $result);
$this->assertFalse($return->result);
$this->assertCount(1, $return->warnings);
$warning = reset($return->warnings);
Expand Down Expand Up @@ -462,7 +463,7 @@ public function test_get_data_request() {
$this->setAdminUser();
$result = external::get_data_request($datarequest->get('id'));

$return = (object) \external_api::clean_returnvalue(external::get_data_request_returns(), $result);
$return = (object) external_api::clean_returnvalue(external::get_data_request_returns(), $result);
$this->assertEquals(api::DATAREQUEST_TYPE_EXPORT, $return->result['type']);
$this->assertEquals('sample comment', $return->result['comments']);
$this->assertEquals($requester->id, $return->result['userid']);
Expand Down Expand Up @@ -542,7 +543,7 @@ public function test_set_context_defaults($modulelevel, $override) {
$result = external::set_context_defaults(CONTEXT_MODULE, $categoryid, $purposeid, $modulename, $override);

// Extract the result.
$return = \external_api::clean_returnvalue(external::set_context_defaults_returns(), $result);
$return = external_api::clean_returnvalue(external::set_context_defaults_returns(), $result);
$this->assertTrue($return['result']);

// Check the assignment context instance.
Expand Down Expand Up @@ -626,7 +627,7 @@ public function test_get_category_options($includeinherit, $includenotset) {
$result = external::get_category_options($includeinherit, $includenotset);

// Extract the options.
$return = (object) \external_api::clean_returnvalue(external::get_category_options_returns(), $result);
$return = (object) external_api::clean_returnvalue(external::get_category_options_returns(), $result);
$options = $return->options;

// Make sure everything checks out.
Expand Down Expand Up @@ -690,7 +691,7 @@ public function test_get_purpose_options($includeinherit, $includenotset) {
$result = external::get_purpose_options($includeinherit, $includenotset);

// Extract the options.
$return = (object) \external_api::clean_returnvalue(external::get_purpose_options_returns(), $result);
$return = (object) external_api::clean_returnvalue(external::get_purpose_options_returns(), $result);
$options = $return->options;

// Make sure everything checks out.
Expand Down Expand Up @@ -749,7 +750,7 @@ public function test_get_activity_options($inheritcategory, $inheritpurpose, $no
$result = external::get_activity_options($nodefaults);

// Extract the options.
$return = (object) \external_api::clean_returnvalue(external::get_activity_options_returns(), $result);
$return = (object) external_api::clean_returnvalue(external::get_activity_options_returns(), $result);
$options = $return->options;

// Make sure the options list is not empty.
Expand Down Expand Up @@ -792,7 +793,7 @@ public function test_bulk_approve_data_requests() {
api::update_request_status($requestid2, api::DATAREQUEST_STATUS_AWAITING_APPROVAL);
$result = external::bulk_approve_data_requests([$requestid1, $requestid2]);

$return = (object) \external_api::clean_returnvalue(external::bulk_approve_data_requests_returns(), $result);
$return = (object) external_api::clean_returnvalue(external::bulk_approve_data_requests_returns(), $result);
$this->assertTrue($return->result);
$this->assertEmpty($return->warnings);
}
Expand All @@ -807,7 +808,7 @@ public function test_bulk_approve_data_requests_non_existent() {

$result = external::bulk_approve_data_requests([42]);

$return = (object) \external_api::clean_returnvalue(external::bulk_approve_data_requests_returns(), $result);
$return = (object) external_api::clean_returnvalue(external::bulk_approve_data_requests_returns(), $result);
$this->assertFalse($return->result);
$this->assertCount(1, $return->warnings);
$warning = reset($return->warnings);
Expand Down Expand Up @@ -895,7 +896,7 @@ public function test_bulk_deny_data_requests() {
api::update_request_status($requestid2, api::DATAREQUEST_STATUS_AWAITING_APPROVAL);
$result = external::bulk_deny_data_requests([$requestid1, $requestid2]);

$return = (object) \external_api::clean_returnvalue(external::bulk_approve_data_requests_returns(), $result);
$return = (object) external_api::clean_returnvalue(external::bulk_approve_data_requests_returns(), $result);
$this->assertTrue($return->result);
$this->assertEmpty($return->warnings);
}
Expand All @@ -908,7 +909,7 @@ public function test_bulk_deny_data_requests_non_existent() {

$this->setAdminUser();
$result = external::bulk_deny_data_requests([42]);
$return = (object) \external_api::clean_returnvalue(external::bulk_approve_data_requests_returns(), $result);
$return = (object) external_api::clean_returnvalue(external::bulk_approve_data_requests_returns(), $result);

$this->assertFalse($return->result);
$this->assertCount(1, $return->warnings);
Expand Down
Loading

0 comments on commit a3cc26f

Please sign in to comment.