Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 37 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| WebhookLogRepository | |
0.00% |
0 / 37 |
|
0.00% |
0 / 2 |
6 | |
0.00% |
0 / 1 |
| storeLog | |
0.00% |
0 / 17 |
|
0.00% |
0 / 1 |
2 | |||
| provideSchema | |
0.00% |
0 / 20 |
|
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 | namespace oat\tao\model\webhooks\log; |
| 22 | |
| 23 | use Doctrine\DBAL\Types\Types; |
| 24 | use oat\generis\persistence\sql\SchemaCollection; |
| 25 | use oat\tao\model\metadata\exception\InconsistencyConfigException; |
| 26 | |
| 27 | class WebhookLogRepository extends AbstractWebhookLogRepository |
| 28 | { |
| 29 | /** |
| 30 | * @throws InconsistencyConfigException |
| 31 | */ |
| 32 | public function storeLog(WebhookEventLogRecord $webhookEventLog): void |
| 33 | { |
| 34 | $this->getPersistence()->insert( |
| 35 | self::TABLE_NAME, |
| 36 | [ |
| 37 | self::COLUMN_EVENT_ID => $webhookEventLog->getEventId(), |
| 38 | self::COLUMN_TASK_ID => $webhookEventLog->getTaskId(), |
| 39 | self::COLUMN_WEBHOOK_ID => $webhookEventLog->getWebhookId(), |
| 40 | self::COLUMN_HTTP_METHOD => $webhookEventLog->getHttpMethod(), |
| 41 | self::COLUMN_ENDPOINT_URL => $webhookEventLog->getEndpointUrl(), |
| 42 | self::COLUMN_EVENT_NAME => $webhookEventLog->getEventName(), |
| 43 | self::COLUMN_HTTP_STATUS_CODE => $webhookEventLog->getHttpStatusCode(), |
| 44 | self::COLUMN_RESPONSE_BODY => $webhookEventLog->getResponseBody(), |
| 45 | self::COLUMN_ACKNOWLEDGEMENT_STATUS => $webhookEventLog->getAcknowledgementStatus(), |
| 46 | self::COLUMN_CREATED_AT => $webhookEventLog->getCreatedAt(), |
| 47 | self::COLUMN_RESULT => $webhookEventLog->getResult(), |
| 48 | self::COLUMN_RESULT_MESSAGE => $webhookEventLog->getResultMessage(), |
| 49 | ] |
| 50 | ); |
| 51 | } |
| 52 | |
| 53 | public function provideSchema(SchemaCollection $schemaCollection) |
| 54 | { |
| 55 | $schema = $schemaCollection->getSchema($this->getOption(self::OPTION_PERSISTENCE)); |
| 56 | |
| 57 | $logTable = $schema->createTable(self::TABLE_NAME); |
| 58 | $logTable->addOption('engine', 'InnoDB'); |
| 59 | |
| 60 | $logTable->addColumn(self::COLUMN_ID, Types::INTEGER, ['autoincrement' => true]); |
| 61 | $logTable->addColumn(self::COLUMN_EVENT_ID, Types::STRING, ['notnull' => false, 'length' => 255]); |
| 62 | $logTable->addColumn(self::COLUMN_TASK_ID, Types::STRING, ['notnull' => false, 'length' => 255]); |
| 63 | $logTable->addColumn(self::COLUMN_WEBHOOK_ID, Types::STRING, ['notnull' => false, 'length' => 255]); |
| 64 | $logTable->addColumn(self::COLUMN_HTTP_METHOD, Types::STRING, ['notnull' => false, 'length' => 255]); |
| 65 | $logTable->addColumn(self::COLUMN_ENDPOINT_URL, Types::STRING, ['notnull' => false, 'length' => 255]); |
| 66 | $logTable->addColumn(self::COLUMN_EVENT_NAME, Types::STRING, ['notnull' => false, 'length' => 255]); |
| 67 | $logTable->addColumn(self::COLUMN_HTTP_STATUS_CODE, Types::SMALLINT, ['notnull' => false]); |
| 68 | $logTable->addColumn(self::COLUMN_RESPONSE_BODY, Types::TEXT, ['notnull' => false]); |
| 69 | $logTable->addColumn(self::COLUMN_ACKNOWLEDGEMENT_STATUS, Types::STRING, ['notnull' => false, 'length' => 255]); |
| 70 | $logTable->addColumn(self::COLUMN_CREATED_AT, Types::INTEGER, ['notnull' => true]); |
| 71 | $logTable->addColumn(self::COLUMN_RESULT, Types::STRING, ['notnull' => true, 'length' => 255]); |
| 72 | $logTable->addColumn(self::COLUMN_RESULT_MESSAGE, Types::TEXT, ['notnull' => false]); |
| 73 | |
| 74 | $logTable->setPrimaryKey([self::COLUMN_ID]); |
| 75 | |
| 76 | $logTable->addIndex([self::COLUMN_EVENT_ID], 'IDX_' . self::TABLE_NAME . '_event_id'); |
| 77 | |
| 78 | $logTable->addIndex([self::COLUMN_WEBHOOK_ID], 'IDX_' . self::TABLE_NAME . '_webhook_id'); |
| 79 | |
| 80 | $logTable->addIndex([self::COLUMN_CREATED_AT], 'IDX_' . self::TABLE_NAME . '_created_at'); |
| 81 | } |
| 82 | } |