protected function addTranslatedColumnSetter(Column $column)
 {
     $visibility = $column->getTable()->isReadOnly() ? 'protected' : $column->getMutatorVisibility();
     $typeHint = '';
     $null = '';
     if ($column->getTypeHint()) {
         $typeHint = $column->getTypeHint();
         if ('array' !== $typeHint) {
             $typeHint = $this->declareClass($typeHint);
         }
         $typeHint .= ' ';
         if (!$column->isNotNull()) {
             $null = ' = null';
         }
     }
     $typeHint = "{$typeHint}\$v{$null}";
     $i18nTablePhpName = $this->builder->getClassNameFromBuilder($this->builder->getNewStubObjectBuilder($this->behavior->getI18nTable()));
     $tablePhpName = $this->builder->getObjectClassName();
     $objectBuilder = $this->builder->getNewObjectBuilder($this->behavior->getI18nTable());
     $comment = '';
     if ($this->isDateType($column->getType())) {
         $objectBuilder->addTemporalMutatorComment($comment, $column);
     } else {
         $objectBuilder->addMutatorComment($comment, $column);
     }
     $comment = preg_replace('/^\\t/m', '', $comment);
     $comment = str_replace('@return     $this|' . $i18nTablePhpName, '@return     $this|' . $tablePhpName, $comment);
     return $this->renderTemplate('objectTranslatedColumnSetter', ['comment' => $comment, 'column' => $column, 'visibility' => $visibility, 'typeHint' => $typeHint, 'columnPhpName' => $column->getPhpName(), 'localeColumnName' => $this->behavior->getLocaleColumn()->getPhpName()]);
 }
 /**
  * Builds the DDL SQL to remove a column
  *
  * @return string
  */
 public function getRemoveColumnDDL(Column $column)
 {
     $pattern = "\nALTER TABLE %s DROP %s;\n";
     return sprintf($pattern, $this->quoteIdentifier($column->getTable()->getName()), $this->quoteIdentifier($column->getName()));
 }
예제 #3
0
 public function getColumnDDL(Column $col)
 {
     $domain = $col->getDomain();
     $ddl = array($this->quoteIdentifier($col->getName()));
     $sqlType = $domain->getSqlType();
     $table = $col->getTable();
     if ($col->isAutoIncrement() && $table && $table->getIdMethodParameters() == null) {
         $sqlType = $col->getType() === PropelTypes::BIGINT ? 'bigserial' : 'serial';
     }
     if ($this->hasSize($sqlType) && $col->isDefaultSqlType($this)) {
         $ddl[] = $sqlType . $domain->printSize();
     } else {
         $ddl[] = $sqlType;
     }
     if ($default = $this->getColumnDefaultValueDDL($col)) {
         $ddl[] = $default;
     }
     if ($notNull = $this->getNullString($col->isNotNull())) {
         $ddl[] = $notNull;
     }
     if ($autoIncrement = $col->getAutoIncrementString()) {
         $ddl[] = $autoIncrement;
     }
     return implode(' ', $ddl);
 }
예제 #4
0
 /**
  * Builds the DDL SQL to add a column
  *
  * @param Column $column
  *
  * @return string
  */
 public function getAddColumnDDL(Column $column)
 {
     $pattern = "\nALTER TABLE %s ADD %s %s;\n";
     $tableColumns = $column->getTable()->getColumns();
     // Default to add first if no column is found before the current one
     $insertPositionDDL = "FIRST";
     foreach ($tableColumns as $i => $tableColumn) {
         // We found the column, use the one before it if it's not the first
         if ($tableColumn->getName() == $column->getName()) {
             // We have a column that is not the first one
             if ($i > 0) {
                 $insertPositionDDL = "AFTER " . $this->quoteIdentifier($tableColumns[$i - 1]->getName());
             }
             break;
         }
     }
     return sprintf($pattern, $this->quoteIdentifier($column->getTable()->getName()), $this->getColumnDDL($column), $insertPositionDDL);
 }
 public function testSetTable()
 {
     $column = new Column();
     $column->setTable($this->getTableMock('books'));
     $this->assertInstanceOf('Propel\\Generator\\Model\\Table', $column->getTable());
     $this->assertSame('books', $column->getTableName());
 }
예제 #6
0
 /**
  * @param Column $column
  *
  * @return bool
  *
  * @throws PropelException
  */
 protected function isColumnForeignKeyOrDuplicated(Column $column)
 {
     $delegateTable = $column->getTable();
     $table = $this->getTable();
     $fks = [];
     if (!isset($this->double_defined)) {
         $this->double_defined = [];
         foreach ($this->delegates + [$table->getName() => 1] as $key => $value) {
             $delegateTable = $this->getDelegateTable($key);
             foreach ($delegateTable->getColumns() as $columnDelegated) {
                 if (isset($this->double_defined[$columnDelegated->getName()])) {
                     $this->double_defined[$columnDelegated->getName()]++;
                 } else {
                     $this->double_defined[$columnDelegated->getName()] = 1;
                 }
             }
         }
     }
     if (1 < $this->double_defined[$column->getName()]) {
         return true;
     }
     foreach ($delegateTable->getForeignKeysReferencingTable($table->getName()) as $fk) {
         /** @var \Propel\Generator\Model\ForeignKey $fk */
         $fks[] = $fk->getForeignColumnName();
     }
     foreach ($table->getForeignKeysReferencingTable($delegateTable->getName()) as $fk) {
         $fks[] = $fk->getForeignColumnName();
     }
     if (in_array($column->getName(), $fks) || $table->hasColumn($column->getName())) {
         return true;
     }
     return false;
 }
예제 #7
0
 /**
  * Builds the DDL SQL to change a column
  * @return string
  */
 public function getChangeColumnDDL(Column $fromColumn, Column $toColumn)
 {
     $pattern = "\nALTER TABLE %s CHANGE %s %s;\n";
     return sprintf($pattern, $this->quoteIdentifier($fromColumn->getTable()->getName()), $this->quoteIdentifier($fromColumn->getName()), $this->getColumnDDL($toColumn));
 }
 protected function addFindOne(Column $column)
 {
     return $this->renderTemplate('queryFindOne', ['objectClassName' => $this->builder->getClassNameFromBuilder($this->builder->getStubObjectBuilder($column->getTable())), 'columnPhpName' => $column->getPhpName(), 'columnName' => $column->getName(), 'localeColumnName' => $this->behavior->getLocaleColumn()->getPhpName()]);
 }
 /**
  * @param Column $column
  *
  * @return bool
  *
  * @throws PropelException
  */
 protected function isColumnForeignKeyOrDuplicated(Column $column)
 {
     $delegateTable = $column->getTable();
     $table = $this->getTable();
     $fks = [];
     foreach ($delegateTable->getForeignKeysReferencingTable($table->getName()) as $fk) {
         /** @var \Propel\Generator\Model\ForeignKey $fk */
         $fks[] = $fk->getForeignColumnName();
     }
     foreach ($table->getForeignKeysReferencingTable($delegateTable->getName()) as $fk) {
         $fks[] = $fk->getForeignColumnName();
     }
     if (in_array($column->getName(), $fks)) {
         return true;
     } else {
         if ($table->hasColumn($column->getName())) {
             throw new PropelException('Column with name «' . $column->getName() . '» (delegated from table «' . $delegateTable->getName() . '») already exists in table «' . $table->getName() . '». Probably database design mistake');
         }
         return false;
     }
 }