ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilFileObjectDatabaseObjective.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
23
29{
30 private ?ilDBInterface $database = null;
31
32 public function prepare(ilDBInterface $db): void
33 {
34 $this->database = $db;
35 }
36
46 public function step_1(): void
47 {
48 $this->abortIfNotPrepared();
49 if ($this->database->tableExists('file_data')) {
50 $this->database->addTableColumn(
51 'file_data',
52 'on_click_mode',
53 [
54 'type' => 'integer',
55 'length' => '1',
56 'notnull' => '1',
58 ]
59 );
60 }
61 }
62
72 public function step_2(): void
73 {
74 $this->abortIfNotPrepared();
75 if (!$this->database->tableExists('file_data')) {
76 return;
77 }
78 if ($this->database->tableColumnExists('file_data', 'downloads')) {
79 return;
80 }
81
82 $this->database->addTableColumn(
83 'file_data',
84 'downloads',
85 [
86 'type' => 'integer',
87 'length' => 8,
88 'notnull' => false,
89 'default' => 0 // will be adjusted in an update query.
90 ]
91 );
92
93 $this->database->manipulate(
94 "
95 UPDATE file_data SET downloads = (
96 SELECT COALESCE(SUM(read_event.read_count), 0) FROM read_event
97 WHERE read_event.obj_id = file_data.file_id
98 );
99 "
100 );
101 }
102
106 public function step_3(): void
107 {
108 $this->abortIfNotPrepared();
109
111 $this->database->insert(
112 'settings',
113 [
114 'module' => ['text', General::MODULE_NAME],
115 'keyword' => ['text', General::F_SHOW_AMOUNT_OF_DOWNLOADS],
116 'value' => ['text', '1'],
117 ]
118 );
119 }
120
124 public function step_4(): void
125 {
126 $this->abortIfNotPrepared();
127 if (!$this->database->tableExists(IconDatabaseRepository::ICON_TABLE_NAME)) {
128 $this->database->createTable(
129 IconDatabaseRepository::ICON_TABLE_NAME,
130 [
131 IconDatabaseRepository::ICON_RESOURCE_IDENTIFICATION => [
132 'type' => 'text',
133 'length' => 64,
134 'notnull' => true,
135 'default' => '',
136 ],
137 IconDatabaseRepository::ICON_ACTIVE => [
138 'type' => 'integer',
139 'length' => 1,
140 'notnull' => false,
141 'default' => 0,
142 ],
143 IconDatabaseRepository::IS_DEFAULT_ICON => [
144 'type' => 'integer',
145 'length' => 1,
146 'notnull' => false,
147 'default' => 0,
148 ]
149 ]
150 );
151 }
152 if (!$this->database->tableExists(IconDatabaseRepository::SUFFIX_TABLE_NAME)) {
153 $this->database->createTable(
154 IconDatabaseRepository::SUFFIX_TABLE_NAME,
155 [
156 IconDatabaseRepository::ICON_RESOURCE_IDENTIFICATION => [
157 'type' => 'text',
158 'length' => 64,
159 'notnull' => true,
160 'default' => '',
161 ],
162 IconDatabaseRepository::SUFFIX => [
163 'type' => 'text',
164 'length' => 32,
165 'notnull' => false,
166 'default' => '',
167 ]
168 ]
169 );
170 }
171 }
172
173 public function step_5(): void
174 {
175 // replace wrong suffixes. currently they are stored with e.g. icon_file_docx and should be docx.
176 // update the whole table with a replace statement.
177 $this->database->manipulate(
178 "UPDATE il_file_icon_suffixes SET suffix = REPLACE(suffix, 'icon_file_', '') WHERE suffix LIKE 'icon_file_%';"
179 );
180 }
181
186 public function step_6(): void
187 {
188 $this->abortIfNotPrepared();
189 if (!$this->database->tableExists('file_data')) {
190 return;
191 }
192 if ($this->database->tableColumnExists(
193 'file_data',
194 'important_info'
195 )) {
196 return;
197 }
198 $this->database->addTableColumn(
199 'file_data',
200 'important_info',
201 [
202 'type' => 'blob',
203 'notnull' => false,
204 'default' => null
205 ]
206 );
207 }
208
215 public function step_7(): void
216 {
217 $query = "UPDATE `object_data` SET `offline` = 0 WHERE `type` = \"file\" AND `offline` IS NULL";
218 $this->database->manipulate($query);
219 }
220
227 private function abortIfNotPrepared(): void
228 {
229 if (null === $this->database) {
230 throw new LogicException(self::class . "::prepare() must be called before db-update-steps execution.");
231 }
232 }
233}
step_2()
adds a new table column called 'downloads' which is used to keep
step_7()
This step sets all files which were created before the "centralizing online/offline status" feature t...
step_6()
Adds a new table column called 'important_info' to store important information regarding a file such ...
step_4()
adds two new tables to store data concerning suffix-specific icons for files
step_1()
adds a new table column called 'direct_download' that is used to determine if the on-click action in ...
step_3()
sets the default visibility of the amount of downloads to visible ('1' or true).
abortIfNotPrepared()
Halts the execution of these update steps if no database was provided.
const CLICK_MODE_DOWNLOAD
Interface ilDBInterface.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...