public function execute() { $query = 'UPDATE ' . $this->table . ' SET ' . $this->get_values() . $this->get_filters(); compiler::break_cache($this->table); cache::break_cache($this->table); return _db::query($query, $this->parameters); }
public function do_submit() { db::connect_root(); db::query('CREATE DATABASE IF NOT EXISTS `' . get::fn($this->username) . '`'); db::query('USE mysql'); if (db::select('user')->retrieve(['user'])->filter(['`user`=:user AND `host`=:host'], ['user' => $this->username, 'host' => '127.0.0.1'])->execute()->rowCount()) { db::query('CREATE USER \'' . get::fn($this->username) . '\'@\'127.0.0.1\' IDENTIFIED BY \'' . $this->password . '\'', [], true); } if (db::select('user')->retrieve(['user'])->filter(['`user`=:user AND `host`=:host'], ['user' => $this->username, 'host' => 'localhost'])->execute()->rowCount()) { db::query('CREATE USER \'' . get::fn($this->username) . '\'@\'localhost\' IDENTIFIED BY \'' . $this->password . '\'', [], true); } db::query('GRANT ALL PRIVILEGES ON `' . get::fn($this->username) . '`.* TO \'' . get::fn($this->username) . '\'@\'127.0.0.1\'', [], true); db::query('GRANT ALL PRIVILEGES ON `' . get::fn($this->username) . '`.* TO \'' . get::fn($this->username) . '\'@\'localhost\'', [], true); if (!is_dir(root . '/.conf')) { mkdir(root . '/.conf'); } ini::save(root . '/.conf/config.ini', ['mysql' => ['server' => '127.0.0.1', 'username' => get::fn($this->username), 'password' => $this->password, 'database' => get::fn($this->username)], 'site' => ['title_tag' => $this->site_name]]); ini::reload(); db::default_connection(); $cms_builder = new \module\cms\object\cms_builder(); $cms_builder->manage(); $i = 0; do { if ($this->{'user_' . $i} && $this->{'password_' . $i}) { $user = new _cms_user(); $user->title = $this->{'user_' . $i}; $user->password = $this->{'password_' . $i}; $user->ulid = $this->{'user_level_' . $i} ?: 1; } $i++; } while (isset($this->{'user_' . $i})); ajax::current()->redirect = '/cms/login'; }
public function do_submit() { $module = new _cms_module([], $this->mid); $field = new field_type([], $this->type); $type = '\\form\\field_' . $field->title; /** @var \form\field $field_type */ $field_type = new $type(''); if ($inner = $field_type->get_database_create_query()) { db::query('ALTER TABLE ' . $module->table_name . ' ADD `' . $this->field_name . '` ' . $field_type->get_database_create_query(), [], 1); } if ($field->title == 'mlink') { $source_module = new _cms_module(['table_name', 'primary_key'], $this->link_module); db::create_table_join(get::__class_name($this), $source_module->table_name); } $res = db::select('_cms_field')->retrieve('MAX(position) AS pos')->filter_field('mid', $this->mid)->execute()->fetchObject(); $insert = db::insert('_cms_field')->add_value('title', $this->title)->add_value('type', $field->title)->add_value('field_name', $this->field_name)->add_value('mid', $this->mid)->add_value('position', $res->pos + 1); if ($field->title == 'link' || $field->title == 'mlink') { $insert->add_value('link_module', $this->link_module)->add_value('link_field', $this->link_field); } $insert->execute(); table::rebuild_modules(); table::reset_module_fields($module->mid); ajax::update($module->get_fields_list()->get()); ajax::update($this->get_html()->get()); }
/** * @return \PDOStatement */ public function execute() { $query = 'DELETE FROM ' . $this->table . $this->get_filters(); compiler::break_cache($this->table); cache::break_cache($this->table); return _db::query($query, $this->parameters); }
public function execute() { $query = 'REPLACE INTO ' . $this->table . ' SET ' . $this->get_values(); _db::query($query, $this->parameters); $id = _db::insert_id(); compiler::break_cache($this->table); cache::break_cache($this->table); return $id; }
public function do_submit() { $module = new _cms_module([], $this->mid); $field = new field_type([], $this->type); $old_field = new _cms_field([], $this->fid); $type = '\\form\\field_' . $field->title; /** @var \form\field $field_type */ $field_type = new $type(''); if ($inner = $field_type->get_database_create_query()) { db::query('ALTER TABLE ' . $module->table_name . ' MODIFY `' . $old_field->field_name . '` `' . $this->field_name . '` ' . $field_type->get_database_create_query(), [], 1); } if ($field->title == 'mlink' && $old_field->type !== 'mlink') { $source_module = new _cms_module(['table_name', 'primary_key'], $this->link_module); db::create_table_join(\classes\get::__class_name($this), $source_module->table_name); } $insert = db::update('_cms_field')->add_value('title', $this->title)->add_value('type', $field->title)->add_value('field_name', $this->field_name)->add_value('link_module', $this->link_module)->add_value('link_field', $this->link_field)->filter_field('fid', $this->fid); $insert->execute(); table::rebuild_modules(); table::reset_module_fields($module->mid); ajax::update($module->get_fields_list()->get()); ajax::update($this->get_html()->get()); }
public static function create_table_json($json) { $sql = 'CREATE TABLE IF NOT EXISTS ' . $json->tablename; $column_strings = []; foreach ($json->fieldset as $field => $structure) { $string = static::get_column_type_json($structure); if ($string) { $column_strings[] = '`' . $field . '` ' . $string; } } foreach ($json->indexes as $type => $indexes) { switch ($type) { case 'primary': $column_strings[] = 'PRIMARY KEY (`' . $indexes . '`)'; break; case 'standard': foreach ($indexes as $index) { $column_strings[] = 'INDEX (`' . implode('`,`', $index) . '`)'; } break; } } $sql .= ' (' . implode(',', $column_strings) . ') '; $setting_strings = []; foreach (_db::$default_table_settings as $setting => $value) { if (is_numeric($setting)) { $setting_strings[] = $value; } else { $setting_strings[] = $setting . ' = ' . $value; } } foreach ($json->settings as $setting => $value) { if (is_numeric($setting)) { $setting_strings[] = $value; } else { $setting_strings[] = $setting . ' = ' . $value; } } $sql .= implode(',', $setting_strings); _db::query($sql); }
public function do_submit() { db::query('CREATE TABLE IF NOT EXISTS `' . $this->table_name . '` ( `' . $this->primary_key . '` int(4) NOT NULL AUTO_INCREMENT, `parent_' . $this->primary_key . '` int(4) NOT NULL DEFAULT "0", `ts` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `cms_created` timestamp NOT NULL DEFAULT "0000-00-00 00:00:00", `live` tinyint(1) NOT NULL DEFAULT "0", `deleted` tinyint(1) NOT NULL DEFAULT "0", `position` int(6) NOT NULL DEFAULT "0", `' . get::fn($this->title_label) . '` varchar(255) NOT NULL, PRIMARY KEY (`' . $this->primary_key . '`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=0;'); $mid = db::insert('_cms_module')->add_value('gid', $this->gid)->add_value('primary_key', $this->primary_key)->add_value('title', $this->title)->add_value('table_name', $this->table_name)->add_value('namespace', $this->namespace)->execute(); $id_field = db::insert('_cms_field')->add_value('field_name', $this->primary_key)->add_value('title', 'ID')->add_value('type', 'int')->add_value('mid', $mid)->add_value('required', false)->add_value('list', false)->add_value('editable', false)->add_value('filter', false)->execute(); db::insert('_cms_field')->add_value('field_name', 'parent_' . $this->primary_key)->add_value('title', 'Parent ID')->add_value('type', 'link')->add_value('mid', $mid)->add_value('link_module', $mid)->add_value('link_field', (int) $id_field + 2)->add_value('required', false)->add_value('list', false)->execute(); db::insert('_cms_field')->add_value('field_name', get::fn($this->title_label))->add_value('title', $this->title_label)->add_value('type', 'string')->add_value('mid', $mid)->execute(); $file = null; if (!$this->namespace) { if (!is_dir(root . '/inc/object/')) { mkdir(root . '/inc/object/'); } if (!file_exists(root . '/inc/object/' . $this->table_name)) { $file = root . '/inc/object/' . $this->table_name; } } else { if (!is_dir(root . '/inc/module/')) { mkdir(root . '/inc/module/'); } if (!is_dir(root . '/inc/module/' . $this->namespace)) { mkdir(root . '/inc/module/' . $this->namespace); } if (!is_dir(root . '/inc/module/' . $this->namespace . '/object/')) { mkdir(root . '/inc/module/' . $this->namespace . '/object'); } if (!file_exists(root . '/inc/module/' . $this->namespace . '/object/' . $this->table_name)) { $file = root . '/inc/module/' . $this->namespace . '/object/' . $this->table_name; } } if ($file) { $class_name = ($this->namespace ? 'module\\' . $this->namespace . '\\' : '') . 'object\\' . $this->table_name; file_put_contents($file . '.php', '<?php namespace ' . ($this->namespace ? 'module\\' . $this->namespace . '\\' : '') . 'object; use classes\\table; use traits\\table_trait; class ' . $this->table_name . ' extends ' . (class_exists('\\core\\' . $class_name) ? '\\core\\' . $class_name : 'table') . ' { use table_trait; /** @var string */ public $' . get::fn($this->title_label) . '; /** @var int */ public $' . get::fn($this->primary_key) . '; }'); } \classes\table::rebuild_modules(); ajax::add_script('window.location = window.location'); }
/** * @return \PDOStatement */ public function execute() { $query = 'SELECT ' . $this->get_fields() . ' FROM ' . $this->table . $this->get_joins() . $this->get_filters() . $this->get_groupings() . $this->get_order() . ' ' . $this->get_limit(); return _db::query($query, $this->parameters); }
/** * @return int * */ public function execute() { $query = 'SELECT COUNT(' . $this->fields[0] . ') AS count FROM ' . $this->table . $this->get_joins() . $this->get_filters() . $this->get_groupings() . ' ' . $this->get_limit(); $res = db::query($query, $this->parameters); return $res->fetchObject()->count; }
} } if ($part_cnt == 500) { $statement = db::$con->prepare($base_sql . implode(',', $sql_sets)); $statement->execute($params); echo '<p>' . $cnt . ' rows imported.</p>'; $params = []; $sql_sets = []; $part_cnt = 0; } } if ($params) { $statement = db::$con->prepare($base_sql . implode(',', $sql_sets)); $statement->execute($params); echo '<p>' . $cnt . ' rows imported.</p>'; $params = []; $sql_sets = []; $part_cnt = 0; } echo '<p><span style="color:green">Completed</span></p>'; } db::query('UPDATE flight SET lid = lid+1'); db::query('UPDATE flight SET ftid = ftid+1'); db::query('UPDATE flight SET `position` = fid'); function get_manu($manu) { $res = db::result('SELECT mid FROM manufacturer WHERE title =:title', array('title' => $manu)); if ($res) { return $res->mid; } }