コード例 #1
0
ファイル: MigrateFileTest.php プロジェクト: dev981/gaptest
 /**
  * Tests the Drupal 6 files to Drupal 8 migration.
  */
 public function testFiles()
 {
     /** @var \Drupal\file\FileInterface $file */
     $file = entity_load('file', 1);
     $this->assertIdentical('Image1.png', $file->getFilename());
     $this->assertIdentical('39325', $file->getSize());
     $this->assertIdentical('public://image-1.png', $file->getFileUri());
     $this->assertIdentical('image/png', $file->getMimeType());
     // It is pointless to run the second half from MigrateDrupal6Test.
     if (empty($this->standalone)) {
         return;
     }
     // Test that we can re-import and also test with file_directory_path set.
     db_truncate(entity_load('migration', 'd6_file')->getIdMap()->mapTableName())->execute();
     $migration = entity_load_unchanged('migration', 'd6_file');
     $dumps = array($this->getDumpDirectory() . '/Variable.php');
     $this->prepare($migration, $dumps);
     // Update the file_directory_path.
     Database::getConnection('default', 'migrate')->update('variable')->fields(array('value' => serialize('files/test')))->condition('name', 'file_directory_path')->execute();
     Database::getConnection('default', 'migrate')->update('variable')->fields(array('value' => serialize($this->getTempFilesDirectory())))->condition('name', 'file_directory_temp')->execute();
     $executable = new MigrateExecutable($migration, $this);
     $executable->import();
     $file = entity_load('file', 2);
     $this->assertIdentical('public://core/modules/simpletest/files/image-2.jpg', $file->getFileUri());
     // Ensure that a temporary file has been migrated.
     $file = entity_load('file', 6);
     $this->assertIdentical('temporary://' . static::getUniqueFilename(), $file->getFileUri());
 }
コード例 #2
0
ファイル: ApiProductCache.php プロジェクト: nevetS/flame
 public function clear($cid = NULL, $wildcard = FALSE)
 {
     if (empty($cid) || $wildcard && $cid == '*') {
         db_truncate('dc_api_product')->execute();
         return;
     }
     $org_op = $prod_op = '=';
     if ($wildcard) {
         if (strpos($cid, ':') !== FALSE) {
             list($orgName, $productName) = explode(':', $cid, 2);
         } else {
             $orgName = $cid;
             $productName = '*';
         }
         if (strpos($orgName, '*') !== FALSE) {
             $orgName = str_replace('*', '%', $orgName);
             $org_op = 'LIKE';
         }
         if (strpos($productName, '*') !== FALSE) {
             $productName = str_replace('*', '%', $productName);
             $prod_op = 'LIKE';
         }
     } else {
         list($orgName, $productName) = @explode(':', $cid, 2);
     }
     db_delete('dc_api_product')->condition('org_name', $orgName, $org_op)->condition('name', $productName, $prod_op)->execute();
 }
コード例 #3
0
 /**
  * Confirms that we can truncate a whole table successfully.
  */
 function testTruncate()
 {
     $num_records_before = db_query("SELECT COUNT(*) FROM {test}")->fetchField();
     $this->assertTrue($num_records_before > 0, 'The table is not empty.');
     db_truncate('test')->execute();
     $num_records_after = db_query("SELECT COUNT(*) FROM {test}")->fetchField();
     $this->assertEqual(0, $num_records_after, 'Truncate really deletes everything.');
 }
コード例 #4
0
ファイル: MigrateNodeTest.php プロジェクト: nsp15/Drupal8
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     /** @var \Drupal\migrate\entity\Migration $migration */
     $migration = entity_load('migration', 'd6_node');
     $executable = new MigrateExecutable($migration, $this);
     $executable->import();
     // This is required for the second import below.
     db_truncate($migration->getIdMap()->mapTableName())->execute();
     $this->standalone = TRUE;
 }
コード例 #5
0
 /**
  * Tests the Drupal 6 menu to Drupal 8 migration.
  */
 public function testMenu()
 {
     $navigation_menu = entity_load('menu', 'navigation');
     $this->assertEqual($navigation_menu->id(), 'navigation');
     $this->assertEqual($navigation_menu->label(), 'Navigation');
     $this->assertEqual($navigation_menu->description, 'The navigation menu is provided by Drupal and is the main interactive menu for any site. It is usually the only menu that contains personalized links for authenticated users, and is often not even visible to anonymous users.');
     // Test that we can re-import using the ConfigEntityBase destination.
     Database::getConnection('default', 'migrate')->update('menu_custom')->fields(array('title' => 'Home Navigation'))->condition('menu_name', 'navigation')->execute();
     db_truncate(entity_load('migration', 'd6_menu')->getIdMap()->mapTableName())->execute();
     $migration = entity_load_unchanged('migration', 'd6_menu');
     $executable = new MigrateExecutable($migration, $this);
     $executable->import();
     $navigation_menu = entity_load_unchanged('menu', 'navigation');
     $this->assertEqual($navigation_menu->label(), 'Home Navigation');
 }
コード例 #6
0
 protected function setUp()
 {
     parent::setUp();
     // Create Basic page node type.
     if ($this->profile != 'standard') {
         $this->drupalCreateContentType(array('type' => 'page', 'name' => 'Basic page'));
     }
     $this->authUser = $this->drupalCreateUser(array('access content', 'create page content', 'edit own page content'));
     // Ensure we have a node page to access.
     $this->node = $this->drupalCreateNode(array('title' => $this->randomMachineName(255), 'uid' => $this->authUser->id()));
     // Enable access logging.
     $this->config('statistics.settings')->set('count_content_views', 1)->save();
     // Clear the logs.
     db_truncate('node_counter');
     $this->client = \Drupal::service('http_client_factory')->fromOptions(['config/curl' => [CURLOPT_TIMEOUT => 10]]);
 }
コード例 #7
0
    /**
     * Tests the Drupal 6 menu to Drupal 8 migration.
     */
    public function testMenu()
    {
        $navigation_menu = Menu::load('navigation');
        $this->assertIdentical('navigation', $navigation_menu->id());
        $this->assertIdentical('Navigation', $navigation_menu->label());
        $expected = <<<EOT
The navigation menu is provided by Drupal and is the main interactive menu for any site. It is usually the only menu that contains personalized links for authenticated users, and is often not even visible to anonymous users.
EOT;
        $this->assertIdentical($expected, $navigation_menu->getDescription());
        // Test that we can re-import using the ConfigEntityBase destination.
        Database::getConnection('default', 'migrate')->update('menu_custom')->fields(array('title' => 'Home Navigation'))->condition('menu_name', 'navigation')->execute();
        $migration = Migration::load('menu');
        db_truncate($migration->getIdMap()->mapTableName())->execute();
        $this->executeMigration($migration);
        $navigation_menu = Menu::load('navigation');
        $this->assertIdentical('Home Navigation', $navigation_menu->label());
    }
コード例 #8
0
ファイル: MigrateDateFormatTest.php プロジェクト: scratch/gai
 /**
  * Tests the Drupal 6 date formats to Drupal 8 migration.
  */
 public function testDateFormats()
 {
     $short_date_format = entity_load('date_format', 'short');
     $this->assertIdentical('\\S\\H\\O\\R\\T m/d/Y - H:i', $short_date_format->getPattern());
     $medium_date_format = entity_load('date_format', 'medium');
     $this->assertIdentical('\\M\\E\\D\\I\\U\\M D, m/d/Y - H:i', $medium_date_format->getPattern());
     $long_date_format = entity_load('date_format', 'long');
     $this->assertIdentical('\\L\\O\\N\\G l, F j, Y - H:i', $long_date_format->getPattern());
     // Test that we can re-import using the EntityDateFormat destination.
     Database::getConnection('default', 'migrate')->update('variable')->fields(array('value' => serialize('\\S\\H\\O\\R\\T d/m/Y - H:i')))->condition('name', 'date_format_short')->execute();
     db_truncate(entity_load('migration', 'd6_date_formats')->getIdMap()->mapTableName())->execute();
     $migration = entity_load_unchanged('migration', 'd6_date_formats');
     $executable = new MigrateExecutable($migration, $this);
     $executable->import();
     $short_date_format = entity_load('date_format', 'short');
     $this->assertIdentical('\\S\\H\\O\\R\\T d/m/Y - H:i', $short_date_format->getPattern());
 }
コード例 #9
0
 /**
  * Tests the Drupal 6 files to Drupal 8 migration.
  */
 public function testFiles()
 {
     /** @var \Drupal\file\FileInterface $file */
     $file = entity_load('file', 1);
     $this->assertEqual($file->getFilename(), 'Image1.png');
     $this->assertEqual($file->getSize(), 39325);
     $this->assertEqual($file->getFileUri(), 'public://image-1.png');
     $this->assertEqual($file->getMimeType(), 'image/png');
     // It is pointless to run the second half from MigrateDrupal6Test.
     if (empty($this->standalone)) {
         return;
     }
     // Test that we can re-import and also test with file_directory_path set.
     db_truncate(entity_load('migration', 'd6_file')->getIdMap()->mapTableName())->execute();
     $migration = entity_load_unchanged('migration', 'd6_file');
     $dumps = array($this->getDumpDirectory() . '/Drupal6SystemFile.php');
     $this->loadDumps($dumps, 'loadMigrateFileStandalone');
     $executable = new MigrateExecutable($migration, $this);
     $executable->import();
     $file = entity_load('file', 2);
     $this->assertEqual($file->getFileUri(), 'public://core/modules/simpletest/files/image-2.jpg');
 }
コード例 #10
0
 protected function setUp()
 {
     parent::setUp();
     // Create Basic page node type.
     if ($this->profile != 'standard') {
         $this->drupalCreateContentType(array('type' => 'page', 'name' => 'Basic page'));
     }
     $this->authUser = $this->drupalCreateUser(array('access content', 'create page content', 'edit own page content', 'administer languages', 'access administration pages'));
     // Ensure we have a node page to access.
     $this->node = $this->drupalCreateNode(array('title' => $this->randomMachineName(255), 'uid' => $this->authUser->id()));
     // Add a custom language and enable path-based language negotiation.
     $this->drupalLogin($this->authUser);
     $this->language = array('predefined_langcode' => 'custom', 'langcode' => 'xx', 'label' => $this->randomMachineName(16), 'direction' => 'ltr');
     $this->drupalPostForm('admin/config/regional/language/add', $this->language, t('Add custom language'));
     $this->drupalPostForm('admin/config/regional/language/detection', array('language_interface[enabled][language-url]' => 1), t('Save settings'));
     $this->drupalLogout();
     // Enable access logging.
     $this->config('statistics.settings')->set('count_content_views', 1)->save();
     // Clear the logs.
     db_truncate('node_counter');
     $this->client = \Drupal::service('http_client_factory')->fromOptions(['config/curl' => [CURLOPT_TIMEOUT => 10]]);
 }
コード例 #11
0
 /**
  * Clears watchdog messages.
  */
 public function clearWatchdog()
 {
     db_truncate('watchdog')->execute();
 }
コード例 #12
0
 public static function disassociateAllNodes()
 {
     db_truncate('lingotek');
 }
コード例 #13
0
 /**
  * Saves the sitemap to the db.
  */
 private function save_sitemap()
 {
     db_truncate('simplesitemap')->execute();
     $values = array();
     foreach ($this->sitemap as $chunk_id => $chunk_data) {
         $values[] = array('id' => $chunk_id, 'sitemap_string' => $chunk_data->sitemap_string, 'sitemap_created' => $chunk_data->sitemap_created);
     }
     $query = db_insert('simplesitemap')->fields(array('id', 'sitemap_string', 'sitemap_created'));
     foreach ($values as $record) {
         $query->values($record);
     }
     $query->execute();
 }
コード例 #14
0
ファイル: LingotekSync.php プロジェクト: kweigand/cck
 public static function disassociateAllChunks()
 {
     db_truncate('{lingotek_config_metadata}')->execute();
 }
コード例 #15
0
 /**
  * Test threshold notify functionality.
  */
 public function testThresholdNotify()
 {
     // Set notify threshold to 5, and user locking to 5.
     \Drupal::configFactory()->getEditable('login_security.settings')->set('user_wrong_count', 5)->set('activity_threshold', 5)->save();
     // Attempt 10 bad logins. Since the user will be locked out after 5, only
     // a single log message should be set, and an attack should not be
     // detected.
     for ($i = 0; $i < 10; $i++) {
         $login = ['name' => $this->badUsers[0]->getUsername(), 'pass' => 'bad_password_' . $i];
         $this->drupalPostForm('user', $login, t('Log in'));
     }
     // Ensure a log message has been set.
     $logs = $this->getLogMessages();
     $this->assertEqual(count($logs), 1, '1 event was logged.');
     $log = array_pop($logs);
     $this->assertBlockedUser($log, $this->badUsers[0]->getUsername());
     db_truncate('watchdog')->execute();
     // Run failed logins as second user to trigger an attack warning.
     for ($i = 0; $i < 10; $i++) {
         $login = ['name' => $this->badUsers[1]->getUsername(), 'pass' => 'bad_password_' . $i];
         $this->drupalPostForm('user', $login, t('Log in'));
     }
     $logs = $this->getLogMessages();
     // 2 logs should be generated.
     $this->assertEqual(count($logs), 2, '2 events were logged.');
     // First log should be the ongoing attack, triggered on attempt after the
     // threshold.
     $log = array_shift($logs);
     $variables = ['@activity_threshold' => 5, '@tracking_current_count' => 6];
     $expected = SafeMarkup::format('Ongoing attack detected: Suspicious activity detected in login form submissions. Too many invalid login attempts threshold reached: currently @tracking_current_count events are tracked, and threshold is configured for @activity_threshold attempts.', $variables);
     $this->assertEqual(SafeMarkup::format($log->message, unserialize($log->variables)), $expected);
     $this->assertEqual($log->severity, RfcLogLevel::WARNING, 'The logged alert was of severity "Warning".');
     // Second log should be a blocked user.
     $log = array_shift($logs);
     $this->assertBlockedUser($log, $this->badUsers[1]->getUsername());
 }
コード例 #16
0
 /**
  * Truncate the watchdog table so we can check for errors later.
  *
  * @BeforeSuite
  */
 public static function prepare($event)
 {
     db_truncate('watchdog')->execute();
 }
コード例 #17
0
 /**
  * Prepare for PHP errors log.
  *
  * @BeforeScenario
  */
 public static function preparePhpErrors(BeforeScenarioScope $scope)
 {
     // Clear out the watchdog table at the beginning of each test scenario.
     db_truncate('watchdog')->execute();
 }
コード例 #18
0
 public static function run()
 {
     if (PHP_SAPI !== 'cli') {
         return;
     }
     ini_set('max_execution_time', 60 * 60);
     ini_set('memory_limit', '2G');
     // Get list of common tables.
     // Check if the "old" database connection is properly defined during the
     // first switch.
     if (db_set_active('old') === NULL) {
         print "ERROR: the 'old' database connection is not defined!\n";
         return;
     }
     $tables_old = db_query('SHOW TABLES')->fetchCol();
     db_set_active();
     $tables_new = db_query('SHOW TABLES')->fetchCol();
     $tables_common = array_intersect($tables_old, $tables_new);
     // This is what we want to migrate. The array values are table names or
     // table name prefixes.
     $base_tables_to_migrate = ['block', 'comment', 'file', 'node', 'taxonomy', 'url', 'user', 'users'];
     $tables_to_migrate = [];
     foreach ($tables_common as $table_name) {
         foreach ($base_tables_to_migrate as $base_table_name) {
             if ($table_name == $base_table_name || strpos($table_name, $base_table_name . '_') === 0) {
                 $tables_to_migrate[] = $table_name;
                 break;
             }
         }
     }
     // Migrate common data.
     foreach ($tables_to_migrate as $table) {
         // Get column info.
         db_set_active('old');
         $columns_old = db_query('SHOW COLUMNS FROM ' . $table)->fetchCol();
         db_set_active();
         $columns_new = db_query('SHOW COLUMNS FROM ' . $table)->fetchCol();
         $exists_only_in_old_db = array_diff($columns_old, $columns_new);
         $exists_only_in_new_db = array_diff($columns_new, $columns_old);
         // Get rows.
         db_set_active('old');
         $rows = db_select($table, 't')->fields('t')->execute()->fetchAll(PDO::FETCH_ASSOC);
         // Prepare table.
         db_set_active();
         db_truncate($table)->execute();
         $table_status = db_query("SHOW TABLE STATUS LIKE '{$table}'")->fetch();
         if (isset($table_status->Auto_increment)) {
             db_query("ALTER TABLE `{$table}` AUTO_INCREMENT = 1");
         }
         // Copy rows.
         foreach ($rows as $row) {
             // Modify row data if required.
             // CASE: some columns were removed in new scheme.
             if (!empty($exists_only_in_old_db) && empty($exists_only_in_new_db)) {
                 foreach ($exists_only_in_old_db as $column) {
                     unset($row[$column]);
                 }
             } elseif (empty($exists_only_in_old_db) && count($exists_only_in_new_db) == 1 && reset($exists_only_in_new_db) == 'langcode') {
                 $row['langcode'] = 'en';
             } elseif (preg_match('/^.*__field_link$/', $table)) {
                 unset($row['field_link_route_name']);
                 unset($row['field_link_route_parameters']);
                 $row['field_link_uri'] = 'internal:/' . $row['field_link_url'];
                 unset($row['field_link_url']);
             } elseif ($table == 'taxonomy_index') {
                 $langcode = db_select('node', 'n')->fields('n', ['langcode'])->condition('n.nid', $row['nid'])->execute()->fetchField();
                 $row['status'] = db_select('node_field_data', 'nfd')->fields('nfd', ['status'])->condition('nfd.nid', $row['nid'])->condition('nfd.langcode', $langcode)->execute()->fetchField();
             }
             // Insert.
             db_insert($table)->fields($row)->execute();
         }
         echo "Migrated {$table} table.\n";
     }
     // Migrate user roles.
     db_set_active('old');
     $rows = db_select('users_roles', 'ur')->fields('ur')->execute()->fetchAll(PDO::FETCH_ASSOC);
     db_set_active();
     db_truncate('user__roles')->execute();
     foreach ($rows as $row) {
         $row = ['bundle' => 'user', 'deleted' => 0, 'entity_id' => $row['uid'], 'revision_id' => $row['uid'], 'langcode' => 'en', 'delta' => 0, 'roles_target_id' => $row['rid']];
         db_insert('user__roles')->fields($row)->execute();
     }
     echo "Migrated user roles.\n";
     echo "Rebuilding caches...\n";
     drupal_flush_all_caches();
     echo "DONE!\n";
 }
コード例 #19
0
ファイル: TransactionTest.php プロジェクト: aWEBoLabs/taxi
 /**
  * Starts over for a new test.
  */
 protected function cleanUp()
 {
     db_truncate('test')->execute();
 }
コード例 #20
0
        FROM {#mediafile}
        where #mediafile_id = :mediafile_id', array('#mediafile' => mediamosa_asset_mediafile_db::TABLE_NAME, '#mediafile_id' => mediamosa_asset_mediafile_db::ID, ':mediafile_id' => $file));
            if ($result->fetchField() == 0) {
                // Collect the data.
                $file_path = $dir . DIRECTORY_SEPARATOR . $folder . DIRECTORY_SEPARATOR . $file;
                $finfo = stat($file_path);
                $more_info = exec('ls -sla ' . $file_path);
                // Make error message.
                mediamosa_db::db_query('
          INSERT INTO {#mediamosa_integrity_check}
            (#type, #object_id, #size, #mtime, #ctime, #details, #created) VALUES
            (:missing_mediarecord, :object_id, :size, :mtime, :ctime, :details, UTC_TIMESTAMP())', array('#mediamosa_integrity_check' => mediamosa_integrity_check_db::TABLE_NAME, '#type' => mediamosa_integrity_check_db::TYPE, '#object_id' => mediamosa_integrity_check_db::OBJECT_ID, '#size' => mediamosa_integrity_check_db::SIZE, '#mtime' => mediamosa_integrity_check_db::MTIME, '#ctime' => mediamosa_integrity_check_db::CTIME, '#details' => mediamosa_integrity_check_db::DETAILS, '#created' => mediamosa_integrity_check_db::CREATED, ':missing_mediarecord' => mediamosa_integrity_check_db::TYPE_MISSING_STILLRECORD, ':object_id' => $file, ':size' => $finfo['size'], ':mtime' => $finfo['mtime'], ':ctime' => $finfo['ctime'], ':details' => $more_info));
            }
        }
        closedir($fh);
    }
    closedir($dh);
}
// Start.
watchdog('integrity_check', 'running...');
variable_set('mediamosa_integrity_run_date_start', date('c'));
// Empty log table.
db_truncate('mediamosa_integrity_check');
// Run checks.
check_media_records();
check_media_files();
check_still_records();
check_still_files();
// End.
variable_set('mediamosa_integrity_run_date_end', date('c'));
watchdog('integrity_check', 'ended...');
コード例 #21
0
 /**
  * Removes all the cache fragments.
  */
 public function wipe()
 {
     // We are not truncating the entity table so hooks are fired.
     $query = new \EntityFieldQuery();
     $results = $query->entityCondition('entity_type', static::ENTITY_TYPE)->execute();
     if (empty($results[static::ENTITY_TYPE])) {
         return;
     }
     if ($this->isFastDeleteEnabled()) {
         db_truncate($this::getTableName())->execute();
         return;
     }
     $this->delete(array_keys($results[static::ENTITY_TYPE]));
 }
コード例 #22
0
 /**
  * Asserts that a field can be changed from one spec to another.
  *
  * @param $old_spec
  *   The beginning field specification.
  * @param $new_spec
  *   The ending field specification.
  */
 protected function assertFieldChange($old_spec, $new_spec)
 {
     $table_name = 'test_table_' . $this->counter++;
     $table_spec = array('fields' => array('serial_column' => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE), 'test_field' => $old_spec), 'primary key' => array('serial_column'));
     db_create_table($table_name, $table_spec);
     $this->pass(format_string('Table %table created.', array('%table' => $table_name)));
     // Check the characteristics of the field.
     $this->assertFieldCharacteristics($table_name, 'test_field', $old_spec);
     // Remove inserted rows.
     db_truncate($table_name)->execute();
     // Change the field.
     db_change_field($table_name, 'test_field', 'test_field', $new_spec);
     // Check the field was changed.
     $this->assertFieldCharacteristics($table_name, 'test_field', $new_spec);
     // Clean-up.
     db_drop_table($table_name);
 }
コード例 #23
0
 public static function disassociateAllSets()
 {
     db_truncate('lingotek_config_metadata')->execute();
 }
コード例 #24
0
ファイル: import.php プロジェクト: bartcornelis/comfortenergy
<?php

# dbext:profile=pluto_comfort_energy_be
###########################################
# Run like this:
#
#    drush php-script ./import.php
#
###########################################
set_include_path(get_include_path() . PATH_SEPARATOR . __DIR__ . '/PHPExcel/Classes/');
include 'PHPExcel/IOFactory.php';
# truncate the telephone table
$result = db_truncate('b50_telephone')->execute();
# insert the records
$records = excel_records();
foreach ($records as $record) {
    $record['updated'] = strftime('%F %T', time());
    print_r($record);
    $id = db_insert('b50_telephone')->fields($record)->execute();
}
function excel_records()
{
    $records = array();
    $input_file = __DIR__ . '/dispatchregio-voor-mazoutprijzen.xlsx';
    $excel = PHPExcel_IOFactory::load($input_file);
    $data = $excel->getActiveSheet()->toArray(null, true, true, true);
    $headers = array_shift($data);
    $headers = array_values($headers);
    foreach ($data as $record) {
        $records[] = array_combine($headers, array_values($record));
    }
コード例 #25
0
function update_users()
{
    db_set_active('alpha');
    // We do not need to import the user pictures.
    $users = db_select('users', 'u')->fields('u')->execute()->fetchAllAssoc('uid');
    $users_data = db_select('users_data', 'ud')->fields('ud')->execute()->fetchAll();
    $users_roles = db_select('users_roles', 'ur')->fields('ur')->execute()->fetchAll();
    db_set_active();
    db_truncate('users')->execute();
    db_truncate('users_data')->execute();
    db_truncate('users_field_data')->execute();
    db_truncate('users_roles')->execute();
    $query = db_insert('users')->fields(array('uid', 'uuid', 'langcode'));
    foreach ($users as $entry) {
        $query->values(array($entry->uid, $entry->uuid, $entry->langcode));
    }
    $query->execute();
    $query = db_insert('users_data')->fields(array('uid', 'module', 'name', 'value', 'serialized'));
    foreach ($users_data as $entry) {
        $query->values(array($entry->uid, $entry->module, $entry->name, $entry->value, $entry->serialized));
    }
    $query->execute();
    $query = db_insert('users_field_data')->fields(array('uid', 'langcode', 'preferred_langcode', 'preferred_admin_langcode', 'name', 'pass', 'mail', 'signature', 'signature_format', 'timezone', 'status', 'created', 'changed', 'access', 'login', 'init', 'default_langcode'));
    foreach ($users as $entry) {
        // We will use the created value for the changed, because we do not have one.
        $query->values(array($entry->uid, $entry->langcode, $entry->preferred_langcode, $entry->preferred_admin_langcode, $entry->name, $entry->pass, $entry->mail, $entry->signature, $entry->signature_format, $entry->timezone, $entry->status, $entry->created, $entry->created, $entry->access, $entry->login, $entry->init, 1));
    }
    $query->execute();
    $query = db_insert('users_roles')->fields(array('uid', 'rid'));
    foreach ($users_roles as $entry) {
        $query->values(array($entry->uid, $entry->rid));
    }
    $query->execute();
    echo "The users have been updated.\n";
}
コード例 #26
0
ファイル: SchemaTest.php プロジェクト: isramv/camp-gdl
 /**
  * Asserts that a field can be changed from one spec to another.
  *
  * @param $old_spec
  *   The beginning field specification.
  * @param $new_spec
  *   The ending field specification.
  */
 protected function assertFieldChange($old_spec, $new_spec, $test_data = NULL)
 {
     $table_name = 'test_table_' . $this->counter++;
     $table_spec = array('fields' => array('serial_column' => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE), 'test_field' => $old_spec), 'primary key' => array('serial_column'));
     db_create_table($table_name, $table_spec);
     $this->pass(format_string('Table %table created.', array('%table' => $table_name)));
     // Check the characteristics of the field.
     $this->assertFieldCharacteristics($table_name, 'test_field', $old_spec);
     // Remove inserted rows.
     db_truncate($table_name)->execute();
     if ($test_data) {
         $id = db_insert($table_name)->fields(['test_field'], [$test_data])->execute();
     }
     // Change the field.
     db_change_field($table_name, 'test_field', 'test_field', $new_spec);
     if ($test_data) {
         $field_value = db_select($table_name)->fields($table_name, ['test_field'])->condition('serial_column', $id)->execute()->fetchField();
         $this->assertIdentical($field_value, $test_data);
     }
     // Check the field was changed.
     $this->assertFieldCharacteristics($table_name, 'test_field', $new_spec);
     // Clean-up.
     db_drop_table($table_name);
 }
コード例 #27
0
 public static function migrateLocaleStrings()
 {
     echo "Migrating locale strings...\n";
     // locales_source => locales_source
     db_set_active('old');
     $rows = db_select('locales_source', 'ls')->fields('ls')->execute()->fetchAll();
     db_set_active();
     db_truncate('locales_source')->execute();
     db_query('ALTER TABLE locales_source AUTO_INCREMENT=1');
     $query = db_insert('locales_source')->fields(['lid', 'source', 'context', 'version']);
     foreach ($rows as $row) {
         $query->values([$row->lid, $row->source, $row->context, '8.0.0-dev']);
     }
     $query->execute();
     // locales_source => locales_source
     db_set_active('old');
     $rows = db_select('locales_target', 'lt')->fields('lt')->execute()->fetchAll();
     db_set_active();
     db_truncate('locales_target')->execute();
     $query = db_insert('locales_target')->fields(['lid', 'translation', 'language', 'customized']);
     foreach ($rows as $row) {
         $query->values([$row->lid, $row->translation, $row->language, $row->customized]);
     }
     $query->execute();
     echo "Migrated locale strings.\n";
 }