ILIAS  trunk Revision v11.0_alpha-1715-g7fc467680fb
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
class.LSOMigratePageIdsIntro.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
21 use ILIAS\Setup;
23 
24 class LSOMigratePageIdsIntro implements Setup\Migration
25 {
26  private const DEFAULT_AMOUNT_OF_STEPS = 1000;
27  private const QUERY = "SELECT page_id, parent_id, parent_type, count(page_id) AS cnt" . PHP_EOL
28  . "FROM page_object" . PHP_EOL
29  . "WHERE page_id = (parent_id * -1)" . PHP_EOL
30  . "AND parent_type = 'cont'";
31 
32  private ilDBInterface $db;
33 
34  public function getLabel(): string
35  {
36  return "Update IDs of intro pages";
37  }
38 
40  {
41  return self::DEFAULT_AMOUNT_OF_STEPS;
42  }
43 
44  public function getPreconditions(Environment $environment): array
45  {
46  return [
48  ];
49  }
50 
51  public function prepare(Environment $environment): void
52  {
53  $this->db = $environment->getResource(Setup\Environment::RESOURCE_DATABASE);
54  }
55 
59  public function step(Environment $environment): void
60  {
61  $result = $this->db->query(self::QUERY . ' LIMIT 1');
62  $row = $this->db->fetchAssoc($result);
63  $query = 'UPDATE page_object' . PHP_EOL
64  . "SET page_id = parent_id, parent_type = 'lsoi'" . PHP_EOL
65  . "WHERE page_id = " . $row['page_id'] . PHP_EOL
66  . "AND parent_id = " . $row['parent_id'] . PHP_EOL
67  . "AND parent_type = " . $this->db->quote($row['parent_type'], 'text');
68  $this->db->manipulate($query);
69  }
70 
71  public function getRemainingAmountOfSteps(): int
72  {
73  $result = $this->db->query(self::QUERY);
74  $row = $this->db->fetchAssoc($result);
75 
76  return (int) $row['cnt'];
77  }
78 }
prepare(Environment $environment)
getResource(string $id)
Consumers of this method should check if the result is what they expect, e.g.
getPreconditions(Environment $environment)
step(Environment $environment)
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