ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilExerciseSampleSolutionMigration.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
21 
26 
28 {
29  protected \ilResourceStorageMigrationHelper $helper;
30 
31  public function getLabel(): string
32  {
33  return "Migration of exercise sample solutions to the resource storage service.";
34  }
35 
37  {
38  return 1000;
39  }
40 
41  public function getPreconditions(Environment $environment): array
42  {
43  return \ilResourceStorageMigrationHelper::getPreconditions();
44  }
45 
46  public function prepare(Environment $environment): void
47  {
48  $this->helper = new \ilResourceStorageMigrationHelper(
50  $environment
51  );
52  }
53 
54  public function step(Environment $environment): void
55  {
56  $r = $this->helper->getDatabase()->query(
57  "SELECT id, exc_id, owner FROM exc_assignment JOIN object_data ON exc_id = obj_id WHERE solution_rid IS NULL LIMIT 1;"
58  );
59  $d = $this->helper->getDatabase()->fetchObject($r);
60  if (!($d instanceof stdClass)) {
61  return;
62  }
63 
64  $exec_id = (int)$d->exc_id;
65  $assignment_id = (int)$d->id;
66  $resource_owner_id = (int)$d->owner;
67  $base_path = $this->buildAbsolutPath($exec_id, $assignment_id);
68  $pattern = '/[^\.].*/m';
69  $rid = "";
70  if (is_dir($base_path)) {
71  $rid = $this->helper->moveFirstFileOfPatternToStorage(
72  $base_path,
73  $pattern,
74  $resource_owner_id
75  );
76  }
77  $this->helper->getDatabase()->update(
78  'exc_assignment',
79  [
80  'solution_rid' => ['text', (string) $rid]
81  ],
82  [
83  'id' => ['integer', $assignment_id],
84  'exc_id' => ['integer', $exec_id]
85  ]
86  );
87  }
88 
89  public function getRemainingAmountOfSteps(): int
90  {
91  $r = $this->helper->getDatabase()->query(
92  "SELECT count(id) AS amount FROM exc_assignment JOIN object_data ON exc_id = obj_id WHERE solution_rid IS NULL"
93  );
94  $d = $this->helper->getDatabase()->fetchObject($r);
95 
96  return (int)$d->amount;
97  }
98 
99  protected function buildAbsolutPath(int $exec_id, int $assignment_id): string
100  {
101  return CLIENT_DATA_DIR
102  . '/ilExercise/'
104  $exec_id,
105  "exc"
106  ) . "/feedb_$assignment_id/0";
107  }
108 }
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
const CLIENT_DATA_DIR
Definition: constants.php:46
static createPathFromId(int $a_container_id, string $a_name)
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.
getPreconditions(Environment $environment)
Objectives the migration depend on.
step(Environment $environment)
Run one step of the migration.
$r