ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
ilDBGenerator Class Reference

This class provides methods for building a DB generation script, getting a full overview on abstract table definitions and more... More...

+ Collaboration diagram for ilDBGenerator:

Public Member Functions

 __construct ()
 Constructor. More...
 
 setTargetEncoding ($a_encoding)
 Set the desired target encoding If the target encoding os different from UTF-8 all text values will be shortened to length of of the current text field. More...
 
 getTargetEncoding ()
 Returns the target encoding. More...
 
 setBlackList ($a_blacklist)
 Set Table Black List. More...
 
 getBlackList ()
 Get Table Black List. More...
 
 setWhiteList ($a_whitelist)
 Set Table White List. More...
 
 getWhiteList ()
 Get Table White List. More...
 
 setFilter ($a_filter, $a_value)
 
 getTables ()
 
 checkProcessing ($a_table)
 Check whether a table should be processed or not. More...
 
 buildDBGenerationScript ($a_filename="")
 Build DB generation script. More...
 
 buildCreateTableStatement ($a_table, $a_file="")
 Build CreateTable statement. More...
 
 buildAddPrimaryKeyStatement ($a_table, $a_file="")
 Build AddPrimaryKey statement. More...
 
 buildAddIndexStatements ($a_table, $a_file="")
 Build AddIndex statements. More...
 
 buildAddUniqueConstraintStatements ($a_table, $a_file="")
 Build AddUniqueConstraint statements. More...
 
 buildCreateSequenceStatement ($a_table, $a_file="")
 Build CreateSequence statement. More...
 
 buildSingularSequenceStatement ($a_file="")
 Build CreateSequence statement (if not belonging to table) More...
 
 buildInsertStatement ($a_table, $a_basedir)
 Write seerialized insert data to array. More...
 
 buildInsertStatementsXML ($a_table, $a_basedir)
 
 buildInsertStatements ($a_table, $a_file="")
 Build Insert statements. More...
 
 getHTMLOverview ($a_filename="")
 Get table definition overview in HTML. More...
 
 addTableToOverview ($a_table, $a_tpl, $a_cnt)
 Add table to overview template. More...
 

Static Public Member Functions

static lookupAbstractedTables ()
 

Protected Member Functions

 openFile ($a_path)
 
 closeFile ($fp)
 
 shortenText ($table, $field, $a_value, $a_size)
 Shorten text depending on target encoding. More...
 

Protected Attributes

 $target_encoding = 'UTF-8'
 
 $whitelist = array()
 
 $blacklist = array()
 
 $tables = array()
 
 $filter = array()
 

Detailed Description

This class provides methods for building a DB generation script, getting a full overview on abstract table definitions and more...

Author
Alex Killing alex..nosp@m.kill.nosp@m.ing@g.nosp@m.mx.d.nosp@m.e
Version
Id
class.ilDBUpdate.php 18649 2009-01-21 09:59:23Z akill

Definition at line 13 of file class.ilDBGenerator.php.

Constructor & Destructor Documentation

◆ __construct()

ilDBGenerator::__construct ( )

Constructor.

Definition at line 41 of file class.ilDBGenerator.php.

References $DIC, $ilDB, ilDBConstants\MODULE_MANAGER, and ilDBConstants\MODULE_REVERSE.

42  {
43  global $DIC;
44  $ilDB = $DIC->database();
45 
46  $this->manager = $ilDB->loadModule(ilDBConstants::MODULE_MANAGER);
47  $this->reverse = $ilDB->loadModule(ilDBConstants::MODULE_REVERSE);
48  $this->il_db = $ilDB;
49  include_once("./Services/Database/classes/class.ilDBAnalyzer.php");
50  $this->analyzer = new ilDBAnalyzer();
51 
52  $this->allowed_attributes = $ilDB->getAllowedAttributes();
53  }
global $DIC
Definition: saml.php:7
global $ilDB
This class gives all kind of DB information using the database manager and reverse module...

Member Function Documentation

◆ addTableToOverview()

ilDBGenerator::addTableToOverview (   $a_table,
  $a_tpl,
  $a_cnt 
)

Add table to overview template.

Definition at line 753 of file class.ilDBGenerator.php.

References $def, $f, and $index.

Referenced by getHTMLOverview().

754  {
755  $fields = $this->analyzer->getFieldInformation($a_table);
756  $indices = $this->analyzer->getIndicesInformation($a_table);
757  $constraints = $this->analyzer->getConstraintsInformation($a_table);
758  $pk = $this->analyzer->getPrimaryKeyInformation($a_table);
759  $auto = $this->analyzer->getAutoIncrementField($a_table);
760  $has_sequence = $this->analyzer->hasSequence($a_table);
761 
762  // table filter
763  if (isset($this->filter["has_sequence"])) {
764  if ((!$has_sequence && $auto == "" && $this->filter["has_sequence"])
765  || (($has_sequence || $auto != "") && !$this->filter["has_sequence"])
766  ) {
767  return false;
768  }
769  }
770 
771  // indices
772  $indices_output = false;
773  if (is_array($indices) && count($indices) > 0 && !$this->filter["skip_indices"]) {
774  foreach ($indices as $index => $def) {
775  $f2 = array();
776  foreach ($def["fields"] as $f => $pos) {
777  $f2[] = $f;
778  }
779  $a_tpl->setCurrentBlock("index");
780  $a_tpl->setVariable("VAL_INDEX", $def["name"]);
781  $a_tpl->setVariable("VAL_FIELDS", implode(", ", $f2));
782  $a_tpl->parseCurrentBlock();
783  $indices_output = true;
784  }
785  $a_tpl->setCurrentBlock("index_table");
786  $a_tpl->parseCurrentBlock();
787  }
788 
789  // constraints
790  $constraints_output = false;
791  if (is_array($constraints) && count($constraints) > 0 && !$this->filter["skip_constraints"]) {
792  foreach ($constraints as $index => $def) {
793  $f2 = array();
794  foreach ($def["fields"] as $f => $pos) {
795  $f2[] = $f;
796  }
797  $a_tpl->setCurrentBlock("constraint");
798  $a_tpl->setVariable("VAL_CONSTRAINT", $def["name"]);
799  $a_tpl->setVariable("VAL_CTYPE", $def["type"]);
800  $a_tpl->setVariable("VAL_CFIELDS", implode(", ", $f2));
801  $a_tpl->parseCurrentBlock();
802  $constraints_output = true;
803  }
804  $a_tpl->setCurrentBlock("constraint_table");
805  $a_tpl->parseCurrentBlock();
806  }
807 
808  // fields
809  $fields_output = false;
810  foreach ($fields as $field => $def) {
811  // field filter
812  if (isset($this->filter["alt_types"])) {
813  if (($def["alt_types"] == "" && $this->filter["alt_types"])
814  || ($def["alt_types"] != "" && !$this->filter["alt_types"])
815  ) {
816  continue;
817  }
818  }
819  if (isset($this->filter["type"])) {
820  if ($def["type"] != $this->filter["type"]) {
821  continue;
822  }
823  }
824  if (isset($this->filter["nativetype"])) {
825  if ($def["nativetype"] != $this->filter["nativetype"]) {
826  continue;
827  }
828  }
829  if (isset($this->filter["unsigned"])) {
830  if ($def["unsigned"] != $this->filter["unsigned"]) {
831  continue;
832  }
833  }
834 
835  $a_tpl->setCurrentBlock("field");
836  if (empty($pk["fields"][$field])) {
837  $a_tpl->setVariable("VAL_FIELD", strtolower($field));
838  } else {
839  $a_tpl->setVariable("VAL_FIELD", "<u>" . strtolower($field) . "</u>");
840  }
841  $a_tpl->setVariable("VAL_TYPE", $def["type"]);
842  $a_tpl->setVariable("VAL_LENGTH", (!is_null($def["length"])) ? $def["length"] : "&nbsp;");
843 
844  if (strtolower($def["default"]) == "current_timestamp") {
845  //$def["default"] = "0000-00-00 00:00:00";
846  unset($def["default"]);
847  }
848 
849  $a_tpl->setVariable("VAL_DEFAULT", (!is_null($def["default"])) ? $def["default"] : "&nbsp;");
850  $a_tpl->setVariable("VAL_NOT_NULL", (!is_null($def["notnull"])) ? (($def["notnull"]) ? "true" : "false") : "&nbsp;");
851  $a_tpl->setVariable("VAL_FIXED", (!is_null($def["fixed"])) ? (($def["fixed"]) ? "true" : "false") : "&nbsp;");
852  $a_tpl->setVariable("VAL_UNSIGNED", (!is_null($def["unsigned"])) ? (($def["unsigned"]) ? "true" : "false") : "&nbsp;");
853  $a_tpl->setVariable("VAL_ALTERNATIVE_TYPES", ($def["alt_types"] != "") ? $def["alt_types"] : "&nbsp;");
854  $a_tpl->setVariable("VAL_NATIVETYPE", ($def["nativetype"] != "") ? $def["nativetype"] : "&nbsp;");
855  $a_tpl->parseCurrentBlock();
856  $fields_output = true;
857  }
858 
859  if ($fields_output) {
860  $a_tpl->setCurrentBlock("field_table");
861  $a_tpl->parseCurrentBlock();
862  }
863 
864  // table information
865  if ($indices_output || $fields_output || $constraints_output) {
866  $a_tpl->setCurrentBlock("table");
867  $a_tpl->setVariable("TXT_TABLE_NAME", strtolower($a_table));
868  if ($has_sequence || $auto != "") {
869  $a_tpl->setVariable("TXT_SEQUENCE", "Has Sequence");
870  } else {
871  $a_tpl->setVariable("TXT_SEQUENCE", "No Sequence");
872  }
873  $a_tpl->setVariable("VAL_CNT", (int) $a_cnt);
874  $a_tpl->parseCurrentBlock();
875 
876  return true;
877  }
878 
879  return false;
880  }
$index
Definition: metadata.php:60
$def
Definition: croninfo.php:21
+ Here is the caller graph for this function:

◆ buildAddIndexStatements()

ilDBGenerator::buildAddIndexStatements (   $a_table,
  $a_file = "" 
)

Build AddIndex statements.

Parameters
stringtable name
filefile resource or empty string

Definition at line 464 of file class.ilDBGenerator.php.

References $f, and $i.

Referenced by buildDBGenerationScript().

465  {
466  $ind = $this->analyzer->getIndicesInformation($a_table, true);
467 
468  if (is_array($ind)) {
469  foreach ($ind as $i) {
470  if ($i["fulltext"]) {
471  $ft = ", true";
472  } else {
473  $ft = ", false";
474  }
475  $in_st = "\n" . '$in_fields = array(';
476  $sep = "";
477  foreach ($i["fields"] as $f => $pos) {
478  $in_st .= $sep . '"' . $f . '"';
479  $sep = ",";
480  }
481  $in_st .= ");\n";
482  $in_st .= '$ilDB->addIndex("' . $a_table . '", $in_fields, "' . $i["name"] . '"' . $ft . ');' . "\n";
483 
484  if ($a_file == "") {
485  echo $in_st;
486  } else {
487  fwrite($a_file, $in_st);
488  }
489  }
490  }
491  }
$i
Definition: disco.tpl.php:19
+ Here is the caller graph for this function:

◆ buildAddPrimaryKeyStatement()

ilDBGenerator::buildAddPrimaryKeyStatement (   $a_table,
  $a_file = "" 
)

Build AddPrimaryKey statement.

Parameters
stringtable name
filefile resource or empty string

Definition at line 435 of file class.ilDBGenerator.php.

References $f.

Referenced by buildDBGenerationScript().

436  {
437  $pk = $this->analyzer->getPrimaryKeyInformation($a_table);
438 
439  if (is_array($pk["fields"]) && count($pk["fields"]) > 0) {
440  $pk_st = "\n" . '$pk_fields = array(';
441  $sep = "";
442  foreach ($pk["fields"] as $f => $pos) {
443  $pk_st .= $sep . '"' . $f . '"';
444  $sep = ",";
445  }
446  $pk_st .= ");\n";
447  $pk_st .= '$ilDB->addPrimaryKey("' . $a_table . '", $pk_fields);' . "\n";
448 
449  if ($a_file == "") {
450  echo $pk_st;
451  } else {
452  fwrite($a_file, $pk_st);
453  }
454  }
455  }
+ Here is the caller graph for this function:

◆ buildAddUniqueConstraintStatements()

ilDBGenerator::buildAddUniqueConstraintStatements (   $a_table,
  $a_file = "" 
)

Build AddUniqueConstraint statements.

Parameters
stringtable name
filefile resource or empty string

Definition at line 500 of file class.ilDBGenerator.php.

References $f, and $i.

Referenced by buildDBGenerationScript().

501  {
502  $con = $this->analyzer->getConstraintsInformation($a_table, true);
503 
504  if (is_array($con)) {
505  foreach ($con as $i) {
506  $in_st = "\n" . '$in_fields = array(';
507  $sep = "";
508  foreach ($i["fields"] as $f => $pos) {
509  $in_st .= $sep . '"' . $f . '"';
510  $sep = ",";
511  }
512  $in_st .= ");\n";
513  $in_st .= '$ilDB->addUniqueConstraint("' . $a_table . '", $in_fields, "' . $i["name"] . '");' . "\n";
514 
515  if ($a_file == "") {
516  echo $in_st;
517  } else {
518  fwrite($a_file, $in_st);
519  }
520  }
521  }
522  }
$i
Definition: disco.tpl.php:19
+ Here is the caller graph for this function:

◆ buildCreateSequenceStatement()

ilDBGenerator::buildCreateSequenceStatement (   $a_table,
  $a_file = "" 
)

Build CreateSequence statement.

Parameters
stringtable name
filefile resource or empty string

Definition at line 531 of file class.ilDBGenerator.php.

Referenced by buildDBGenerationScript().

532  {
533  $seq = $this->analyzer->hasSequence($a_table);
534  if ($seq !== false) {
535  $seq_st = "\n" . '$ilDB->createSequence("' . $a_table . '", ' . (int) $seq . ');' . "\n";
536 
537  if ($a_file == "") {
538  echo $seq_st;
539  } else {
540  fwrite($a_file, $seq_st);
541  }
542  }
543  }
+ Here is the caller graph for this function:

◆ buildCreateTableStatement()

ilDBGenerator::buildCreateTableStatement (   $a_table,
  $a_file = "" 
)

Build CreateTable statement.

Parameters
stringtable name
filefile resource or empty string

Definition at line 384 of file class.ilDBGenerator.php.

References $def, $f, and fields.

Referenced by buildDBGenerationScript().

385  {
386  $fields = $this->analyzer->getFieldInformation($a_table, true);
387  $this->fields = $fields;
388  $create_st = "\n\n//\n// " . $a_table . "\n//\n";
389  $create_st .= '$fields = array (' . "\n";
390  $f_sep = "";
391  foreach ($fields as $f => $def) {
392  $create_st .= "\t" . $f_sep . '"' . $f . '" => array (' . "\n";
393  $f_sep = ",";
394  $a_sep = "";
395  foreach ($def as $k => $v) {
396  if ($k != "nativetype" && $k != "alt_types" && $k != "autoincrement" && !is_null($v)) {
397  switch ($k) {
398  case "notnull":
399  case "unsigned":
400  case "fixed":
401  $v = $v ? "true" : "false";
402  break;
403 
404  case "default":
405  case "type":
406  $v = '"' . $v . '"';
407  break;
408 
409  default:
410  break;
411  }
412  $create_st .= "\t\t" . $a_sep . '"' . $k . '" => ' . $v . "\n";
413  $a_sep = ",";
414  }
415  }
416  $create_st .= "\t" . ')' . "\n";
417  }
418  $create_st .= ');' . "\n";
419  $create_st .= '$ilDB->createTable("' . $a_table . '", $fields);' . "\n";
420 
421  if ($a_file == "") {
422  echo $create_st;
423  } else {
424  fwrite($a_file, $create_st);
425  }
426  }
$errors fields
Definition: imgupload.php:51
$def
Definition: croninfo.php:21
+ Here is the caller graph for this function:

◆ buildDBGenerationScript()

ilDBGenerator::buildDBGenerationScript (   $a_filename = "")

Build DB generation script.

Parameters
stringoutput filename, if no filename is given, script is echoed

Definition at line 291 of file class.ilDBGenerator.php.

References $end, $ok, $path, $start, $table, buildAddIndexStatements(), buildAddPrimaryKeyStatement(), buildAddUniqueConstraintStatements(), buildCreateSequenceStatement(), buildCreateTableStatement(), buildInsertStatement(), buildInsertStatements(), buildSingularSequenceStatement(), checkProcessing(), closeFile(), getTables(), and openFile().

292  {
293  if (@is_dir($a_filename)) {
294  $isDirectory = true;
295  $path = $a_filename;
296  } else {
297  $isDirectory = false;
298  $path = '';
299  }
300 
301  $file = "";
302  if ($a_filename != "" and !$isDirectory) {
303  $file = fopen($a_filename, "w");
304 
305  $start = '<?php' . "\n" . 'function setupILIASDatabase()' . "\n{\n";
306  $start .= "\t" . 'global $ilDB;' . "\n\n";
307  fwrite($file, $start);
308  } elseif ($isDirectory) {
309  ;
310  } else {
311  echo "<pre>";
312  }
313 
314  $this->getTables();
315 
316  foreach ($this->tables as $table) {
317  if ($this->checkProcessing($table)) {
318  if ($a_filename != "") {
319  flush();
320  }
321 
322  if ($isDirectory) {
323  $file = $this->openFile($path . '/' . $table);
324  }
325 
326  // create table statement
327  $this->buildCreateTableStatement($table, $file);
328 
329  // primary key
330  $this->buildAddPrimaryKeyStatement($table, $file);
331 
332  // indices
333  $this->buildAddIndexStatements($table, $file);
334 
335  // constraints (currently unique keys)
336  $this->buildAddUniqueConstraintStatements($table, $file);
337 
338  // auto increment sequence
339  $this->buildCreateSequenceStatement($table, $file);
340 
341  if (in_array($table, array('usr_session_stats', 'usr_session_raw'))) {
342  continue;
343  }
344 
345  // inserts
346  if ($isDirectory) {
347  $this->buildInsertStatement($table, $path);
348  #$this->buildInsertStatementsXML($table,$path);
349  } else {
350  $this->buildInsertStatements($table, $file);
351  }
352 
353  if ($isDirectory) {
354  $this->closeFile($file);
355  }
356  } else {
357  if ($a_filename != "") {
358  echo "<br><b>missing: " . $table . "</b>";
359  flush();
360  }
361  }
362  }
363 
364  // sequence(s) without table (of same name)
365  $this->buildSingularSequenceStatement($file);
366 
367  if ($a_filename == "") {
368  echo "</pre>";
369  } elseif (!$isDirectory) {
370  $end = "\n}\n?>\n";
371  $ok = fwrite($file, $end);
372  var_dump($ok);
373  fclose($file);
374  }
375  }
$path
Definition: aliased.php:25
buildAddIndexStatements($a_table, $a_file="")
Build AddIndex statements.
buildInsertStatement($a_table, $a_basedir)
Write seerialized insert data to array.
buildAddPrimaryKeyStatement($a_table, $a_file="")
Build AddPrimaryKey statement.
buildCreateTableStatement($a_table, $a_file="")
Build CreateTable statement.
buildInsertStatements($a_table, $a_file="")
Build Insert statements.
$start
Definition: bench.php:8
buildSingularSequenceStatement($a_file="")
Build CreateSequence statement (if not belonging to table)
if(empty($password)) $table
Definition: pwgen.php:24
checkProcessing($a_table)
Check whether a table should be processed or not.
buildAddUniqueConstraintStatements($a_table, $a_file="")
Build AddUniqueConstraint statements.
buildCreateSequenceStatement($a_table, $a_file="")
Build CreateSequence statement.
+ Here is the call graph for this function:

◆ buildInsertStatement()

ilDBGenerator::buildInsertStatement (   $a_table,
  $a_basedir 
)

Write seerialized insert data to array.

Parameters
object$a_table
object$a_basedir
Returns

Definition at line 581 of file class.ilDBGenerator.php.

References $DIC, $f, $row, $rows, $values, fields, and shortenText().

Referenced by buildDBGenerationScript().

582  {
583  global $DIC;
584  $ilLogger = $DIC->logger()->root();
585 
586  $ilLogger->log('Starting export of:' . $a_table);
587 
588  $set = $this->il_db->query("SELECT * FROM " . $this->il_db->quoteIdentifier($a_table));
589  $row = 0;
590 
591  umask(0000);
592  mkdir($a_basedir . '/' . $a_table . '_inserts', fileperms($a_basedir));
593 
594  $filenum = 1;
595  while ($rec = $this->il_db->fetchAssoc($set)) {
596  $values = array();
597  foreach ($rec as $f => $v) {
598  if ($this->fields[$f]['type'] == 'text' and $this->fields[$f]['length'] >= 1000) {
599  $v = $this->shortenText($a_table, $f, $v, $this->fields[$f]['length']);
600  }
601 
602  $values[$f] = array(
603  $this->fields[$f]['type'],
604  $v,
605  );
606  }
607 
608  $rows[$a_table][$row++] = $values;
609 
610  if ($row >= 1000) {
611  $ilLogger->log('Writing insert statements after 1000 lines...');
612  $fp = fopen($a_basedir . '/' . $a_table . '_inserts/' . $filenum++ . '.data', 'w');
613  fwrite($fp, serialize((array) $rows));
614  fclose($fp);
615 
616  $row = 0;
617  unset($rows);
618  }
619  }
620  if ($rows) {
621  $fp = fopen($a_basedir . '/' . $a_table . '_inserts/' . $filenum++ . '.data', 'w');
622  fwrite($fp, serialize((array) $rows) . "\n");
623  fclose($fp);
624  }
625 
626  $ilLogger->log('Finished export of: ' . $a_table);
627  if (function_exists('memory_get_usage')) {
628  $ilLogger->log('Memory usage: ' . memory_get_usage(true));
629  }
630 
631  return true;
632  }
global $DIC
Definition: saml.php:7
$errors fields
Definition: imgupload.php:51
$values
shortenText($table, $field, $a_value, $a_size)
Shorten text depending on target encoding.
$row
$rows
Definition: xhr_table.php:10
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ buildInsertStatements()

ilDBGenerator::buildInsertStatements (   $a_table,
  $a_file = "" 
)

Build Insert statements.

Parameters
stringtable name
filefile resource or empty string

Definition at line 682 of file class.ilDBGenerator.php.

References $f, $values, and fields.

Referenced by buildDBGenerationScript().

683  {
684  if ($a_table == "lng_data") {
685  return;
686  }
687 
688  $set = $this->il_db->query("SELECT * FROM " . $this->il_db->quoteIdentifier($a_table));
689  $ins_st = "";
690  $first = true;
691  while ($rec = $this->il_db->fetchAssoc($set)) {
692  $fields = array();
693  $types = array();
694  $values = array();
695  $i_str = array();
696  foreach ($rec as $f => $v) {
697  $fields[] = $f;
698  $types[] = '"' . $this->fields[$f]["type"] . '"';
699  $v = str_replace('\\', '\\\\', $v);
700  $values[] = "'" . str_replace("'", "\'", $v) . "'";
701  $i_str[] = "'" . $f . "' => array('" . $this->fields[$f]["type"] . "', '" . str_replace("'", "\'", $v) . "')";
702  }
703  $fields_str = "(" . implode(",", $fields) . ")";
704  $types_str = "array(" . implode(",", $types) . ")";
705  $values_str = "array(" . implode(",", $values) . ")";
706  $ins_st = "\n" . '$ilDB->insert("' . $a_table . '", array(' . "\n";
707  $ins_st .= implode(", ", $i_str) . "));\n";
708  //$ins_st.= "\t".$fields_str."\n";
709  //$ins_st.= "\t".'VALUES '."(%s".str_repeat(",%s", count($fields) - 1).')"'.",\n";
710  //$ins_st.= "\t".$types_str.','.$values_str.');'."\n";
711 
712  if ($a_file == "") {
713  echo $ins_st;
714  } else {
715  fwrite($a_file, $ins_st);
716  }
717  $ins_st = "";
718  }
719  }
$errors fields
Definition: imgupload.php:51
$values
+ Here is the caller graph for this function:

◆ buildInsertStatementsXML()

ilDBGenerator::buildInsertStatementsXML (   $a_table,
  $a_basedir 
)
Parameters
object$a_table
object$a_file[optional]
Returns

Definition at line 641 of file class.ilDBGenerator.php.

References $f, $values, $w, fields, and shortenText().

642  {
643  include_once './Services/Xml/classes/class.ilXmlWriter.php';
644  $w = new ilXmlWriter();
645  $w->xmlStartTag('Table', array( 'name' => $a_table ));
646 
647  $set = $this->il_db->query("SELECT * FROM " . $this->il_db->quoteIdentifier($a_table));
648  $ins_st = "";
649  $first = true;
650  while ($rec = $this->il_db->fetchAssoc($set)) {
651  #$ilLog->write('Num: '.$num++);
652  $w->xmlStartTag('Row');
653 
654  $fields = array();
655  $types = array();
656  $values = array();
657  foreach ($rec as $f => $v) {
658  if ($this->fields[$f]['type'] == 'text' and $this->fields[$f]['length'] >= 1000) {
659  $v = $this->shortenText($a_table, $f, $v, $this->fields[$f]['length']);
660  }
661 
662  $w->xmlElement('Value', array(
663  'name' => $f,
664  'type' => $this->fields[$f]['type'],
665  ), $v);
666  }
667 
668  $w->xmlEndTag('Row');
669  }
670  $w->xmlEndTag('Table');
671 
672  $w->xmlDumpFile($a_basedir . '/' . $a_table . '.xml', false);
673  }
XML writer class.
$w
$errors fields
Definition: imgupload.php:51
$values
shortenText($table, $field, $a_value, $a_size)
Shorten text depending on target encoding.
+ Here is the call graph for this function:

◆ buildSingularSequenceStatement()

ilDBGenerator::buildSingularSequenceStatement (   $a_file = "")

Build CreateSequence statement (if not belonging to table)

Parameters
filefile resource or empty string

Definition at line 551 of file class.ilDBGenerator.php.

References $r.

Referenced by buildDBGenerationScript().

552  {
553  $r = $this->manager->listSequences();
554 
555  foreach ($r as $seq) {
556  if (!in_array($seq, $this->tables)) {
557  // 12570
558  if ($seq == "sahs_sc13_seq") {
559  continue;
560  }
561 
562  $create_st = "\n" . '$ilDB->createSequence("' . $seq . '");' . "\n";
563 
564  if ($a_file == "") {
565  echo $create_st;
566  } else {
567  fwrite($a_file, $create_st);
568  }
569  }
570  }
571  }
$r
Definition: example_031.php:79
+ Here is the caller graph for this function:

◆ checkProcessing()

ilDBGenerator::checkProcessing (   $a_table)

Check whether a table should be processed or not.

Definition at line 236 of file class.ilDBGenerator.php.

Referenced by buildDBGenerationScript(), and getHTMLOverview().

237  {
238  // check black list
239  if (in_array($a_table, $this->blacklist)) {
240  return false;
241  }
242 
243  // check white list
244  if (count($this->whitelist) > 0 && !in_array($a_table, $this->whitelist)) {
245  return false;
246  }
247 
248  return true;
249  }
+ Here is the caller graph for this function:

◆ closeFile()

ilDBGenerator::closeFile (   $fp)
protected

Definition at line 271 of file class.ilDBGenerator.php.

References $end.

Referenced by buildDBGenerationScript().

272  {
273  if (1) {
274  #fwrite ($fp, $end);
275  fclose($fp);
276 
277  return;
278  }
279 
280  $end = "\n}\n?>\n";
281  fwrite($fp, $end);
282  fclose($fp);
283  }
+ Here is the caller graph for this function:

◆ getBlackList()

ilDBGenerator::getBlackList ( )

Get Table Black List.

Returns
array Table Black List

Definition at line 181 of file class.ilDBGenerator.php.

References $blacklist.

182  {
183  return $this->blacklist;
184  }

◆ getHTMLOverview()

ilDBGenerator::getHTMLOverview (   $a_filename = "")

Get table definition overview in HTML.

Parameters
stringoutput filename, if no filename is given, script is echoed

Definition at line 727 of file class.ilDBGenerator.php.

References $table, $tpl, addTableToOverview(), checkProcessing(), getTables(), and ILIAS_VERSION.

728  {
729  $tpl = new ilTemplate("tpl.db_overview.html", true, true, "Services/Database");
730 
731  $this->getTables();
732  $cnt = 1;
733  foreach ($this->tables as $table) {
734  if ($this->checkProcessing($table)) {
735  // create table statement
736  if ($this->addTableToOverview($table, $tpl, $cnt)) {
737  $cnt++;
738  }
739  }
740  }
741 
742  $tpl->setVariable("TXT_TITLE", "ILIAS Abstract DB Tables (" . ILIAS_VERSION . ")");
743 
744  if ($a_filename == "") {
745  echo $tpl->get();
746  }
747  }
const ILIAS_VERSION
$tpl
Definition: ilias.php:10
addTableToOverview($a_table, $a_tpl, $a_cnt)
Add table to overview template.
special template class to simplify handling of ITX/PEAR
if(empty($password)) $table
Definition: pwgen.php:24
checkProcessing($a_table)
Check whether a table should be processed or not.
+ Here is the call graph for this function:

◆ getTables()

ilDBGenerator::getTables ( )
Returns
array

Definition at line 224 of file class.ilDBGenerator.php.

References $r, and $tables.

Referenced by buildDBGenerationScript(), and getHTMLOverview().

225  {
226  $r = $this->manager->listTables();
227  $this->tables = $r;
228 
229  return $this->tables;
230  }
$r
Definition: example_031.php:79
+ Here is the caller graph for this function:

◆ getTargetEncoding()

ilDBGenerator::getTargetEncoding ( )

Returns the target encoding.

Returns
string

Definition at line 158 of file class.ilDBGenerator.php.

References $target_encoding.

Referenced by shortenText().

159  {
160  return $this->target_encoding;
161  }
+ Here is the caller graph for this function:

◆ getWhiteList()

ilDBGenerator::getWhiteList ( )

Get Table White List.

Returns
array Table White List

Definition at line 205 of file class.ilDBGenerator.php.

References $whitelist.

206  {
207  return $this->whitelist;
208  }

◆ lookupAbstractedTables()

static ilDBGenerator::lookupAbstractedTables ( )
static
Returns
array
Deprecated:
abstraction_progress is no longer used in ILIAS

Definition at line 59 of file class.ilDBGenerator.php.

References $DIC, $ilDB, $query, $res, $row, and ilDBConstants\FETCHMODE_OBJECT.

60  {
61  global $DIC;
62  $ilDB = $DIC->database();
63 
64  $query = "SELECT DISTINCT(table_name) FROM abstraction_progress ";
65  $res = $ilDB->query($query);
66  $names = array();
67  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
68  $names[] = $row->table_name;
69  }
70 
71  // tables that have been already created in an abstracted
72  // way or tables that have been renamed after being abstracted
73  // (see db_update script)
74  $abs_tables = array_merge($names, array(
75  'acc_access_key',
76  'acc_user_access_key',
77  'ldap_rg_mapping',
78  'page_anchor',
79  'qpl_question_orderinghorizontal',
80  'qpl_question_fileupload',
81  'chat_smilies',
82  'style_color',
83  'style_template_class',
84  'style_template',
85  'page_style_usage',
86  'style_setting',
87  'page_editor_settings',
88  'mep_data',
89  'license_data',
90  'loginname_history',
91  'mep_item',
92  'qpl_a_cloze',
93  'qpl_a_imagemap',
94  'qpl_a_matching',
95  'qpl_num_range',
96  'qpl_qst_cloze',
97  'qpl_qst_essay',
98  'qpl_qst_fileupload',
99  'qpl_qst_flash',
100  'qpl_qst_horder',
101  'qpl_qst_imagemap',
102  'qpl_qst_javaapplet',
103  'qpl_qst_matching',
104  'qpl_qst_mc',
105  'qpl_qst_numeric',
106  'qpl_qst_ordering',
107  'qpl_qst_sc',
108  'qpl_qst_textsubset',
109  'qpl_qst_type',
110  'qpl_sol_sug',
111  'udf_text',
112  'udf_clob',
113  'xmlnestedsettmp',
114  'cache_text',
115  'cache_clob',
116  'qpl_a_errortext',
117  'qpl_qst_errortext',
118  'tst_rnd_cpy',
119  'tst_rnd_qpl_title',
120  'qpl_a_mdef',
121  ));
122 
123  return $abs_tables;
124  }
global $DIC
Definition: saml.php:7
foreach($_POST as $key=> $value) $res
$query
$row
global $ilDB

◆ openFile()

ilDBGenerator::openFile (   $a_path)
protected

Definition at line 252 of file class.ilDBGenerator.php.

References $start.

Referenced by buildDBGenerationScript().

253  {
254  if (1) {
255  $file = fopen($a_path, "w");
256  $start .= "\t" . 'global $ilDB;' . "\n\n";
257  fwrite($file, $start);
258 
259  return $file;
260  }
261 
262  $file = fopen($a_path, "w");
263  $start = '<?php' . "\n" . 'function setupILIASDatabase()' . "\n{\n";
264  $start .= "\t" . 'global $ilDB;' . "\n\n";
265  fwrite($file, $start);
266 
267  return $file;
268  }
$start
Definition: bench.php:8
+ Here is the caller graph for this function:

◆ setBlackList()

ilDBGenerator::setBlackList (   $a_blacklist)

Set Table Black List.

(Tables that should not be included in the processing)

Parameters
array$a_blacklistTable Black List

Definition at line 170 of file class.ilDBGenerator.php.

171  {
172  $this->blacklist = $a_blacklist;
173  }

◆ setFilter()

ilDBGenerator::setFilter (   $a_filter,
  $a_value 
)
Parameters
$a_filter
$a_value

Definition at line 215 of file class.ilDBGenerator.php.

216  {
217  $this->filter[$a_filter] = $a_value;
218  }

◆ setTargetEncoding()

ilDBGenerator::setTargetEncoding (   $a_encoding)

Set the desired target encoding If the target encoding os different from UTF-8 all text values will be shortened to length of of the current text field.

E.g: il_meta_keyword keyword(4000) target encoding: UTF16

=> $value = mb_convert_encoding($value,'UTF-8','UTF-16'); $value = mb_strcut($value,0,4000,'UTF16'); $value = mb_convert_encoding($value,'UTF-16','UTF-8');

Parameters
object$a_encoding
Returns

Definition at line 147 of file class.ilDBGenerator.php.

148  {
149  $this->target_encoding = $a_encoding;
150  }

◆ setWhiteList()

ilDBGenerator::setWhiteList (   $a_whitelist)

Set Table White List.

Per default all tables are included in the processing. If a white list ist provided, only them will be used.

Parameters
array$a_whitelistTable White List

Definition at line 194 of file class.ilDBGenerator.php.

195  {
196  $this->whitelist = $a_whitelist;
197  }

◆ shortenText()

ilDBGenerator::shortenText (   $table,
  $field,
  $a_value,
  $a_size 
)
protected

Shorten text depending on target encoding.

Parameters
string$table
string$field
string$a_value
int$a_size
Returns
string

Definition at line 892 of file class.ilDBGenerator.php.

References $DIC, $table, fields, getTargetEncoding(), and ilStr\shortenText().

Referenced by buildInsertStatement(), and buildInsertStatementsXML().

893  {
894  global $DIC;
895  $ilLogger = $DIC->logger()->root();
896 
897  if ($this->getTargetEncoding() == 'UTF-8') {
898  return $a_value;
899  }
900  // Convert to target encoding
901  $shortened = mb_convert_encoding($a_value, $this->getTargetEncoding(), 'UTF-8');
902  // Shorten
903  include_once './Services/Utilities/classes/class.ilStr.php';
904  $shortened = ilStr::shortenText($shortened, 0, $a_size, $this->getTargetEncoding());
905  // Convert back to UTF-8
906  $shortened = mb_convert_encoding($shortened, 'UTF-8', $this->getTargetEncoding());
907 
908  if (strlen($a_value) != strlen($shortened)) {
909  $ilLogger->log('Table : ' . $table);
910  $ilLogger->log('Field : ' . $field);
911  $ilLogger->log('Type : ' . $this->fields[$field]['type']);
912  $ilLogger->log('Length : ' . $this->fields[$field]['length']);
913  $ilLogger->log('Before : ' . $a_value);
914  $ilLogger->log('Shortened : ' . $shortened);
915  $ilLogger->log('Strlen Before: ' . strlen($a_value));
916  $ilLogger->log('Strlen After : ' . strlen($shortened));
917  }
918 
919  return $shortened;
920  }
static shortenText($a_string, $a_start_pos, $a_num_bytes, $a_encoding='UTF-8')
Shorten text to the given number of bytes.
global $DIC
Definition: saml.php:7
$errors fields
Definition: imgupload.php:51
getTargetEncoding()
Returns the target encoding.
if(empty($password)) $table
Definition: pwgen.php:24
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $blacklist

ilDBGenerator::$blacklist = array()
protected

Definition at line 27 of file class.ilDBGenerator.php.

Referenced by getBlackList().

◆ $filter

ilDBGenerator::$filter = array()
protected

Definition at line 35 of file class.ilDBGenerator.php.

◆ $tables

ilDBGenerator::$tables = array()
protected

Definition at line 31 of file class.ilDBGenerator.php.

Referenced by getTables().

◆ $target_encoding

ilDBGenerator::$target_encoding = 'UTF-8'
protected

Definition at line 19 of file class.ilDBGenerator.php.

Referenced by getTargetEncoding().

◆ $whitelist

ilDBGenerator::$whitelist = array()
protected

Definition at line 23 of file class.ilDBGenerator.php.

Referenced by getWhiteList().


The documentation for this class was generated from the following file: