Joomla Platform  13.1
Documentation des API du framework Joomla Platform
 Tout Classes Espaces de nommage Fichiers Fonctions Variables Pages
postgresql.php
Aller à la documentation de ce fichier.
1 <?php
2 /**
3  * @package Joomla.Platform
4  * @subpackage Database
5  *
6  * @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
7  * @license GNU General Public License version 2 or later; see LICENSE
8  */
9 
10 defined('JPATH_PLATFORM') or die;
11 
12 /**
13  * PostgreSQL export driver.
14  *
15  * @package Joomla.Platform
16  * @subpackage Database
17  * @since 12.1
18  */
20 {
21  /**
22  * Builds the XML data for the tables to export.
23  *
24  * @return string An XML string
25  *
26  * @since 12.1
27  * @throws Exception if an error occurs.
28  */
29  protected function buildXml()
30  {
31  $buffer = array();
32 
33  $buffer[] = '<?xml version="1.0"?>';
34  $buffer[] = '<postgresqldump 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[] = '</postgresqldump>';
41 
42  return implode("\n", $buffer);
43  }
44 
45  /**
46  * Builds the XML structure to export.
47  *
48  * @return array An array of XML lines (strings).
49  *
50  * @since 12.1
51  * @throws Exception if an error occurs.
52  */
53  protected function buildXmlStructure()
54  {
55  $buffer = array();
56 
57  foreach ($this->from as $table)
58  {
59  // Replace the magic prefix if found.
60  $table = $this->getGenericTableName($table);
61 
62  // Get the details columns information.
63  $fields = $this->db->getTableColumns($table, false);
64  $keys = $this->db->getTableKeys($table);
65  $sequences = $this->db->getTableSequences($table);
66 
67  $buffer[] = ' <table_structure name="' . $table . '">';
68 
69  foreach ($sequences as $sequence)
70  {
71  if (version_compare($this->db->getVersion(), '9.1.0') < 0)
72  {
73  $sequence->start_value = null;
74  }
75 
76  $buffer[] = ' <sequence Name="' . $sequence->sequence . '"' . ' Schema="' . $sequence->schema . '"' .
77  ' Table="' . $sequence->table . '"' . ' Column="' . $sequence->column . '"' . ' Type="' . $sequence->data_type . '"' .
78  ' Start_Value="' . $sequence->start_value . '"' . ' Min_Value="' . $sequence->minimum_value . '"' .
79  ' Max_Value="' . $sequence->maximum_value . '"' . ' Increment="' . $sequence->increment . '"' .
80  ' Cycle_option="' . $sequence->cycle_option . '"' .
81  ' />';
82  }
83 
84  foreach ($fields as $field)
85  {
86  $buffer[] = ' <field Field="' . $field->column_name . '"' . ' Type="' . $field->type . '"' . ' Null="' . $field->null . '"' .
87  (isset($field->default) ? ' Default="' . $field->default . '"' : '') . ' Comments="' . $field->comments . '"' .
88  ' />';
89  }
90 
91  foreach ($keys as $key)
92  {
93  $buffer[] = ' <key Index="' . $key->idxName . '"' . ' is_primary="' . $key->isPrimary . '"' . ' is_unique="' . $key->isUnique . '"' .
94  ' Query="' . $key->Query . '" />';
95  }
96 
97  $buffer[] = ' </table_structure>';
98  }
99 
100  return $buffer;
101  }
102 
103  /**
104  * Checks if all data and options are in order prior to exporting.
105  *
106  * @return JDatabaseExporterPostgresql Method supports chaining.
107  *
108  * @since 12.1
109  * @throws Exception if an error is encountered.
110  */
111  public function check()
112  {
113  // Check if the db connector has been set.
114  if (!($this->db instanceof JDatabaseDriverPostgresql))
115  {
116  throw new Exception('JPLATFORM_ERROR_DATABASE_CONNECTOR_WRONG_TYPE');
117  }
118 
119  // Check if the tables have been specified.
120  if (empty($this->from))
121  {
122  throw new Exception('JPLATFORM_ERROR_NO_TABLES_SPECIFIED');
123  }
124 
125  return $this;
126  }
127 }