ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilExportImportDirectory.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
4
6
14{
15 private const PATH_PREFIX = 'export';
16
20 protected function getPathPrefix() : string
21 {
22 return self::PATH_PREFIX;
23 }
24
29 public function hasFilesFor(int $user_id, string $type) : bool
30 {
31 return (bool) count($this->getFilesFor($user_id, $type));
32 }
33
39 public function getFilesFor(int $user_id, string $type) : array
40 {
41 if (!$this->exists()) {
42 return [];
43 }
44 $finder = $this->storage->finder()
45 ->in([$this->getRelativePath()])
46 ->files()
47 ->depth('< 1')
48 ->sortByName();
49 $files = [];
50 foreach ($finder as $file) {
51 $basename = basename($file->getPath());
52 if ($this->matchesType($type, $basename)) {
53 $files[base64_encode($file->getPath())] = $basename;
54 }
55 }
56 if ($this->storage->hasDir($this->getRelativePath() . '/' . (string) $user_id)) {
57 $finder = $this->storage->finder()->in([$this->getRelativePath() . '/' . (string) $user_id])
58 ->depth('< 1')
59 ->files()
60 ->sortByName();
61 foreach ($finder as $file) {
62 $basename = basename($file->getPath());
63 if ($this->matchesType($type, $basename)) {
64 $files[base64_encode($file->getPath())] = $basename;
65 }
66 }
67 }
68 asort($files);
69 return $files;
70 }
71
77 protected function matchesType(string $type, string $filename) : bool
78 {
79 $matches = [];
80 $result = preg_match('/[0-9]{10}__[0-9]{1,6}__([a-z]{1,4})_[0-9]{2,9}.zip/', $filename, $matches);
81 if (!$result) {
82 return false;
83 }
84 if (isset($matches[1]) && $matches[1] == $type) {
85 return true;
86 }
87 return false;
88 }
89
96 public function getAbsolutePathForHash(int $user_id, string $type, string $post_hash) : string
97 {
98 foreach ($this->getFilesFor($user_id, $type) as $hash => $file) {
99 if (strcmp($hash, $post_hash) === 0) {
100 $file_path = base64_decode($hash);
101 return ilUtil::getDataDir() . '/' . base64_decode($hash);
102 }
103 }
104 return '';
105 }
106}
$result
$filename
Definition: buildRTE.php:89
An exception for terminatinating execution or to throw for unit testing.
getAbsolutePathForHash(int $user_id, string $type, string $post_hash)
matchesType(string $type, string $filename)
Check if filename matches a given type.
hasFilesFor(int $user_id, string $type)
getFilesFor(int $user_id, string $type)
static getDataDir()
get data directory (outside webspace)
Interface Filesystem The filesystem interface provides the public interface for the Filesystem servic...
Definition: Filesystem.php:22
$type