ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilExerciseTutorFeedbackFileMigration.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 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, 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;"
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  $user_id = (int)$d->usr_id;
69  $base_path = $this->buildAbsolutPath($exec_id, $assignment_id, $user_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_mem_ass_status',
85  [
86  'feedback_rcid' => ['text', $collection_id]
87  ],
88  [
89  'ass_id' => ['integer', $assignment_id],
90  'usr_id' => ['integer', $user_id]
91  ]
92  );
93  }
94 
95  public function getRemainingAmountOfSteps(): int
96  {
97  $r = $this->helper->getDatabase()->query(
98  "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 = ''"
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, int $user_id): string
106  {
107  return CLIENT_DATA_DIR
108  . '/ilExercise/'
110  $exec_id,
111  "exc"
112  ) . "/feedb_$assignment_id/$user_id";
113  }
114 }
step(Environment $environment)
Run one step of the migration.
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
buildAbsolutPath(int $exec_id, int $assignment_id, int $user_id)
getRemainingAmountOfSteps()
Count up how many "things" need to be migrated.
const CLIENT_DATA_DIR
Definition: constants.php:46
getPreconditions(Environment $environment)
Objectives the migration depend on.
static createPathFromId(int $a_container_id, string $a_name)
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