ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilExerciseInstructionFilesMigration.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
21 //namespace ILIAS\Exercise\Setup;
22 
27 
32 {
33  protected \ilResourceStorageMigrationHelper $helper;
34 
35  public function getLabel(): string
36  {
37  return "Migration of exercise instructions files to the resource storage service.";
38  }
39 
41  {
42  return 1000;
43  }
44 
45  public function getPreconditions(Environment $environment): array
46  {
47  return \ilResourceStorageMigrationHelper::getPreconditions();
48  }
49 
50  public function prepare(Environment $environment): void
51  {
52  $this->helper = new \ilResourceStorageMigrationHelper(
54  $environment
55  );
56  }
57 
58  public function step(Environment $environment): void
59  {
60  $r = $this->helper->getDatabase()->query(
61  "SELECT id, exc_id, owner FROM exc_assignment JOIN object_data ON exc_id = obj_id WHERE if_rcid IS NULL OR if_rcid = '' LIMIT 1;"
62  );
63  $d = $this->helper->getDatabase()->fetchObject($r);
64  if (!($d instanceof stdClass)) {
65  return;
66  }
67 
68  $exec_id = (int)$d->exc_id;
69  $assignment_id = (int)$d->id;
70  $resource_owner_id = (int)$d->owner;
71  $base_path = $this->buildAbsolutPath($exec_id, $assignment_id);
72  if (is_dir($base_path)) {
73  $collection_id = $this->helper->moveFilesOfPathToCollection(
74  $base_path,
75  $resource_owner_id
76  );
77  } else {
78  $collection = $this->helper->getCollectionBuilder()->new($resource_owner_id);
79  if ($this->helper->getCollectionBuilder()->store($collection)) {
80  $collection_id = $collection->getIdentification()->serialize();
81  } else {
82  throw new ilException("Could not build collection");
83  }
84  }
85 
86  $this->helper->getDatabase()->update(
87  'exc_assignment',
88  [
89  'if_rcid' => ['text', $collection_id]
90  ],
91  [
92  'id' => ['integer', $assignment_id],
93  'exc_id' => ['integer', $exec_id]
94  ]
95  );
96  }
97 
98  public function getRemainingAmountOfSteps(): int
99  {
100  $r = $this->helper->getDatabase()->query(
101  "SELECT count(id) AS amount FROM exc_assignment JOIN object_data ON exc_id = obj_id WHERE if_rcid IS NULL OR if_rcid = ''"
102  );
103  $d = $this->helper->getDatabase()->fetchObject($r);
104 
105  return (int)$d->amount;
106  }
107 
108  protected function buildAbsolutPath(int $exec_id, int $assignment_id): string
109  {
110  return CLIENT_WEB_DIR
111  . '/ilExercise/'
113  $exec_id,
114  "exc"
115  ) . "/ass_$assignment_id";
116  }
117 }
getPreconditions(Environment $environment)
Objectives the migration depend on.
A migration is a potentially long lasting operation that can be broken into discrete steps...
Definition: Migration.php:28
prepare(Environment $environment)
Prepare the migration by means of some environment.
step(Environment $environment)
Run one step of the migration.
static createPathFromId(int $a_container_id, string $a_name)
getRemainingAmountOfSteps()
Count up how many "things" need to be migrated.
const CLIENT_WEB_DIR
Definition: constants.php:47
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
getDefaultAmountOfStepsPerRun()
Tell the default amount of steps to be executed for one run of the migration.
$r