示例#1
0
 public function testIdentifierName()
 {
     $this->assertEquals('column_name_here', SchemaUtils::cleanIdentifier('column name here'));
     $this->assertEquals('column_name_here', SchemaUtils::cleanIdentifier('column name$here'));
     $this->assertEquals('column_name_here', SchemaUtils::cleanIdentifier('column  name  $here'));
     $this->assertEquals('column_', SchemaUtils::cleanIdentifier('column '));
     $this->assertEquals('column_3', SchemaUtils::cleanIdentifier('column 3'));
 }
示例#2
0
// GET all table columns, or POST one new table column
$app->map("/{$v}/tables/:table/columns/?", function ($table_name) use($ZendDb, $params, $requestPayload, $app, $acl) {
    $params['table_name'] = $table_name;
    if ($app->request()->isPost()) {
        /**
         * @todo  check if a column by this name already exists
         * @todo  build this into the method when we shift its location to the new layer
         */
        if (!$acl->hasTablePrivilege($table_name, 'alter')) {
            throw new UnauthorizedTableAlterException(__t('permission_table_alter_access_forbidden_on_table', ['table_name' => $table_name]));
        }
        $tableGateway = new TableGateway($acl, $table_name, $ZendDb);
        // Through API:
        // Remove spaces and symbols from column name
        // And in lowercase
        $requestPayload['column_name'] = SchemaUtils::cleanColumnName($requestPayload['column_name']);
        $params['column_name'] = $tableGateway->addColumn($table_name, $requestPayload);
    }
    $response = TableSchema::getSchemaArray($table_name, $params);
    JsonView::render($response);
})->via('GET', 'POST');
// GET or PUT one column
$app->map("/{$v}/tables/:table/columns/:column/?", function ($table, $column) use($ZendDb, $acl, $params, $requestPayload, $app) {
    if ($app->request()->isDelete()) {
        $tableGateway = new TableGateway($acl, $table, $ZendDb);
        $success = $tableGateway->dropColumn($column);
        $response = ['message' => __t('unable_to_remove_column_x', ['column_name' => $column]), 'success' => false];
        if ($success) {
            $response['success'] = true;
            $response['message'] = __t('column_x_was_removed');
        }