Skip to content

Commit

Permalink
Merge pull request #537 from jrchamp/fix/restore-try-catch-namespace
Browse files Browse the repository at this point in the history
Fix: restore try catch namespace
  • Loading branch information
jrchamp authored Nov 2, 2023
2 parents a969f57 + 8ce37a4 commit 9dc0f49
Show file tree
Hide file tree
Showing 19 changed files with 150 additions and 87 deletions.
1 change: 1 addition & 0 deletions backup/moodle2/restore_zoom_stepslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

require_once($CFG->dirroot . '/mod/zoom/locallib.php');

use moodle_exception;
use restore_path_element;

/**
Expand Down
4 changes: 3 additions & 1 deletion classes/analytics/indicator/activity_base.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@

namespace mod_zoom\analytics\indicator;

use core_analytics\local\indicator\community_of_inquiry_activity;

/**
* Activity base class.
*/
abstract class activity_base extends \core_analytics\local\indicator\community_of_inquiry_activity {
abstract class activity_base extends community_of_inquiry_activity {
/**
* Grading not implemented.
*
Expand Down
9 changes: 6 additions & 3 deletions classes/analytics/indicator/cognitive_depth.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@

namespace mod_zoom\analytics\indicator;

use cm_info;
use lang_string;

/**
* Cognitive depth indicator - zoom.
*/
Expand All @@ -33,8 +36,8 @@ class cognitive_depth extends activity_base {
*
* @return object
*/
public static function get_name(): \lang_string {
return new \lang_string('indicator:cognitivedepth', 'mod_zoom');
public static function get_name(): lang_string {
return new lang_string('indicator:cognitivedepth', 'mod_zoom');
}

/**
Expand All @@ -53,7 +56,7 @@ public function get_indicator_type() {
*
* @return integer
*/
public function get_cognitive_depth_level(\cm_info $cm) {
public function get_cognitive_depth_level(cm_info $cm) {
return self::COGNITIVE_LEVEL_1;
}
}
9 changes: 6 additions & 3 deletions classes/analytics/indicator/social_breadth.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@

namespace mod_zoom\analytics\indicator;

use cm_info;
use lang_string;

/**
* Social breadth indicator.
*/
Expand All @@ -35,8 +38,8 @@ class social_breadth extends activity_base {
*
* @return object
*/
public static function get_name(): \lang_string {
return new \lang_string('indicator:socialbreadth', 'mod_zoom');
public static function get_name(): lang_string {
return new lang_string('indicator:socialbreadth', 'mod_zoom');
}

/**
Expand All @@ -55,7 +58,7 @@ public function get_indicator_type() {
*
* @return integer
*/
public function get_social_breadth_level(\cm_info $cm) {
public function get_social_breadth_level(cm_info $cm) {
return self::SOCIAL_LEVEL_2;
}
}
4 changes: 3 additions & 1 deletion classes/api_limit_exception.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@

namespace mod_zoom;

use stdClass;

/**
* Exceeded daily API limit.
*/
Expand All @@ -43,7 +45,7 @@ class api_limit_exception extends webservice_exception {
public function __construct($response, $errorcode, $retryafter) {
$this->retryafter = $retryafter;

$a = new \stdClass();
$a = new stdClass();
$a->response = $response;
parent::__construct(
$response,
Expand Down
9 changes: 6 additions & 3 deletions classes/event/join_meeting_button_clicked.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@

namespace mod_zoom\event;

use coding_exception;
use moodle_url;

/**
* Records when a join meeting button is clicked.
*/
Expand All @@ -44,9 +47,9 @@ protected function validate_data() {
$fieldstovalidate = ['cmid' => "integer", 'meetingid' => "integer", 'userishost' => "boolean"];
foreach ($fieldstovalidate as $field => $shouldbe) {
if (is_null($this->other[$field])) {
throw new \coding_exception("The $field value must be set in other.");
throw new coding_exception("The $field value must be set in other.");
} else if (gettype($this->other[$field]) != $shouldbe) {
throw new \coding_exception("The $field value must be an $shouldbe.");
throw new coding_exception("The $field value must be an $shouldbe.");
}
}
}
Expand Down Expand Up @@ -76,6 +79,6 @@ public function get_description() {
* @return moodle_url
*/
public function get_url() {
return new \moodle_url('/mod/zoom/view.php', ['id' => $this->other['cmid']]);
return new moodle_url('/mod/zoom/view.php', ['id' => $this->other['cmid']]);
}
}
14 changes: 9 additions & 5 deletions classes/invitation.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@

namespace mod_zoom;

use coding_exception;
use context_module;
use moodle_exception;

/**
* Invitation class.
*/
Expand Down Expand Up @@ -81,11 +85,11 @@ public function get_display_string(int $coursemoduleid, int $userid = null) {
}

// Check user capabilities, and remove parts of the invitation they don't have permission to view.
if (!has_capability('mod/zoom:viewjoinurl', \context_module::instance($coursemoduleid), $userid)) {
if (!has_capability('mod/zoom:viewjoinurl', context_module::instance($coursemoduleid), $userid)) {
$displaystring = $this->remove_element($displaystring, 'joinurl');
}

if (!has_capability('mod/zoom:viewdialin', \context_module::instance($coursemoduleid), $userid)) {
if (!has_capability('mod/zoom:viewdialin', context_module::instance($coursemoduleid), $userid)) {
$displaystring = $this->remove_element($displaystring, 'onetapmobile');
$displaystring = $this->remove_element($displaystring, 'dialin');
$displaystring = $this->remove_element($displaystring, 'sip');
Expand All @@ -94,7 +98,7 @@ public function get_display_string(int $coursemoduleid, int $userid = null) {
// Fix the formatting of the onetapmobile section if it exists.
$displaystring = $this->add_paragraph_break_above_element($displaystring, 'onetapmobile');
}
} catch (\moodle_exception $e) {
} catch (moodle_exception $e) {
// If the regex parsing fails, log a debugging message and return the whole invitation.
debugging($e->getMessage(), DEBUG_DEVELOPER);
return $this->invitation;
Expand All @@ -120,7 +124,7 @@ private function remove_element(string $invitation, string $element): string {

$configregex = $this->get_config_invitation_regex();
if (!array_key_exists($element, $configregex)) {
throw new \coding_exception('Cannot remove element: ' . $element
throw new coding_exception('Cannot remove element: ' . $element
. '. See mod/zoom/classes/invitation.php:get_default_invitation_regex for valid elements.');
}

Expand All @@ -134,7 +138,7 @@ private function remove_element(string $invitation, string $element): string {

// If invitation is null, an error occurred in preg_replace.
if ($invitation === null) {
throw new \moodle_exception(
throw new moodle_exception(
'invitationmodificationfailed',
'mod_zoom',
$PAGE->url,
Expand Down
61 changes: 36 additions & 25 deletions classes/privacy/provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,31 @@

namespace mod_zoom\privacy;

use context;
use context_module;
use core_privacy\local\metadata\collection;
use core_privacy\local\metadata\provider as metadata_provider;
use core_privacy\local\request\approved_contextlist;
use core_privacy\local\request\approved_userlist;
use core_privacy\local\request\contextlist;
use core_privacy\local\request\core_userlist_provider;
use core_privacy\local\request\helper;
use core_privacy\local\request\plugin\provider as request_plugin_provider;
use core_privacy\local\request\transform;
use core_privacy\local\request\userlist;
use core_privacy\local\request\writer;

/**
* Ad hoc task that performs the actions for approved data privacy requests.
*/
class provider implements
\core_privacy\local\request\core_userlist_provider,
\core_privacy\local\metadata\provider,
\core_privacy\local\request\plugin\provider {
class provider implements core_userlist_provider, metadata_provider, request_plugin_provider {
/**
* Returns meta data about this system.
*
* @param collection $coll The collection to add metadata to.
* @return collection The array of metadata
*/
public static function get_metadata(\core_privacy\local\metadata\collection $coll): \core_privacy\local\metadata\collection {
public static function get_metadata(collection $coll): collection {
// Add all user data fields to the collection.

$coll->add_database_table('zoom_meeting_participants', [
Expand Down Expand Up @@ -76,10 +87,10 @@ public static function get_metadata(\core_privacy\local\metadata\collection $col
* @param int $userid The user to search.
* @return contextlist $contextlist The list of contexts used in this plugin.
*/
public static function get_contexts_for_userid(int $userid): \core_privacy\local\request\contextlist {
public static function get_contexts_for_userid(int $userid): contextlist {
// Query the database for context IDs give a specific user ID and return these to the user.

$contextlist = new \core_privacy\local\request\contextlist();
$contextlist = new contextlist();

$sql = 'SELECT c.id
FROM {context} c
Expand Down Expand Up @@ -110,10 +121,10 @@ public static function get_contexts_for_userid(int $userid): \core_privacy\local
*
* @param userlist $userlist The userlist containing the list of users who have data in this context/plugin combination.
*/
public static function get_users_in_context(\core_privacy\local\request\userlist $userlist) {
public static function get_users_in_context(userlist $userlist) {
$context = $userlist->get_context();

if (!($context instanceof \context_module)) {
if (!($context instanceof context_module)) {
return;
}

Expand Down Expand Up @@ -159,7 +170,7 @@ public static function get_users_in_context(\core_privacy\local\request\userlist
* @param approved_contextlist $contextlist The approved contexts to export information for.
* @link http://tandl.churchward.ca/2018/06/implementing-moodles-privacy-api-in.html
*/
public static function export_user_data(\core_privacy\local\request\approved_contextlist $contextlist) {
public static function export_user_data(approved_contextlist $contextlist) {
global $DB;

if (empty($contextlist->count())) {
Expand Down Expand Up @@ -197,20 +208,20 @@ public static function export_user_data(\core_privacy\local\request\approved_con

$participantinstances = $DB->get_recordset_sql($sql, $params);
foreach ($participantinstances as $participantinstance) {
$context = \context_module::instance($participantinstance->cmid);
$contextdata = \core_privacy\local\request\helper::get_context_data($context, $user);
$context = context_module::instance($participantinstance->cmid);
$contextdata = helper::get_context_data($context, $user);

$instancedata = [
'topic' => $participantinstance->topic,
'participant_name' => $participantinstance->name,
'user_email' => $participantinstance->user_email,
'join_time' => \core_privacy\local\request\transform::datetime($participantinstance->join_time),
'leave_time' => \core_privacy\local\request\transform::datetime($participantinstance->leave_time),
'join_time' => transform::datetime($participantinstance->join_time),
'leave_time' => transform::datetime($participantinstance->leave_time),
'duration' => $participantinstance->duration,
];

$contextdata = (object) array_merge((array) $contextdata, $instancedata);
\core_privacy\local\request\writer::with_context($context)->export_data([], $contextdata);
writer::with_context($context)->export_data([], $contextdata);
}

$participantinstances->close();
Expand Down Expand Up @@ -240,18 +251,18 @@ public static function export_user_data(\core_privacy\local\request\approved_con

$recordingviewinstances = $DB->get_recordset_sql($sql, $params);
foreach ($recordingviewinstances as $recordingviewinstance) {
$context = \context_module::instance($recordingviewinstance->cmid);
$contextdata = \core_privacy\local\request\helper::get_context_data($context, $user);
$context = context_module::instance($recordingviewinstance->cmid);
$contextdata = helper::get_context_data($context, $user);

$instancedata = [
'recording_name' => $recordingviewinstance->name,
'userid' => $recordingviewinstance->userid,
'viewed' => $recordingviewinstance->viewed,
'timemodified' => \core_privacy\local\request\transform::datetime($recordingviewinstance->timemodified),
'timemodified' => transform::datetime($recordingviewinstance->timemodified),
];

$contextdata = (object) array_merge((array) $contextdata, $instancedata);
\core_privacy\local\request\writer::with_context($context)->export_data([], $contextdata);
writer::with_context($context)->export_data([], $contextdata);
}

$recordingviewinstances->close();
Expand All @@ -262,10 +273,10 @@ public static function export_user_data(\core_privacy\local\request\approved_con
*
* @param context $context Context to delete data from.
*/
public static function delete_data_for_all_users_in_context(\context $context) {
public static function delete_data_for_all_users_in_context(context $context) {
global $DB;

if (!($context instanceof \context_module)) {
if (!($context instanceof context_module)) {
return;
}

Expand Down Expand Up @@ -299,7 +310,7 @@ public static function delete_data_for_all_users_in_context(\context $context) {
*
* @param approved_contextlist $contextlist The approved contexts and user information to delete information for.
*/
public static function delete_data_for_user(\core_privacy\local\request\approved_contextlist $contextlist) {
public static function delete_data_for_user(approved_contextlist $contextlist) {
global $DB;

if (empty($contextlist->count())) {
Expand All @@ -309,7 +320,7 @@ public static function delete_data_for_user(\core_privacy\local\request\approved
$user = $contextlist->get_user();

foreach ($contextlist->get_contexts() as $context) {
if (!($context instanceof \context_module)) {
if (!($context instanceof context_module)) {
continue;
}

Expand Down Expand Up @@ -337,11 +348,11 @@ public static function delete_data_for_user(\core_privacy\local\request\approved
*
* @param approved_userlist $userlist The approved context and user information to delete information for.
*/
public static function delete_data_for_users(\core_privacy\local\request\approved_userlist $userlist) {
public static function delete_data_for_users(approved_userlist $userlist) {
global $DB;
$context = $userlist->get_context();

if (!($context instanceof \context_module)) {
if (!($context instanceof context_module)) {
return;
}

Expand Down
4 changes: 3 additions & 1 deletion classes/retry_failed_exception.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@

namespace mod_zoom;

use stdClass;

/**
* Couldn't succeed within the allowed number of retries.
*/
Expand All @@ -34,7 +36,7 @@ class retry_failed_exception extends webservice_exception {
* @param int $errorcode Web service response error code
*/
public function __construct($response, $errorcode) {
$a = new \stdClass();
$a = new stdClass();
$a->response = $response;
$a->maxretries = webservice::MAX_RETRIES;
parent::__construct($response, $errorcode, 'zoomerr_maxretries', 'mod_zoom', '', $a);
Expand Down
4 changes: 3 additions & 1 deletion classes/search/activity.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@

namespace mod_zoom\search;

use core_search\base_activity;

/**
* Search area for mod_zoom activities.
*/
class activity extends \core_search\base_activity {
class activity extends base_activity {
/**
* Returns true if this area uses file indexing.
*
Expand Down
Loading

0 comments on commit 9dc0f49

Please sign in to comment.