XOOPS  2.6.0
PrefixStripper.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 
17 
34 class PrefixStripper extends Schema
35 {
36 
37  private $xPrefix = '';
38  private $xDbName = '';
39  private $tableList = array();
40 
44  public function __construct(array $tables=array(), array $sequences=array(), SchemaConfig $schemaConfig=null)
45  {
46  $this->xPrefix = strtolower(\XoopsBaseConfig::get('db-prefix') . '_');
47  $this->xDbName = strtolower(\XoopsBaseConfig::get('db-name'));
48  parent::__construct($tables, $sequences, $schemaConfig);
49  }
50 
60  public function setTableFilter(array $tableList)
61  {
62  $this->tableList = $tableList;
63  }
64 
72  public function addTable(Table $table)
73  {
74  //echo '<h2>addTable()</h2>';
75  try {
76  $name = $table->getName();
77  $len = strlen($this->xPrefix);
78  if (substr_compare($name, $this->xPrefix, 0, $len)===0) {
79  $name = substr($name, $len);
80  if (empty($this->tableList) || in_array($name, $this->tableList)) {
81  $idGeneratorType = 0; // how should we handle this?
82  $newtable = new Table(
83  $name,
84  $table->getColumns(),
85  $table->getIndexes(),
86  $table->getForeignKeys(),
87  $idGeneratorType,
88  $table->getOptions()
89  );
90  $this->_addTable($newtable);
91  }
92  }
93  //Debug::dump($table);
94  } catch (\Exception $e) {
95  \Xoops::getInstance()->events()->triggerEvent('core.exception', $e);
96  throw $e;
97  }
98  }
99 
107  public function addSequence(Sequence $sequence)
108  {
109  //echo '<h2>addSequence()</h2>';
110  try {
111  $this->_addSequence($sequence);
112  //Debug::dump($sequence);
113  } catch (\Exception $e) {
114  \Xoops::getInstance()->events()->triggerEvent('core.exception', $e);
115  throw $e;
116  }
117  }
118 }
static getInstance()
Definition: Xoops.php:160
__construct(array $tables=array(), array $sequences=array(), SchemaConfig $schemaConfig=null)
static get($name)