public static function approve_data_request($requestid) {
        global $USER;

        // Check first whether the user can manage data requests.
        if (!self::can_manage_data_requests($USER->id)) {
            $context = context_system::instance();
            throw new required_capability_exception($context, 'tool/dataprivacy:managedatarequests', 'nopermissions', '');
        }

        // Check if request is already awaiting for approval.
        $request = new data_request($requestid);
        if ($request->get('status') != self::DATAREQUEST_STATUS_AWAITING_APPROVAL) {
            throw new moodle_exception('errorrequestnotwaitingforapproval', 'tool_dataprivacy');
        }

        // Check if current user has permission to approve delete data request.
        if ($request->get('type') == self::DATAREQUEST_TYPE_DELETE && !self::can_create_data_deletion_request_for_other()) {
            throw new required_capability_exception(context_system::instance(),
                'tool/dataprivacy:requestdeleteforotheruser', 'nopermissions', '');
        }

        // Update the status and the DPO.
        $result = self::update_request_status($requestid, self::DATAREQUEST_STATUS_APPROVED, $USER->id);

        // Fire an ad hoc task to initiate the data request process.
        $task = new process_data_request_task();
        $task->set_custom_data(['requestid' => $requestid]);
        if ($request->get('type') == self::DATAREQUEST_TYPE_EXPORT) {
            $task->set_userid($request->get('userid'));
        }
        manager::queue_adhoc_task($task, true);

        return $result;
    }
public static function approve_data_request($requestid) {
        global $USER;

        // Check first whether the user can manage data requests.
        if (!self::can_manage_data_requests($USER->id)) {
            $context = context_system::instance();
            throw new required_capability_exception($context, 'tool/dataprivacy:managedatarequests', 'nopermissions', '');
        }

        // Check if request is already awaiting for approval.
        $request = new data_request($requestid);
        if ($request->get('status') != self::DATAREQUEST_STATUS_AWAITING_APPROVAL) {
            throw new moodle_exception('errorrequestnotwaitingforapproval', 'tool_dataprivacy');
        }

        // Check if current user has permission to approve delete data request.
        if ($request->get('type') == self::DATAREQUEST_TYPE_DELETE && !self::can_create_data_deletion_request_for_other()) {
            throw new required_capability_exception(context_system::instance(),
                'tool/dataprivacy:requestdeleteforotheruser', 'nopermissions', '');
        }

        // Update the status and the DPO.
        $result = self::update_request_status($requestid, self::DATAREQUEST_STATUS_APPROVED, $USER->id);

        // Fire an ad hoc task to initiate the data request process.
        $task = new process_data_request_task();
        $task->set_custom_data(['requestid' => $requestid]);
        if ($request->get('type') == self::DATAREQUEST_TYPE_EXPORT) {
            $task->set_userid($request->get('userid'));
        }
        manager::queue_adhoc_task($task, true);

        return $result;
    }
public static function approve_data_request ( $ requestid ) { global $ USER ; // Check first whether the user can manage data requests. if ( ! self :: can_manage_data_requests ( $ USER -> id ) ) { $ context = context_system :: instance ( ) ; throw new required_capability_exception ( $ context , 'tool/dataprivacy:managedatarequests' , 'nopermissions' , '' ) ; } // Check if request is already awaiting for approval. $ request = new data_request ( $ requestid ) ; if ( $ request -> get ( 'status' ) != self :: DATAREQUEST_STATUS_AWAITING_APPROVAL ) { throw new moodle_exception ( 'errorrequestnotwaitingforapproval' , 'tool_dataprivacy' ) ; } // Check if current user has permission to approve delete data request. if ( $ request -> get ( 'type' ) == self :: DATAREQUEST_TYPE_DELETE && ! self :: can_create_data_deletion_request_for_other ( ) ) { throw new required_capability_exception ( context_system :: instance ( ) , 'tool/dataprivacy:requestdeleteforotheruser' , 'nopermissions' , '' ) ; } // Update the status and the DPO. $ result = self :: update_request_status ( $ requestid , self :: DATAREQUEST_STATUS_APPROVED , $ USER -> id ) ; // Fire an ad hoc task to initiate the data request process. $ task = new process_data_request_task ( ) ; $ task -> set_custom_data ( [ 'requestid' => $ requestid ] ) ; if ( $ request -> get ( 'type' ) == self :: DATAREQUEST_TYPE_EXPORT ) { $ task -> set_userid ( $ request -> get ( 'userid' ) ) ; } manager :: queue_adhoc_task ( $ task , true ) ; return $ result ; }
Approves a data request based on the request ID.

@param int $requestid The request identifier
@return bool
@throws coding_exception
@throws dml_exception
@throws invalid_persistent_exception
@throws required_capability_exception
@throws moodle_exception
Approves a data request based on the request ID .