ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilExercisePeerFeedbackMigration.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 peer feedback files 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 pe.ass_id, pe.giver_id, pe.ass_id, pe.peer_id, od.owner, od.obj_id FROM exc_assignment_peer pe JOIN exc_assignment ass ON pe.ass_id = ass.id JOIN object_data od ON ass.exc_id = od.obj_id WHERE pe.migrated = 0 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 $giver_id = (int) $d->giver_id;
61 $peer_id = (int) $d->peer_id;
62 $resource_owner_id = (int) $d->owner;
63 $base_path = $this->buildAbsolutPath($exec_id, $assignment_id, $peer_id, $giver_id);
64
65 if (is_dir($base_path)) {
66 if ($dh = opendir($base_path)) {
67 while (($file = readdir($dh)) !== false) {
68 if ($file != '.' && $file != '..' && is_dir($base_path . '/' . $file)) {
69 if (is_numeric($file)) {
70 $crit_id = (int) $file;
71 $fb_dir = $base_path . "/" . $file;
72
73 $pattern = '/[^\.].*/m';
74 $rid = "";
75 if (is_dir($fb_dir)) {
76 $rid = $this->helper->moveFirstFileOfPatternToStorage(
77 $fb_dir,
78 $pattern,
79 $resource_owner_id
80 );
81 if (!is_null($rid)) {
82 $db->insert("exc_crit_file", [
83 "ass_id" => ["integer", $assignment_id],
84 "giver_id" => ["integer", $giver_id],
85 "peer_id" => ["integer", $peer_id],
86 "criteria_id" => ["integer", $crit_id],
87 "rid" => ["text", $rid]
88 ]);
89 }
90 }
91 }
92 }
93 }
94 closedir($dh);
95 }
96 }
97
98 $this->helper->getDatabase()->update(
99 'exc_assignment_peer',
100 [
101 'migrated' => ['integer', 1]
102 ],
103 [
104 'ass_id' => ['integer', $assignment_id],
105 'giver_id' => ['integer', $giver_id],
106 'peer_id' => ['integer', $peer_id]
107 ]
108 );
109 }
110
112 {
113 $r = $this->helper->getDatabase()->query(
114 "SELECT count(pe.id) as amount FROM exc_assignment_peer pe JOIN exc_assignment ass ON pe.ass_id = ass.id JOIN object_data od ON ass.exc_id = od.obj_id WHERE pe.migrated = 0"
115 );
116 $d = $this->helper->getDatabase()->fetchObject($r);
117
118 return (int) $d->amount;
119 }
120
121 protected function buildAbsolutPath(int $exec_id, int $assignment_id, int $peer_id, int $giver_id): string
122 {
123 // ilExercise/X/exc_*EXC_ID*/peer_up_*ASS_ID*/*TAKER_ID*/*GIVER_ID*/*CRIT_ID*/
124 return CLIENT_DATA_DIR
125 . '/ilExercise/'
127 $exec_id,
128 "exc"
129 ) . "/peer_up_$assignment_id/" . $peer_id . "/" . $giver_id;
130 }
131}
getPreconditions(Environment $environment)
Objectives the migration depend on.
step(Environment $environment)
Run one step of the migration.
getRemainingAmountOfSteps()
Count up how many "things" need to be migrated.
getDefaultAmountOfStepsPerRun()
Tell the default amount of steps to be executed for one run of the migration.
buildAbsolutPath(int $exec_id, int $assignment_id, int $peer_id, int $giver_id)
prepare(Environment $environment)
Prepare the migration by means of some environment.
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