19declare(strict_types=1);
32use Sabre\DAV\Exception\Forbidden;
50 $this->stakeholder = new \ilObjFileStakeholder();
61 return $this->
manager ?? $this->
manager = $DIC->resourceStorage()->manage();
66 return $this->file_info_repository ?? $this->file_info_repository = new \ilObjFileInfoRepository();
71 if (!$this->
filter->checkName($name)) {
75 if (!$this->
filter->canUserIn(Action::WRITE, $parent)) {
79 $object = match ($type) {
80 Type::COURSE => new \ilObjCourse(),
81 Type::GROUP => new \ilObjGroup(),
82 Type::FOLDER => new \ilObjFolder(),
83 Type::CATEGORY => new \ilObjCategory(),
84 Type::FILE => new \ilObjFile(),
88 if (!$this->
filter->canUserCreate($type, $parent)) {
92 if ($object ===
null) {
93 throw new \InvalidArgumentException(
94 "Cannot create object of type {$type->name}"
98 $object->setTitle($name);
100 if ($type === Type::FILE) {
101 $rid = $this->
manager()->stream(
107 $object->setResourceId($rid->serialize());
114 $object->createReference();
118 $proxy = $this->
getByRefId($object->getRefId(), $type);
119 if ($proxy ===
null || !$this->
filter->filterProxy($proxy)) {
127 if (!$this->
filter->checkName($name)) {
130 if (($proxy = $this->
get($name, $parent,
true)) !==
null && $proxy->getType() === Type::FILE) {
152 $new_type = match ($parent_type) {
153 Type::COURSE, Type::GROUP, Type::FOLDER => Type::FOLDER,
154 Type::CATEGORY => Type::CATEGORY,
172 bool $with_recently_deleted =
false,
174 if (!$this->
filter->checkName($path)) {
181 if ($parent !==
null) {
182 foreach ($this->
in($parent, $with_recently_deleted) as $proxy) {
183 if (!$this->
filter->filterProxy($proxy)) {
187 if ($proxy->getName() ===
$path) {
194 if (!str_starts_with(
$path, $this->config->getRefIdPrefix())) {
197 $ref_id = (
int) substr(
$path, strlen($this->config->getRefIdPrefix()));
203 if ($proxy ===
null || !$this->
filter->filterProxy($proxy)) {
211 $ref_id = $node_data[
'ref_id'] ?? 0;
216 if (isset($this->storage[
$ref_id])) {
217 return $this->storage[
$ref_id];
220 $type ??= Type::tryFrom($node_data[
'type'] ??
'') ??
Type::UNKNOWN;
222 $stream_resolver =
null;
225 $title = $node_data[
'title'] ??
'$';
226 if (!$this->
filter->checkName($title)) {
230 if ($type === Type::FILE) {
232 $infos = $this->
info()->getByRefId((
int) $node_data[
'ref_id']);
237 $node_data[
'obj_id'] ?? 0,
239 strtotime($node_data[
'last_update'] ??
'') ?: 0,
240 $infos?->getMimeType(),
241 (
int) $infos?->getFileSize()->inBytes(),
244 if (!$this->
filter->filterProxy($file_tree_proxy)) {
248 return $this->storage[
$ref_id] = $file_tree_proxy;
253 $node_data[
'obj_id'] ?? 0,
255 strtotime($node_data[
'last_update'] ??
'') ?: 0,
259 if (!$this->
filter->filterProxy($tree_proxy)) {
263 return $this->storage[
$ref_id] = $tree_proxy;
269 $this->
tree()->getNodeData($by_ref_id),
289 $info_name_collision =
false;
292 'duplicates' => $duplicates,
293 'forbidden' => $forbidden,
294 'info_name_collision' => $info_name_collision,
298 $object_types = $this->config->getSupportedObjectTypes();
300 foreach ($this->
tree()->getChildsByTypeFilter(
$ref_id, $object_types) as $item) {
301 $title = (string) ($item[
'title'] ??
'');
306 $info_name_collision =
true;
309 if (!$this->
filter->checkName($title)) {
310 $forbidden[] = $title;
313 if (isset($seen[$title])) {
314 $duplicates[] = $title;
317 $seen[$title] =
true;
321 'duplicates' => $duplicates,
322 'forbidden' => $forbidden,
323 'info_name_collision' => $info_name_collision,
334 $object_types = $this->config->getSupportedObjectTypes();
337 $this->
tree()->getChildsByTypeFilter(
$ref_id, $object_types) as $item
340 if (!$this->
filter->checkName($item[
'title'] ??
'$')) {
345 if ($proxy ===
null) {
348 if (!$this->
filter->filterProxy($proxy)) {
355 if ($with_recently_deleted) {
356 foreach ($this->
tree()->getSavedNodeData(
$ref_id) as $saved_node) {
357 if (Type::tryFrom($saved_node[
'type'] ??
'') !== Type::FILE) {
361 $deleted = new \DateTimeImmutable($saved_node[
'deleted'] ??
'now');
363 $threshold = (new \DateTimeImmutable())->modify(
364 "-{$this->config->getDeletedObjectsRetentionPeriod()} seconds"
366 if ($deleted < $threshold) {
371 if ($proxy ===
null) {
374 if (!$this->
filter->filterProxy($proxy)) {
388 if (!$this->
filter->checkName($entity->getName())) {
392 if (!$this->
filter->canUserFor(Action::WRITE, $entity)) {
397 $object->setTitle($entity->getName());
403 public function delete(
Entity $entity):
bool
405 $ref_id = $entity->getObjectProxy()?->getRefId();
415 $DIC->repository()->internal()->domain()->deletion()->deleteObjectsByRefIds([
$ref_id]);
Stream factory which enables the user to create streams without the knowledge of the concrete class.
static ofString(string $string)
Creates a new stream with an initial value.
Virtual text file shown in every container that lists ILIAS objects which cannot be exposed via WebDA...
ResourceStakeholder $stakeholder
ilObjFileInfoRepository $file_info_repository
getByNodeData(array $node_data, ?Type $type=null)
__construct(private Config $config, private Filter $filter)
createObject(Type $type, Container $parent, string $name)
in(Container $container, bool $with_recently_deleted=false)
getByRefId(int $by_ref_id, ?Type $type=null)
analyseProblems(Container $container)
Inspect raw children of a container and report titles that cannot be exposed via WebDAV.
createContainer(Container $parent, string $name)
createFile(Container $parent, string $name)
static getInstanceByRefId(int $ref_id, bool $stop_on_error=true)
get an instance of an Ilias object by reference id
static restoreObjects(int $a_cur_ref_id, array $a_ref_ids)
Move objects from trash back to repository.
Tree class data representation in hierachical trees using the Nested Set Model with Gaps by Joe Celco...
Interface ResourceStakeholder.
filter(string $filter_id, array $class_path, string $cmd, bool $activated=true, bool $expanded=true)