XOOPS  2.6.0
ImportSchema.php
Go to the documentation of this file.
1 <?php
2 /*
3  You may not change or alter any portion of this comment or credits
4  of supporting developers from this source code or any supporting source code
5  which is considered copyrighted (c) material of the original comment or credit authors.
6 
7  This program is distributed in the hope that it will be useful,
8  but WITHOUT ANY WARRANTY; without even the implied warranty of
9  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 */
11 
13 
20 
35 {
36 
37  private $xPrefix = '';
38  private $xDbName = '';
39  private $schemaArray = array();
40 
44  public function __construct()
45  {
46  $this->xPrefix = strtolower(\XoopsBaseConfig::get('db-prefix') . '_');
47  $this->xDbName = strtolower(\XoopsBaseConfig::get('db-name'));
48  }
49 
57  public function importSchemaArray(array $schemaArray)
58  {
59  $tables = array();
60  $sequences = array();
61  $this->schemaArray = $schemaArray;
62  foreach ($schemaArray as $type => $entity) {
63  switch ($type) {
64  case 'tables':
65  $tables = $this->importTables($entity);
66  break;
67  case 'sequence':
68  $sequences = $this->importSequences($entity);
69  break;
70  }
71  }
72  return new Schema($tables, $sequences);
73  }
74 
82  public function importTables(array $tableArray)
83  {
84  $tables=array();
85  foreach ($tableArray as $name => $tabledef) {
86  //echo '<h2>Table: ' . $name . '</h2>';
87  //Debug::dump($tabledef);
88  $tableName = $this->xPrefix . $name;
89  $columns = array();
90  $indexes = array();
91  $fkConstraints = array();
92  $options = array();
93  $idGeneratorType = 0;
94  foreach ($tabledef['columns'] as $colName => $colOptions) {
95  $colType = \Doctrine\DBAL\Types\Type::getType($colOptions['type']);
96  unset($colOptions['type']);
97  $columns[] = new Column($colName, $colType, $colOptions);
98  }
99 
100  if (isset($tabledef['indexes'])) {
101  foreach ($tabledef['indexes'] as $indexName => $indexDef) {
102  $indexes[] = new Index(
103  $indexName,
104  $indexDef['columns'],
105  $indexDef['unique'],
106  $indexDef['primary']
107  );
108  }
109  }
110 
111  if (isset($tabledef['constraint'])) {
112  foreach ($tabledef['constraint'] as $constraintDef) {
113  $fkConstraints[] = new ForeignKeyConstraint(
114  $constraintDef['localcolumns'],
115  $constraintDef['foreigntable'],
116  $constraintDef['foreigncolumns'],
117  $constraintDef['name'] = null,
118  $constraintDef['options']
119  );
120  }
121  }
122 
123  if (isset($tabledef['options']))
124  $options = $tabledef['options'];
125  $tables[] = new Table(
126  $tableName,
127  $columns,
128  $indexes,
129  $fkConstraints,
130  $idGeneratorType,
131  $options
132  );
133  }
134  return $tables;
135  }
136 
144  public function importSequences(array $sequenceArray)
145  {
146  $sequences = array();
147 
148  foreach ($sequenceArray as $name => $sequenceDef) {
149  //echo '<h2>Sequence: ' . $name . '</h2>';
150  //Debug::dump($sequencedef);
151  $sequences[] = new Sequence(
152  $sequenceDef['name'],
153  $sequenceDef['allocationsize'],
154  $sequenceDef['initialvalue']
155  );
156  }
157  return $sequences;
158  }
159 }
$options['editor']
static get($name)
$type
Definition: misc.php:33