Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
36 / 36 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| RdsNotificationService | |
100.00% |
36 / 36 |
|
100.00% |
2 / 2 |
2 | |
100.00% |
1 / 1 |
| prepareNotification | |
100.00% |
11 / 11 |
|
100.00% |
1 / 1 |
1 | |||
| provideSchema | |
100.00% |
25 / 25 |
|
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) 2020 (original work) Open Assessment Technologies SA; |
| 19 | * |
| 20 | */ |
| 21 | |
| 22 | namespace oat\tao\model\notification\implementation; |
| 23 | |
| 24 | use common_exception_InconsistentData; |
| 25 | use common_persistence_SqlPersistence; |
| 26 | use Doctrine\DBAL\Platforms\AbstractPlatform; |
| 27 | use oat\generis\persistence\sql\SchemaCollection; |
| 28 | use oat\tao\model\notification\Notification; |
| 29 | |
| 30 | /** |
| 31 | * Class RdsNotificationService |
| 32 | * |
| 33 | * @deprecated This class is used by client only. It will be moved to client specific extension |
| 34 | */ |
| 35 | class RdsNotificationService extends AbstractSqlNotificationService |
| 36 | { |
| 37 | /** |
| 38 | * @param Notification $notification |
| 39 | * |
| 40 | * @return array |
| 41 | */ |
| 42 | protected function prepareNotification(Notification $notification): array |
| 43 | { |
| 44 | /** @var AbstractPlatform $platform */ |
| 45 | $platform = $this->getPersistence()->getPlatForm(); |
| 46 | return [ |
| 47 | self::NOTIFICATION_FIELD_RECIPIENT => $notification->getRecipient(), |
| 48 | self::NOTIFICATION_FIELD_STATUS => $notification->getStatus(), |
| 49 | self::NOTIFICATION_FIELD_SENDER => $notification->getSenderId(), |
| 50 | self::NOTIFICATION_FIELD_SENDER_NAME => $notification->getSenderName(), |
| 51 | self::NOTIFICATION_FIELD_TITLE => $notification->getTitle(), |
| 52 | self::NOTIFICATION_FIELD_MESSAGE => $notification->getMessage(), |
| 53 | self::NOTIFICATION_FIELD_CREATION => $platform->getNowExpression(), |
| 54 | self::NOTIFICATION_FIELD_UPDATED => $platform->getNowExpression(), |
| 55 | ]; |
| 56 | } |
| 57 | |
| 58 | /** |
| 59 | * Allows a class to adapt the schemas as required |
| 60 | * |
| 61 | * @param SchemaCollection $schemaCollection |
| 62 | * |
| 63 | * @throws common_exception_InconsistentData |
| 64 | */ |
| 65 | public function provideSchema(SchemaCollection $schemaCollection): void |
| 66 | { |
| 67 | $schema = $schemaCollection->getSchema($this->getOption(self::OPTION_PERSISTENCE)); |
| 68 | $queueTable = $schema->createTable(self::NOTIFICATION_TABLE); |
| 69 | |
| 70 | $queueTable->addOption('engine', 'MyISAM'); |
| 71 | $queueTable->addColumn(self::NOTIFICATION_FIELD_ID, 'integer', ['notnull' => true, 'autoincrement' => true]); |
| 72 | $queueTable->addColumn(self::NOTIFICATION_FIELD_RECIPIENT, 'string', ['notnull' => true, 'length' => 255]); |
| 73 | $queueTable->addColumn( |
| 74 | self::NOTIFICATION_FIELD_STATUS, |
| 75 | 'integer', |
| 76 | ['default' => 0, 'notnull' => false, 'length' => 255] |
| 77 | ); |
| 78 | $queueTable->addColumn(self::NOTIFICATION_FIELD_TITLE, 'string', ['length' => 255]); |
| 79 | $queueTable->addColumn(self::NOTIFICATION_FIELD_MESSAGE, 'text', ['default' => null]); |
| 80 | $queueTable->addColumn( |
| 81 | self::NOTIFICATION_FIELD_SENDER, |
| 82 | 'string', |
| 83 | ['default' => null, 'notnull' => false, 'length' => 255] |
| 84 | ); |
| 85 | $queueTable->addColumn( |
| 86 | self::NOTIFICATION_FIELD_SENDER_NAME, |
| 87 | 'string', |
| 88 | ['default' => null, 'notnull' => false, 'length' => 255] |
| 89 | ); |
| 90 | $queueTable->addColumn(self::NOTIFICATION_FIELD_CREATION, 'datetime', ['notnull' => true]); |
| 91 | $queueTable->addColumn(self::NOTIFICATION_FIELD_UPDATED, 'datetime', ['notnull' => true]); |
| 92 | $queueTable->setPrimaryKey([self::NOTIFICATION_FIELD_ID]); |
| 93 | } |
| 94 | } |