Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 31 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| CleanupUploadTmp | |
0.00% |
0 / 31 |
|
0.00% |
0 / 1 |
20 | |
0.00% |
0 / 1 |
| __invoke | |
0.00% |
0 / 31 |
|
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) 2015 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT); |
| 19 | * |
| 20 | */ |
| 21 | |
| 22 | namespace oat\tao\model\upload; |
| 23 | |
| 24 | use oat\oatbox\filesystem\Directory; |
| 25 | use oat\oatbox\filesystem\File; |
| 26 | use oat\oatbox\filesystem\FileSystemService; |
| 27 | use oat\oatbox\service\ConfigurableService; |
| 28 | use oat\oatbox\action\Action; |
| 29 | |
| 30 | /** |
| 31 | * Remove all stored at tmp space files |
| 32 | * |
| 33 | */ |
| 34 | class CleanupUploadTmp extends ConfigurableService implements Action |
| 35 | { |
| 36 | /** |
| 37 | * @param array $params |
| 38 | * @return \common_report_Report |
| 39 | */ |
| 40 | public function __invoke($params) |
| 41 | { |
| 42 | |
| 43 | /** @var UploadService $uploadService */ |
| 44 | $tmpSpaceFlySystemId = $this->getServiceManager()->get(UploadService::SERVICE_ID)->getUploadFSid(); |
| 45 | |
| 46 | $fs = $this->getServiceManager()->get(FileSystemService::SERVICE_ID)->getFileSystem($tmpSpaceFlySystemId); |
| 47 | $report = new \common_report_Report(\common_report_Report::TYPE_INFO, __('Cleaning up tmp space started')); |
| 48 | $files = 0; |
| 49 | $dirs = 0; |
| 50 | foreach ($fs->listContents() as $fileInfo) { |
| 51 | if ('file' === $fileInfo['type']) { |
| 52 | $file = new File($tmpSpaceFlySystemId, $fileInfo['path']); |
| 53 | $file->setServiceLocator($this->getServiceManager()); |
| 54 | $file->delete(); |
| 55 | $files++; |
| 56 | } |
| 57 | if ('dir' === $fileInfo['type']) { |
| 58 | $dir = new Directory($tmpSpaceFlySystemId, $fileInfo['path']); |
| 59 | $dir->setServiceLocator($this->getServiceManager()); |
| 60 | $dir->deleteSelf(); |
| 61 | $dirs++; |
| 62 | } |
| 63 | |
| 64 | $report->add(new \common_report_Report( |
| 65 | \common_report_Report::TYPE_SUCCESS, |
| 66 | __('Removing: %s', $fileInfo['path']) |
| 67 | )); |
| 68 | } |
| 69 | |
| 70 | $report->add(new \common_report_Report(\common_report_Report::TYPE_SUCCESS, __('Total:'))); |
| 71 | $report->add(new \common_report_Report(\common_report_Report::TYPE_SUCCESS, __('Removed %s files', $files))); |
| 72 | $report->add(new \common_report_Report( |
| 73 | \common_report_Report::TYPE_SUCCESS, |
| 74 | __('Removed %s directories', $dirs) |
| 75 | )); |
| 76 | |
| 77 | $report->add(new \common_report_Report( |
| 78 | \common_report_Report::TYPE_SUCCESS, |
| 79 | __('Cleaning up tmp space complete') |
| 80 | )); |
| 81 | |
| 82 | return $report; |
| 83 | } |
| 84 | } |