public static function confirm_contexts_for_deletion($ids) {
        $warnings = [];
        $params = external_api::validate_parameters(self::confirm_contexts_for_deletion_parameters(), [
            'ids' => $ids
        ]);
        $ids = $params['ids'];

        // Validate context and access to manage the registry.
        self::validate_context(\context_system::instance());
        api::check_can_manage_data_registry();

        $result = true;
        if (!empty($ids)) {
            $expiredcontextstoapprove = [];
            // Loop through the deletion of expired contexts and their children if necessary.
            foreach ($ids as $id) {
                $expiredcontext = new expired_context($id);
                $targetcontext = context_helper::instance_by_id($expiredcontext->get('contextid'));

                if (!$targetcontext instanceof \context_user) {
                    // Fetch this context's child contexts. Make sure that all of the child contexts are flagged for deletion.
                    // User context children do not need to be considered.
                    $childcontexts = $targetcontext->get_child_contexts();
                    foreach ($childcontexts as $child) {
                        if ($expiredchildcontext = expired_context::get_record(['contextid' => $child->id])) {
                            // Add this child context to the list for approval.
                            $expiredcontextstoapprove[] = $expiredchildcontext;
                        } else {
                            // This context has not yet been flagged for deletion.
                            $result = false;
                            $message = get_string('errorcontexthasunexpiredchildren', 'tool_dataprivacy',
                                $targetcontext->get_context_name(false));
                            $warnings[] = [
                                'item' => 'tool_dataprivacy_ctxexpired',
                                'warningcode' => 'errorcontexthasunexpiredchildren',
                                'message' => $message
                            ];
                            // Exit the process.
                            break 2;
                        }
                    }
                }

                $expiredcontextstoapprove[] = $expiredcontext;
            }

            // Proceed with the approval if everything's in order.
            if ($result) {
                // Mark expired contexts as approved for deletion.
                foreach ($expiredcontextstoapprove as $expired) {
                    // Only mark expired contexts that are pending approval.
                    if ($expired->get('status') == expired_context::STATUS_EXPIRED) {
                        api::set_expired_context_status($expired, expired_context::STATUS_APPROVED);
                    }
                }
            }

        } else {
            // We don't have anything to process.
            $result = false;
            $warnings[] = [
                'item' => 'tool_dataprivacy_ctxexpired',
                'warningcode' => 'errornoexpiredcontexts',
                'message' => get_string('errornoexpiredcontexts', 'tool_dataprivacy')
            ];
        }

        return [
            'result' => $result,
            'warnings' => $warnings
        ];
    }
public static function confirm_contexts_for_deletion($ids) {
        $warnings = [];
        $params = external_api::validate_parameters(self::confirm_contexts_for_deletion_parameters(), [
            'ids' => $ids
        ]);
        $ids = $params['ids'];

        // Validate context and access to manage the registry.
        self::validate_context(\context_system::instance());
        api::check_can_manage_data_registry();

        $result = true;
        if (!empty($ids)) {
            $expiredcontextstoapprove = [];
            // Loop through the deletion of expired contexts and their children if necessary.
            foreach ($ids as $id) {
                $expiredcontext = new expired_context($id);
                $targetcontext = context_helper::instance_by_id($expiredcontext->get('contextid'));

                if (!$targetcontext instanceof \context_user) {
                    // Fetch this context's child contexts. Make sure that all of the child contexts are flagged for deletion.
                    // User context children do not need to be considered.
                    $childcontexts = $targetcontext->get_child_contexts();
                    foreach ($childcontexts as $child) {
                        if ($expiredchildcontext = expired_context::get_record(['contextid' => $child->id])) {
                            // Add this child context to the list for approval.
                            $expiredcontextstoapprove[] = $expiredchildcontext;
                        } else {
                            // This context has not yet been flagged for deletion.
                            $result = false;
                            $message = get_string('errorcontexthasunexpiredchildren', 'tool_dataprivacy',
                                $targetcontext->get_context_name(false));
                            $warnings[] = [
                                'item' => 'tool_dataprivacy_ctxexpired',
                                'warningcode' => 'errorcontexthasunexpiredchildren',
                                'message' => $message
                            ];
                            // Exit the process.
                            break 2;
                        }
                    }
                }

                $expiredcontextstoapprove[] = $expiredcontext;
            }

            // Proceed with the approval if everything's in order.
            if ($result) {
                // Mark expired contexts as approved for deletion.
                foreach ($expiredcontextstoapprove as $expired) {
                    // Only mark expired contexts that are pending approval.
                    if ($expired->get('status') == expired_context::STATUS_EXPIRED) {
                        api::set_expired_context_status($expired, expired_context::STATUS_APPROVED);
                    }
                }
            }

        } else {
            // We don't have anything to process.
            $result = false;
            $warnings[] = [
                'item' => 'tool_dataprivacy_ctxexpired',
                'warningcode' => 'errornoexpiredcontexts',
                'message' => get_string('errornoexpiredcontexts', 'tool_dataprivacy')
            ];
        }

        return [
            'result' => $result,
            'warnings' => $warnings
        ];
    }
public static function confirm_contexts_for_deletion ( $ ids ) { $ warnings = [ ] ; $ params = external_api :: validate_parameters ( self :: confirm_contexts_for_deletion_parameters ( ) , [ 'ids' => $ ids ] ) ; $ ids = $ params [ 'ids' ] ; // Validate context and access to manage the registry. self :: validate_context ( \ context_system :: instance ( ) ) ; api :: check_can_manage_data_registry ( ) ; $ result = true ; if ( ! empty ( $ ids ) ) { $ expiredcontextstoapprove = [ ] ; // Loop through the deletion of expired contexts and their children if necessary. foreach ( $ ids as $ id ) { $ expiredcontext = new expired_context ( $ id ) ; $ targetcontext = context_helper :: instance_by_id ( $ expiredcontext -> get ( 'contextid' ) ) ; if ( ! $ targetcontext instanceof \ context_user ) { // Fetch this context's child contexts. Make sure that all of the child contexts are flagged for deletion. // User context children do not need to be considered. $ childcontexts = $ targetcontext -> get_child_contexts ( ) ; foreach ( $ childcontexts as $ child ) { if ( $ expiredchildcontext = expired_context :: get_record ( [ 'contextid' => $ child -> id ] ) ) { // Add this child context to the list for approval. $ expiredcontextstoapprove [ ] = $ expiredchildcontext ; } else { // This context has not yet been flagged for deletion. $ result = false ; $ message = get_string ( 'errorcontexthasunexpiredchildren' , 'tool_dataprivacy' , $ targetcontext -> get_context_name ( false ) ) ; $ warnings [ ] = [ 'item' => 'tool_dataprivacy_ctxexpired' , 'warningcode' => 'errorcontexthasunexpiredchildren' , 'message' => $ message ] ; // Exit the process. break 2 ; } } } $ expiredcontextstoapprove [ ] = $ expiredcontext ; } // Proceed with the approval if everything's in order. if ( $ result ) { // Mark expired contexts as approved for deletion. foreach ( $ expiredcontextstoapprove as $ expired ) { // Only mark expired contexts that are pending approval. if ( $ expired -> get ( 'status' ) == expired_context :: STATUS_EXPIRED ) { api :: set_expired_context_status ( $ expired , expired_context :: STATUS_APPROVED ) ; } } } } else { // We don't have anything to process. $ result = false ; $ warnings [ ] = [ 'item' => 'tool_dataprivacy_ctxexpired' , 'warningcode' => 'errornoexpiredcontexts' , 'message' => get_string ( 'errornoexpiredcontexts' , 'tool_dataprivacy' ) ] ; } return [ 'result' => $ result , 'warnings' => $ warnings ] ; }
Confirm a given array of expired context record IDs

@since Moodle 3.5
@param int[] $ids Array of record IDs from the expired contexts table.
@return array
@throws coding_exception
@throws dml_exception
@throws invalid_parameter_exception
@throws restricted_context_exception
Confirm a given array of expired context record IDs