DatabaseBackend
class DatabaseBackend implements FloodInterface (View source)
Defines the database flood backend. This is the default Drupal backend.
Constants
| TABLE_NAME |
The database table name. |
Properties
| protected Connection | $connection | The database connection used to store flood event information. |
|
| protected RequestStack | $requestStack | The request stack. |
Methods
Registers an event for the current visitor to the flood control mechanism.
Inserts an event into the flood table.
Makes the flood control mechanism forget an event for the current visitor.
Checks whether a user is allowed to proceed with the specified event.
Cleans up expired flood events. This method is called automatically on cron run.
Check if the flood table exists and create it if not.
Defines the schema for the flood table.
Details
__construct(Connection $connection, RequestStack $request_stack)
Construct the DatabaseBackend.
register(string $name, int $window = 3600, string $identifier = NULL)
Registers an event for the current visitor to the flood control mechanism.
protected
doInsert(string $name, int $window, string $identifier)
Inserts an event into the flood table.
clear(string $name, string $identifier = NULL)
Makes the flood control mechanism forget an event for the current visitor.
true
isAllowed(string $name, int $threshold, int $window = 3600, string $identifier = NULL)
Checks whether a user is allowed to proceed with the specified event.
Events can have thresholds saying that each user can only do that event a certain number of times in a time window. This function verifies that the current user has not exceeded this threshold.
garbageCollection()
Cleans up expired flood events. This method is called automatically on cron run.
protected
ensureTableExists()
Check if the flood table exists and create it if not.
protected
catchException(Exception $e)
Act on an exception when flood might be stale.
If the table does not yet exist, that's fine, but if the table exists and yet the query failed, then the flood is stale and the exception needs to propagate.
schemaDefinition()
| internal |
Defines the schema for the flood table.