Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
32 / 32 |
|
100.00% |
4 / 4 |
CRAP | |
100.00% |
1 / 1 |
NewSqlResultStorage | |
100.00% |
32 / 32 |
|
100.00% |
4 / 4 |
4 | |
100.00% |
1 / 1 |
getVariablesSortingField | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
prepareVariableDataForSchema | |
100.00% |
13 / 13 |
|
100.00% |
1 / 1 |
1 | |||
getDateFromMicroTime | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
createVariablesTable | |
100.00% |
17 / 17 |
|
100.00% |
1 / 1 |
1 |
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) 2014-2020 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT); |
19 | */ |
20 | |
21 | namespace oat\taoOutcomeRds\model; |
22 | |
23 | use Doctrine\DBAL\Schema\Schema; |
24 | use taoResultServer_models_classes_Variable as Variable; |
25 | |
26 | /** |
27 | * Implements tao results storage for NewSql |
28 | */ |
29 | class NewSqlResultStorage extends AbstractRdsResultStorage |
30 | { |
31 | public const CREATED_AT = 'created_at'; |
32 | |
33 | /** |
34 | * @inheritDoc |
35 | */ |
36 | protected function getVariablesSortingField() |
37 | { |
38 | return self::CREATED_AT; |
39 | } |
40 | |
41 | /** |
42 | * @inheritdoc |
43 | */ |
44 | protected function prepareVariableDataForSchema($deliveryResultIdentifier, $test, Variable $variable, $callId) |
45 | { |
46 | $serializedVariable = $this->serializeVariableValue($variable); |
47 | |
48 | $persistence = $this->getPersistence(); |
49 | |
50 | $createdAt = $this->getDateFromMicroTime($variable->getCreationTime()); |
51 | |
52 | return [ |
53 | self::VARIABLES_TABLE_ID => $persistence->getUniquePrimaryKey(), |
54 | self::VARIABLES_FK_COLUMN => $deliveryResultIdentifier, |
55 | self::TEST_COLUMN => 'deprecated', |
56 | self::VARIABLE_IDENTIFIER => $variable->getIdentifier(), |
57 | self::VARIABLE_VALUE => $serializedVariable, |
58 | self::VARIABLE_HASH => $deliveryResultIdentifier |
59 | . md5($deliveryResultIdentifier . $serializedVariable . $callId), |
60 | self::CREATED_AT => $createdAt->format($persistence->getPlatform()->getDateTimeFormatString()), |
61 | ]; |
62 | } |
63 | |
64 | /** |
65 | * Converts float microtime to a DateTime. |
66 | * @param string $microTime |
67 | * |
68 | * @return \DateTime |
69 | */ |
70 | public function getDateFromMicroTime($microTime) |
71 | { |
72 | return date_create_from_format('U.u', number_format($microTime, 6, '.', '')); |
73 | } |
74 | |
75 | /** |
76 | * @inheritDoc |
77 | */ |
78 | public function createVariablesTable(Schema $schema) |
79 | { |
80 | $table = $schema->createtable(self::VARIABLES_TABLENAME); |
81 | $table->addOption('engine', 'MyISAM'); |
82 | |
83 | $table->addColumn(self::VARIABLES_TABLE_ID, 'string', ['length' => 36]); |
84 | $table->addColumn(self::CALL_ID_TEST_COLUMN, 'string', ['notnull' => false, 'length' => 255]); |
85 | $table->addColumn(self::CALL_ID_ITEM_COLUMN, 'string', ['notnull' => false, 'length' => 255]); |
86 | $table->addColumn(self::TEST_COLUMN, 'string', ['notnull' => false, 'length' => 255]); |
87 | $table->addColumn(self::ITEM_COLUMN, 'string', ['notnull' => false, 'length' => 255]); |
88 | $table->addColumn(self::VARIABLE_VALUE, 'text', ['notnull' => false]); |
89 | $table->addColumn(self::VARIABLE_IDENTIFIER, 'string', ['notnull' => false, 'length' => 255]); |
90 | $table->addColumn(self::VARIABLES_FK_COLUMN, 'string', ['length' => 255]); |
91 | $table->addColumn(self::VARIABLE_HASH, 'string', ['length' => 255, 'notnull' => false]); |
92 | $table->addColumn(self::CREATED_AT, 'datetime', []); |
93 | |
94 | $table->setPrimaryKey([self::VARIABLES_TABLE_ID]); |
95 | $table->addUniqueIndex([self::VARIABLE_HASH], self::UNIQUE_VARIABLE_INDEX); |
96 | $table->addIndex([self::CALL_ID_ITEM_COLUMN], self::CALL_ID_ITEM_INDEX); |
97 | $table->addIndex([self::CALL_ID_TEST_COLUMN], self::CALL_ID_TEST_INDEX); |
98 | |
99 | return $table; |
100 | } |
101 | } |