3 declare(strict_types=1);
48 $ilDB = $DIC->database();
54 $this->allowed_attributes =
$ilDB->getAllowedAttributes();
64 $ilDB = $DIC->database();
66 $query =
"SELECT DISTINCT(table_name) FROM abstraction_progress ";
70 $names[] = $row->table_name;
76 $abs_tables = array_merge($names, array(
78 'acc_user_access_key',
81 'qpl_question_orderinghorizontal',
82 'qpl_question_fileupload',
85 'style_template_class',
89 'page_editor_settings',
100 'qpl_qst_fileupload',
104 'qpl_qst_javaapplet',
110 'qpl_qst_textsubset',
144 $this->target_encoding = $a_encoding;
159 $this->blacklist = $a_blacklist;
175 $this->whitelist = $a_whitelist;
183 public function setFilter(
string $a_filter,
string $a_value): void
185 $this->
filter[$a_filter] = $a_value;
193 return $this->tables = $this->manager->listTables();
202 if (in_array($a_table, $this->blacklist,
true)) {
207 if (count($this->whitelist) > 0 && !in_array($a_table, $this->whitelist,
true)) {
220 $file = fopen($a_path,
'wb');
221 $start .=
"\t" .
'global $ilDB;' .
"\n\n";
222 fwrite($file, $start);
241 if (@is_dir($a_filename)) {
250 if ($a_filename !==
"" && !$is_dir) {
251 $file = fopen($a_filename,
'wb');
253 $start =
'<?php' .
"\n" .
'function setupILIASDatabase()' .
"\n{\n";
254 $start .=
"\t" .
'global $ilDB;' .
"\n\n";
255 fwrite($file, $start);
262 if ($a_filename !==
"") {
285 if (in_array($table, array(
'usr_session_stats',
'usr_session_raw',
'il_plugin'))) {
292 #$this->buildInsertStatementsXML($table,$path); 300 } elseif ($a_filename !==
"") {
301 echo
"<br><b>missing: " . $table .
"</b>";
309 if ($a_filename ===
"") {
311 } elseif (!$is_dir) {
313 $ok = fwrite($file, $end);
325 $fields = $this->analyzer->getFieldInformation($a_table,
true);
327 $create_st =
"\n\n//\n// " . $a_table .
"\n//\n";
328 $create_st .=
'$fields = array (' .
"\n";
330 foreach ($fields as
$f => $def) {
331 $create_st .=
"\t" . $f_sep .
'"' .
$f .
'" => array (' .
"\n";
334 foreach ($def as $k => $v) {
335 if ($k !==
"nativetype" && $k !==
"alt_types" && $k !==
"autoincrement" && !is_null($v)) {
340 $v = $v ?
"true" :
"false";
351 $create_st .=
"\t\t" . $a_sep .
'"' . $k .
'" => ' . $v .
"\n";
355 $create_st .=
"\t" .
')' .
"\n";
357 $create_st .=
');' .
"\n";
358 $create_st .=
'$ilDB->createTable("' . $a_table .
'", $fields);' .
"\n";
360 if ($a_file === null) {
363 fwrite($a_file, $create_st);
372 $pk = $this->analyzer->getPrimaryKeyInformation($a_table);
374 if (is_array($pk[
"fields"]) && count($pk[
"fields"]) > 0) {
375 $pk_st =
"\n" .
'$pk_fields = array(';
377 foreach ($pk[
"fields"] as
$f => $pos) {
378 $pk_st .= $sep .
'"' .
$f .
'"';
382 $pk_st .=
'$ilDB->addPrimaryKey("' . $a_table .
'", $pk_fields);' .
"\n";
384 if ($a_file === null) {
387 fwrite($a_file, $pk_st);
397 $ind = $this->analyzer->getIndicesInformation($a_table,
true);
399 if (is_array($ind)) {
400 foreach ($ind as
$i) {
401 if ($i[
"fulltext"]) {
406 $in_st =
"\n" .
'$in_fields = array(';
408 foreach ($i[
"fields"] as
$f => $pos) {
409 $in_st .= $sep .
'"' .
$f .
'"';
413 $in_st .=
'$ilDB->addIndex("' . $a_table .
'", $in_fields, "' . $i[
"name"] .
'"' . $ft .
');' .
"\n";
415 if ($a_file === null) {
418 fwrite($a_file, $in_st);
427 private function printOrWrite(
string $string, $file_handle = null): void
429 if ($file_handle === null) {
432 fwrite($file_handle, $string);
441 $con = $this->analyzer->getConstraintsInformation($a_table,
true);
443 if (is_array($con)) {
445 foreach ($con as
$i) {
446 $in_st =
"\n" .
'$in_fields = array(';
448 foreach ($i[
"fields"] as
$f => $pos) {
449 $in_st .= $sep .
'"' .
$f .
'"';
453 $in_st .=
'$ilDB->addUniqueConstraint("' . $a_table .
'", $in_fields, "' . $i[
"name"] .
'");' .
"\n";
465 $seq = $this->analyzer->hasSequence($a_table);
466 if ($seq !==
false) {
467 $seq_st =
"\n" .
'$ilDB->createSequence("' . $a_table .
'", ' . (
int) $seq .
');' .
"\n";
478 $r = $this->manager->listSequences();
480 foreach ($r as $seq) {
481 if (!in_array($seq, $this->tables,
true)) {
483 if ($seq ===
"sahs_sc13_seq") {
487 $create_st =
"\n" .
'$ilDB->createSequence("' . $seq .
'");' .
"\n";
500 $ilLogger = $DIC->logger()->root();
502 $ilLogger->log(
'Starting export of:' . $a_table);
504 $set = $this->il_db->query(
"SELECT * FROM " . $this->il_db->quoteIdentifier($a_table));
509 $concurrentDirectory = $a_basedir .
'/' . $a_table .
'_inserts',
510 fileperms($a_basedir)
511 ) && !is_dir($concurrentDirectory)) {
512 throw new \RuntimeException(sprintf(
'Directory "%s" was not created', $concurrentDirectory));
516 while ($rec = $this->il_db->fetchAssoc($set)) {
518 foreach ($rec as
$f => $v) {
519 if ($this->
fields[
$f][
'type'] ===
'text' && $this->
fields[
$f][
'length'] >= 1000) {
529 $rows[$a_table][$row++] = $values;
532 $ilLogger->log(
'Writing insert statements after 1000 lines...');
533 $fp = fopen($a_basedir .
'/' . $a_table .
'_inserts/' . $filenum++ .
'.data',
'wb');
534 fwrite($fp, serialize(
$rows));
542 $fp = fopen($a_basedir .
'/' . $a_table .
'_inserts/' . $filenum++ .
'.data',
'wb');
543 fwrite($fp, serialize(
$rows) .
"\n");
547 $ilLogger->log(
'Finished export of: ' . $a_table);
548 if (function_exists(
'memory_get_usage')) {
549 $ilLogger->log(
'Memory usage: ' . memory_get_usage(
true));
560 if ($a_table ===
"lng_data") {
564 $set = $this->il_db->query(
"SELECT * FROM " . $this->il_db->quoteIdentifier($a_table));
566 while ($rec = $this->il_db->fetchAssoc($set)) {
571 foreach ($rec as
$f => $v) {
572 $v = str_replace(
'\\',
'\\\\', $v);
573 $i_str[] =
"'" .
$f .
"' => array('" . $this->
fields[
$f][
"type"] .
"', '" . str_replace(
579 $ins_st =
"\n" .
'$ilDB->insert("' . $a_table .
'", array(' .
"\n";
580 $ins_st .= implode(
", ", $i_str) .
"));\n";
590 protected function shortenText(
string $table,
string $field,
string $a_value,
int $a_size): string
593 $ilLogger = $DIC->logger()->root();
603 $shortened = mb_convert_encoding($shortened,
'UTF-8', $this->
getTargetEncoding());
605 if (strlen($a_value) != strlen($shortened)) {
606 $ilLogger->log(
'Table : ' . $table);
607 $ilLogger->log(
'Field : ' . $field);
608 $ilLogger->log(
'Type : ' . $this->
fields[$field][
'type']);
609 $ilLogger->log(
'Length : ' . $this->
fields[$field][
'length']);
610 $ilLogger->log(
'Before : ' . $a_value);
611 $ilLogger->log(
'Shortened : ' . $shortened);
612 $ilLogger->log(
'Strlen Before: ' . strlen($a_value));
613 $ilLogger->log(
'Strlen After : ' . strlen($shortened));
checkProcessing(string $a_table)
Check whether a table should be processed or not.
buildDBGenerationScript(string $a_filename="")
Build DB generation script.
printOrWrite(string $string, $file_handle=null)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setBlackList(array $a_blacklist)
Set Table Black List.
buildSingularSequenceStatement($file_handle=null)
static lookupAbstractedTables()
buildInsertStatements(string $a_table, $file_handle=null)
buildCreateSequenceStatement(string $a_table, $file_handle=null)
setWhiteList(array $a_whitelist)
Set Table White List.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
buildCreateTableStatement(string $a_table, $a_file=null)
__construct()
Constructor.
shortenText(string $table, string $field, string $a_value, int $a_size)
Shorten text depending on target encoding.
static shortenText(string $a_string, int $a_start_pos, int $a_num_bytes, string $a_encoding='UTF-8')
Shorten text to the given number of bytes.
setTargetEncoding(string $a_encoding)
Set the desired target encoding If the target encoding os different from UTF-8 all text values will b...
buildAddUniqueConstraintStatements(string $a_table, $file_handle=null)
buildAddIndexStatements(string $a_table, $a_file=null)
buildAddPrimaryKeyStatement(string $a_table, $a_file=null)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
buildInsertStatement(string $a_table, string $a_basedir)
Write seerialized insert data to array.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
array $allowed_attributes
setFilter(string $a_filter, string $a_value)