ILIAS  release_7 Revision v7.30-3-g800a261c036
class.PRGUpdateCRSRefLPSettingMigration.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21use ILIAS\Setup;
24
26{
27 private const DEFAULT_AMOUNT_OF_STEPS = 1000;
29
33 private mixed $io;
34
35 public function getLabel() : string
36 {
37 return "Update LP Settings of Course References";
38 }
39
40 public function getDefaultAmountOfStepsPerRun() : int
41 {
43 }
44
45 public function getPreconditions(Environment $environment) : array
46 {
47 return [
50 ];
51 }
52
53 public function prepare(Environment $environment) : void
54 {
55 $this->db = $environment->getResource(Setup\Environment::RESOURCE_DATABASE);
56 }
57
61 public function step(Environment $environment) : void
62 {
63 $query = "SELECT distinct od.obj_id AS objid " . PHP_EOL .
64 "FROM object_reference oref " . PHP_EOL .
65 "JOIN object_data od ON od.obj_id = oref.obj_id AND od.type = 'crsr'" . PHP_EOL .
66 "JOIN tree ON oref.ref_id = tree.child" . PHP_EOL .
67 "JOIN tree t2 ON t2.path > tree.path" . PHP_EOL .
68 "JOIN object_reference oref2 ON oref2.ref_id = t2.child" . PHP_EOL .
69 "JOIN object_data od2 ON od2.obj_id = oref2.obj_id AND od2.type = 'prg'" . PHP_EOL .
70 "WHERE od.obj_id NOT IN (" . PHP_EOL .
71 "SELECT obj_id FROM ut_lp_settings WHERE obj_type = 'crsr' AND u_mode = "
73 ")" . PHP_EOL .
74 "LIMIT 1";
75
76 $result = $this->db->query($query);
77 $row = $this->db->fetchAssoc($result);
78 $q = 'DELETE FROM ut_lp_settings WHERE obj_id = ' . (int) $row['objid'];
79 $this->db->manipulate($q);
80
81 $q = 'INSERT INTO ut_lp_settings (obj_id, obj_type, u_mode)' . PHP_EOL .
82 'VALUES (' .
83 (int) $row['objid'] .
84 ', "crsr", ' .
86 ');';
87 $this->db->manipulate($q);
88 }
89
90 public function getRemainingAmountOfSteps() : int
91 {
92 $query = "SELECT count(distinct od.obj_id) AS cnt " . PHP_EOL .
93 "FROM object_reference oref " . PHP_EOL .
94 "JOIN object_data od ON od.obj_id = oref.obj_id AND od.type = 'crsr'" . PHP_EOL .
95 "JOIN tree ON oref.ref_id = tree.child" . PHP_EOL .
96 "JOIN tree t2 ON t2.path > tree.path" . PHP_EOL .
97 "JOIN object_reference oref2 ON oref2.ref_id = t2.child" . PHP_EOL .
98 "JOIN object_data od2 ON od2.obj_id = oref2.obj_id AND od2.type = 'prg'" . PHP_EOL .
99 "WHERE od.obj_id NOT IN (" . PHP_EOL .
100 "SELECT obj_id FROM ut_lp_settings WHERE obj_type = 'crsr' AND u_mode = "
102 ")";
103 $result = $this->db->query($query);
104 $row = $this->db->fetchAssoc($result);
105
106 return (int) $row['cnt'];
107 }
108}
$result
An exception for terminatinating execution or to throw for unit testing.
Wrapper around symfonies input and output facilities to provide just the functionality required for t...
Definition: IOWrapper.php:17
An environment holds resources to be used in the setup process.
Definition: Environment.php:12
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:13
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$query