Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 24
0.00% covered (danger)
0.00%
0 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
NewSqlSchema
0.00% covered (danger)
0.00%
0 / 24
0.00% covered (danger)
0.00%
0 / 3
12
0.00% covered (danger)
0.00%
0 / 1
 createRevisionTable
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 1
2
 createRevisionDataTable
0.00% covered (danger)
0.00%
0 / 13
0.00% covered (danger)
0.00%
0 / 1
2
 getSchema
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3/**
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; under version 2
7 * of the License (non-upgradable).
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17 *
18 * Copyright (c) 2020 (original work) Open Assessment Technologies SA;
19 *
20 */
21
22namespace oat\taoRevision\model\storage;
23
24use Doctrine\DBAL\Schema\Schema;
25use Doctrine\DBAL\Schema\Table;
26use oat\oatbox\service\ConfigurableService;
27
28class NewSqlSchema extends ConfigurableService
29{
30    public function createRevisionTable(Table $revisionTable)
31    {
32        $revisionTable->addColumn(NewSqlStorage::REVISION_RESOURCE, 'string', ['notnull' => false, 'length' => 255]);
33        $revisionTable->addColumn(NewSqlStorage::REVISION_VERSION, 'string', ['notnull' => false, 'length' => 50]);
34        $revisionTable->addColumn(NewSqlStorage::REVISION_USER, 'string', ['notnull' => true, 'length' => 255]);
35        $revisionTable->addColumn(NewSqlStorage::REVISION_CREATED, 'string', ['notnull' => true]);
36        $revisionTable->addColumn(NewSqlStorage::REVISION_MESSAGE, 'string', ['notnull' => true, 'length' => 4000]);
37        $revisionTable->setPrimaryKey([NewSqlStorage::REVISION_RESOURCE, NewSqlStorage::REVISION_VERSION]);
38    }
39
40    public function createRevisionDataTable(Table $dataTable, Table $revisionTable)
41    {
42        $dataTable->addColumn(NewSqlStorage::DATA_RESOURCE_ID, 'string', ['notnull' => false, 'length' => 50]);
43        $dataTable->addColumn(NewSqlStorage::DATA_RESOURCE, 'string', ['notnull' => false, 'length' => 255]);
44        $dataTable->addColumn(NewSqlStorage::DATA_VERSION, 'string', ['notnull' => false, 'length' => 50]);
45        $dataTable->addColumn(NewSqlStorage::DATA_SUBJECT, 'string', ['notnull' => true, 'length' => 255]);
46        $dataTable->addColumn(NewSqlStorage::DATA_PREDICATE, 'string', ['length' => 255]);
47        $dataTable->addColumn(NewSqlStorage::DATA_OBJECT, 'text', ['default' => null, 'notnull' => false]);
48        $dataTable->addColumn(NewSqlStorage::DATA_LANGUAGE, 'string', ['length' => 50]);
49
50        $dataTable->setPrimaryKey([NewSqlStorage::DATA_RESOURCE_ID]);
51
52        $dataTable->addForeignKeyConstraint(
53            $revisionTable,
54            [NewSqlStorage::REVISION_RESOURCE, NewSqlStorage::REVISION_VERSION],
55            [NewSqlStorage::REVISION_RESOURCE, NewSqlStorage::REVISION_VERSION]
56        );
57    }
58
59    /**
60     * @inheritDoc
61     */
62    public function getSchema(Schema $schema)
63    {
64        /** @var Table $revisionTable */
65        $revisionTable = $schema->createtable(NewSqlStorage::REVISION_TABLE_NAME);
66        $this->createRevisionTable($revisionTable);
67        /** @var Table $dataTable */
68        $dataTable = $schema->createtable(NewSqlStorage::DATA_TABLE_NAME);
69        $this->createRevisionDataTable($dataTable, $revisionTable);
70
71        return $schema;
72    }
73}