ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilExerciseTutorTeamFeedbackFileMigration.php
Go to the documentation of this file.
1 <?php
2 
19 declare(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  $r = $this->helper->getDatabase()->query(
58  "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;"
59  );
60  $d = $this->helper->getDatabase()->fetchObject($r);
61  if (!($d instanceof stdClass)) {
62  return;
63  }
64 
65  $exec_id = (int)$d->exc_id;
66  $assignment_id = (int)$d->id;
67  $resource_owner_id = (int)$d->owner;
68  $team_id = (int)$d->team_id;
69  $base_path = $this->buildAbsolutPath($exec_id, $assignment_id, $team_id);
70  if (is_dir($base_path)) {
71  $collection_id = $this->helper->moveFilesOfPathToCollection(
72  $base_path,
73  $resource_owner_id
74  );
75  } else {
76  $collection = $this->helper->getCollectionBuilder()->new($resource_owner_id);
77  if ($this->helper->getCollectionBuilder()->store($collection)) {
78  $collection_id = $collection->getIdentification()->serialize();
79  } else {
80  throw new ilException("Could not build collection");
81  }
82  }
83  $this->helper->getDatabase()->update(
84  'exc_team_data',
85  [
86  'feedback_rcid' => ['text', $collection_id]
87  ],
88  [
89  'id' => ['integer', $team_id]
90  ]
91  );
92  }
93 
94  public function getRemainingAmountOfSteps(): int
95  {
96  $r = $this->helper->getDatabase()->query(
97  "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 = ''"
98  );
99  $d = $this->helper->getDatabase()->fetchObject($r);
100 
101  return (int)$d->amount;
102  }
103 
104  protected function buildAbsolutPath(int $exec_id, int $assignment_id, int $user_id): string
105  {
106  return CLIENT_DATA_DIR
107  . '/ilExercise/'
109  $exec_id,
110  "exc"
111  ) . "/feedb_$assignment_id/$user_id";
112  }
113 }
getPreconditions(Environment $environment)
Objectives the migration depend on.
getDefaultAmountOfStepsPerRun()
Tell the default amount of steps to be executed for one run of the migration.
A migration is a potentially long lasting operation that can be broken into discrete steps...
Definition: Migration.php:28
step(Environment $environment)
Run one step of the migration.
const CLIENT_DATA_DIR
Definition: constants.php:46
static createPathFromId(int $a_container_id, string $a_name)
buildAbsolutPath(int $exec_id, int $assignment_id, int $user_id)
getRemainingAmountOfSteps()
Count up how many "things" need to be migrated.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
An environment holds resources to be used in the setup process.
Definition: Environment.php:27
prepare(Environment $environment)
Prepare the migration by means of some environment.
$r