ILIAS  release_8 Revision v8.19-1-g4e8f2f9140c
All Data Structures Namespaces Files Functions Variables Modules Pages
ilFixMissingQuestionDuplicationMigration Class Reference
+ Inheritance diagram for ilFixMissingQuestionDuplicationMigration:
+ Collaboration diagram for ilFixMissingQuestionDuplicationMigration:

Public Member Functions

 getLabel ()
 
 getDefaultAmountOfStepsPerRun ()
 Tell the default amount of steps to be executed for one run of the migration. More...
 
 getPreconditions (Environment $environment)
 Objectives the migration depend on. More...
 
 prepare (Environment $environment)
 Prepare the migration by means of some environment. More...
 
 step (Environment $environment)
 Run one step of the migration. More...
 
 getRemainingAmountOfSteps ()
 Count up how many "things" need to be migrated. More...
 

Private Attributes

ilDBInterface $db
 
bool $ilias_is_initialized = false
 

Additional Inherited Members

- Data Fields inherited from ILIAS\Setup\Migration
const INFINITE = -1
 

Detailed Description

Member Function Documentation

◆ getDefaultAmountOfStepsPerRun()

ilFixMissingQuestionDuplicationMigration::getDefaultAmountOfStepsPerRun ( )

Tell the default amount of steps to be executed for one run of the migration.

Return Migration::INFINITE if all units should be migrated at once.

Implements ILIAS\Setup\Migration.

Definition at line 35 of file class.ilFixMissingQuestionDuplicationMigration.php.

35  : int
36  {
37  return 10;
38  }

◆ getLabel()

ilFixMissingQuestionDuplicationMigration::getLabel ( )
Returns
string - a meaningful and concise description for your migration.

Implements ILIAS\Setup\Migration.

Definition at line 30 of file class.ilFixMissingQuestionDuplicationMigration.php.

30  : string
31  {
32  return 'Fix Missing Question Duplication When Creating in Test And Pool';
33  }

◆ getPreconditions()

ilFixMissingQuestionDuplicationMigration::getPreconditions ( Environment  $environment)

Objectives the migration depend on.

Exceptions
UnachievableExceptionif the objective is not achievable
Returns
Objective[]

Implements ILIAS\Setup\Migration.

Definition at line 40 of file class.ilFixMissingQuestionDuplicationMigration.php.

40  : array
41  {
42  return [
43  new \ilDatabaseInitializedObjective()
44  ];
45  }

◆ getRemainingAmountOfSteps()

ilFixMissingQuestionDuplicationMigration::getRemainingAmountOfSteps ( )

Count up how many "things" need to be migrated.

This helps the admin to decide how big he can create the steps and also how long a migration takes

Implements ILIAS\Setup\Migration.

Definition at line 92 of file class.ilFixMissingQuestionDuplicationMigration.php.

References $query.

92  : int
93  {
94  $query = 'SELECT COUNT(qst.question_id) AS cnt FROM tst_tests AS tst'
95  . ' INNER JOIN tst_test_question AS tst_qst'
96  . ' ON tst.test_id = tst_qst.test_fi'
97  . ' INNER JOIN qpl_questions AS qst'
98  . ' ON tst_qst.question_fi = qst.question_id'
99  . ' WHERE tst.question_set_type = "FIXED_QUEST_SET"'
100  . ' AND qst.obj_fi != tst.obj_fi'
101  . ' AND ISNULL(qst.original_id)';
102  $result = $this->db->query($query);
103  $row = $this->db->fetchAssoc($result);
104 
105  return (int) ($row['cnt'] ?? 0);
106  }
$query

◆ prepare()

ilFixMissingQuestionDuplicationMigration::prepare ( Environment  $environment)

Prepare the migration by means of some environment.

This is not supposed to modify the environment, but will be run to prime the migration object to run step and getRemainingAmountOfSteps afterwards.

Implements ILIAS\Setup\Migration.

Definition at line 47 of file class.ilFixMissingQuestionDuplicationMigration.php.

References ILIAS\Setup\Environment\getResource().

47  : void
48  {
49  $this->db = $environment->getResource(Environment::RESOURCE_DATABASE);
50  }
getResource(string $id)
Consumers of this method should check if the result is what they expect, e.g.
+ Here is the call graph for this function:

◆ step()

ilFixMissingQuestionDuplicationMigration::step ( Environment  $environment)

Run one step of the migration.

Implements ILIAS\Setup\Migration.

Definition at line 52 of file class.ilFixMissingQuestionDuplicationMigration.php.

References assQuestion\_instanciateQuestion(), ilContext\CONTEXT_CRON, ilContext\init(), and ilInitialisation\initILIAS().

52  : void
53  {
54  if (!$this->ilias_is_initialized) {
57  $this->ilias_is_initialized = true;
58  }
59  $query_main = 'SELECT qst.question_id FROM tst_tests AS tst'
60  . ' INNER JOIN tst_test_question AS tst_qst'
61  . ' ON tst.test_id = tst_qst.test_fi'
62  . ' INNER JOIN qpl_questions AS qst'
63  . ' ON tst_qst.question_fi = qst.question_id'
64  . ' WHERE tst.question_set_type = "FIXED_QUEST_SET"'
65  . ' AND qst.obj_fi != tst.obj_fi'
66  . ' AND ISNULL(qst.original_id)';
67  $result_main = $this->db->query($query_main);
68  while ($question = $this->db->fetchAssoc($result_main)) {
69  $question_obj = assQuestion::_instanciateQuestion((int) $question['question_id']);
70  $clone_id = $question_obj->duplicate(false);
71 
72  $this->db->update(
73  'qpl_questions',
74  ['original_id' => ['integer', $clone_id]],
75  ['original_id' => ['integer', $question['question_id']]]
76  );
77 
78  $test_query = 'SELECT obj_fi FROM tst_test_question INNER JOIN tst_tests ON tst_test_question.test_fi = tst_tests.test_id WHERE question_fi = %s';
79  $test_result = $this->db->queryF($test_query, ['integer'], [$question['question_id']]);
80 
81  $this->db->update(
82  'qpl_questions',
83  [
84  'original_id' => ['integer', $clone_id],
85  'obj_fi' => ['integer', ($this->db->fetchObject($test_result))->obj_fi]
86  ],
87  ['question_id' => ['integer', $question['question_id']]]
88  );
89  }
90  }
const CONTEXT_CRON
static initILIAS()
ilias initialisation
static init(string $a_type)
Init context by type.
static _instanciateQuestion(int $question_id)
+ Here is the call graph for this function:

Field Documentation

◆ $db

ilDBInterface ilFixMissingQuestionDuplicationMigration::$db
private

◆ $ilias_is_initialized

bool ilFixMissingQuestionDuplicationMigration::$ilias_is_initialized = false
private

The documentation for this class was generated from the following file: