Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 11 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| FileSink | |
0.00% |
0 / 11 |
|
0.00% |
0 / 2 |
30 | |
0.00% |
0 / 1 |
| send | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
| getFilePath | |
0.00% |
0 / 7 |
|
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) 2008-2010 (original work) Deutsche Institut für Internationale Pädagogische Forschung |
| 19 | * (under the project TAO-TRANSFER); |
| 20 | * 2009-2012 (update and modification) Public Research Centre Henri Tudor |
| 21 | * (under the project TAO-SUSTAIN & TAO-DEV); |
| 22 | * 2013 (update and modification) Open Assessment Technologies SA (under the project TAO-PRODUCT); |
| 23 | * |
| 24 | */ |
| 25 | |
| 26 | namespace oat\tao\model\messaging\transportStrategy; |
| 27 | |
| 28 | use oat\oatbox\service\ConfigurableService; |
| 29 | use oat\tao\model\messaging\Transport; |
| 30 | use oat\tao\model\messaging\Message; |
| 31 | use oat\oatbox\user\User; |
| 32 | |
| 33 | /** |
| 34 | * An implementation that writes the messages to the filesystem |
| 35 | * |
| 36 | * @access public |
| 37 | * @author Bertrand Chevrier, <bertrand.chevrier@tudor.lu> |
| 38 | * @package tao |
| 39 | */ |
| 40 | class FileSink extends ConfigurableService implements Transport |
| 41 | { |
| 42 | public const CONFIG_FILEPATH = 'path'; |
| 43 | |
| 44 | public function send(Message $message) |
| 45 | { |
| 46 | $messageFile = $this->getFilePath($message->getTo()); |
| 47 | \common_Logger::d('Wrote message to ' . $messageFile); |
| 48 | $written = file_put_contents($messageFile, $message->getBody()); |
| 49 | return $written !== false; |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * Get file path to save message |
| 54 | * @param User $receiver |
| 55 | * @param boolean $refresh whether the file path must be regenerated. |
| 56 | */ |
| 57 | public function getFilePath(User $receiver) |
| 58 | { |
| 59 | $basePath = $this->getOption(self::CONFIG_FILEPATH); |
| 60 | if (is_null($basePath) || !file_exists($basePath)) { |
| 61 | throw new \common_exception_InconsistentData('Missing path ' . self::CONFIG_FILEPATH . ' for ' . __CLASS__); |
| 62 | } |
| 63 | $path = $basePath . \tao_helpers_File::getSafeFileName($receiver->getIdentifier()) . DIRECTORY_SEPARATOR; |
| 64 | if (!file_exists($path)) { |
| 65 | mkdir($path); |
| 66 | } |
| 67 | return $path . \tao_helpers_File::getSafeFileName('message.html', $path); |
| 68 | } |
| 69 | } |