ILIAS  trunk Revision v11.0_alpha-1723-g8e69f309bab
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
class.ilTestQuestionPoolFileUploadQuestionMigration.php
Go to the documentation of this file.
1 <?php
2 
21 
23 {
25 
26  public function getLabel(): string
27  {
28  return 'File Upload Question Migration';
29  }
30 
32  {
33  return 1000;
34  }
35 
36  public function getPreconditions(Environment $environment): array
37  {
39  }
40 
41  public function prepare(Environment $environment): void
42  {
43  $this->helper = new \ilResourceStorageMigrationHelper(
45  $environment
46  );
47  }
48 
49  public function step(Environment $environment): void
50  {
51  $db = $this->helper->getDatabase();
52  $res = $db->query(
53  'SELECT
54  tst_solutions.solution_id AS solution_id,
55  tst_active.user_fi AS user_id,
56  tst_solutions.question_fi AS question_id,
57  tst_solutions.active_fi AS active_id,
58  tst_active.test_fi AS test_id,
59  tst_solutions.value1 AS filename,
60  tst_solutions.value2 AS revision_name
61  FROM tst_solutions
62  INNER JOIN qpl_qst_fileupload ON qpl_qst_fileupload.question_fi = tst_solutions.question_fi
63  INNER JOIN tst_active ON tst_active.active_id = tst_solutions.active_fi
64  WHERE tst_solutions.value2 != "rid";'
65  );
66 
67  $res = $db->fetchAssoc($res);
68 
69  // read common data for all files of this question id
70  $user_id = (int) $res['user_id'];
71  $active_id = (int) $res['active_id'];
72  $test_id = (int) $res['test_id'];
73  $question_id = (int) $res['question_id'];
74  $filename = $res['filename'];
75  $revision_name = $res['revision_name'];
76  $solution_id = (int) $res['solution_id'];
77 
78  // build path to file
79  $path = $this->buildAbsolutPath(
80  $test_id,
81  $active_id,
82  $question_id,
83  $filename
84  );
85 
86  $rid = null;
87 
88  if (file_exists($path)) {
89  $rid = $this->helper->movePathToStorage(
90  $path,
91  $user_id,
92  null,
93  static function () use ($revision_name): string {
94  return $revision_name;
95  }
96  );
97  }
98  if ($rid !== null) {
99  $rid = $rid->serialize(); // no files found
100  }
101 
102  // store the rid in as value1 and 'rid' as value2
103  $db->update(
104  'tst_solutions',
105  [
106  'value1' => ['string', $rid],
107  'value2' => ['string', 'rid']
108  ],
109  [
110  'solution_id' => ['integer', $solution_id]
111  ]
112  );
113  }
114 
115  public function getRemainingAmountOfSteps(): int
116  {
117  $database = $this->helper->getDatabase();
118  $res = $database->query(
119  "SELECT COUNT(*) as count
120  FROM tst_solutions
121  INNER JOIN qpl_qst_fileupload ON qpl_qst_fileupload.question_fi = tst_solutions.question_fi
122  INNER JOIN tst_active ON tst_active.active_id = tst_solutions.active_fi
123  WHERE tst_solutions.value2 != 'rid';"
124  );
125 
126  return (int) $database->fetchAssoc($res)['count'];
127  }
128 
129  protected function buildAbsolutPath(
130  int $test_id,
131  int $active_id,
132  int $question_id,
133  string $filename
134  ): string {
135  return CLIENT_WEB_DIR
136  . '/assessment'
137  . '/tst_' . $test_id
138  . '/' . $active_id
139  . '/' . $question_id
140  . '/files/'
141  . $filename;
142  }
143 
144 }
getRemainingAmountOfSteps()
Count up how many "things" need to be migrated.
$res
Definition: ltiservices.php:66
A migration is a potentially long lasting operation that can be broken into discrete steps...
Definition: Migration.php:28
$path
Definition: ltiservices.php:29
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
prepare(Environment $environment)
Prepare the migration by means of some environment.
buildAbsolutPath(int $test_id, int $active_id, int $question_id, string $filename)
getPreconditions(Environment $environment)
Objectives the migration depend on.
step(Environment $environment)
Run one step of the migration.
const CLIENT_WEB_DIR
Definition: constants.php:47
getDefaultAmountOfStepsPerRun()
Tell the default amount of steps to be executed for one run of the migration.
$filename
Definition: buildRTE.php:78
An environment holds resources to be used in the setup process.
Definition: Environment.php:27