ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilExerciseSubmissionMigration.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
23
25{
26 protected \ilResourceStorageMigrationHelper $helper;
27
28 public function getLabel(): string
29 {
30 return "Migration of exercise submission to the resource storage service.";
31 }
32
34 {
35 return 1000;
36 }
37
38 public function getPreconditions(Environment $environment): array
39 {
40 return \ilResourceStorageMigrationHelper::getPreconditions();
41 }
42
43 public function prepare(Environment $environment): void
44 {
45 $this->helper = new \ilResourceStorageMigrationHelper(
47 $environment
48 );
49 }
50
51 public function step(Environment $environment): void
52 {
53 $db = $this->helper->getDatabase();
54 $r = $db->query(
55 "SELECT er.returned_id, er.obj_id, er.ass_id, od.owner, er.user_id, er.team_id FROM exc_returned er JOIN object_data od ON er.obj_id = od.obj_id WHERE er.rid IS NULL LIMIT 1;"
56 );
57 $d = $this->helper->getDatabase()->fetchObject($r);
58 $exec_id = (int) $d->obj_id;
59 $assignment_id = (int) $d->ass_id;
60 $returned_id = (int) $d->returned_id;
61 $resource_owner_id = (int) $d->owner;
62 $user_id = ((int) $d->team_id) > 0
63 ? (int) $d->team_id
64 : (int) $d->user_id;
65 $base_path = $this->buildAbsolutPath($exec_id, $assignment_id, $user_id);
66 $pattern = '/[^\.].*/m';
67 $rid = "";
68 if (is_dir($base_path)) {
69 $rid = $this->helper->moveFirstFileOfPatternToStorage(
70 $base_path,
71 $pattern,
72 $resource_owner_id
73 );
74 }
75 $this->helper->getDatabase()->update(
76 'exc_returned',
77 [
78 'rid' => ['text', (string) $rid]
79 ],
80 [
81 'ass_id' => ['integer', $assignment_id],
82 'returned_id' => ['integer', $returned_id]
83 ]
84 );
85 }
86
87 public function getRemainingAmountOfSteps(): int
88 {
89 $r = $this->helper->getDatabase()->query(
90 "SELECT count(er.returned_id) as amount FROM exc_returned er JOIN object_data od ON er.obj_id = od.obj_id WHERE er.rid IS NULL;"
91 );
92 $d = $this->helper->getDatabase()->fetchObject($r);
93
94 return (int) $d->amount;
95 }
96
97 protected function buildAbsolutPath(int $exec_id, int $assignment_id, int $user_id): string
98 {
99 // ilExercise/X/exc_*EXC_ID*/subm_*ASS_ID*/*USER_ID*/*TIMESTAMP*_filename.pdf
100 return CLIENT_DATA_DIR
101 . '/ilExercise/'
103 $exec_id,
104 "exc"
105 ) . "/subm_$assignment_id/" . $user_id;
106 }
107}
step(Environment $environment)
Run one step of the migration.
buildAbsolutPath(int $exec_id, int $assignment_id, int $user_id)
prepare(Environment $environment)
Prepare the migration by means of some environment.
getPreconditions(Environment $environment)
Objectives the migration depend on.
getDefaultAmountOfStepsPerRun()
Tell the default amount of steps to be executed for one run of the migration.
getRemainingAmountOfSteps()
Count up how many "things" need to be migrated.
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