48 include_once(
"./Services/Database/classes/class.ilDBAnalyzer.php");
51 $this->allowed_attributes = $ilDB->getAllowedAttributes();
62 $query =
"SELECT DISTINCT(table_name) FROM abstraction_progress ";
74 'acc_user_access_key',
77 'qpl_question_orderinghorizontal',
78 'qpl_question_fileupload',
81 'style_template_class',
85 'page_editor_settings',
100 'qpl_qst_javaapplet',
106 'qpl_qst_textsubset',
147 $this->target_encoding = $a_encoding;
170 $this->blacklist = $a_blacklist;
194 $this->whitelist = $a_whitelist;
215 $this->filter[$a_filter] = $a_value;
224 $r = $this->manager->listTables();
237 if (in_array($a_table, $this->blacklist)) {
242 if (count($this->whitelist) > 0 && !in_array($a_table, $this->whitelist)) {
253 $file = fopen($a_path,
"w");
254 $start .=
"\t" .
'global $ilDB;' .
"\n\n";
255 fwrite(
$file, $start);
260 $file = fopen($a_path,
"w");
261 $start =
'<?php' .
"\n" .
'function setupILIASDatabase()' .
"\n{\n";
262 $start .=
"\t" .
'global $ilDB;' .
"\n\n";
263 fwrite(
$file, $start);
291 if (@is_dir($a_filename)) {
295 $isDirectory =
false;
300 if ($a_filename !=
"" and !$isDirectory) {
301 $file = fopen($a_filename,
"w");
303 $start =
'<?php' .
"\n" .
'function setupILIASDatabase()' .
"\n{\n";
304 $start .=
"\t" .
'global $ilDB;' .
"\n\n";
305 fwrite(
$file, $start);
306 } elseif ($isDirectory) {
314 foreach ($this->tables as
$table) {
316 if ($a_filename !=
"") {
339 if (in_array($table,
array(
'usr_session_stats',
'usr_session_raw',
'il_plugin'))) {
346 #$this->buildInsertStatementsXML($table,$path); 355 if ($a_filename !=
"") {
356 echo
"<br><b>missing: " . $table .
"</b>";
365 if ($a_filename ==
"") {
367 } elseif (!$isDirectory) {
384 $fields = $this->analyzer->getFieldInformation($a_table,
true);
386 $create_st =
"\n\n//\n// " . $a_table .
"\n//\n";
387 $create_st .=
'$fields = array (' .
"\n";
389 foreach ($fields as $f =>
$def) {
390 $create_st .=
"\t" . $f_sep .
'"' . $f .
'" => array (' .
"\n";
393 foreach (
$def as $k => $v) {
394 if ($k !=
"nativetype" && $k !=
"alt_types" && $k !=
"autoincrement" && !is_null($v)) {
399 $v = $v ?
"true" :
"false";
410 $create_st .=
"\t\t" . $a_sep .
'"' . $k .
'" => ' . $v .
"\n";
414 $create_st .=
"\t" .
')' .
"\n";
416 $create_st .=
');' .
"\n";
417 $create_st .=
'$ilDB->createTable("' . $a_table .
'", $fields);' .
"\n";
422 fwrite($a_file, $create_st);
435 $pk = $this->analyzer->getPrimaryKeyInformation($a_table);
437 if (is_array($pk[
"fields"]) && count($pk[
"fields"]) > 0) {
438 $pk_st =
"\n" .
'$pk_fields = array(';
440 foreach ($pk[
"fields"] as $f => $pos) {
441 $pk_st .= $sep .
'"' . $f .
'"';
445 $pk_st .=
'$ilDB->addPrimaryKey("' . $a_table .
'", $pk_fields);' .
"\n";
450 fwrite($a_file, $pk_st);
464 $ind = $this->analyzer->getIndicesInformation($a_table,
true);
466 if (is_array($ind)) {
467 foreach ($ind as
$i) {
468 if ($i[
"fulltext"]) {
473 $in_st =
"\n" .
'$in_fields = array(';
475 foreach ($i[
"fields"] as $f => $pos) {
476 $in_st .= $sep .
'"' . $f .
'"';
480 $in_st .=
'$ilDB->addIndex("' . $a_table .
'", $in_fields, "' . $i[
"name"] .
'"' . $ft .
');' .
"\n";
485 fwrite($a_file, $in_st);
500 $con = $this->analyzer->getConstraintsInformation($a_table,
true);
502 if (is_array($con)) {
503 foreach ($con as
$i) {
504 $in_st =
"\n" .
'$in_fields = array(';
506 foreach ($i[
"fields"] as $f => $pos) {
507 $in_st .= $sep .
'"' . $f .
'"';
511 $in_st .=
'$ilDB->addUniqueConstraint("' . $a_table .
'", $in_fields, "' . $i[
"name"] .
'");' .
"\n";
516 fwrite($a_file, $in_st);
531 $seq = $this->analyzer->hasSequence($a_table);
532 if ($seq !==
false) {
533 $seq_st =
"\n" .
'$ilDB->createSequence("' . $a_table .
'", ' . (int) $seq .
');' .
"\n";
538 fwrite($a_file, $seq_st);
551 $r = $this->manager->listSequences();
553 foreach (
$r as $seq) {
554 if (!in_array($seq, $this->tables)) {
556 if ($seq ==
"sahs_sc13_seq") {
560 $create_st =
"\n" .
'$ilDB->createSequence("' . $seq .
'");' .
"\n";
565 fwrite($a_file, $create_st);
583 $ilLog->write(
'Starting export of:' . $a_table);
585 $set = $this->il_db->query(
"SELECT * FROM " . $this->il_db->quoteIdentifier($a_table));
589 mkdir($a_basedir .
'/' . $a_table .
'_inserts', fileperms($a_basedir));
592 while ($rec = $this->il_db->fetchAssoc($set)) {
594 foreach ($rec as $f => $v) {
595 if ($this->
fields[$f][
'type'] ==
'text' and $this->
fields[$f][
'length'] >= 1000) {
600 $this->
fields[$f][
'type'],
608 $ilLog->write(
'Writing insert statements after 1000 lines...');
609 $fp = fopen($a_basedir .
'/' . $a_table .
'_inserts/' . $filenum++ .
'.data',
'w');
618 $fp = fopen($a_basedir .
'/' . $a_table .
'_inserts/' . $filenum++ .
'.data',
'w');
623 $ilLog->write(
'Finished export of: ' . $a_table);
624 if (function_exists(
'memory_get_usage')) {
625 $ilLog->write(
'Memory usage: ' . memory_get_usage(
true));
642 include_once
'./Services/Xml/classes/class.ilXmlWriter.php';
644 $w->xmlStartTag(
'Table',
array(
'name' => $a_table ));
646 $set = $this->il_db->query(
"SELECT * FROM " . $this->il_db->quoteIdentifier($a_table));
649 while ($rec = $this->il_db->fetchAssoc($set)) {
650 #$ilLog->write('Num: '.$num++); 651 $w->xmlStartTag(
'Row');
656 foreach ($rec as $f => $v) {
657 if ($this->
fields[$f][
'type'] ==
'text' and $this->
fields[$f][
'length'] >= 1000) {
663 'type' => $this->
fields[$f][
'type'],
667 $w->xmlEndTag(
'Row');
669 $w->xmlEndTag(
'Table');
671 $w->xmlDumpFile($a_basedir .
'/' . $a_table .
'.xml',
false);
683 if ($a_table ==
"lng_data") {
687 $set = $this->il_db->query(
"SELECT * FROM " . $this->il_db->quoteIdentifier($a_table));
690 while ($rec = $this->il_db->fetchAssoc($set)) {
695 foreach ($rec as $f => $v) {
697 $types[] =
'"' . $this->
fields[$f][
"type"] .
'"';
698 $v = str_replace(
'\\',
'\\\\', $v);
699 $values[] =
"'" . str_replace(
"'",
"\'", $v) .
"'";
700 $i_str[] =
"'" . $f .
"' => array('" . $this->
fields[$f][
"type"] .
"', '" . str_replace(
"'",
"\'", $v) .
"')";
702 $fields_str =
"(" . implode($fields,
",") .
")";
703 $types_str =
"array(" . implode($types,
",") .
")";
704 $values_str =
"array(" . implode($values,
",") .
")";
705 $ins_st =
"\n" .
'$ilDB->insert("' . $a_table .
'", array(' .
"\n";
706 $ins_st .= implode($i_str,
", ") .
"));\n";
714 fwrite($a_file, $ins_st);
728 $tpl =
new ilTemplate(
"tpl.db_overview.html",
true,
true,
"Services/Database");
732 foreach ($this->tables as
$table) {
741 $tpl->setVariable(
"TXT_TITLE",
"ILIAS Abstract DB Tables (" .
ILIAS_VERSION .
")");
743 if ($a_filename ==
"") {
754 $fields = $this->analyzer->getFieldInformation($a_table);
755 $indices = $this->analyzer->getIndicesInformation($a_table);
756 $constraints = $this->analyzer->getConstraintsInformation($a_table);
757 $pk = $this->analyzer->getPrimaryKeyInformation($a_table);
758 $auto = $this->analyzer->getAutoIncrementField($a_table);
759 $has_sequence = $this->analyzer->hasSequence($a_table);
762 if (isset($this->filter[
"has_sequence"])) {
763 if ((!$has_sequence && $auto ==
"" && $this->filter[
"has_sequence"])
764 || (($has_sequence || $auto !=
"") && !$this->filter[
"has_sequence"])
771 $indices_output =
false;
772 if (is_array($indices) && count($indices) > 0 && !$this->filter[
"skip_indices"]) {
775 foreach (
$def[
"fields"] as $f => $pos) {
778 $a_tpl->setCurrentBlock(
"index");
779 $a_tpl->setVariable(
"VAL_INDEX",
$def[
"name"]);
780 $a_tpl->setVariable(
"VAL_FIELDS", implode($f2,
", "));
781 $a_tpl->parseCurrentBlock();
782 $indices_output =
true;
784 $a_tpl->setCurrentBlock(
"index_table");
785 $a_tpl->parseCurrentBlock();
789 $constraints_output =
false;
790 if (is_array($constraints) && count($constraints) > 0 && !$this->filter[
"skip_constraints"]) {
793 foreach (
$def[
"fields"] as $f => $pos) {
796 $a_tpl->setCurrentBlock(
"constraint");
797 $a_tpl->setVariable(
"VAL_CONSTRAINT",
$def[
"name"]);
798 $a_tpl->setVariable(
"VAL_CTYPE",
$def[
"type"]);
799 $a_tpl->setVariable(
"VAL_CFIELDS", implode($f2,
", "));
800 $a_tpl->parseCurrentBlock();
801 $constraints_output =
true;
803 $a_tpl->setCurrentBlock(
"constraint_table");
804 $a_tpl->parseCurrentBlock();
808 $fields_output =
false;
809 foreach ($fields as $field =>
$def) {
811 if (isset($this->filter[
"alt_types"])) {
812 if ((
$def[
"alt_types"] ==
"" && $this->filter[
"alt_types"])
813 || (
$def[
"alt_types"] !=
"" && !$this->filter[
"alt_types"])
818 if (isset($this->filter[
"type"])) {
819 if (
$def[
"type"] != $this->filter[
"type"]) {
823 if (isset($this->filter[
"nativetype"])) {
824 if (
$def[
"nativetype"] != $this->filter[
"nativetype"]) {
828 if (isset($this->filter[
"unsigned"])) {
829 if (
$def[
"unsigned"] != $this->filter[
"unsigned"]) {
834 $a_tpl->setCurrentBlock(
"field");
835 if (empty($pk[
"fields"][$field])) {
836 $a_tpl->setVariable(
"VAL_FIELD", strtolower($field));
838 $a_tpl->setVariable(
"VAL_FIELD",
"<u>" . strtolower($field) .
"</u>");
840 $a_tpl->setVariable(
"VAL_TYPE",
$def[
"type"]);
841 $a_tpl->setVariable(
"VAL_LENGTH", (!is_null(
$def[
"length"])) ?
$def[
"length"] :
" ");
843 if (strtolower($def[
"default"]) ==
"current_timestamp") {
845 unset($def[
"default"]);
848 $a_tpl->setVariable(
"VAL_DEFAULT", (!is_null($def[
"default"])) ? $def[
"default"] :
" ");
849 $a_tpl->setVariable(
"VAL_NOT_NULL", (!is_null($def[
"notnull"])) ? (($def[
"notnull"]) ?
"true" :
"false") :
" ");
850 $a_tpl->setVariable(
"VAL_FIXED", (!is_null($def[
"fixed"])) ? (($def[
"fixed"]) ?
"true" :
"false") :
" ");
851 $a_tpl->setVariable(
"VAL_UNSIGNED", (!is_null($def[
"unsigned"])) ? (($def[
"unsigned"]) ?
"true" :
"false") :
" ");
852 $a_tpl->setVariable(
"VAL_ALTERNATIVE_TYPES", ($def[
"alt_types"] !=
"") ? $def[
"alt_types"] :
" ");
853 $a_tpl->setVariable(
"VAL_NATIVETYPE", ($def[
"nativetype"] !=
"") ? $def[
"nativetype"] :
" ");
854 $a_tpl->parseCurrentBlock();
855 $fields_output =
true;
858 if ($fields_output) {
859 $a_tpl->setCurrentBlock(
"field_table");
860 $a_tpl->parseCurrentBlock();
864 if ($indices_output || $fields_output || $constraints_output) {
865 $a_tpl->setCurrentBlock(
"table");
866 $a_tpl->setVariable(
"TXT_TABLE_NAME", strtolower($a_table));
867 if ($has_sequence || $auto !=
"") {
868 $a_tpl->setVariable(
"TXT_SEQUENCE",
"Has Sequence");
870 $a_tpl->setVariable(
"TXT_SEQUENCE",
"No Sequence");
872 $a_tpl->setVariable(
"VAL_CNT", (
int) $a_cnt);
873 $a_tpl->parseCurrentBlock();
901 include_once
'./Services/Utilities/classes/class.ilStr.php';
904 $shortened = mb_convert_encoding($shortened,
'UTF-8', $this->
getTargetEncoding());
906 if (strlen($a_value) != strlen($shortened)) {
907 $ilLog->write(
'Table : ' .
$table);
908 $ilLog->write(
'Field : ' . $field);
909 $ilLog->write(
'Type : ' . $this->
fields[$field][
'type']);
910 $ilLog->write(
'Length : ' . $this->
fields[$field][
'length']);
911 $ilLog->write(
'Before : ' . $a_value);
912 $ilLog->write(
'Shortened : ' . $shortened);
913 $ilLog->write(
'Strlen Before: ' . strlen($a_value));
914 $ilLog->write(
'Strlen After : ' . strlen($shortened));
getWhiteList()
Get Table White List.
static shortenText($a_string, $a_start_pos, $a_num_bytes, $a_encoding='UTF-8')
Shorten text to the given number of bytes.
setTargetEncoding($a_encoding)
Set the desired target encoding If the target encoding os different from UTF-8 all text values will b...
buildAddIndexStatements($a_table, $a_file="")
Build AddIndex statements.
buildInsertStatement($a_table, $a_basedir)
Write seerialized insert data to array.
setFilter($a_filter, $a_value)
buildAddPrimaryKeyStatement($a_table, $a_file="")
Build AddPrimaryKey statement.
buildCreateTableStatement($a_table, $a_file="")
Build CreateTable statement.
addTableToOverview($a_table, $a_tpl, $a_cnt)
Add table to overview template.
static lookupAbstractedTables()
buildInsertStatements($a_table, $a_file="")
Build Insert statements.
setWhiteList($a_whitelist)
Set Table White List.
__construct()
Constructor.
getTargetEncoding()
Returns the target encoding.
foreach($_POST as $key=> $value) $res
special template class to simplify handling of ITX/PEAR
getHTMLOverview($a_filename="")
Get table definition overview in HTML.
shortenText($table, $field, $a_value, $a_size)
Shorten text depending on target encoding.
Create styles array
The data for the language used.
buildInsertStatementsXML($a_table, $a_basedir)
buildSingularSequenceStatement($a_file="")
Build CreateSequence statement (if not belonging to table)
if(!file_exists("$old.txt")) if($old===$new) if(file_exists("$new.txt")) $file
if(empty($password)) $table
setBlackList($a_blacklist)
Set Table Black List.
This class gives all kind of DB information using the MDB2 manager and reverse module.
checkProcessing($a_table)
Check whether a table should be processed or not.
buildDBGenerationScript($a_filename="")
Build DB generation script.
This class provides methods for building a DB generation script, getting a full overview on abstract ...
buildAddUniqueConstraintStatements($a_table, $a_file="")
Build AddUniqueConstraint statements.
getBlackList()
Get Table Black List.
buildCreateSequenceStatement($a_table, $a_file="")
Build CreateSequence statement.