1 <?php
  2   3   4   5   6   7   8 
  9 
 10 defined('JPATH_PLATFORM') or die;
 11 
 12  13  14  15  16  17  18 
 19 class JDatabaseExporterPdomysql extends JDatabaseExporter
 20 {
 21      22  23  24  25  26  27  28 
 29     protected function buildXml()
 30     {
 31         $buffer   = array();
 32 
 33         $buffer[] = '<?xml version="1.0"?>';
 34         $buffer[] = '<mysqldump xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">';
 35         $buffer[] = ' <database name="">';
 36 
 37         $buffer   = array_merge($buffer, $this->buildXmlStructure());
 38 
 39         $buffer[] = ' </database>';
 40         $buffer[] = '</mysqldump>';
 41 
 42         return implode("\n", $buffer);
 43     }
 44 
 45      46  47  48  49  50  51  52 
 53     protected function buildXmlStructure()
 54     {
 55         $buffer = array();
 56 
 57         foreach ($this->from as $table)
 58         {
 59             
 60             $table = $this->getGenericTableName($table);
 61 
 62             
 63             $fields = $this->db->getTableColumns($table, false);
 64             $keys   = $this->db->getTableKeys($table);
 65 
 66             $buffer[] = '  <table_structure name="' . $table . '">';
 67 
 68             foreach ($fields as $field)
 69             {
 70                 $buffer[] = '   <field Field="' . $field->Field . '"' . ' Type="' . $field->Type . '"' . ' Null="' . $field->Null . '"' . ' Key="' .
 71                     $field->Key . '"' . (isset($field->Default) ? ' Default="' . $field->Default . '"' : '') . ' Extra="' . $field->Extra . '"' .
 72                     ' />';
 73             }
 74 
 75             foreach ($keys as $key)
 76             {
 77                 $buffer[] = '   <key Table="' . $table . '"' . ' Non_unique="' . $key->Non_unique . '"' . ' Key_name="' . $key->Key_name . '"' .
 78                     ' Seq_in_index="' . $key->Seq_in_index . '"' . ' Column_name="' . $key->Column_name . '"' . ' Collation="' . $key->Collation . '"' .
 79                     ' Null="' . $key->Null . '"' . ' Index_type="' . $key->Index_type . '"' .
 80                     ' Comment="' . htmlspecialchars($key->Comment, ENT_COMPAT, 'UTF-8') . '"' . ' />';
 81             }
 82 
 83             $buffer[] = '  </table_structure>';
 84         }
 85 
 86         return $buffer;
 87     }
 88 
 89      90  91  92  93  94  95  96 
 97     public function check()
 98     {
 99         
100         if (!($this->db instanceof JDatabaseDriverPdomysql))
101         {
102             throw new Exception('JPLATFORM_ERROR_DATABASE_CONNECTOR_WRONG_TYPE');
103         }
104 
105         
106         if (empty($this->from))
107         {
108             throw new Exception('JPLATFORM_ERROR_NO_TABLES_SPECIFIED');
109         }
110 
111         return $this;
112     }
113 }
114