public function __call($m, $a) { $ignore_ofs_methods = array('__destruct'); if (in_array($m, $ignore_ofs_methods)) { return 'IGNORE_OFS_COMMAND_COMPLETE'; } // if the command is in the list of commands to run on all ofs objects, do so $all_ofs_methods = array('append_header', 'append_footer'); if (in_array($m, $all_ofs_methods)) { foreach ($this->ofs as $set_id => $ofs) { call_user_func_array(array(&$ofs, $m), $a); } return 'ALL_OFS_COMMAND_COMPLETE'; } $use_replica_set_id = format::get_context_replica_set_id(); if ($use_replica_set_id == -10) { // context_replica_set_id -10 means object does not have slonySetId defined // use the natural first replica set as the replica context $first_replica_set = pgsql8::get_slony_replica_set_natural_first(dbsteward::$new_database); $use_replica_set_id = (int) $first_replica_set['id']; } // make sure replica set id to use is known if (!isset($this->ofs[$use_replica_set_id])) { if ($this->skip_unknown_set_ids) { dbsteward::notice("[OFS RSR] context replica set ID is " . $use_replica_set_id . ", but no replica set by that ID, skipping output"); return FALSE; } throw new exception("context replica set ID " . $use_replica_set_id . " not defined"); } $active_set_ofs = $this->ofs[$use_replica_set_id]; dbsteward::debug("[OFS RSR] __call calling " . $use_replica_set_id . " ofs::" . $m); return call_user_func_array(array(&$active_set_ofs, $m), $a); }
public static function has_permission(&$node_object, $node_permission) { $permission_operations = pgsql8_permission::get_permission_operations($node_permission); // for each of the rights the node_permission provides foreach ($permission_operations as $permission_operation) { // look at each of the permissions on the node_object and see if the right is given foreach (dbx::get_permissions($node_object) as $node_object_permission) { if (strcasecmp($node_object_permission->getName(), $node_permission->getName()) == 0) { if (strcasecmp($node_object_permission['role'], $node_permission['role']) == 0) { // if this node_object_permission of node_object provides the right // the permission is confirmed provided in the object already if (in_array($permission_operation, pgsql8_permission::get_permission_operations($node_object_permission))) { // so move on to the next permission_operation continue 2; } } } } // if we get here if the right is not found in the in_array comparison for the object dbsteward::debug("permission_operation " . $permission_operation . " not found in " . $node_object['name'] . " permissions for " . $node_permission['role']); return false; } // if we get here then all rights were found to be provided in the object already // so the answer to has_permission? is yes return true; }
/** * Parses all rows in CREATE TABLE command. * * @param $node_schema schema table belongs to * @param $node_table table being parsed * @param $command command without 'CREATE TABLE ... (' string */ private static function parse_rows(&$node_schema, &$node_table, $command) { $line = $command; $post_columns = false; while (strlen($line) > 0) { $command_end = sql_parser::get_command_end($line, 0); $subCommand = trim(substr($line, 0, $command_end)); if ($post_columns) { $line = self::parse_post_columns($node_table, $subCommand); break; } else { if (substr($line, $command_end, 1) == ')') { $post_columns = true; } } // look for modifier tokens and act accordingly $tokens = preg_split("/[\\s]+/", $subCommand, -1, PREG_SPLIT_NO_EMPTY); // start at 2, first is always name, second is always type for ($i = 2; $i < count($tokens); $i++) { if (strcasecmp($tokens[$i], 'UNIQUE') == 0) { // CREATE TABLE test_table ( // test_table_id varchar(64) PRIMARY KEY, // test_table_col_c varchar(100) UNIQUE NOT NULL // ); // NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "test_table_pkey" for table "test_table" // NOTICE: CREATE TABLE / UNIQUE will create implicit index "test_table_test_table_col_c_key" for table "test_table" dbsteward::debug("NOTICE: CREATE TABLE with UNIQUE column attribute -- creating implicit index \"" . pgsql8_index::index_name(sql_parser::get_object_name($node_table->get_name()), sql_parser::get_object_name($tokens[0]), 'key') . "\" for table \"" . $node_schema->get_name() . '.' . $node_table->get_name() . "\""); $node_index =& dbx::create_table_index($node_table, pgsql8_index::index_name(sql_parser::get_object_name($node_table['name']), sql_parser::get_object_name($tokens[0]), 'key')); dbx::set_attribute($node_index, 'unique', 'true'); dbx::set_attribute($node_index, 'using', 'btree'); $node_index->addChild('indexDimension', sql_parser::get_object_name($tokens[0]))->addAttribute('name', $tokens[0] . '_unq'); // make sure we don't process this token again unset($tokens[$i]); $tokens = array_merge($tokens); $i--; continue; } // @TODO: other cases? // other cases is how you would fix pgsql8_column::parse_definition() throwing 'column definition parse fail' exceptions } $subCommand = implode(' ', $tokens); self::parse_column_defs($node_schema, $node_table, $subCommand); $line = $command_end >= strlen($line) ? "" : substr($line, $command_end + 1); } $line = trim($line); if (strlen($line) > 0) { throw new exception("Cannot parse CREATE TABLE '" . $node_table['name'] . "' - do not know how to parse '" . $line . "'"); } }
public static function table_dependency_sort(&$table_list, $recursion_index = FALSE) { dbsteward::debug("DEPTH " . sprintf("%03d", self::$table_dependency_sort_depth) . "\t" . "ENTER table_dependency_sort()"); self::$table_dependency_sort_depth++; for ($i = 0; $i < floor(count($table_list) / 2); $i++) { $append_list = array(); for ($j = $i + 1; $j < count($table_list); $j++) { if ($recursion_index !== FALSE) { $j = $recursion_index; } // i depends on j ? if (self::table_has_dependency($table_list[$i], $table_list[$j])) { dbsteward::debug("DEPTH " . sprintf("%03d", self::$table_dependency_sort_depth) . "\t" . $table_list[$i]['schema']['name'] . "." . $table_list[$i]['table']['name'] . " " . $i . "\tDEPENDS ON\t" . $table_list[$j]['schema']['name'] . "." . $table_list[$j]['table']['name'] . " " . $j); $append_list = array_merge($append_list, array($table_list[$i])); // discard the i entry in main array unset($table_list[$i]); // reindex main list $table_list = array_merge($table_list); // the table_list is one smaller, decrement the indices used on it $i--; if ($i < 0) { $i = 0; } $j--; // check for things j is dependant on self::table_dependency_sort($table_list, $j); } if ($recursion_index !== FALSE) { break; } } if (count($append_list) > 0) { // j's dependencies have been added to the end from recursion // now can add the i dependent on j append_list $table_list = array_merge($table_list, $append_list); // do this i index again since the array was reformed $i--; } } self::$table_dependency_sort_depth--; dbsteward::debug("DEPTH " . sprintf("%03d", self::$table_dependency_sort_depth) . "\t" . "RETURN table_dependency_sort()"); }
public static function cmd($command, $error_fatal = TRUE) { dbsteward::debug("dbsteward::cmd( " . $command . " )"); $output = array(); $return_value = 0; $last_line = exec($command, $output, $return_value); if ($return_value > 0) { if ($error_fatal) { dbsteward::error("ERROR(" . $return_value . ") with command: " . $command); dbsteward::error(implode("\n", $output)); throw new exception("ERROR(" . $return_value . ") with command: " . $command); } } return TRUE; }