public function __construct(TableInformation $parent, \Doctrine\DBAL\Schema\Table $table, \Doctrine\DBAL\Schema\Column $column) { $this->table = $parent; foreach ($table->getForeignKeys() as $foreign) { if (in_array($column->getName(), $foreign->getColumns())) { $foreign_columns = $foreign->getForeignColumns(); $this->foreignTable = $foreign->getForeignTableName(); $this->foreignColumn = reset($foreign_columns); $this->isForeign = true; } } if ($primary_key = $table->getPrimaryKey()) { $this->isPrimary = in_array($column->getName(), $primary_key->getColumns()); } $this->name = $column->getName(); $this->type = $column->getType()->getName(); $this->length = $column->getLength(); $this->precision = $column->getPrecision(); $this->default = $column->getDefault(); $this->isNotNull = $column->getNotnull(); $this->isUnsigned = $column->getUnsigned(); $this->isFixed = $column->getFixed(); $this->isAutoIncrement = $column->getAutoincrement(); $this->comment = $column->getComment(); if ($this->type === \Doctrine\DBAL\Types\Type::BLOB) { $this->length = min($this->bytesFromIni('post_max_size'), $this->bytesFromIni('upload_max_filesize')); } }
/** * Method for create a input for new form * * @param \Doctrine\DBAL\Schema\Column $objColumn * @param array $arrForeignKeys Foreign keys * @return string */ public function createInput(Column $objColumn, $arrForeignKeys) { if ($objColumn->getType() instanceof FloatType) { $objInputFilter = new GeneratorFilterInputTypeFloat($objColumn, $arrForeignKeys); return $objInputFilter->getStrCreateInputFilter(); } return '$filter' . $this->underscoreToCamelcase($objColumn->getName()) . ' = new BaseInputFilter(' . '"' . $this->underscoreToLowerCamelcase($objColumn->getName()) . '", ' . $this->getParamsToHaystack($arrForeignKeys[$objColumn->getName()]) . ', ' . (bool) $objColumn->getNotnull() . ', true' . $this->getStrMinAndMaxlength($objColumn, $arrForeignKeys) . ');' . PHP_EOL . '$this->add($filter' . $this->underscoreToCamelcase($objColumn->getName()) . ');' . PHP_EOL . PHP_EOL; }
/** * @param \Doctrine\DBAL\Schema\Column $column * @param mixed $value */ public function generateField($column, $value = null) { if ($value) { $this->value = $value; } $this->setLabel($column->getName()); $this->name = $column->getName(); return $this; }
/** * Creates a column replacement, which has a quoted name. * * @param Column $column * * @return Column */ private function createColumnReplacement(Column $column) { $columnConfig = $column->toArray(); $columnConfig['platformOptions'] = $column->getPlatformOptions(); $columnConfig['customSchemaOptions'] = $column->getCustomSchemaOptions(); return new Column($this->platform->quoteIdentifier($column->getName()), $column->getType(), $columnConfig); }
/** * Check for Sequence Duplicates. * * Episodes of the same entity that overlap in time. * * @access public * @return boolean the result of the operation * @param mixed $oMixed The Entity to do operation on */ public function execute($oMixed) { $oOperation = $this->oOperation; $oConnection = $this->oConnection; # execute operation, only care if its successful $bResult = $oOperation->execute($oMixed); $sTableName = $this->sTableName; if (true === $bResult) { try { $oInnerQuery = new QueryBuilder($oConnection); $oInnerQuery->select('count(*)')->from($sTableName, 's2')->andWhere('s1.' . $this->oFromColum->getName() . ' < s2.' . $this->oToColumn->getName() . ' ')->andWhere('s2.' . $this->oFromColum->getName() . ' < s1.' . $this->oToColumn->getName() . ' '); # process the key columns foreach ($this->oNaturalKeyColumns as $oColumn) { $oInnerQuery->andWhere('s1.' . $oColumn->getName() . ' = s2.' . $oColumn->getName() . ' '); } // verify the consistence $sSql = "SELECT count(*) FROM '.{$sTableName}.' AS s1\n WHERE 1 < (\n '.{$oInnerQuery->getSql}().' \n ); "; $iCount = (int) $oConnection->fetchColumn($sSql, array(), 0); if ($iCount > 0) { throw new VoucherException('This entity has a sequence duplicate unable to finish operation'); } } catch (DBALException $e) { throw new VoucherException($e->getMessage(), 0, $e); } } return $bResult; }
public function getSql(Column $column, $table) { if (!$table instanceof Table) { $table = new Identifier($table); } $sql = array(); $normalized = $column->getType()->getNormalizedPostGISColumnOptions($column->getCustomSchemaOptions()); $srid = $normalized['srid']; // PostGIS 1.5 uses -1 for undefined SRID's if ($srid <= 0) { $srid = -1; } $type = strtoupper($normalized['geometry_type']); if ('ZM' === substr($type, -2)) { $dimension = 4; $type = substr($type, 0, -2); } elseif ('M' === substr($type, -1)) { $dimension = 3; } elseif ('Z' === substr($type, -1)) { $dimension = 3; $type = substr($type, 0, -1); } else { $dimension = 2; } // Geometry columns are created by the AddGeometryColumn stored procedure $sql[] = sprintf("SELECT AddGeometryColumn('%s', '%s', %d, '%s', %d)", $table->getName(), $column->getName(), $srid, $type, $dimension); if ($column->getNotnull()) { // Add a NOT NULL constraint to the field $sql[] = sprintf('ALTER TABLE %s ALTER %s SET NOT NULL', $table->getQuotedName($this->platform), $column->getQuotedName($this->platform)); } return $sql; }
/** * Do checks for columns. * * @param Column $column * @param array $alterData * * @return boolean */ protected function checkColumn(Column $column, array $alterData) { // Not needed to be implemented yet if ($alterData['propertyName'] !== $column->getName()) { return false; } return false; }
/** * Do checks for columns. * * @param Column $column * @param IgnoredChange $ignoredChange * * @return boolean */ protected function checkColumn(Column $column, IgnoredChange $ignoredChange) { // Not needed to be implemented yet if ($ignoredChange->getPropertyName() !== $column->getName()) { return false; } return false; }
/** * @group DBAL-64 */ public function testQuotedColumnName() { $string = Type::getType('string'); $column = new Column("`bar`", $string, array()); $mysqlPlatform = new \Doctrine\DBAL\Platforms\MySqlPlatform(); $sqlitePlatform = new \Doctrine\DBAL\Platforms\SqlitePlatform(); $this->assertEquals('bar', $column->getName()); $this->assertEquals('`bar`', $column->getQuotedName($mysqlPlatform)); $this->assertEquals('"bar"', $column->getQuotedName($sqlitePlatform)); }
/** * @param Column $column * @param Collection $foreignKeyColumns * @param Collection $foreignTables * @param Collection $indexes * @return ColumnInterface */ protected function buildColumn(Column $column, Collection $foreignKeyColumns, Collection $foreignTables, Collection $indexes) { $uniqued = $indexes->filter(function (Index $index) use($column) { return $index->getColumns()[0] == $column->getName() && $index->isUnique(); })->count() > 0; if ($column->getAutoincrement()) { return new ColumnAutoincrement($column, null, null, $uniqued); } else { if ($foreignKeyColumns->has($column->getName())) { $table = $foreignKeyColumns->get($column->getName()); return new ColumnSelect($column, $table, $foreignTables->get($table), $uniqued); } else { if ($column->getType()->getName() == Type::INTEGER) { return new ColumnNumericText($column, null, null, $uniqued); } else { return new ColumnText($column, null, null, $uniqued); } } } }
/** * @param \Doctrine\DBAL\Schema\Column $column * @param mixed $value * @return string */ protected function getHtmlAttributes($column, $value = null) { $result = ""; if (isset($value)) { $result .= "value='{$value}' "; } if ($name = $column->getName()) { $fieldName = $this->generateFieldName($name); $result .= "id='field_{$name}' {$fieldName}"; } return $result; }
/** * @param \Doctrine\DBAL\Schema\Column $column * @param mixed $value */ public function generateField($column, $value = null) { $multiple = false; $options = $column->getValues(); $options_temp = array(); foreach ($options as $index => $option) { $option = str_replace("'", '', $option); $option = str_replace("\"", '', $option); $options_temp[$option] = $option; } $options = $options_temp; if (!$column->hasUniqueValue()) { $multiple = true; } $value = explode(",", $value); $name = $column->getName(); return $this->generateFilledField($options, $name, $multiple, $value); }
/** * @param Column $column * @return string */ protected function guessFormItemType(Column $column) { $name = $column->getName(); $foreignKey = $this->getForeignKey($name); if (!is_null($foreignKey)) { return 'select'; } $type = $column->getType()->getName(); if ($type == 'string' && $this->isEnumColumn($name)) { return 'select'; } $lookup = ['string' => 'text', 'text' => 'ckeditor', 'integer' => 'text', 'float' => 'text', 'boolean' => 'checkbox', 'date' => 'date', 'time' => 'time', 'datetime' => 'timestamp']; return Arr::get($lookup, $type, 'text'); }
/** * Build field mapping from a schema column definition * * @param string $tableName * @param \Doctrine\DBAL\Schema\Column $column * * @return array */ private function buildFieldMapping($tableName, Column $column) { $fieldMapping = array('fieldName' => $this->getFieldNameForColumn($tableName, $column->getName(), false), 'columnName' => $column->getName(), 'type' => $column->getType()->getName(), 'nullable' => !$column->getNotNull()); // Type specific elements switch ($fieldMapping['type']) { case Type::TARRAY: case Type::BLOB: case Type::GUID: case Type::JSON_ARRAY: case Type::OBJECT: case Type::SIMPLE_ARRAY: case Type::STRING: case Type::TEXT: $fieldMapping['length'] = $column->getLength(); $fieldMapping['options']['fixed'] = $column->getFixed(); break; case Type::DECIMAL: case Type::FLOAT: $fieldMapping['precision'] = $column->getPrecision(); $fieldMapping['scale'] = $column->getScale(); break; case Type::INTEGER: case Type::BIGINT: case Type::SMALLINT: $fieldMapping['options']['unsigned'] = $column->getUnsigned(); break; } // Comment if (($comment = $column->getComment()) !== null) { $fieldMapping['options']['comment'] = $comment; } // Weather if (($default = $column->getDefault()) !== null) { $fieldMapping['options']['default'] = $default; } return $fieldMapping; }
public function acceptColumn(Table $table, Column $column) { $this->addViolation('Table ' . $table->getName() . ' column ' . $column->getName(), $this->isReservedWord($column->getName())); }
/** * @param Table $table * @param string $columnName * @param Column $targetColumn * @param array $options * @throws \Doctrine\DBAL\Schema\SchemaException */ protected function addRelationColumn(Table $table, $columnName, Column $targetColumn, array $options = []) { if ($targetColumn->getName() !== 'id') { throw new SchemaException(sprintf('The target column name must be "id". Relation column: "%s::%s". Target column name: "%s".', $table->getName(), $columnName, $targetColumn->getName())); } $columnTypeName = $targetColumn->getType()->getName(); if (!in_array($columnTypeName, [Type::INTEGER, Type::STRING, Type::SMALLINT, Type::BIGINT])) { throw new SchemaException(sprintf('The type of relation column "%s::%s" must be an integer or string. "%s" type is not supported.', $table->getName(), $columnName, $columnTypeName)); } if ($columnTypeName === Type::STRING && $targetColumn->getLength() !== null) { $options['length'] = $targetColumn->getLength(); } $table->addColumn($columnName, $columnTypeName, $options); }
/** * @return string */ public function getName() { return $this->column->getName(); }
/** * Maps an individual column in to a Form element * * @param Column $column * @return ElementInterface */ protected function mapColumn(Column $column, $fks) { $attributes = ['name' => $column->getName(), 'id' => str_replace('_', '-', $column->getName()), 'class' => null]; if ($this->helper->isEmail($column)) { $element = new Email($attributes); } elseif ($this->helper->isPassword($column)) { $element = new Password($attributes); } elseif ($this->helper->isHidden($column)) { $element = new Hidden($attributes); } elseif ($this->helper->isBoolean($column)) { $element = new Boolean($attributes); } elseif ($this->helper->isDate($column)) { $element = new Date($attributes); } elseif ($this->helper->isSelect($column, $fks)) { $element = new Select($attributes); } elseif ($this->helper->isTextArea($column)) { $element = new TextArea($attributes); } elseif ($this->helper->isString($column)) { $attributes['maxlength'] = $column->getLength(); $element = new Text($attributes); } elseif ($this->helper->isNumeric($column)) { $element = new Numeric($attributes); } else { $element = new Text($attributes); } $element->setRequired($column->getNotnull()); return $element; }
/** * @param \Doctrine\DBAL\Schema\Column $column * return boolean */ public function isLikeImage($column) { $type = $column->getType()->getName(); $name = $column->getName(); $result = false; if (($name == "image" || $name == "picture") && ($type == "string" || $type == "text")) { $result = true; } return $result; }
/** * @param Column $column * @param \SimpleXMLElement $xml */ private static function saveColumn($column, $xml) { $xml->addChild('name', $column->getName()); switch ($column->getType()) { case 'SmallInt': case 'Integer': case 'BigInt': $xml->addChild('type', 'integer'); $default = $column->getDefault(); if (is_null($default) && $column->getAutoincrement()) { $default = '0'; } $xml->addChild('default', $default); $xml->addChild('notnull', self::toBool($column->getNotnull())); if ($column->getAutoincrement()) { $xml->addChild('autoincrement', '1'); } if ($column->getUnsigned()) { $xml->addChild('unsigned', 'true'); } $length = '4'; if ($column->getType() == 'SmallInt') { $length = '2'; } elseif ($column->getType() == 'BigInt') { $length = '8'; } $xml->addChild('length', $length); break; case 'String': $xml->addChild('type', 'text'); $default = trim($column->getDefault()); if ($default === '') { $default = false; } $xml->addChild('default', $default); $xml->addChild('notnull', self::toBool($column->getNotnull())); $xml->addChild('length', $column->getLength()); break; case 'Text': $xml->addChild('type', 'clob'); $xml->addChild('notnull', self::toBool($column->getNotnull())); break; case 'Decimal': $xml->addChild('type', 'decimal'); $xml->addChild('default', $column->getDefault()); $xml->addChild('notnull', self::toBool($column->getNotnull())); $xml->addChild('length', '15'); break; case 'Boolean': $xml->addChild('type', 'integer'); $xml->addChild('default', $column->getDefault()); $xml->addChild('notnull', self::toBool($column->getNotnull())); $xml->addChild('length', '1'); break; case 'DateTime': $xml->addChild('type', 'timestamp'); $xml->addChild('default', $column->getDefault()); $xml->addChild('notnull', self::toBool($column->getNotnull())); break; } }
/** * @param Column $column * @return string * @throws \RuntimeException */ private function doctrineColumnToProcessingType(Column $column) { if (!isset($this->doctrineProcessingTypeMap[$column->getType()->getName()])) { throw new \RuntimeException(sprintf("No processing type mapping for doctrine type %s", $column->getType()->getName())); } $processingType = $this->doctrineProcessingTypeMap[$column->getType()->getName()]; if (!$column->getNotnull() || $column->getAutoincrement()) { $processingType .= "OrNull"; if (!class_exists($processingType)) { throw new \RuntimeException("Missing null type: for nullable column: " . $column->getName()); } } Assertion::implementsInterface($processingType, 'Prooph\\Processing\\Type\\Type'); return $processingType; }
/** * @param \Doctrine\DBAL\Schema\Column $column * * @return string */ private function checkForUnique($column) { if (in_array($column->getName(), $this->uniqueFields)) { return ":unique"; } return ''; }
/** * @param \Doctrine\DBAL\Schema\Column $column * * @return string */ private function generateTextInput($column) { $fieldInput = $column->getName() . ':text'; return $fieldInput; }
/** * Process blob|binary type of the table field. * * @param Column $column * @param bool $isUnique * @return string */ protected function processBlob(Column $column, $isUnique) { return $this->grammar->binary($column->getName(), $column->getDefault(), !$column->getNotnull(), $isUnique); }
/** * Get the field type for a given column. * * @param string $name * @param \Doctrine\DBAL\Schema\Column $column * * @return string */ protected function getFieldTypeFor($name, $column) { if (isset($this->contenttypes[$name]['fields'][$column->getName()])) { $type = $this->contenttypes[$name]['fields'][$column->getName()]['type']; } elseif ($column->getType()) { $type = get_class($column->getType()); } if ($column->getName() === 'slug') { $type = 'slug'; } if ($type === 'select' && isset($this->contenttypes[$name]['fields'][$column->getName()]['multiple']) && $this->contenttypes[$name]['fields'][$column->getName()]['multiple'] === true) { $type = 'selectmultiple'; } if (isset($this->typemap[$type])) { $type = $this->typemap[$type]; } else { $type = $this->typemap['text']; } return $type; }
/** * __toString * * @return string column name */ public function __toString() { return $this->column->getName(); }
/** * @param Column $column */ protected function _addColumn(Column $column) { $columnName = $column->getName(); $columnName = strtolower($columnName); if (isset($this->_columns[$columnName])) { throw SchemaException::columnAlreadyExists($this->getName(), $columnName); } $this->_columns[$columnName] = $column; }
/** * Check if column is deleted_at. * * @param Column $column * @return bool */ protected function isSoftDeletes(Column $column) { return !is_null($this->deletedAtColumn) && $column->getName() === $this->deletedAtColumn && !$column->getNotnull(); }
/** * Get the field type for a given column. * * @param string $name * @param \Doctrine\DBAL\Schema\Column $column * * @return string */ protected function getFieldTypeFor($name, $column) { $contentKey = $this->schemaManager->getKeyForTable($name); if ($contentKey && isset($this->contenttypes[$contentKey]['fields'][$column->getName()])) { $type = $this->contenttypes[$contentKey]['fields'][$column->getName()]['type']; } elseif ($column->getType()) { $type = get_class($column->getType()); } if ($type === 'select' && isset($this->contenttypes[$contentKey]['fields'][$column->getName()]['multiple']) && $this->contenttypes[$contentKey]['fields'][$column->getName()]['multiple'] === true) { $type = 'selectmultiple'; } if (isset($this->typemap[$type])) { $type = $this->typemap[$type]; } else { $type = $this->typemap['text']; } return $type; }
protected function convertDoctrineTypeToString(Column $column, $isPrimary) { $type = SerializeTrait::getTypeByDoctrineType($column->getType()); $name = $column->getName(); switch ($type) { case TableInterface::TYPE_BIGINT: $result = <<<PHP \t\t\t'{$name}' => self::TYPE_BIGINT PHP; break; case TableInterface::TYPE_BLOB: $result = <<<PHP \t\t\t'{$name}' => self::TYPE_BLOB PHP; break; case TableInterface::TYPE_BOOLEAN: $result = <<<PHP \t\t\t'{$name}' => self::TYPE_BOOLEAN PHP; break; case TableInterface::TYPE_DATETIME: $result = <<<PHP \t\t\t'{$name}' => self::TYPE_DATETIME PHP; break; case TableInterface::TYPE_DATE: $result = <<<PHP \t\t\t'{$name}' => self::TYPE_DATE PHP; break; case TableInterface::TYPE_DECIMAL: $result = <<<PHP \t\t\t'{$name}' => self::TYPE_DECIMAL PHP; break; case TableInterface::TYPE_FLOAT: $result = <<<PHP \t\t\t'{$name}' => self::TYPE_FLOAT PHP; break; case TableInterface::TYPE_INT: $result = <<<PHP \t\t\t'{$name}' => self::TYPE_INT PHP; break; case TableInterface::TYPE_SMALLINT: $result = <<<PHP \t\t\t'{$name}' => self::TYPE_SMALLINT PHP; break; case TableInterface::TYPE_TEXT: $result = <<<PHP \t\t\t'{$name}' => self::TYPE_TEXT PHP; break; case TableInterface::TYPE_ARRAY: $result = <<<PHP \t\t\t'{$name}' => self::TYPE_ARRAY PHP; break; case TableInterface::TYPE_OBJECT: $result = <<<PHP \t\t\t'{$name}' => self::TYPE_OBJECT PHP; break; case TableInterface::TYPE_TIME: $result = <<<PHP \t\t\t'{$name}' => self::TYPE_TIME PHP; break; case TableInterface::TYPE_VARCHAR: default: $result = <<<PHP \t\t\t'{$name}' => self::TYPE_VARCHAR PHP; break; } if ($column->getAutoincrement()) { $result .= ' | self::AUTO_INCREMENT'; } if ($isPrimary) { $result .= ' | self::PRIMARY_KEY'; } return $result . ','; }