ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilExerciseSampleSolutionMigration.php
Go to the documentation of this file.
1<?php
2
19declare(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 $db = $this->helper->getDatabase();
57 $r = $this->helper->getDatabase()->query(
58 "SELECT id, exc_id, owner FROM exc_assignment JOIN object_data ON exc_id = obj_id WHERE solution_rid IS NULL LIMIT 1;"
59 );
60 $d = $this->helper->getDatabase()->fetchObject($r);
61 $exec_id = (int) $d->exc_id;
62 $assignment_id = (int) $d->id;
63 $resource_owner_id = (int) $d->owner;
64 $base_path = $this->buildAbsolutPath($exec_id, $assignment_id);
65 $pattern = '/[^\.].*/m';
66 $rid = "";
67 if (is_dir($base_path)) {
68 $rid = $this->helper->moveFirstFileOfPatternToStorage(
69 $base_path,
70 $pattern,
71 $resource_owner_id
72 );
73 }
74 $this->helper->getDatabase()->update(
75 'exc_assignment',
76 [
77 'solution_rid' => ['text', (string) $rid]
78 ],
79 [
80 'id' => ['integer', $assignment_id],
81 'exc_id' => ['integer', $exec_id]
82 ]
83 );
84 }
85
86 public function getRemainingAmountOfSteps(): int
87 {
88 $r = $this->helper->getDatabase()->query(
89 "SELECT count(id) AS amount FROM exc_assignment JOIN object_data ON exc_id = obj_id WHERE solution_rid IS NULL"
90 );
91 $d = $this->helper->getDatabase()->fetchObject($r);
92
93 return (int) $d->amount;
94 }
95
96 protected function buildAbsolutPath(int $exec_id, int $assignment_id): string
97 {
98 return CLIENT_DATA_DIR
99 . '/ilExercise/'
101 $exec_id,
102 "exc"
103 ) . "/feedb_$assignment_id/0";
104 }
105}
getPreconditions(Environment $environment)
Objectives the migration depend on.
getRemainingAmountOfSteps()
Count up how many "things" need to be migrated.
prepare(Environment $environment)
Prepare the migration by means of some environment.
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.
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