26 if (ini_get(
'memory_limit') !=
'-1') ini_set(
'memory_limit',
'-1');
27 error_reporting(E_ALL);
29 if (php_sapi_name() !=
'cli') trigger_error(
"You can only run this script from the command line\n", E_USER_ERROR);
31 $SYSTEM_ROOT = (isset($_SERVER[
'argv'][1])) ? $_SERVER[
'argv'][1] :
'';
33 if (empty($SYSTEM_ROOT)) {
34 echo
"ERROR: You need to supply the path to the System Root as the first argument\n";
38 if (!is_dir($SYSTEM_ROOT) || !is_readable($SYSTEM_ROOT.
'/core/include/init.inc')) {
39 echo
"ERROR: Path provided doesn't point to a Matrix installation's System Root. Please provide correct path and try again.\n";
43 define(
'SQ_SYSTEM_ROOT', $SYSTEM_ROOT);
44 define(
'SQ_LOG_PATH', SQ_SYSTEM_ROOT.
'/data/private/logs');
46 require_once
'DB.php';
47 require_once $SYSTEM_ROOT.
'/data/private/conf/main.inc';
48 require_once
'XML/Tree.php';
49 require_once $SYSTEM_ROOT.
'/fudge/dev/dev.inc';
50 require_once $SYSTEM_ROOT.
'/core/include/general.inc';
52 $info = parse_tables_xml($SYSTEM_ROOT.
'/core/assets/tables.xml');
54 $dal_conf = require_once($SYSTEM_ROOT.
'/data/private/conf/db.inc');
59 bam(
'Dropping Oracle sequences');
61 $oci_seqs = $oci_db->getAll(
'SELECT sequence_name FROM user_sequences');
62 foreach($oci_seqs as $key => $value) {
63 $del_seqs[] = strtolower(substr($value[0], 0, strlen($value[0]) - 4));
66 foreach ($info[
'sequences'] as $sequence) {
67 if ($sequence ==
'trig_id') {
73 $key = $info[
'tables'][$table][
'primary_key'][0];
74 $sequence_values[$sequence] =
MatrixDAL::executeSqlOne(
'SELECT '.$key.
' FROM sq_'.$table.
' WHERE rownum = 1 ORDER BY '.$key.
' DESC');
77 if(isset($del_seqs)) {
78 foreach ($del_seqs as $sequence) {
79 printName(
'Dropping: '.strtolower($sequence).
'_seq');
81 printUpdateStatus(
'OK');
87 bam(
'Rebuilding Sequences');
89 foreach ($info[
'sequences'] as $sequence) {
91 $new_seq_start = $sequence_values[$sequence] + 1;
93 printName(
'Creating sq_'.$sequence.
'_seq (New start: '.$new_seq_start.
')');
95 printUpdateStatus(
'OK');
106 function parse_tables_xml($xml_file)
109 $root = &$input->getTreeFromFile();
111 if (PEAR::isError($root)) {
112 trigger_error($root->getMessage().
"\n".$root->getUserInfo(), E_USER_WARNING);
115 if ($root->name !=
'schema' || $root->children[0]->name !=
'tables' || $root->children[1]->name !=
'sequences') {
116 trigger_error($root->getMessage().
"\n".$root->getUserInfo(), E_USER_WARNING);
121 $info[
'tables'] = Array();
125 for ($i = 0; $i < count($root->children[0]->children); $i++) {
126 $table = &$root->children[0]->children[$i];
127 $table_name = $table->attributes[
'name'];
129 $info[
'tables'][$table_name] = Array();
130 $info[
'tables'][$table_name][
'rollback'] = (($table->attributes[
'require_rollback'] == 1) ?
true :
false);
131 $table_cols = &$table->children[0]->children;
135 $info[
'tables'][$table_name][
'columns'] = Array();
137 for ($j = 0; $j < count($table_cols); $j++) {
138 $table_column = &$table_cols[$j];
139 $column_name = $table_column->attributes[
'name'];
141 $info[
'tables'][$table_name][
'columns'][$column_name] = Array();
142 $info[
'tables'][$table_name][
'columns'][$column_name][
'allow_null'] = (($table_column->attributes[
'allow_null'] == 1) ?
true :
false);
149 for ($k = 0; $k < count($table_column->children); $k++) {
150 $column_var = &$table_column->children[$k];
152 switch (strtolower($column_var->name)) {
156 if (is_null($type)) $type = $column_var->content;
158 case 'type_variations' :
160 for ($l = 0; $l < count($column_var->children); $l++) {
161 $variation = &$column_var->children[$l];
162 if ($variation->name ==
'oci8') {
163 $type = $variation->content;
169 if (trim($column_var->content) !=
'') {
170 $default = $column_var->content;
178 $info[
'tables'][$table_name][
'columns'][$column_name][
'type'] = $type;
179 $info[
'tables'][$table_name][
'columns'][$column_name][
'default'] = $default;
183 $info[
'tables'][$table_name][
'primary_key'] = Array();
184 $info[
'tables'][$table_name][
'unique_key'] = Array();
186 $table_keys = &$table->children[1]->children;
187 for ($jj = 0; $jj < count($table_keys); $jj++) {
188 $table_key = &$table_keys[$jj];
191 $key_columns = Array();
192 for ($k = 0; $k < count($table_key->children); $k++) {
193 $col_name = $table_key->children[$k]->attributes[
'name'];
194 $key_columns[] = $col_name;
197 if ($table_key->name ==
'primary_key') {
198 $info[
'tables'][$table_name][
'primary_key'][] = $col_name;
200 if ($table_key->name ==
'unique_key') {
201 $info[
'tables'][$table_name][
'unique_key'][] = $col_name;
209 $table_indexes = &$table->children[2]->children;
210 for ($kk = 0; $kk < count($table_indexes); $kk++) {
211 $table_index = &$table_indexes[$kk];
214 for ($k = 0; $k < count($table_index->children); $k++) {
215 $index_col_name = $table_index->children[$k]->attributes[
'name'];
219 $index_name = array_get_index($table_index->attributes,
'name', $index_col_name);
220 $index_type = array_get_index($table_index->attributes,
'type', null);
221 $index_db_type = array_get_index($table_index->attributes,
'db', null);
224 'name' => $index_name,
225 'type' => $index_type,
226 'db_type' => $index_db_type,
228 $info[
'tables'][$table_name][
'indexes'][$index_col_name] = $index_info;
236 for ($i = 0; $i < count($root->children[1]->children); $i++) {
237 $sequence = &$root->children[1]->children[$i];
238 $sequence_name = $sequence->attributes[
'name'];
239 $info[
'sequences'][] = $sequence_name;
250 function printName($name)
252 printf (
'%s%'.(60 - strlen($name)).
's', $name,
'');
257 function printUpdateStatus($status)
259 echo
"[ $status ]\n";
265 echo
'Standard Message: ' . $db->getMessage() .
"\n";
266 echo
'Standard Code: ' . $db->getMessage() .
"\n";
267 echo
'DBMS/User Message: ' . $db->getUserInfo() .
"\n";
268 echo
'DBMS/Debug Message: ' . $db->getDebugInfo() .
"\n";