Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| AbstractWebhookLogRepository | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
20 | |
0.00% |
0 / 1 |
| getPersistence | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
20 | |||
| 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 common_persistence_SqlPersistence; |
| 24 | use oat\generis\persistence\PersistenceManager; |
| 25 | use oat\oatbox\service\ConfigurableService; |
| 26 | use oat\tao\model\metadata\exception\InconsistencyConfigException; |
| 27 | |
| 28 | abstract class AbstractWebhookLogRepository extends ConfigurableService implements WebhookLogRepositoryInterface |
| 29 | { |
| 30 | /** @var common_persistence_SqlPersistence|null */ |
| 31 | private $persistence; |
| 32 | |
| 33 | public const OPTION_PERSISTENCE = 'persistence'; |
| 34 | |
| 35 | public const TABLE_NAME = 'webhook_event_log'; |
| 36 | public const COLUMN_ID = 'id'; |
| 37 | protected const COLUMN_EVENT_ID = 'event_id'; |
| 38 | protected const COLUMN_TASK_ID = 'task_id'; |
| 39 | protected const COLUMN_WEBHOOK_ID = 'webhook_id'; |
| 40 | protected const COLUMN_HTTP_METHOD = 'http_method'; |
| 41 | protected const COLUMN_ENDPOINT_URL = 'endpoint_url'; |
| 42 | protected const COLUMN_EVENT_NAME = 'event_name'; |
| 43 | protected const COLUMN_HTTP_STATUS_CODE = 'http_status_code'; |
| 44 | protected const COLUMN_RESPONSE_BODY = 'response_body'; |
| 45 | protected const COLUMN_ACKNOWLEDGEMENT_STATUS = 'acknowledgement_status'; |
| 46 | protected const COLUMN_CREATED_AT = 'created_at'; |
| 47 | protected const COLUMN_RESULT = 'result'; |
| 48 | protected const COLUMN_RESULT_MESSAGE = 'result_message'; |
| 49 | |
| 50 | /** |
| 51 | * @throws InconsistencyConfigException |
| 52 | */ |
| 53 | protected function getPersistence(): common_persistence_SqlPersistence |
| 54 | { |
| 55 | if (!$this->persistence) { |
| 56 | $persistenceId = $this->getOption(self::OPTION_PERSISTENCE) ?: 'default'; |
| 57 | /** @var PersistenceManager $persistenceManager */ |
| 58 | $persistenceManager = $this->getServiceLocator()->get(PersistenceManager::SERVICE_ID); |
| 59 | $persistence = $persistenceManager->getPersistenceById($persistenceId); |
| 60 | if (!$persistence instanceof common_persistence_SqlPersistence) { |
| 61 | throw new InconsistencyConfigException( |
| 62 | "Configured persistence '$persistenceId' is not sql persistence" |
| 63 | ); |
| 64 | } |
| 65 | $this->persistence = $persistence; |
| 66 | } |
| 67 | return $this->persistence; |
| 68 | } |
| 69 | } |