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