本文整理汇总了PHP中db_truncate函数的典型用法代码示例。如果您正苦于以下问题:PHP db_truncate函数的具体用法?PHP db_truncate怎么用?PHP db_truncate使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了db_truncate函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testFiles
/**
* 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: clear
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: testTruncate
/**
* 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: setUp
/**
* {@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: testMenu
/**
* 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: setUp
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: testMenu
/**
* 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: testDateFormats
/**
* 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: testFiles
/**
* 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: setUp
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: clearWatchdog
/**
* Clears watchdog messages.
*/
public function clearWatchdog()
{
db_truncate('watchdog')->execute();
}
示例12: disassociateAllNodes
public static function disassociateAllNodes()
{
db_truncate('lingotek');
}
示例13: save_sitemap
/**
* 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: disassociateAllChunks
public static function disassociateAllChunks()
{
db_truncate('{lingotek_config_metadata}')->execute();
}
示例15: testThresholdNotify
/**
* 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());
}