diff --git a/core/includes/bootstrap.inc b/core/includes/bootstrap.inc index a2f97f6..abab495 100644 --- a/core/includes/bootstrap.inc +++ b/core/includes/bootstrap.inc @@ -190,7 +190,7 @@ /** * The maximum number of characters in a module or theme name. */ -const DRUPAL_EXTENSION_NAME_MAX_LENGTH = 40; +const DRUPAL_EXTENSION_NAME_MAX_LENGTH = 50; /** * Special system language code (only applicable to UI language). diff --git a/core/includes/module.inc b/core/includes/module.inc index d0af053..af8904b 100644 --- a/core/includes/module.inc +++ b/core/includes/module.inc @@ -8,6 +8,7 @@ use Drupal\Component\Utility\NestedArray; use Drupal\Core\Cache\CacheBackendInterface; use Drupal\Core\DependencyInjection\ContainerBuilder; +use Drupal\Core\Extension\ExtensionNameLengthException; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\Yaml\Parser; @@ -262,7 +263,7 @@ function module_enable($module_list, $enable_dependencies = TRUE) { } // Throw an exception if the module name is too long. if (strlen($module) > DRUPAL_EXTENSION_NAME_MAX_LENGTH) { - throw new \Exception(format_string('Module name %name is over the maximum allowed length of @max characters.', array( + throw new ExtensionNameLengthException(format_string('Module name %name is over the maximum allowed length of @max characters.', array( '%name' => $module, '@max' => DRUPAL_EXTENSION_NAME_MAX_LENGTH, ))); diff --git a/core/includes/theme.inc b/core/includes/theme.inc index 6266bfe..2a9e40c 100644 --- a/core/includes/theme.inc +++ b/core/includes/theme.inc @@ -10,9 +10,10 @@ use Drupal\Core\Cache\CacheBackendInterface; use Drupal\Core\Config\Config; +use Drupal\Core\Extension\ExtensionNameLengthException; use Drupal\Core\Template\Attribute; -use Drupal\Core\Utility\ThemeRegistry; use Drupal\Core\Theme\ThemeSettings; +use Drupal\Core\Utility\ThemeRegistry; /** * @defgroup content_flags Content markers @@ -1562,7 +1563,7 @@ function theme_enable($theme_list) { foreach ($theme_list as $key) { // Throw an exception if the theme name is too long. if (strlen($key) > DRUPAL_EXTENSION_NAME_MAX_LENGTH) { - throw new \Exception(format_string('Theme name %name is over the maximum allowed length of @max characters.', array( + throw new ExtensionNameLengthException(format_string('Theme name %name is over the maximum allowed length of @max characters.', array( '%name' => $key, '@max' => DRUPAL_EXTENSION_NAME_MAX_LENGTH, ))); diff --git a/core/modules/file/file.install b/core/modules/file/file.install index 8b60e4a..2db5c47 100644 --- a/core/modules/file/file.install +++ b/core/modules/file/file.install @@ -293,12 +293,14 @@ function file_update_8002() { * Convert the 'module' column in {file_usage} to the maximum shortname length. */ function file_update_8003() { - $spec = array( - 'description' => 'The name of the module that is using the file.', - 'type' => 'varchar', - 'length' => '40', - 'not null' => TRUE, - 'default' => '', - ); - db_change_field('file_usage', 'module', 'module', $spec); + if (db_field_exists('file_usage', 'module')) { + $spec = array( + 'description' => 'The name of the module that is using the file.', + 'type' => 'varchar', + 'length' => SYSTEM_UPDATE_8056_NAME_MAX_LENGTH, + 'not null' => TRUE, + 'default' => '', + ); + db_change_field('file_usage', 'module', 'module', $spec); + } } diff --git a/core/modules/node/node.install b/core/modules/node/node.install index 68dbd2c..9caf73e 100644 --- a/core/modules/node/node.install +++ b/core/modules/node/node.install @@ -320,7 +320,7 @@ function node_schema() { 'module' => array( 'description' => 'The module defining this node type.', 'type' => 'varchar', - 'length' => DRUPAL_EXTENSION_NAME_MAX_LENGTH, + 'length' => SYSTEM_UPDATE_8056_NAME_MAX_LENGTH, 'not null' => TRUE, ), 'description' => array( @@ -755,16 +755,17 @@ function node_update_8015() { * Convert the 'module' column in {node_type} to the maximum shortname length. */ function node_update_8016() { - $spec = array( - 'description' => 'The module defining this node type.', - 'type' => 'varchar', - 'length' => '40', - 'not null' => TRUE, - ); - db_change_field('node_type', 'module', 'module', $spec); + if (db_field_exists('node_type', 'module')) { + $spec = array( + 'description' => 'The module defining this node type.', + 'type' => 'varchar', + 'length' => SYSTEM_UPDATE_8056_NAME_MAX_LENGTH, + 'not null' => TRUE, + ); + db_change_field('node_type', 'module', 'module', $spec); + } } - /** * @} End of "addtogroup updates-7.x-to-8.x" * The next series of updates should start at 9000. diff --git a/core/modules/search/search.install b/core/modules/search/search.install index 83f5579..b4d879c 100644 --- a/core/modules/search/search.install +++ b/core/modules/search/search.install @@ -214,23 +214,3 @@ function search_update_8001() { )); db_add_primary_key('search_index', array('word', 'sid', 'langcode', 'type')); } - -/** - * Use max allowed module name size for type fields in {search_dataset}, - * {search_index} and {search_node_links}. - */ -function search_update_8002() { - $dataset_type_spec = array( - 'type' => 'varchar', - 'length' => 40, - 'not null' => TRUE, - 'description' => 'Type of item, e.g. node.', - ); - db_change_field('search_dataset', 'type', 'type', $dataset_type_spec); - - $dataset_type_spec['description'] = 'The {search_dataset}.type of the searchable item to which the word belongs.'; - db_change_field('search_index', 'type', 'type', $dataset_type_spec); - - $dataset_type_spec['description'] = 'The {search_dataset}.type of the searchable item containing the link to the node.'; - db_change_field('search_node_links', 'type', 'type', $dataset_type_spec); -} diff --git a/core/modules/system/lib/Drupal/system/Tests/Module/ModuleEnable.php b/core/modules/system/lib/Drupal/system/Tests/Module/ModuleEnable.php index 1b41d3e..97b4d03 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Module/ModuleEnable.php +++ b/core/modules/system/lib/Drupal/system/Tests/Module/ModuleEnable.php @@ -54,7 +54,7 @@ function testModuleNameLength() { module_enable(array($module_name)); $this->fail($message); } - catch (\Exception $e) { + catch (ExtensionNameLengthException $e) { $this->pass($message); } } diff --git a/core/modules/system/system.install b/core/modules/system/system.install index b2a211c..39931df 100644 --- a/core/modules/system/system.install +++ b/core/modules/system/system.install @@ -1230,6 +1230,13 @@ function system_update_last_removed() { */ /** + * The maximum number of characters in a module name for system_update_8056(). + * + * @see DRUPAL_EXTENSION_NAME_MAX_LENGTH + */ +const SYSTEM_UPDATE_8056_NAME_MAX_LENGTH = 50; + +/** * Move from the Garland theme. */ function system_update_8001() { @@ -1986,16 +1993,6 @@ function system_update_8048() { ), ); db_add_field('menu_links', 'uuid', $column, $keys); - - // Change the length of the 'module' column to 40. - $spec = array( - 'description' => 'The name of the module that generated this link.', - 'type' => 'varchar', - 'length' => '40', - 'not null' => TRUE, - 'default' => 'system', - ); - db_change_field('menu_links', 'module', 'module', $spec); } /** @@ -2152,6 +2149,23 @@ function system_update_8055() { } /** + * Change the length of the 'module' column to the maximum length. + */ +function system_update_8056() { + if (db_field_exists('menu_links', 'module')) { + $spec = array( + 'description' => 'The name of the module that generated this link.', + 'type' => 'varchar', + 'length' => SYSTEM_UPDATE_8056_NAME_MAX_LENGTH, + 'not null' => TRUE, + 'default' => 'system', + ); + db_change_field('menu_links', 'module', 'module', $spec); + } + +} + +/** * @} End of "defgroup updates-7.x-to-8.x". * The next series of updates should start at 9000. */ diff --git a/core/modules/user/user.install b/core/modules/user/user.install index 1adaaa7..bd43c40 100644 --- a/core/modules/user/user.install +++ b/core/modules/user/user.install @@ -1051,36 +1051,40 @@ function user_update_8017() { } /** - * Convert the 'module' column in {role_permission} and {users_data} and the - * 'theme' column in {users_data} to the maximum shortname length. + * Use the maximum allowed module name length in module name database fields. */ function user_update_8018() { + if (db_field_exists('role_permission', 'module')) { $spec = array( 'type' => 'varchar', - 'length' => DRUPAL_EXTENSION_NAME_MAX_LENGTH, + 'length' => SYSTEM_UPDATE_8056_NAME_MAX_LENGTH, 'not null' => TRUE, 'default' => '', 'description' => "The module declaring the permission.", ); db_change_field('role_permission', 'module', 'module', $spec); - $spec = array( - 'description' => 'The name of the module declaring the variable.', - 'type' => 'varchar', - 'length' => DRUPAL_EXTENSION_NAME_MAX_LENGTH, - 'not null' => TRUE, - 'default' => '', - ); - db_change_field('users_data', 'module', 'module', $spec); + if (db_field_exists('users_data', 'module')) { + $spec = array( + 'description' => 'The name of the module declaring the variable.', + 'type' => 'varchar', + 'length' => SYSTEM_UPDATE_8056_NAME_MAX_LENGTH, + 'not null' => TRUE, + 'default' => '', + ); + db_change_field('users_data', 'module', 'module', $spec); + } - $spec = array( - 'type' => 'varchar', - 'length' => DRUPAL_EXTENSION_NAME_MAX_LENGTH, - 'not null' => TRUE, - 'default' => '', - 'description' => "User's default theme.", - ); - db_change_field('users', 'theme', 'theme', $spec); + if (db_field_exists('users', 'theme')) { + $spec = array( + 'type' => 'varchar', + 'length' => SYSTEM_UPDATE_8056_NAME_MAX_LENGTH, + 'not null' => TRUE, + 'default' => '', + 'description' => "User's default theme.", + ); + db_change_field('users', 'theme', 'theme', $spec); + } } /**