ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
ilSeparateQuestionListSettingMigration.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
21 namespace ILIAS\Test\Setup;
22 
23 use ILIAS\Setup;
27 use ilDBInterface;
28 use Exception;
30 
32 {
33  private const DEFAULT_AMOUNT_OF_STEPS = 1;
34  private ilDBInterface $db;
35 
39  private mixed $io;
40 
41  public function getLabel(): string
42  {
43  return "Update QuestionList Settings";
44  }
45 
47  {
48  return self::DEFAULT_AMOUNT_OF_STEPS;
49  }
50 
51  public function getPreconditions(Environment $environment): array
52  {
53  return [
56  ];
57  }
58 
59  public function prepare(Environment $environment): void
60  {
61  $this->db = $environment->getResource(Setup\Environment::RESOURCE_DATABASE);
62  }
63 
67  public function step(Environment $environment): void
68  {
69  $result = $this->db->manipulate(
70  'UPDATE tst_tests SET show_questionlist = 1 WHERE usr_pass_overview_mode > 0 AND show_questionlist IS NULL LIMIT 1'
71  );
72 
73  if ($result === 0) {
74  $this->db->manipulate(
75  'UPDATE tst_tests SET show_questionlist = 0 WHERE usr_pass_overview_mode = 0 AND show_questionlist IS NULL LIMIT 1'
76  );
77  }
78  }
79 
80  public function getRemainingAmountOfSteps(): int
81  {
82  $result = $this->db->query(
83  "SELECT count(*) as cnt FROM tst_tests WHERE show_questionlist is NULL"
84  );
85  $row = $this->db->fetchAssoc($result);
86 
87  return (int) $row['cnt'] ?? 0;
88  }
89 }
prepare(Environment $environment)
Prepare the migration by means of some environment.
A migration is a potentially long lasting operation that can be broken into discrete steps...
Definition: Migration.php:28
getDefaultAmountOfStepsPerRun()
Tell the default amount of steps to be executed for one run of the migration.
getPreconditions(Environment $environment)
Objectives the migration depend on.
getResource(string $id)
Consumers of this method should check if the result is what they expect, e.g.
getRemainingAmountOfSteps()
Count up how many "things" need to be migrated.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
An environment holds resources to be used in the setup process.
Definition: Environment.php:27