ILIAS  release_8 Revision v8.24
class.ilAdvancedMDRecordImportFiles.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4/*
5 +-----------------------------------------------------------------------------+
6 | ILIAS open source |
7 +-----------------------------------------------------------------------------+
8 | Copyright (c) 1998-2006 ILIAS open source, University of Cologne |
9 | |
10 | This program is free software; you can redistribute it and/or |
11 | modify it under the terms of the GNU General Public License |
12 | as published by the Free Software Foundation; either version 2 |
13 | of the License, or (at your option) any later version. |
14 | |
15 | This program is distributed in the hope that it will be useful, |
16 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
18 | GNU General Public License for more details. |
19 | |
20 | You should have received a copy of the GNU General Public License |
21 | along with this program; if not, write to the Free Software |
22 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
23 +-----------------------------------------------------------------------------+
24*/
25
32{
33 public const IMPORT_NAME = 'ilias_adv_md_record';
34
35 private string $import_dir = '';
36
37 public function __construct()
38 {
39 $this->import_dir = ilFileUtils::getDataDir() . '/ilAdvancedMetaData/import';
40 $this->init();
41 }
42
43 public function getImportDirectory(): string
44 {
45 return $this->import_dir;
46 }
47
53 public function getImportFileByCreationDate(int $a_unix_time): string
54 {
55 $unix_time = $a_unix_time;
56 return $this->getImportDirectory() . '/' . self::IMPORT_NAME . '_' . $unix_time . '.xml';
57 }
58
63 public function deleteFileByCreationDate(int $a_unix_time): bool
64 {
65 $unix_time = $a_unix_time;
66 return unlink($this->getImportDirectory() . '/' . self::IMPORT_NAME . '_' . $unix_time . '.xml');
67 }
68
75 public function moveUploadedFile(string $a_temp_name): int
76 {
77 $creation_time = time();
78 $file_name = $this->getImportDirectory() . '/' . self::IMPORT_NAME . '_' . $creation_time . '.xml';
79
80 if (!ilFileUtils::moveUploadedFile($a_temp_name, '', $file_name, false)) {
81 return 0;
82 }
83 return $creation_time;
84 }
85
89 private function init(): void
90 {
91 if (!is_dir($this->import_dir)) {
92 ilFileUtils::makeDirParents($this->import_dir);
93 }
94 }
95}
getImportFileByCreationDate(int $a_unix_time)
Get import file by creation date.
init()
init function: create import directory, delete old files
moveUploadedFile(string $a_temp_name)
move uploaded files @access public
deleteFileByCreationDate(int $a_unix_time)
Delete a file.
static makeDirParents(string $a_dir)
Create a new directory and all parent directories.
static getDataDir()
get data directory (outside webspace)
static moveUploadedFile(string $a_file, string $a_name, string $a_target, bool $a_raise_errors=true, string $a_mode="move_uploaded")
move uploaded file