private static function log() { $args = func_get_args(); foreach ($args as $a) { \bbn\tools::log($a, 'dbsync'); } }
public function log() { $ar = func_get_args(); $cn = \bbn\str\text::encode_filename(str_replace('\\', '_', get_class($this))); foreach ($ar as $a) { \bbn\tools::log($a, $cn); } }
/** * Empties the structure tables for a given database and refill them with the current structure * * @param string $db * @return void */ public function update($db = '') { apc_clear_cache(); apc_clear_cache("user"); if (empty($db)) { $db = $this->db->current; } if (\bbn\str\text::check_name($db)) { $change = $this->db->current === $db ? false : $this->db->current; if ($change) { $this->db->change($db); } $schema = $this->db->modelize(); if ($change) { $this->db->change($change); } /* $projects = []; $r1 = $this->db->query("SELECT * FROM `{$this->admin_db}`.`{$this->prefix}projects` WHERE `db` LIKE '$db'"); while ( $d1 = $r1->get_row() ){ $projects[$d1['id']] = $d1; $projects[$d1['id']]['forms'] = []; $r2 = $this->db->query(" SELECT id FROM `{$this->admin_db}`.`{$this->prefix}forms` WHERE `id_project` = ?", $d1['id']); while ( $d2 = $r2->get_row() ){ $projects[$d1['id']]['forms'][$d2['id']] = $this->get_form_config(); } } */ $this->db->query("DELETE IGNORE FROM `{$this->prefix}dbs` WHERE id LIKE '{$db}.%'"); $this->db->query("DELETE IGNORE FROM `{$this->prefix}tables` WHERE id LIKE '{$db}.%'"); $this->db->query("DELETE IGNORE FROM `{$this->prefix}columns` WHERE id LIKE '{$db}.%'"); $this->db->query("DELETE IGNORE FROM `{$this->prefix}keys` WHERE id LIKE '{$db}.%'"); $this->db->raw_query("\n INSERT IGNORE INTO `{$this->admin_db}`.`{$this->prefix}dbs`\n (`id`, `host`, `db`)\n VALUES\n ('{$db}', '{$this->db->host}', '{$db}')"); $has_history = false; if (\bbn\appui\history::$is_used && isset($schema[\bbn\appui\history::$htable])) { $has_history = 1; } foreach ($schema as $t => $vars) { if (strpos($t, '.' . $this->prefix) === false) { $tmp = explode(".", $t); $db = $tmp[0]; $table = $tmp[1]; $this->db->insert_update($this->admin_db . '.' . $this->prefix . 'tables', ['id' => $t, 'db' => $db, 'table' => $table]); foreach ($vars['fields'] as $col => $f) { $config = new \stdClass(); if ($has_history && array_key_exists(\bbn\appui\history::$hcol, $vars['fields']) && $col !== \bbn\appui\history::$hcol) { $config->history = 1; } if (isset($f['default'])) { $config->default = $f['default']; } if (!empty($f['extra'])) { $config->extra = $f['extra']; } if (isset($f['signed']) && $f['signed'] == 1) { $config->signed = 1; } if (isset($f['null']) && $f['null'] == '1') { $config->null = 1; } if (isset($f['maxlength']) && $f['maxlength'] > 0) { $config->maxlength = (int) $f['maxlength']; } if (isset($f['keys'])) { $config->keys = []; foreach ($f['keys'] as $key) { $config->keys[$key] = $vars['keys'][$key]; } } $this->db->insert_update($this->admin_db . '.' . $this->prefix . 'columns', ['id' => $t . '.' . $col, 'table' => $t, 'column' => $col, 'position' => $f['position'], 'type' => $f['type'], 'null' => $f['null'], 'key' => $f['key'], 'config' => json_encode($config)]); } } } foreach ($schema as $t => $vars) { if (strpos($t, '.' . $this->prefix) === false) { if (is_array($vars['keys'])) { foreach ($vars['keys'] as $k => $arr) { $pos = 1; foreach ($arr['columns'] as $c) { $this->db->insert_update($this->admin_db . '.' . $this->prefix . 'keys', ['id' => $t . '.' . $c . '.' . $k, 'key' => $k, 'column' => $t . '.' . $c, 'position' => $pos, 'ref_column' => is_null($arr['ref_column']) ? null : $arr['ref_db'] . '.' . $arr['ref_table'] . '.' . $arr['ref_column']]); $pos++; } } } else { \bbn\tools::log($t); \bbn\tools::log($vars['keys']); } } } /* foreach ( $projects as $i => $p ){ $this->db->insert($this->admin_db.'.'.$this->prefix.'projects',[ 'id' => $i, 'id_client' => $p['id_client'], 'db' => $p['db'], 'name' => $p['name'], 'config' => $p['config']]); foreach ( $p['forms'] as $j => $form ){ $this->db->insert($this->admin_db.'.'.$this->prefix.'forms',[ 'id' => $j, 'id_project' => $i ]); foreach ( $form as $field ){ $this->db->insert_ignore($this->admin_db.'.'.$this->prefix.'fields',[ 'id' => $field['id'], 'id_form' => $j, 'column' => $field['column'], 'title' => $field['title'], 'position' => $field['position'], 'configuration' => json_encode($field['configuration']) ]); } } } * */ } }
public function log($st) { $args = func_get_args(); foreach ($args as $a) { \bbn\tools::log($a, 'db'); } }
public function debug($file = 'misc') { $i = debug_backtrace(); \bbn\tools::log(print_r($i, 1)); }