cleanupPermissionPageMatches (function)

Last updated: Sat, Apr 15, 2023 6:40 pm
Return to Knowledgebase

Purpose

Cleans up orphaned permission-page matches

Location

users/helpers/permissions.php

Parameters

This function does not take any arguments

Returns

Data Type Description of Returned Data
nothing If the query is successful, the function logs a message indicating the number of orphaned permission-page matches that were deleted. If the query fails, the function logs an error message.

Further Documentation:

The cleanupPermissionPageMatches function cleans up orphaned permission-page matches. Orphaned permission-page matches occur when a page is deleted but the permission-page match associated with that page remains in the database. This function deletes those orphaned permission-page matches to keep the database clean.

The function first checks if the $db object has been set. If not, it creates a new instance of the DB class from the UserSpice framework. Next, the function checks if a user is logged in. If a user is logged in, it sets $userId to the ID of the currently logged-in user. If no user is logged in, it sets $userId to 1 (which is the ID of the master user in UserSpice).

The function then executes a SQL query to delete any permission-page matches where the page ID is not in the pages table. If the query is successful, the function logs a message indicating the number of orphaned permission-page matches that were deleted. If the query fails, the function logs an error message.

Here is an example of how the cleanupPermissionPageMatches function can be used:

cleanupPermissionPageMatches();


In this example, the function is simply called without any parameters. The function will delete any orphaned permission-page matches in the database and log a message indicating how many matches were deleted.