2012-03-14 15:29:10 +00:00
< ? php
/**
* @ file
* Schema API handling functions .
*/
Issue #2124069 by voleger, andypost, martin107, damiankloip, cburschka, dawehner, kim.pepper, daffie, pcambra, ParisLiakos, Xano, longwave, MerryHamster, vacho, kostyashupenko, catch, alexpott, amateescu, Mile23, claudiu.cristea, larowlan, almaudoh, Berdir, zviryatko: Convert schema.inc to the update.update_hook_registry service (UpdateHookRegistry)
2021-06-23 15:55:26 +00:00
use Drupal\Core\Update\UpdateHookRegistry ;
2012-03-14 15:29:10 +00:00
/**
2012-05-17 12:58:49 +00:00
* @ addtogroup schemaapi
2012-03-14 15:29:10 +00:00
* @ {
*/
2012-10-09 20:32:40 +00:00
/**
* Indicates that a module has not been installed yet .
Issue #2124069 by voleger, andypost, martin107, damiankloip, cburschka, dawehner, kim.pepper, daffie, pcambra, ParisLiakos, Xano, longwave, MerryHamster, vacho, kostyashupenko, catch, alexpott, amateescu, Mile23, claudiu.cristea, larowlan, almaudoh, Berdir, zviryatko: Convert schema.inc to the update.update_hook_registry service (UpdateHookRegistry)
2021-06-23 15:55:26 +00:00
*
* @ deprecated in drupal : 9.3 . 0 and is removed from drupal : 10.0 . 0. Use
* \Drupal\Core\Update\UpdateHookRegistry :: SCHEMA_UNINSTALLED constant
* instead .
*
* @ see https :// www . drupal . org / node / 2444417
2012-10-09 20:32:40 +00:00
*/
Issue #2124069 by voleger, andypost, martin107, damiankloip, cburschka, dawehner, kim.pepper, daffie, pcambra, ParisLiakos, Xano, longwave, MerryHamster, vacho, kostyashupenko, catch, alexpott, amateescu, Mile23, claudiu.cristea, larowlan, almaudoh, Berdir, zviryatko: Convert schema.inc to the update.update_hook_registry service (UpdateHookRegistry)
2021-06-23 15:55:26 +00:00
const SCHEMA_UNINSTALLED = UpdateHookRegistry :: SCHEMA_UNINSTALLED ;
2012-10-09 20:32:40 +00:00
2012-03-14 15:29:10 +00:00
/**
* Returns an array of available schema versions for a module .
*
* @ param string $module
* A module name .
*
* @ return array | bool
2013-01-10 23:50:55 +00:00
* If the module has updates , an array of available updates sorted by
* version . Otherwise , FALSE .
Issue #2124069 by voleger, andypost, martin107, damiankloip, cburschka, dawehner, kim.pepper, daffie, pcambra, ParisLiakos, Xano, longwave, MerryHamster, vacho, kostyashupenko, catch, alexpott, amateescu, Mile23, claudiu.cristea, larowlan, almaudoh, Berdir, zviryatko: Convert schema.inc to the update.update_hook_registry service (UpdateHookRegistry)
2021-06-23 15:55:26 +00:00
*
* @ deprecated in drupal : 9.3 . 0 and is removed from drupal : 10.0 . 0.
* Use \Drupal\Core\Update\SchemaDataInterface :: getAvailableUpdates () instead .
*
* @ see https :// www . drupal . org / node / 2444417
* @ see \Drupal\Core\Update\UpdateHookRegistry :: getAvailableUpdates ()
2012-03-14 15:29:10 +00:00
*/
function drupal_get_schema_versions ( $module ) {
Issue #2124069 by voleger, andypost, martin107, damiankloip, cburschka, dawehner, kim.pepper, daffie, pcambra, ParisLiakos, Xano, longwave, MerryHamster, vacho, kostyashupenko, catch, alexpott, amateescu, Mile23, claudiu.cristea, larowlan, almaudoh, Berdir, zviryatko: Convert schema.inc to the update.update_hook_registry service (UpdateHookRegistry)
2021-06-23 15:55:26 +00:00
@ trigger_error ( 'drupal_get_schema_versions() is deprecated in drupal:9.3.0 and is removed from drupal:10.0.0. Use \Drupal\Core\Update\UpdateHookRegistry::getAvailableUpdates() instead. See https://www.drupal.org/node/2444417' , E_USER_DEPRECATED );
return \Drupal :: service ( 'update.update_hook_registry' ) -> getAvailableUpdates ( $module );
2012-03-14 15:29:10 +00:00
}
/**
* Returns the currently installed schema version for a module .
*
* @ param string $module
* A module name .
* @ param bool $reset
2012-10-09 20:32:40 +00:00
* Set to TRUE after installing or uninstalling an extension .
2012-03-14 15:29:10 +00:00
* @ param bool $array
* Set to TRUE if you want to get information about all modules in the
* system .
*
* @ return string | int
* The currently installed schema version , or SCHEMA_UNINSTALLED if the
* module is not installed .
Issue #2124069 by voleger, andypost, martin107, damiankloip, cburschka, dawehner, kim.pepper, daffie, pcambra, ParisLiakos, Xano, longwave, MerryHamster, vacho, kostyashupenko, catch, alexpott, amateescu, Mile23, claudiu.cristea, larowlan, almaudoh, Berdir, zviryatko: Convert schema.inc to the update.update_hook_registry service (UpdateHookRegistry)
2021-06-23 15:55:26 +00:00
*
* @ deprecated in drupal : 9.3 . 0 and is removed from drupal : 10.0 . 0.
* Use \Drupal\Core\Update\UpdateHookRegistry :: getInstalledVersion () or
* \Drupal\Core\Update\UpdateHookRegistry :: getAllInstalledVersions ()
* instead .
*
* @ see https :// www . drupal . org / node / 2444417
* @ see \Drupal\Core\Update\UpdateHookRegistry :: getInstalledVersion ()
2012-03-14 15:29:10 +00:00
*/
function drupal_get_installed_schema_version ( $module , $reset = FALSE , $array = FALSE ) {
Issue #2124069 by voleger, andypost, martin107, damiankloip, cburschka, dawehner, kim.pepper, daffie, pcambra, ParisLiakos, Xano, longwave, MerryHamster, vacho, kostyashupenko, catch, alexpott, amateescu, Mile23, claudiu.cristea, larowlan, almaudoh, Berdir, zviryatko: Convert schema.inc to the update.update_hook_registry service (UpdateHookRegistry)
2021-06-23 15:55:26 +00:00
@ trigger_error ( 'drupal_get_installed_schema_version() is deprecated in drupal:9.3.0 and is removed from drupal:10.0.0. Use \Drupal\Core\Update\UpdateHookRegistry::getInstalledVersion() or \Drupal\Core\Update\UpdateHookRegistry::getAllInstalledVersions() instead. See https://www.drupal.org/node/2444417' , E_USER_DEPRECATED );
/** @var \Drupal\Core\Update\UpdateHookRegistry $service */
$service = \Drupal :: service ( 'update.update_hook_registry' );
2012-03-14 15:29:10 +00:00
if ( $array ) {
Issue #2124069 by voleger, andypost, martin107, damiankloip, cburschka, dawehner, kim.pepper, daffie, pcambra, ParisLiakos, Xano, longwave, MerryHamster, vacho, kostyashupenko, catch, alexpott, amateescu, Mile23, claudiu.cristea, larowlan, almaudoh, Berdir, zviryatko: Convert schema.inc to the update.update_hook_registry service (UpdateHookRegistry)
2021-06-23 15:55:26 +00:00
return $service -> getAllInstalledVersions ();
2012-03-14 15:29:10 +00:00
}
Issue #2124069 by voleger, andypost, martin107, damiankloip, cburschka, dawehner, kim.pepper, daffie, pcambra, ParisLiakos, Xano, longwave, MerryHamster, vacho, kostyashupenko, catch, alexpott, amateescu, Mile23, claudiu.cristea, larowlan, almaudoh, Berdir, zviryatko: Convert schema.inc to the update.update_hook_registry service (UpdateHookRegistry)
2021-06-23 15:55:26 +00:00
return $service -> getInstalledVersion (( string ) $module );
2012-03-14 15:29:10 +00:00
}
/**
* Updates the installed version information for a module .
*
* @ param string $module
* A module name .
* @ param string $version
* The new schema version .
Issue #2124069 by voleger, andypost, martin107, damiankloip, cburschka, dawehner, kim.pepper, daffie, pcambra, ParisLiakos, Xano, longwave, MerryHamster, vacho, kostyashupenko, catch, alexpott, amateescu, Mile23, claudiu.cristea, larowlan, almaudoh, Berdir, zviryatko: Convert schema.inc to the update.update_hook_registry service (UpdateHookRegistry)
2021-06-23 15:55:26 +00:00
*
* @ deprecated in drupal : 9.3 . 0 and is removed from drupal : 10.0 . 0.
* Use \Drupal\Core\Update\UpdateHookRegistry :: setInstalledVersion ()
* instead .
*
* @ see https :// www . drupal . org / node / 2444417
* @ see \Drupal\Core\Update\UpdateHookRegistry :: setInstalledVersion ()
2012-03-14 15:29:10 +00:00
*/
function drupal_set_installed_schema_version ( $module , $version ) {
Issue #2124069 by voleger, andypost, martin107, damiankloip, cburschka, dawehner, kim.pepper, daffie, pcambra, ParisLiakos, Xano, longwave, MerryHamster, vacho, kostyashupenko, catch, alexpott, amateescu, Mile23, claudiu.cristea, larowlan, almaudoh, Berdir, zviryatko: Convert schema.inc to the update.update_hook_registry service (UpdateHookRegistry)
2021-06-23 15:55:26 +00:00
@ trigger_error ( 'drupal_set_installed_schema_version() is deprecated in drupal:9.3.0 and is removed from drupal:10.0.0. Use \Drupal\Core\Update\UpdateHookRegistry::setInstalledVersion() instead. See https://www.drupal.org/node/2444417' , E_USER_DEPRECATED );
\Drupal :: service ( 'update.update_hook_registry' ) -> setInstalledVersion ( $module , $version );
2012-03-14 15:29:10 +00:00
}
/**
* Creates all tables defined in a module ' s hook_schema () .
*
* @ param string $module
* The module for which the tables will be created .
Issue #2908886 by andypost, martin107, kim.pepper, daffie, aleevas, vacho, catch, longwave, alexpott, voleger, dww: Split off schema management out of schema.inc
2021-04-22 15:00:44 +00:00
*
* @ deprecated in drupal : 9.2 . 0 and is removed from drupal : 10.0 . 0. No direct
* replacement is provided .
*
* @ see https :// www . drupal . org / node / 2970993
* @ see \Drupal\Core\Extension\ModuleInstaller :: installSchema ()
2012-03-14 15:29:10 +00:00
*/
function drupal_install_schema ( $module ) {
Issue #2908886 by andypost, martin107, kim.pepper, daffie, aleevas, vacho, catch, longwave, alexpott, voleger, dww: Split off schema management out of schema.inc
2021-04-22 15:00:44 +00:00
@ trigger_error ( 'drupal_install_schema() is deprecated in drupal:9.2.0 and is removed from drupal:10.0.0. No direct replacement is provided. See https://www.drupal.org/node/2970993' , E_USER_DEPRECATED );
2015-06-13 20:22:27 +00:00
$schema = drupal_get_module_schema ( $module );
2012-03-14 15:29:10 +00:00
_drupal_schema_initialize ( $schema , $module , FALSE );
foreach ( $schema as $name => $table ) {
2017-04-18 12:14:45 +00:00
\Drupal :: database () -> schema () -> createTable ( $name , $table );
2012-03-14 15:29:10 +00:00
}
}
/**
* Removes all tables defined in a module ' s hook_schema () .
*
* @ param string $module
* The module for which the tables will be removed .
Issue #2908886 by andypost, martin107, kim.pepper, daffie, aleevas, vacho, catch, longwave, alexpott, voleger, dww: Split off schema management out of schema.inc
2021-04-22 15:00:44 +00:00
*
* @ deprecated in drupal : 9.2 . 0 and is removed from drupal : 10.0 . 0. No direct
* replacement is provided .
*
* @ see https :// www . drupal . org / node / 2970993
* @ see \Drupal\Core\Extension\ModuleInstaller :: uninstallSchema ()
2012-03-14 15:29:10 +00:00
*/
function drupal_uninstall_schema ( $module ) {
Issue #2908886 by andypost, martin107, kim.pepper, daffie, aleevas, vacho, catch, longwave, alexpott, voleger, dww: Split off schema management out of schema.inc
2021-04-22 15:00:44 +00:00
@ trigger_error ( 'drupal_uninstall_schema() is deprecated in drupal:9.2.0 and is removed from drupal:10.0.0. No direct replacement is provided. See https://www.drupal.org/node/2970993' , E_USER_DEPRECATED );
Issue #2848479 by voleger, yogeshmpawar, marvin_B8, gaurav.kapoor, hgunicamp, mondrake, daffie, alexpott, xjm, cilefen: Replace all calls to db_drop_table, which is deprecated
2018-07-24 13:57:22 +00:00
$tables = drupal_get_module_schema ( $module );
_drupal_schema_initialize ( $tables , $module , FALSE );
$schema = \Drupal :: database () -> schema ();
foreach ( $tables as $table ) {
Issue #2848817 by voleger, andypost, hgunicamp, JacobSanford, techtud, alexpott, vidhatanand, Sharique, JayKandari, kiamlaluno, cilefen, borisson_: Replace all calls to db_table_exists, which is deprecated
2018-08-06 09:41:05 +00:00
if ( $schema -> tableExists ( $table [ 'name' ])) {
Issue #2848479 by voleger, yogeshmpawar, marvin_B8, gaurav.kapoor, hgunicamp, mondrake, daffie, alexpott, xjm, cilefen: Replace all calls to db_drop_table, which is deprecated
2018-07-24 13:57:22 +00:00
$schema -> dropTable ( $table [ 'name' ]);
2012-03-14 15:29:10 +00:00
}
}
}
/**
2015-06-13 20:22:27 +00:00
* Returns a module ' s schema .
2012-03-14 15:29:10 +00:00
*
* This function can be used to retrieve a schema specification in
* hook_schema (), so it allows you to derive your tables from existing
* specifications .
*
* @ param string $module
* The module to which the table belongs .
* @ param string $table
* The name of the table . If not given , the module ' s complete schema
* is returned .
Issue #2908886 by andypost, martin107, kim.pepper, daffie, aleevas, vacho, catch, longwave, alexpott, voleger, dww: Split off schema management out of schema.inc
2021-04-22 15:00:44 +00:00
*
* @ deprecated in drupal : 9.2 . 0 and is removed from drupal : 10.0 . 0. No direct
* replacement is provided . Testing classes could use
* \Drupal\TestTools\Extension\SchemaInspector for introspection .
*
* @ see https :// www . drupal . org / node / 2970993
* @ see \Drupal\TestTools\Extension\SchemaInspector :: getTablesSpecification ()
2012-03-14 15:29:10 +00:00
*/
2015-06-13 20:22:27 +00:00
function drupal_get_module_schema ( $module , $table = NULL ) {
Issue #2908886 by andypost, martin107, kim.pepper, daffie, aleevas, vacho, catch, longwave, alexpott, voleger, dww: Split off schema management out of schema.inc
2021-04-22 15:00:44 +00:00
@ trigger_error ( 'drupal_get_module_schema() is deprecated in drupal:9.2.0 and is removed from drupal:10.0.0. No direct replacement is provided. Testing classes could use \Drupal\TestTools\Extension\SchemaInspector for introspection. See https://www.drupal.org/node/2970993' , E_USER_DEPRECATED );
2012-03-14 15:29:10 +00:00
// Load the .install file to get hook_schema.
module_load_install ( $module );
2014-02-15 10:06:58 +00:00
$schema = \Drupal :: moduleHandler () -> invoke ( $module , 'schema' );
2012-03-14 15:29:10 +00:00
2012-11-19 11:39:30 +00:00
if ( isset ( $table )) {
if ( isset ( $schema [ $table ])) {
return $schema [ $table ];
}
2017-03-04 01:20:24 +00:00
return [];
2012-03-14 15:29:10 +00:00
}
elseif ( ! empty ( $schema )) {
return $schema ;
}
2017-03-04 01:20:24 +00:00
return [];
2012-03-14 15:29:10 +00:00
}
/**
* Fills in required default values for table definitions from hook_schema () .
*
* @ param array $schema
* The schema definition array as it was returned by the module ' s
* hook_schema () .
* @ param string $module
* The module for which hook_schema () was invoked .
* @ param bool $remove_descriptions
* ( optional ) Whether to additionally remove 'description' keys of all tables
* and fields to improve performance of serialize () and unserialize () .
* Defaults to TRUE .
Issue #2908886 by andypost, martin107, kim.pepper, daffie, aleevas, vacho, catch, longwave, alexpott, voleger, dww: Split off schema management out of schema.inc
2021-04-22 15:00:44 +00:00
*
* @ deprecated in drupal : 9.2 . 0 and is removed from drupal : 10.0 . 0. No direct
* replacement is provided .
*
* @ see https :// www . drupal . org / node / 2970993
2012-03-14 15:29:10 +00:00
*/
function _drupal_schema_initialize ( & $schema , $module , $remove_descriptions = TRUE ) {
Issue #2908886 by andypost, martin107, kim.pepper, daffie, aleevas, vacho, catch, longwave, alexpott, voleger, dww: Split off schema management out of schema.inc
2021-04-22 15:00:44 +00:00
@ trigger_error ( '_drupal_schema_initialize() is deprecated in drupal:9.2.0 and is removed from drupal:10.0.0. No direct replacement is provided. See https://www.drupal.org/node/2970993' , E_USER_DEPRECATED );
2012-03-14 15:29:10 +00:00
// Set the name and module key for all tables.
foreach ( $schema as $name => & $table ) {
if ( empty ( $table [ 'module' ])) {
$table [ 'module' ] = $module ;
}
if ( ! isset ( $table [ 'name' ])) {
$table [ 'name' ] = $name ;
}
if ( $remove_descriptions ) {
unset ( $table [ 'description' ]);
foreach ( $table [ 'fields' ] as & $field ) {
unset ( $field [ 'description' ]);
}
}
}
}
/**
2012-05-17 12:58:49 +00:00
* @ } End of " addtogroup schemaapi " .
2012-03-14 15:29:10 +00:00
*/