Ejemplo n.º 1
0
 /**
  * Assert that none of the tables defined in a module's hook_schema() exist.
  *
  * @param $module
  *   The name of the module.
  */
 function assertModuleTablesDoNotExist($module)
 {
     $tables = array_keys(drupal_get_schema_unprocessed($module));
     $tables_exist = FALSE;
     foreach ($tables as $table) {
         if (db_table_exists($table)) {
             $tables_exist = TRUE;
         }
     }
     return $this->assertFalse($tables_exist, format_string('None of the database tables defined by the @module module exist.', array('@module' => $module)));
 }
Ejemplo n.º 2
0
/**
 * Perform Drupal 6.x to 7.x updates that are required for update.php
 * to function properly.
 *
 * This function runs when update.php is run the first time for 7.x,
 * even before updates are selected or performed. It is important
 * that if updates are not ultimately performed that no changes are
 * made which make it impossible to continue using the prior version.
 */
function update_fix_d7_requirements()
{
    $ret = array();
    // Rewrite the settings.php file if necessary.
    // @see update_prepare_d7_bootstrap().
    global $update_rewrite_settings, $db_url;
    if (!empty($update_rewrite_settings)) {
        $databases = update_parse_db_url($db_url);
        file_put_contents(conf_path() . '/settings.php', "\n" . '$databases = ' . var_export($databases, TRUE) . ';', FILE_APPEND);
    }
    if (drupal_get_installed_schema_version('system') < 7000 && !variable_get('update_d7_requirements', FALSE)) {
        // Add the cache_path table.
        $schema['cache_path'] = drupal_get_schema_unprocessed('system', 'cache');
        $schema['cache_path']['description'] = 'Cache table used for path alias lookups.';
        db_create_table($ret, 'cache_path', $schema['cache_path']);
        variable_set('update_d7_requirements', TRUE);
        // Add column for locale context.
        if (db_table_exists('locales_source')) {
            db_add_field($ret, 'locales_source', 'context', array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => '', 'description' => 'The context this string applies to.'));
        }
    }
    return $ret;
}
Ejemplo n.º 3
0
 /**
  * Installs a specific table from a module schema definition.
  *
  * @param string $module
  *   The name of the module that defines the table's schema.
  * @param string|array $tables
  *   The name or an array of the names of the tables to install.
  *
  * @throws \RuntimeException
  *   Thrown when $module is not enabled or when the table schema cannot be
  *   found in the module specified.
  */
 protected function installSchema($module, $tables)
 {
     // drupal_get_schema_unprocessed() is technically able to install a schema
     // of a non-enabled module, but its ability to load the module's .install
     // file depends on many other factors. To prevent differences in test
     // behavior and non-reproducible test failures, we only allow the schema of
     // explicitly loaded/enabled modules to be installed.
     if (!$this->container->get('module_handler')->moduleExists($module)) {
         throw new \RuntimeException(format_string("'@module' module is not enabled.", array('@module' => $module)));
     }
     $tables = (array) $tables;
     foreach ($tables as $table) {
         $schema = drupal_get_schema_unprocessed($module, $table);
         if (empty($schema)) {
             throw new \RuntimeException(format_string("Unknown '@table' table schema in '@module' module.", array('@module' => $module, '@table' => $table)));
         }
         $this->container->get('database')->schema()->createTable($table, $schema);
     }
     // We need to refresh the schema cache, as any call to drupal_get_schema()
     // would not know of/return the schema otherwise.
     // @todo Refactor Schema API to make this obsolete.
     drupal_get_schema(NULL, TRUE);
     $this->pass(format_string('Installed %module tables: %tables.', array('%tables' => '{' . implode('}, {', $tables) . '}', '%module' => $module)));
 }