本文整理汇总了PHP中SilverStripe\ORM\DB::require_table方法的典型用法代码示例。如果您正苦于以下问题:PHP DB::require_table方法的具体用法?PHP DB::require_table怎么用?PHP DB::require_table使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SilverStripe\ORM\DB
的用法示例。
在下文中一共展示了DB::require_table方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: requireTable
/**
* Check the database schema and update it as necessary.
*
* @uses DataExtension->augmentDatabase()
*/
public function requireTable()
{
// Only build the table if we've actually got fields
$fields = self::database_fields($this->class);
$table = static::getSchema()->tableName($this->class);
$extensions = self::database_extensions($this->class);
$indexes = $this->databaseIndexes();
// Validate relationship configuration
$this->validateModelDefinitions();
if ($fields) {
$hasAutoIncPK = get_parent_class($this) === 'SilverStripe\\ORM\\DataObject';
DB::require_table($table, $fields, $indexes, $hasAutoIncPK, $this->stat('create_table_options'), $extensions);
} else {
DB::dont_require_table($table);
}
// Build any child tables for many_many items
if ($manyMany = $this->uninherited('many_many')) {
$extras = $this->uninherited('many_many_extraFields');
foreach ($manyMany as $relationship => $childClass) {
// Build field list
if ($this->class === $childClass) {
$childField = "ChildID";
} else {
$childTable = $this->getSchema()->tableName($childClass);
$childField = "{$childTable}ID";
}
$manymanyFields = array("{$table}ID" => "Int", $childField => "Int");
if (isset($extras[$relationship])) {
$manymanyFields = array_merge($manymanyFields, $extras[$relationship]);
}
// Build index list
$manymanyIndexes = array("{$table}ID" => true, $childField => true);
$manyManyTable = "{$table}_{$relationship}";
DB::require_table($manyManyTable, $manymanyFields, $manymanyIndexes, true, null, $extensions);
}
}
// Let any extentions make their own database fields
$this->extend('augmentDatabase', $dummy);
}
示例2: requireTable
/**
* Check the database schema and update it as necessary.
*
* @uses DataExtension->augmentDatabase()
*/
public function requireTable()
{
// Only build the table if we've actually got fields
$schema = static::getSchema();
$fields = $schema->databaseFields(static::class, false);
$table = $schema->tableName(static::class);
$extensions = self::database_extensions(static::class);
$indexes = $this->databaseIndexes();
if ($fields) {
$hasAutoIncPK = get_parent_class($this) === self::class;
DB::require_table($table, $fields, $indexes, $hasAutoIncPK, $this->stat('create_table_options'), $extensions);
} else {
DB::dont_require_table($table);
}
// Build any child tables for many_many items
if ($manyMany = $this->uninherited('many_many')) {
$extras = $this->uninherited('many_many_extraFields');
foreach ($manyMany as $component => $spec) {
// Get many_many spec
$manyManyComponent = $schema->manyManyComponent(static::class, $component);
list($relationClass, $parentClass, $componentClass, $parentField, $childField, $tableOrClass) = $manyManyComponent;
// Skip if backed by actual class
if (class_exists($tableOrClass)) {
continue;
}
// Build fields
$manymanyFields = array($parentField => "Int", $childField => "Int");
if (isset($extras[$component])) {
$manymanyFields = array_merge($manymanyFields, $extras[$component]);
}
// Build index list
$manymanyIndexes = array($parentField => true, $childField => true);
DB::require_table($tableOrClass, $manymanyFields, $manymanyIndexes, true, null, $extensions);
}
}
// Let any extentions make their own database fields
$this->extend('augmentDatabase', $dummy);
}
示例3: augmentDatabase
public function augmentDatabase()
{
$owner = $this->owner;
$class = get_class($owner);
$baseTable = $this->baseTable();
$classTable = $owner->getSchema()->tableName($owner);
$isRootClass = $class === $owner->baseClass();
// Build a list of suffixes whose tables need versioning
$allSuffixes = array();
$versionableExtensions = $owner->config()->versionableExtensions;
if (count($versionableExtensions)) {
foreach ($versionableExtensions as $versionableExtension => $suffixes) {
if ($owner->hasExtension($versionableExtension)) {
foreach ((array) $suffixes as $suffix) {
$allSuffixes[$suffix] = $versionableExtension;
}
}
}
}
// Add the default table with an empty suffix to the list (table name = class name)
$allSuffixes[''] = null;
foreach ($allSuffixes as $suffix => $extension) {
// Check tables for this build
if ($suffix) {
$suffixBaseTable = "{$baseTable}_{$suffix}";
$suffixTable = "{$classTable}_{$suffix}";
} else {
$suffixBaseTable = $baseTable;
$suffixTable = $classTable;
}
$fields = DataObject::database_fields($owner->class);
unset($fields['ID']);
if ($fields) {
$options = Config::inst()->get($owner->class, 'create_table_options', Config::FIRST_SET);
$indexes = $owner->databaseIndexes();
$extensionClass = $allSuffixes[$suffix];
if ($suffix && ($extension = $owner->getExtensionInstance($extensionClass))) {
if (!$extension instanceof VersionableExtension) {
throw new LogicException("Extension {$extensionClass} must implement VersionableExtension");
}
// Allow versionable extension to customise table fields and indexes
$extension->setOwner($owner);
if ($extension->isVersionedTable($suffixTable)) {
$extension->updateVersionableFields($suffix, $fields, $indexes);
}
$extension->clearOwner();
}
// Build _Live table
if ($this->hasStages()) {
$liveTable = $this->stageTable($suffixTable, static::LIVE);
DB::require_table($liveTable, $fields, $indexes, false, $options);
}
// Build _versions table
//Unique indexes will not work on versioned tables, so we'll convert them to standard indexes:
$nonUniqueIndexes = $this->uniqueToIndex($indexes);
if ($isRootClass) {
// Create table for all versions
$versionFields = array_merge(Config::inst()->get('SilverStripe\\ORM\\Versioning\\Versioned', 'db_for_versions_table'), (array) $fields);
$versionIndexes = array_merge(Config::inst()->get('SilverStripe\\ORM\\Versioning\\Versioned', 'indexes_for_versions_table'), (array) $nonUniqueIndexes);
} else {
// Create fields for any tables of subclasses
$versionFields = array_merge(array("RecordID" => "Int", "Version" => "Int"), (array) $fields);
$versionIndexes = array_merge(array('RecordID_Version' => array('type' => 'unique', 'value' => '"RecordID","Version"'), 'RecordID' => true, 'Version' => true), (array) $nonUniqueIndexes);
}
// Cleanup any orphans
$this->cleanupVersionedOrphans("{$suffixBaseTable}_versions", "{$suffixTable}_versions");
// Build versions table
DB::require_table("{$suffixTable}_versions", $versionFields, $versionIndexes, true, $options);
} else {
DB::dont_require_table("{$suffixTable}_versions");
if ($this->hasStages()) {
$liveTable = $this->stageTable($suffixTable, static::LIVE);
DB::dont_require_table($liveTable);
}
}
}
}