ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
MigrateTranslations.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
23use ILIAS\Setup;
26
28{
29 private const TESTS_PER_STEP = 100;
30
31 private \ilDBInterface $db;
32
33 public function getLabel(): string
34 {
35 return 'Remove Table for Content Translation Information & Move Information to Translations';
36 }
37
39 {
40 return 1;
41 }
42
43 public function getPreconditions(Environment $environment): array
44 {
45 return [
46 new \ilDatabaseInitializedObjective()
47 ];
48 }
49
50 public function prepare(Environment $environment): void
51 {
52 $this->db = $environment->getResource(Setup\Environment::RESOURCE_DATABASE);
53 }
54
55 public function step(Environment $environment): void
56 {
57 if (!$this->db->tableExists('obj_content_master_lng')) {
58 return;
59 }
60 $query_result = $this->db->query(
61 'SELECT obj_id, master_lang, fallback_lang FROM obj_content_master_lng LIMIT ' . self::TESTS_PER_STEP
62 );
63
64 while (($row = $this->db->fetchObject($query_result)) !== null) {
65 $this->db->update(
66 'object_translation',
67 [
68 'lang_base' => [\ilDBConstants::T_INTEGER, 1]
69 ],
70 [
71 'obj_id' => [\ilDBConstants::T_INTEGER, $row->obj_id],
72 'lang_code' => [\ilDBConstants::T_TEXT, $row->master_lang]
73 ]
74 );
75 if ($row->fallback_lang !== null && $row->fallback_lang !== '') {
76 $this->db->update(
77 'object_translation',
78 [
79 'lang_default' => [\ilDBConstants::T_INTEGER, 0]
80 ],
81 [
82 'obj_id' => [\ilDBConstants::T_INTEGER, $row->obj_id]
83 ]
84 );
85 $this->db->update(
86 'object_translation',
87 [
88 'lang_default' => [\ilDBConstants::T_INTEGER, 1]
89 ],
90 [
91 'obj_id' => [\ilDBConstants::T_INTEGER, $row->obj_id],
92 'lang_code' => [\ilDBConstants::T_TEXT, $row->fallback_lang]
93 ]
94 );
95 }
96 $this->db->manipulate(
97 "DELETE FROM obj_content_master_lng WHERE obj_id = {$row->obj_id}"
98 );
99 }
100
101 if ($this->getRemainingAmountOfSteps() === 1) {
102 $this->db->dropTable('obj_content_master_lng');
103 }
104 }
105
107 {
108 if (!$this->db->tableExists('obj_content_master_lng')) {
109 return 0;
110 }
111
112 $drop_table_steps = 0;
113 if ($this->db->tableExists('obj_content_master_lng')) {
114 $drop_table_steps = 1;
115 }
116
117 return ((int) ceil(
118 $this->db->fetchObject(
119 $this->db->query('
120 SELECT DISTINCT COUNT(obj_id) as cnt
121 FROM obj_content_master_lng
122 ')
123 )->cnt / self::TESTS_PER_STEP
124 )) + $drop_table_steps;
125 }
126}
prepare(Environment $environment)
Prepare the migration by means of some environment.
step(Environment $environment)
Run one step of the migration.
getDefaultAmountOfStepsPerRun()
Tell the default amount of steps to be executed for one run of the migration.
getPreconditions(Environment $environment)
Objectives the migration depend on.
getRemainingAmountOfSteps()
Count up how many "things" need to be migrated.
An environment holds resources to be used in the setup process.
Definition: Environment.php:28
getResource(string $id)
Consumers of this method should check if the result is what they expect, e.g.
A migration is a potentially long lasting operation that can be broken into discrete steps.
Definition: Migration.php:29
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Agent.php:19
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...