ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilExerciseInstructionFilesMigration.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21//namespace ILIAS\Exercise\Setup;
22
27
32{
33 protected \ilResourceStorageMigrationHelper $helper;
34
35 public function getLabel(): string
36 {
37 return "Migration of exercise instructions files to the resource storage service.";
38 }
39
41 {
42 return 1000;
43 }
44
45 public function getPreconditions(Environment $environment): array
46 {
47 return \ilResourceStorageMigrationHelper::getPreconditions();
48 }
49
50 public function prepare(Environment $environment): void
51 {
52 $this->helper = new \ilResourceStorageMigrationHelper(
54 $environment
55 );
56 }
57
58 public function step(Environment $environment): void
59 {
60 $db = $this->helper->getDatabase();
61 $r = $this->helper->getDatabase()->query(
62 "SELECT id, exc_id, owner FROM exc_assignment JOIN object_data ON exc_id = obj_id WHERE if_rcid IS NULL OR if_rcid = '' LIMIT 1;"
63 );
64 $d = $this->helper->getDatabase()->fetchObject($r);
65 $exec_id = (int) $d->exc_id;
66 $assignment_id = (int) $d->id;
67 $resource_owner_id = (int) $d->owner;
68 $base_path = $this->buildAbsolutPath($exec_id, $assignment_id);
69 if (is_dir($base_path)) {
70 $collection_id = $this->helper->moveFilesOfPathToCollection(
71 $base_path,
72 $resource_owner_id
73 );
74 } else {
75 $collection = $this->helper->getCollectionBuilder()->new($resource_owner_id);
76 if ($this->helper->getCollectionBuilder()->store($collection)) {
77 $collection_id = $collection->getIdentification()->serialize();
78 } else {
79 throw new ilException("Could not build collection");
80 }
81 }
82
83 $this->helper->getDatabase()->update(
84 'exc_assignment',
85 [
86 'if_rcid' => ['text', $collection_id]
87 ],
88 [
89 'id' => ['integer', $assignment_id],
90 'exc_id' => ['integer', $exec_id]
91 ]
92 );
93 }
94
95 public function getRemainingAmountOfSteps(): int
96 {
97 $r = $this->helper->getDatabase()->query(
98 "SELECT count(id) AS amount FROM exc_assignment JOIN object_data ON exc_id = obj_id WHERE if_rcid IS NULL OR if_rcid = ''"
99 );
100 $d = $this->helper->getDatabase()->fetchObject($r);
101
102 return (int) $d->amount;
103 }
104
105 protected function buildAbsolutPath(int $exec_id, int $assignment_id): string
106 {
107 return CLIENT_WEB_DIR
108 . '/ilExercise/'
110 $exec_id,
111 "exc"
112 ) . "/ass_$assignment_id";
113 }
114}
Base class for ILIAS Exception handling.
getRemainingAmountOfSteps()
Count up how many "things" need to be migrated.
getPreconditions(Environment $environment)
Objectives the migration depend on.
prepare(Environment $environment)
Prepare the migration by means of some environment.
getDefaultAmountOfStepsPerRun()
Tell the default amount of steps to be executed for one run of the migration.
step(Environment $environment)
Run one step of the migration.
static createPathFromId(int $a_container_id, string $a_name)
const CLIENT_WEB_DIR
Definition: constants.php:47
An environment holds resources to be used in the setup process.
Definition: Environment.php:28
A migration is a potentially long lasting operation that can be broken into discrete steps.
Definition: Migration.php:29