10 defined(
'JPATH_PLATFORM') or die;
25 protected $cache = array();
41 protected $from = array();
49 protected $asFormat =
'xml';
57 protected $options = null;
66 public function __construct()
68 $this->options =
new stdClass;
70 $this->cache = array(
'columns' => array(),
'keys' => array());
75 $this->withStructure();
90 public function asXml()
92 $this->asFormat =
'xml';
105 abstract public function check();
116 public function from($from)
133 protected function getDropColumnSQL($table, $name)
135 return 'ALTER TABLE ' . $this->db->quoteName($table) .
' DROP COLUMN ' . $this->db->quoteName($name);
147 protected function getRealTableName($table)
149 $prefix = $this->db->getPrefix();
152 $table = preg_replace(
'|^#__|', $prefix, $table);
166 protected function mergeStructure()
168 $prefix = $this->db->getPrefix();
169 $tables = $this->db->getTableList();
171 if ($this->from instanceof SimpleXMLElement)
177 $xml =
new SimpleXMLElement($this->from);
181 $xmlTables = $xml->xpath(
'database/table_structure');
183 foreach ($xmlTables as $table)
186 $tableName = (string) $table[
'name'];
187 $tableName = preg_replace(
'|^#__|', $prefix, $tableName);
189 if (in_array($tableName, $tables))
192 if ($queries = $this->getAlterTableSQL($xml->database->table_structure))
195 foreach ($queries as $query)
197 $this->db->setQuery((
string) $query);
201 $this->db->execute();
203 catch (RuntimeException $e)
205 $this->addLog(
'Fail: ' . $this->db->getQuery());
209 $this->addLog(
'Pass: ' . $this->db->getQuery());
216 $sql = $this->xmlToCreate($table);
218 $this->db->setQuery((
string) $sql);
222 $this->db->execute();
224 catch (RuntimeException $e)
226 $this->addLog(
'Fail: ' . $this->db->getQuery());
230 $this->addLog(
'Pass: ' . $this->db->getQuery());
260 public function withStructure($setting =
true)
262 $this->options->withStructure = (boolean) $setting;