Activator
in package
Uses
UtilsProvider, Activator
The activator class handles the plugin relevant activation hooks: Uninstall, activation, deactivation and installation. The "installation" means installing needed database tables.
Table of Contents
Constants
- CHILD_UDF_NAME = 'fn_realmedialibrary_childs'
- DB_CHILD_QUERY_SUPPORTED = '_cqs'
Properties
- $charsetCollate : string
- See `$this->getCharsetCollate()`.
- $childSupportCurrentType : mixed
Methods
- activate() : mixed
- Method gets fired when the user activates the plugin.
- checkChildQuery() : mixed
- Check if the current instance type works as expected.
- checkDirtyFunction() : bool
- Checks if the Database supports functions but the function is not yet created (due to exports for example).
- createChildQueryFunction() : mixed
- Create a MySQL function wp_realmedialibrary_childs to read recursively children of a folder.
- dbDelta() : mixed
- Install tables, stored procedures or whatever in the database.
- deactivate() : mixed
- Method gets fired when the user deactivates the plugin.
- getCharsetCollate() : mixed
- Get the charset collate definition for the SQL command. Similar to `$wpdb->get_charset_collate()` but it ensures to **not** mix the collates of our plugin database tables.
- getDatabaseVersion() : mixed
- Get the current persisted database version.
- getFirstDatabaseTableName() : mixed
- getMaxIndexLength() : mixed
- Indexes have a maximum size of 767 bytes. Historically, we haven't need to be concerned about that.
- getPluginConstantPrefix() : string
- Get the prefix of this plugin so composer packages can dynamically build other constant values on it.
- getPreviousDatabaseVersions() : array<string|int, string>
- Get a list of previous installed database versions.
- install() : bool
- Run an installation or dbDelta within a callable.
- isMigrationLocked() : If
- Check if the migration is locked. It uses a time span of 10 minutes (like Yoast SEO plugin).
- persistPreviousVersion() : mixed
- Persist the previous installed versions of this plugin so we can e.g. start migrations.
- registerCapabilities() : mixed
- Register custom capabilities with e.g. `wp_roles()` and `->add_cap()`. If you add capabilities, please also remove them through the `deactivate` method.
- removeColumnsFromTable() : mixed
- `dbDelta` does currently not support removing columns from tables. For this, we need to read the structure of the table and remove the column accordingly on existence.
- removeIndicesFromTable() : mixed
- `dbDelta` does currently not support removing indices from tables so updating e.g. `UNIQUE KEYS` does not work.
- removePreviousPersistedVersions() : mixed
- Remove the previous persisted versions from the saved option. This is useful if you have successfully finished your migration.
- removeTables() : mixed
- Remove database tables if they exist.
- supportsChildQuery() : bool
- Checks if the current database supports functions or recursive drill-down query.
Constants
CHILD_UDF_NAME
public
mixed
CHILD_UDF_NAME
= 'fn_realmedialibrary_childs'
DB_CHILD_QUERY_SUPPORTED
public
mixed
DB_CHILD_QUERY_SUPPORTED
= '_cqs'
Properties
$charsetCollate
See `$this->getCharsetCollate()`.
private
string
$charsetCollate
= null
$childSupportCurrentType
private
mixed
$childSupportCurrentType
= null
Methods
activate()
Method gets fired when the user activates the plugin.
public
activate() : mixed
checkChildQuery()
Check if the current instance type works as expected.
public
checkChildQuery() : mixed
checkDirtyFunction()
Checks if the Database supports functions but the function is not yet created (due to exports for example).
public
checkDirtyFunction(string $function_name) : bool
Parameters
- $function_name : string
Return values
boolcreateChildQueryFunction()
Create a MySQL function wp_realmedialibrary_childs to read recursively children of a folder.
public
createChildQueryFunction() : mixed
dbDelta()
Install tables, stored procedures or whatever in the database.
public
dbDelta(bool $errorlevel) : mixed
This method is always called when the version bumps up or for the first initial activation.
Parameters
- $errorlevel : bool
-
If true throw errors
deactivate()
Method gets fired when the user deactivates the plugin.
public
deactivate() : mixed
getCharsetCollate()
Get the charset collate definition for the SQL command. Similar to `$wpdb->get_charset_collate()` but it ensures to **not** mix the collates of our plugin database tables.
public
getCharsetCollate() : mixed
Tags
getDatabaseVersion()
Get the current persisted database version.
public
getDatabaseVersion() : mixed
getFirstDatabaseTableName()
public
getFirstDatabaseTableName() : mixed
getMaxIndexLength()
Indexes have a maximum size of 767 bytes. Historically, we haven't need to be concerned about that.
public
getMaxIndexLength() : mixed
As of 4.2, however, we moved to utf8mb4, which uses 4 bytes per character. This means that an index which used to have room for floor(767/3) = 255 characters, now only has room for floor(767/4) = 191 characters.
Tags
getPluginConstantPrefix()
Get the prefix of this plugin so composer packages can dynamically build other constant values on it.
public
getPluginConstantPrefix() : string
Tags
Return values
stringgetPreviousDatabaseVersions()
Get a list of previous installed database versions.
public
getPreviousDatabaseVersions() : array<string|int, string>
Return values
array<string|int, string>install()
Run an installation or dbDelta within a callable.
public
install([bool $errorlevel = false ][, callable $installThisCallable = null ]) : bool
Parameters
- $errorlevel : bool = false
-
Set true to throw errors.
- $installThisCallable : callable = null
-
Set a callable to install this one instead of the default.
Return values
bool —Returns false
when e.g. the migration got locked
isMigrationLocked()
Check if the migration is locked. It uses a time span of 10 minutes (like Yoast SEO plugin).
public
isMigrationLocked([int $set = null ]) : If
Parameters
- $set : int = null
Tags
Return values
If —$set
is a numeric, it returns a boolean indicating if the update of the migration was successful, otherwise it returns a boolean
if the migration is locked.
persistPreviousVersion()
Persist the previous installed versions of this plugin so we can e.g. start migrations.
public
persistPreviousVersion() : mixed
registerCapabilities()
Register custom capabilities with e.g. `wp_roles()` and `->add_cap()`. If you add capabilities, please also remove them through the `deactivate` method.
public
registerCapabilities() : mixed
removeColumnsFromTable()
`dbDelta` does currently not support removing columns from tables. For this, we need to read the structure of the table and remove the column accordingly on existence.
public
removeColumnsFromTable(string $tableName, array<string|int, string> $columnNames) : mixed
Parameters
- $tableName : string
-
This is not escaped, so use only the result of
$this->getTableName()
! - $columnNames : array<string|int, string>
removeIndicesFromTable()
`dbDelta` does currently not support removing indices from tables so updating e.g. `UNIQUE KEYS` does not work.
public
removeIndicesFromTable(string $tableName, array<string|int, array<string|int, mixed>> $indexConfigurations) : mixed
For this, you need to add a new index name and remove the old one.
The index needs to be configured like this:
$indexConfigurations = [
'PRIMARY' = ['myColumn1', 'myColumn2']
]
Parameters
- $tableName : string
-
This is not escaped, so use only the result of
$this->getTableName()
! - $indexConfigurations : array<string|int, array<string|int, mixed>>
Tags
removePreviousPersistedVersions()
Remove the previous persisted versions from the saved option. This is useful if you have successfully finished your migration.
public
removePreviousPersistedVersions(callable $filter) : mixed
Parameters
- $filter : callable
removeTables()
Remove database tables if they exist.
public
removeTables(array<string|int, string> $tableNames) : mixed
Parameters
- $tableNames : array<string|int, string>
-
This is not escaped, so use only the result of
$this->getTableName()
!
supportsChildQuery()
Checks if the current database supports functions or recursive drill-down query.
public
supportsChildQuery([bool $force = false ][, string $type = 'legacy' ]) : bool
Parameters
- $force : bool = false
- $type : string = 'legacy'
-
Can be 'legacy' or 'function'.