ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilExerciseTutorTeamFeedbackFileMigration.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 team 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, te.id team_id FROM exc_assignment ass JOIN object_data ob ON ass.exc_id = ob.obj_id JOIN il_exc_team te ON te.ass_id = ass.id JOIN exc_team_data td ON te.id = td.id WHERE td.feedback_rcid IS NULL OR td.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 $team_id = (int) $d->team_id;
66 $base_path = $this->buildAbsolutPath($exec_id, $assignment_id, $team_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_team_data',
82 [
83 'feedback_rcid' => ['text', $collection_id]
84 ],
85 [
86 'id' => ['integer', $team_id]
87 ]
88 );
89 }
90
91 public function getRemainingAmountOfSteps(): int
92 {
93 $r = $this->helper->getDatabase()->query(
94 "SELECT count(*) AS amount FROM exc_assignment ass JOIN object_data ob ON ass.exc_id = ob.obj_id JOIN il_exc_team te ON te.ass_id = ass.id JOIN exc_team_data td ON te.id = td.id WHERE td.feedback_rcid IS NULL OR td.feedback_rcid = ''"
95 );
96 $d = $this->helper->getDatabase()->fetchObject($r);
97
98 return (int) $d->amount;
99 }
100
101 protected function buildAbsolutPath(int $exec_id, int $assignment_id, int $user_id): string
102 {
103 return CLIENT_DATA_DIR
104 . '/ilExercise/'
106 $exec_id,
107 "exc"
108 ) . "/feedb_$assignment_id/$user_id";
109 }
110}
Base class for ILIAS Exception handling.
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.
getPreconditions(Environment $environment)
Objectives the migration depend on.
getRemainingAmountOfSteps()
Count up how many "things" need to be migrated.
buildAbsolutPath(int $exec_id, int $assignment_id, int $user_id)
step(Environment $environment)
Run one step of the migration.
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