RainLab\Builder\Classes\TableMigrationCodeGenerator::generateCreateOrUpdateUpCode PHP Метод

generateCreateOrUpdateUpCode() защищенный Метод

protected generateCreateOrUpdateUpCode ( $tableDiff, $isNewTable, $newOrUpdatedTable )
    protected function generateCreateOrUpdateUpCode($tableDiff, $isNewTable, $newOrUpdatedTable)
    {
        $result = null;
        $hasColumnChanges = $this->tableHasNameOrColumnChanges($tableDiff, true);
        $changedPrimaryKey = $this->getChangedOrRemovedPrimaryKey($tableDiff);
        $addedPrimaryKey = $this->findPrimaryKeyIndex($tableDiff->addedIndexes, $newOrUpdatedTable);
        if ($tableDiff->getNewName()) {
            $result .= $this->generateTableRenameCode($tableDiff->name, $tableDiff->newName);
            if ($hasColumnChanges || $changedPrimaryKey) {
                $result .= $this->eol;
            }
        }
        if (!$hasColumnChanges && !$changedPrimaryKey && !$addedPrimaryKey) {
            return $this->makeTabs($result);
        }
        $tableName = $tableDiff->getNewName() ? $tableDiff->newName : $tableDiff->name;
        $result .= $this->generateSchemaTableMethodStart($tableName, $isNewTable);
        if ($changedPrimaryKey) {
            $result .= $this->generatePrimaryKeyDrop($tableDiff->fromTable);
        }
        foreach ($tableDiff->addedColumns as $column) {
            $result .= $this->generateColumnCode($column, self::COLUMN_MODE_CREATE);
        }
        foreach ($tableDiff->changedColumns as $columnDiff) {
            $result .= $this->generateColumnCode($columnDiff, self::COLUMN_MODE_CHANGE);
        }
        foreach ($tableDiff->renamedColumns as $oldName => $column) {
            $result .= $this->generateColumnRenameCode($oldName, $column->getName());
        }
        foreach ($tableDiff->removedColumns as $name => $column) {
            $result .= $this->generateColumnRemoveCode($name);
        }
        $primaryKey = $changedPrimaryKey ? $this->findPrimaryKeyIndex($tableDiff->changedIndexes, $newOrUpdatedTable) : $this->findPrimaryKeyIndex($tableDiff->addedIndexes, $newOrUpdatedTable);
        if ($primaryKey) {
            $result .= $this->generatePrimaryKeyCode($primaryKey, self::COLUMN_MODE_CREATE);
        }
        $result .= $this->generateSchemaTableMethodEnd();
        return $this->makeTabs($result);
    }