当前位置: 首页>>代码示例>>PHP>>正文


PHP Connection::schema方法代码示例

本文整理汇总了PHP中Drupal\Core\Database\Connection::schema方法的典型用法代码示例。如果您正苦于以下问题:PHP Connection::schema方法的具体用法?PHP Connection::schema怎么用?PHP Connection::schema使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Drupal\Core\Database\Connection的用法示例。


在下文中一共展示了Connection::schema方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: execute

 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $io = new DrupalStyle($input, $output);
     $uid = $input->getArgument('user');
     $user = User::load($uid);
     if (!$user) {
         $io->error(sprintf($this->trans('commands.user.password.reset.errors.invalid-user'), $uid));
         return 1;
     }
     $password = $input->getArgument('password');
     if (!$password) {
         $io->error(sprintf($this->trans('commands.user.password.reset.errors.empty-password'), $uid));
         return 1;
     }
     try {
         $user->setPassword($password);
         $user->save();
         $schema = $this->database->schema();
         $flood = $schema->findTables('flood');
         if ($flood) {
             $this - $this->chainQueue->addCommand('user:login:clear:attempts', ['uid' => $uid]);
         }
     } catch (\Exception $e) {
         $io->error($e->getMessage());
         return 1;
     }
     $io->success(sprintf($this->trans('commands.user.password.reset.messages.reset-successful'), $uid));
 }
开发者ID:ibonelli,项目名称:DrupalConsole,代码行数:31,代码来源:PasswordResetCommand.php

示例2: testEntitySchemaUpdate

 /**
  * Tests that entity schema responds to changes in the entity type definition.
  */
 public function testEntitySchemaUpdate()
 {
     $this->installModule('entity_schema_test');
     $storage_definitions = $this->entityManager->getFieldStorageDefinitions('entity_test');
     $this->entityManager->onFieldStorageDefinitionCreate($storage_definitions['custom_base_field']);
     $this->entityManager->onFieldStorageDefinitionCreate($storage_definitions['custom_bundle_field']);
     $schema_handler = $this->database->schema();
     $tables = array('entity_test', 'entity_test_revision', 'entity_test_field_data', 'entity_test_field_revision');
     $dedicated_tables = array('entity_test__custom_bundle_field', 'entity_test_revision__custom_bundle_field');
     // Initially only the base table and the dedicated field data table should
     // exist.
     foreach ($tables as $index => $table) {
         $this->assertEqual($schema_handler->tableExists($table), !$index, SafeMarkup::format('Entity schema correct for the @table table.', array('@table' => $table)));
     }
     $this->assertTrue($schema_handler->tableExists($dedicated_tables[0]), SafeMarkup::format('Field schema correct for the @table table.', array('@table' => $table)));
     // Update the entity type definition and check that the entity schema now
     // supports translations and revisions.
     $this->updateEntityType(TRUE);
     foreach ($tables as $table) {
         $this->assertTrue($schema_handler->tableExists($table), SafeMarkup::format('Entity schema correct for the @table table.', array('@table' => $table)));
     }
     foreach ($dedicated_tables as $table) {
         $this->assertTrue($schema_handler->tableExists($table), SafeMarkup::format('Field schema correct for the @table table.', array('@table' => $table)));
     }
     // Revert changes and check that the entity schema now does not support
     // neither translations nor revisions.
     $this->updateEntityType(FALSE);
     foreach ($tables as $index => $table) {
         $this->assertEqual($schema_handler->tableExists($table), !$index, SafeMarkup::format('Entity schema correct for the @table table.', array('@table' => $table)));
     }
     $this->assertTrue($schema_handler->tableExists($dedicated_tables[0]), SafeMarkup::format('Field schema correct for the @table table.', array('@table' => $table)));
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:35,代码来源:EntitySchemaTest.php

示例3: createTable

 /**
  * Create a new table from a Drupal table definition if it doesn't exist.
  *
  * @param string $name
  *   The name of the table to create.
  * @param array $table
  *   A Schema API table definition array.
  */
 protected function createTable($name, array $table)
 {
     // This must be on the database connection to be shared among classes.
     if (empty($this->database->migrateTables[$name])) {
         $this->database->migrateTables[$name] = TRUE;
         $this->database->schema()->createTable($name, $table);
     }
 }
开发者ID:dev981,项目名称:gaptest,代码行数:16,代码来源:DrupalDumpBase.php

示例4: createTable

 /**
  * Create a new table from a Drupal table definition if it doesn't exist.
  *
  * @param $name
  *   The name of the table to create.
  * @param $table
  *   A Schema API table definition array.
  */
 protected function createTable($name, $table = NULL)
 {
     // This must be on the database connection to be shared among classes.
     if (empty($this->database->migrateTables[$name])) {
         $this->database->migrateTables[$name] = TRUE;
         $this->database->schema()->createTable($name, $table ?: $this->tableDefinitions()[$name]);
     }
 }
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:16,代码来源:Drupal6DumpBase.php

示例5: doTestTable

 /**
  * Ensures that table gets created on the fly.
  */
 protected function doTestTable()
 {
     // Test that we can create a tree storage with an arbitrary table name and
     // that selecting from the storage creates the table.
     $tree_storage = new MenuTreeStorage($this->container->get('database'), $this->container->get('cache.menu'), $this->container->get('cache_tags.invalidator'), 'test_menu_tree');
     $this->assertFalse($this->connection->schema()->tableExists('test_menu_tree'), 'Test table is not yet created');
     $tree_storage->countMenuLinks();
     $this->assertTrue($this->connection->schema()->tableExists('test_menu_tree'), 'Test table was created');
 }
开发者ID:ddrozdik,项目名称:dmaps,代码行数:12,代码来源:MenuTreeStorageTest.php

示例6: testCustomBundleFieldCreateDelete

 /**
  * Tests the custom bundle field creation and deletion.
  */
 public function testCustomBundleFieldCreateDelete()
 {
     // Install the module which adds the field.
     $this->moduleHandler->install(array('entity_bundle_field_test'), FALSE);
     $definition = $this->entityManager->getFieldDefinitions('entity_test', 'custom')['custom_field'];
     $this->assertNotNull($definition, 'Field definition found.');
     // Make sure the table has been created.
     $table = $this->entityManager->getStorage('entity_test')->_fieldTableName($definition);
     $this->assertTrue($this->database->schema()->tableExists($table), 'Table created');
     $this->moduleHandler->uninstall(array('entity_bundle_field_test'), FALSE);
     $this->assertFalse($this->database->schema()->tableExists($table), 'Table dropped');
 }
开发者ID:anatalsceo,项目名称:en-classe,代码行数:15,代码来源:EntityBundleFieldTest.php

示例7: ensureTableExists

 /**
  * Checks if the table exists and create it if not.
  *
  * @return bool
  *   TRUE if the table was created, FALSE otherwise.
  */
 protected function ensureTableExists()
 {
     try {
         if (!$this->connection->schema()->tableExists($this->tableName)) {
             $this->connection->schema()->createTable($this->tableName, $this->schemaDefinition());
             return TRUE;
         }
     } catch (SchemaObjectExistsException $e) {
         // If another process has already created the table, attempting to
         // recreate it will throw an exception. In this case just catch the
         // exception and do nothing.
         return TRUE;
     }
     return FALSE;
 }
开发者ID:eigentor,项目名称:tommiblog,代码行数:21,代码来源:RevisionTracker.php

示例8: execute

 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $io = new DrupalStyle($input, $output);
     $uid = $input->getArgument('uid');
     $account = User::load($uid);
     if (!$account) {
         // Error loading User entity.
         $io->error(sprintf($this->trans('commands.user.login.clear.attempts.errors.invalid-user'), $uid));
         return 1;
     }
     // Define event name and identifier.
     $event = 'user.failed_login_user';
     // Identifier is created by uid and IP address,
     // Then we defined a generic identifier.
     $identifier = "{$account->id()}-";
     // Retrieve current database connection.
     $schema = $this->database->schema();
     $flood = $schema->findTables('flood');
     if (!$flood) {
         $io->error($this->trans('commands.user.login.clear.attempts.errors.no-flood'));
         return 1;
     }
     // Clear login attempts.
     $this->database->delete('flood')->condition('event', $event)->condition('identifier', $this->database->escapeLike($identifier) . '%', 'LIKE')->execute();
     // Command executed successful.
     $io->success(sprintf($this->trans('commands.user.login.clear.attempts.messages.successful'), $uid));
 }
开发者ID:ibonelli,项目名称:DrupalConsole,代码行数:30,代码来源:LoginCleanAttemptsCommand.php

示例9: removeIndex

 /**
  * {@inheritdoc}
  */
 public function removeIndex($index)
 {
     if (!is_object($index)) {
         // If the index got deleted, create a dummy to simplify the code. Since we
         // can't know, we assume the index was read-only, just to be on the safe
         // side.
         $index = Index::create(array('id' => $index, 'read_only' => TRUE));
     }
     try {
         if (!isset($this->configuration['field_tables'][$index->id()]) && !isset($this->configuration['index_tables'][$index->id()])) {
             return;
         }
         // Don't delete the index data of read-only indexes.
         if (!$index->isReadOnly()) {
             foreach ($this->configuration['field_tables'][$index->id()] as $field) {
                 if ($this->database->schema()->tableExists($field['table'])) {
                     $this->database->schema()->dropTable($field['table']);
                 }
             }
             if ($this->database->schema()->tableExists($this->configuration['index_tables'][$index->id()])) {
                 $this->database->schema()->dropTable($this->configuration['index_tables'][$index->id()]);
             }
         }
         unset($this->configuration['field_tables'][$index->id()]);
         unset($this->configuration['index_tables'][$index->id()]);
         $this->server->save();
     } catch (\Exception $e) {
         throw new SearchApiException($e->getMessage(), $e->getCode(), $e);
     }
 }
开发者ID:alexku,项目名称:travisintegrationtest,代码行数:33,代码来源:Database.php

示例10: dropTables

 /**
  * Drop the tables used for the sample data.
  *
  * @param \Drupal\Core\Database\Connection $connection
  *   The connection to use to drop the tables.
  */
 public function dropTables(Connection $connection)
 {
     $tables = $this->routingTableDefinition();
     $schema = $connection->schema();
     foreach ($tables as $name => $table) {
         $schema->dropTable($name);
     }
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:14,代码来源:RoutingFixtures.php

示例11: testEntityIndexCreateWithData

 /**
  * Tests creating a multi-field index when there are existing entities.
  */
 public function testEntityIndexCreateWithData()
 {
     // Save an entity.
     $name = $this->randomString();
     $entity = $this->entityManager->getStorage('entity_test_update')->create(array('name' => $name));
     $entity->save();
     // Add an entity index, run the update. Ensure that the index is created
     // despite having data.
     $this->addEntityIndex();
     $this->entityDefinitionUpdateManager->applyUpdates();
     $this->assertTrue($this->database->schema()->indexExists('entity_test_update', 'entity_test_update__new_index'), 'Index added.');
 }
开发者ID:nstielau,项目名称:drops-8,代码行数:15,代码来源:EntityDefinitionUpdateTest.php

示例12: fieldSizeMap

 /**
  * Given a database field type, return a Drupal size.
  *
  * @param string $type
  *   The MySQL field type.
  *
  * @return string
  *   The Drupal schema field size.
  */
 protected function fieldSizeMap($type)
 {
     // Convert everything to lowercase.
     $map = array_map('strtolower', $this->connection->schema()->getFieldTypeMap());
     $map = array_flip($map);
     $schema_type = explode(':', $map[$type])[0];
     // Only specify size on these types.
     if (in_array($schema_type, ['blob', 'float', 'int', 'text'])) {
         // The MySql map contains type:size. Remove the type part.
         return explode(':', $map[$type])[1];
     }
 }
开发者ID:jeyram,项目名称:camp-gdl,代码行数:21,代码来源:DbDumpCommand.php

示例13: execute

 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $io = new DrupalStyle($input, $output);
     $database = $input->getOption('database');
     $table = $input->getArgument('table');
     $databaseConnection = $this->resolveConnection($io, $database);
     if ($table) {
         $this->redBean = $this->getRedBeanConnection($database);
         $tableInfo = $this->redBean->inspect($table);
         $tableHeader = [$this->trans('commands.database.table.debug.messages.column'), $this->trans('commands.database.table.debug.messages.type')];
         $tableRows = [];
         foreach ($tableInfo as $column => $type) {
             $tableRows[] = ['column' => $column, 'type' => $type];
         }
         $io->table($tableHeader, $tableRows);
         return 0;
     }
     $schema = $this->database->schema();
     $tables = $schema->findTables('%');
     $io->comment(sprintf($this->trans('commands.database.table.debug.messages.table-show'), $databaseConnection['database']));
     $io->table([$this->trans('commands.database.table.debug.messages.table')], $tables);
     return 0;
 }
开发者ID:ibonelli,项目名称:DrupalConsole,代码行数:26,代码来源:TableDebugCommand.php

示例14: ensureTableExists

 /**
  * Check if the config table exists and create it if not.
  *
  * @return bool
  *   TRUE if the table was created, FALSE otherwise.
  *
  * @throws \Drupal\Core\Config\StorageException
  *   If a database error occurs.
  */
 protected function ensureTableExists()
 {
     try {
         if (!$this->connection->schema()->tableExists($this->table)) {
             $this->connection->schema()->createTable($this->table, static::schemaDefinition());
             return TRUE;
         }
     } catch (SchemaObjectExistsException $e) {
         return TRUE;
     } catch (\Exception $e) {
         throw new StorageException($e->getMessage(), NULL, $e);
     }
     return FALSE;
 }
开发者ID:anatalsceo,项目名称:en-classe,代码行数:23,代码来源:DatabaseStorage.php

示例15: execute

 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $io = new DrupalStyle($input, $output);
     $database = $input->getArgument('database');
     $yes = $input->getOption('yes');
     $databaseConnection = $this->resolveConnection($io, $database);
     if (!$yes) {
         if (!$io->confirm(sprintf($this->trans('commands.database.drop.question.drop-tables'), $databaseConnection['database']), true)) {
             return 1;
         }
     }
     $schema = $this->database->schema();
     $tables = $schema->findTables('%');
     $tableRows = [];
     foreach ($tables as $table) {
         if ($schema->dropTable($table)) {
             $tableRows['success'][] = [$table];
         } else {
             $tableRows['error'][] = [$table];
         }
     }
     $io->success(sprintf($this->trans('commands.database.drop.messages.table-drop'), count($tableRows['success'])));
     return 0;
 }
开发者ID:ibonelli,项目名称:DrupalConsole,代码行数:27,代码来源:DropCommand.php


注:本文中的Drupal\Core\Database\Connection::schema方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。