[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/libraries/vendor/joomla/database/src/Mysql/ -> MysqlExporter.php (source)

   1  <?php
   2  /**
   3   * Part of the Joomla Framework Database Package
   4   *
   5   * @copyright  Copyright (C) 2005 - 2021 Open Source Matters, Inc. All rights reserved.
   6   * @license    GNU General Public License version 2 or later; see LICENSE
   7   */
   8  
   9  namespace Joomla\Database\Mysql;
  10  
  11  use Joomla\Database\DatabaseExporter;
  12  
  13  /**
  14   * MySQL Database Exporter.
  15   *
  16   * @since  1.0
  17   */
  18  class MysqlExporter extends DatabaseExporter
  19  {
  20      /**
  21       * Builds the XML data for the tables to export.
  22       *
  23       * @return  string  An XML string
  24       *
  25       * @since   1.0
  26       * @throws  \Exception if an error occurs.
  27       */
  28  	protected function buildXml()
  29      {
  30          $buffer = [];
  31  
  32          $buffer[] = '<?xml version="1.0"?>';
  33          $buffer[] = '<mysqldump xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">';
  34          $buffer[] = ' <database name="">';
  35  
  36          if ($this->options->withStructure)
  37          {
  38              $buffer = array_merge($buffer, $this->buildXmlStructure());
  39          }
  40  
  41          if ($this->options->withData)
  42          {
  43              $buffer = array_merge($buffer, $this->buildXmlData());
  44          }
  45  
  46          $buffer[] = ' </database>';
  47          $buffer[] = '</mysqldump>';
  48  
  49          return implode("\n", $buffer);
  50      }
  51  
  52      /**
  53       * Builds the XML structure to export.
  54       *
  55       * @return  array  An array of XML lines (strings).
  56       *
  57       * @since   1.0
  58       * @throws  \Exception if an error occurs.
  59       */
  60  	protected function buildXmlStructure()
  61      {
  62          $buffer = [];
  63  
  64          foreach ($this->from as $table)
  65          {
  66              // Replace the magic prefix if found.
  67              $table = $this->getGenericTableName($table);
  68  
  69              // Get the details columns information.
  70              $fields = $this->db->getTableColumns($table, false);
  71              $keys   = $this->db->getTableKeys($table);
  72  
  73              $buffer[] = '  <table_structure name="' . $table . '">';
  74  
  75              foreach ($fields as $field)
  76              {
  77                  $buffer[] = '   <field Field="' . $field->Field . '" Type="' . $field->Type . '" Null="' . $field->Null . '" Key="' .
  78                      $field->Key . '"' . (isset($field->Default) ? ' Default="' . $field->Default . '"' : '') . ' Extra="' . $field->Extra . '"' .
  79                      ' />';
  80              }
  81  
  82              foreach ($keys as $key)
  83              {
  84                  $buffer[] = '   <key Table="' . $table . '" Non_unique="' . $key->Non_unique . '" Key_name="' . $key->Key_name . '"' .
  85                      ' Seq_in_index="' . $key->Seq_in_index . '" Column_name="' . $key->Column_name . '" Collation="' . $key->Collation . '"' .
  86                      ' Null="' . $key->Null . '" Index_type="' . $key->Index_type . '"' .
  87                      ' Sub_part="' . $key->Sub_part . '"' .
  88                      ' Comment="' . htmlspecialchars($key->Comment, \ENT_COMPAT, 'UTF-8') . '"' .
  89                      ' />';
  90              }
  91  
  92              $buffer[] = '  </table_structure>';
  93          }
  94  
  95          return $buffer;
  96      }
  97  
  98      /**
  99       * Checks if all data and options are in order prior to exporting.
 100       *
 101       * @return  $this
 102       *
 103       * @since   1.0
 104       * @throws  \RuntimeException
 105       */
 106  	public function check()
 107      {
 108          // Check if the db connector has been set.
 109          if (!($this->db instanceof MysqlDriver))
 110          {
 111              throw new \RuntimeException('Database connection wrong type.');
 112          }
 113  
 114          // Check if the tables have been specified.
 115          if (empty($this->from))
 116          {
 117              throw new \RuntimeException('ERROR: No Tables Specified');
 118          }
 119  
 120          return $this;
 121      }
 122  }


Generated: Wed Sep 7 05:41:13 2022 Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer