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


PHP FieldStorageDefinitionInterface::hasData方法代码示例

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


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

示例1: onFieldStorageDefinitionUpdate

 /**
  * {@inheritdoc}
  */
 public function onFieldStorageDefinitionUpdate(FieldStorageDefinitionInterface $storage_definition, FieldStorageDefinitionInterface $original)
 {
     if (!$storage_definition->hasData()) {
         // There is no data. Re-create the tables completely.
         if ($this->database->supportsTransactionalDDL()) {
             // If the database supports transactional DDL, we can go ahead and rely
             // on it. If not, we will have to rollback manually if something fails.
             $transaction = $this->database->startTransaction();
         }
         try {
             $original_schema = $this->_fieldSqlSchema($original);
             foreach ($original_schema as $name => $table) {
                 $this->database->schema()->dropTable($name, $table);
             }
             $schema = $this->_fieldSqlSchema($storage_definition);
             foreach ($schema as $name => $table) {
                 $this->database->schema()->createTable($name, $table);
             }
         } catch (\Exception $e) {
             if ($this->database->supportsTransactionalDDL()) {
                 $transaction->rollback();
             } else {
                 // Recreate tables.
                 $original_schema = $this->_fieldSqlSchema($original);
                 foreach ($original_schema as $name => $table) {
                     if (!$this->database->schema()->tableExists($name)) {
                         $this->database->schema()->createTable($name, $table);
                     }
                 }
             }
             throw $e;
         }
     } else {
         if ($storage_definition->getColumns() != $original->getColumns()) {
             throw new FieldStorageDefinitionUpdateForbiddenException("The SQL storage cannot change the schema for an existing field with data.");
         }
         // There is data, so there are no column changes. Drop all the prior
         // indexes and create all the new ones, except for all the priors that
         // exist unchanged.
         $table = static::_fieldTableName($original);
         $revision_table = static::_fieldRevisionTableName($original);
         $schema = $storage_definition->getSchema();
         $original_schema = $original->getSchema();
         foreach ($original_schema['indexes'] as $name => $columns) {
             if (!isset($schema['indexes'][$name]) || $columns != $schema['indexes'][$name]) {
                 $real_name = static::_fieldIndexName($storage_definition, $name);
                 $this->database->schema()->dropIndex($table, $real_name);
                 $this->database->schema()->dropIndex($revision_table, $real_name);
             }
         }
         $table = static::_fieldTableName($storage_definition);
         $revision_table = static::_fieldRevisionTableName($storage_definition);
         foreach ($schema['indexes'] as $name => $columns) {
             if (!isset($original_schema['indexes'][$name]) || $columns != $original_schema['indexes'][$name]) {
                 $real_name = static::_fieldIndexName($storage_definition, $name);
                 $real_columns = array();
                 foreach ($columns as $column_name) {
                     // Indexes can be specified as either a column name or an array with
                     // column name and length. Allow for either case.
                     if (is_array($column_name)) {
                         $real_columns[] = array(static::_fieldColumnName($storage_definition, $column_name[0]), $column_name[1]);
                     } else {
                         $real_columns[] = static::_fieldColumnName($storage_definition, $column_name);
                     }
                 }
                 $this->database->schema()->addIndex($table, $real_name, $real_columns);
                 $this->database->schema()->addIndex($revision_table, $real_name, $real_columns);
             }
         }
     }
 }
开发者ID:alnutile,项目名称:drunatra,代码行数:74,代码来源:ContentEntityDatabaseStorage.php


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