protected function generateDefaultMethodCall($default, $column) { $columnName = $column->getName(); $typeName = $column->getType()->getName(); $type = MigrationColumnType::toMigrationMethodName($typeName, $columnName); if (in_array($type, MigrationColumnType::getIntegerTypes()) || in_array($type, MigrationColumnType::getDecimalTypes()) || $type == MigrationColumnType::TYPE_BOOLEAN) { return sprintf('->default(%s)', $default); } return sprintf('->default(\'%s\')', $this->quoteParameter($default)); }
protected function validateDefaultValues() { foreach ($this->columns as $column) { if (!strlen($column['default'])) { continue; } $default = trim($column['default']); if (in_array($column['type'], MigrationColumnType::getIntegerTypes())) { if (!preg_match('/^\\-?[0-9]+$/', $default)) { throw new ValidationException(['columns' => Lang::get('rainlab.builder::lang.database.error_integer_default_value', ['column' => $column['name']])]); } if ($column['unsigned'] && $default < 0) { throw new ValidationException(['columns' => Lang::get('rainlab.builder::lang.database.error_unsigned_negative_value', ['column' => $column['name']])]); } continue; } if (in_array($column['type'], MigrationColumnType::getDecimalTypes())) { if (!preg_match('/^\\-?([0-9]+\\.[0-9]+|[0-9]+)$/', $default)) { throw new ValidationException(['columns' => Lang::get('rainlab.builder::lang.database.error_decimal_default_value', ['column' => $column['name']])]); } continue; } if ($column['type'] == MigrationColumnType::TYPE_BOOLEAN) { if (!preg_match('/^0|1$/', $default)) { throw new ValidationException(['columns' => Lang::get('rainlab.builder::lang.database.error_boolean_default_value', ['column' => $column['name']])]); } } } }