function update($f3) { $uuid = $f3->get('REQUEST.uuid'); print_r($f3->get('REQUEST')); if (!empty($uuid)) { $db = new \DB\Jig('db/', \DB\Jig::FORMAT_JSON); $item = new \DB\Jig\Mapper($db, 'units.json'); $item->load(array('@uuid==?', $uuid)); if ($item->dry()) { echo 'New Unit'; } foreach ($f3->get('REQUEST') as $k => $v) { if ($k == "message") { $db_mess = new \DB\Jig('db/', \DB\Jig::FORMAT_JSON); $message = new \DB\Jig\Mapper($db_mess, 'messages.json'); $message->copyFrom('REQUEST.message'); $message->save(); } else { $item->{$k} = $v; } } $item->save(); echo 'Ok !'; } else { echo 'UUID not set.'; } }
public function check_configuration() { $config = new DB\Jig\Mapper($this->db, 'sysconfig.json'); if (!$config->load()) { echo json_encode(array('message' => 'No config file found')); F3::error(428); exit; } }
function update($f3) { $uuid = $f3->get('REQUEST.uuid'); //print_r($f3->get('REQUEST')); if (!empty($uuid)) { $db = new DB\Jig('db/', DB\Jig::FORMAT_JSON); $item = new DB\Jig\Mapper($db, 'victims'); $item->load(array('@uuid==?', $uuid)); if ($item->dry()) { echo 'New Victim'; } foreach ($f3->get('REQUEST') as $k => $v) { $item->{$k} = $v; } $item->save(); } else { echo 'UUID not set.'; } }
public function check_uniq_value($value, $table, $field_name) { $table = new DB\Jig\Mapper($this->db, "{$table}.json"); $match = $table->find(array("(isset(@{$field_name}) && @{$field_name} == ?)", $value)); if ($match) { self::show_error("{$field_name} must be unique", 409); } }
public function put_data($f3, $args) { $table = explode('=', $args[0])[1]; if ($table) { Common::check_permissions('U', $table, $this->token); $params = json_decode($f3->get('BODY')); $records = new \DB\Jig\Mapper($this->db, $table . '.json'); $record = $records->load(['@_id == ?', $args['id']]); foreach ($params as $key => $value) { if (!preg_match('/id/', $key)) { if ($table == 'users') { // users table "special" if ($key == 'userName' && $value && $value != $record[$key]) { Common::check_uniq_value($value, 'users', 'userName'); $record[$key] = $value; } if ($key == 'password' && $value) { $record[$key] = password_hash($value, PASSWORD_DEFAULT); } } else { $record[$key] = $value; } } } $result = $record->update(); if ($table == 'users') { unset($result['password']); } echo json_encode($result); } else { Common::show_error('Table name required', 500); } }
public static function buildConfig() { $fw = \Base::instance(); $new = "{$fw['installerCFG.db5.dbname']}`.`{$fw['installerCFG.db5.prefix']}"; // create instance of the final config file $fw->newCFG = new \DB\Jig("../data", \DB\Jig::FORMAT_JSON); $mapper = new \DB\Jig\Mapper($fw->newCFG, 'config.json'); $mapper->ACTIVE_DB = "MYSQL"; $mapper->DB_MYSQL = array("dsn" => $fw->get('installerCFG.dsn.5'), "user" => $fw->get('installerCFG.dbuser'), "password" => $fw->get('installerCFG.dbpass')); $mapper->prefix = $fw->get('installerCFG.db5.prefix'); // Get entries from configuration table $cfgData = $fw->db5->exec("SELECT `name`, `value` FROM `{$new}config` WHERE `to_config_file` = 1 ORDER BY `name` ASC "); foreach ($cfgData as $cfgItem) { /* experimental */ if ($cfgItem['value'] == "TRUE") { $cfgItem['value'] = TRUE; } elseif ($cfgItem['value'] == "FALSE") { $cfgItem['value'] = FALSE; } $cfgItem['name'] = explode("__", $cfgItem['name']); if (isset($cfgItem['name'][1])) { // nested key structures, like bb2__verbose -> bb2[verbose] if (empty($mapper->{$cfgItem['name'][0]})) { $mapper->{$cfgItem['name'][0]} = []; } $mapper->{$cfgItem['name'][0]}[$cfgItem['name'][1]] = $cfgItem['value']; } else { if (NULL === ($c = json_decode($cfgItem['value']))) { $mapper->{$cfgItem['name'][0]} = $cfgItem['value']; } else { $mapper->{$cfgItem['name'][0]} = $c; } } } // Get optional modules, that were enabled $modules = []; foreach ($fw['installerCFG.optional'] as $moduleName => $moduleOpt) { if ($moduleOpt[0] != "-") { $modules[$moduleName] = 1; } } if (sizeof($modules) > 0) { $mapper->modules_enabled = $modules; } // Build page stat cache $statSQL = ["SET @users = (SELECT COUNT(*) FROM `{$new}users`U WHERE U.groups > 0);", "SET @authors = (SELECT COUNT(*) FROM `{$new}users`U WHERE ( U.groups & 4 ) );", "SET @reviews = (SELECT COUNT(*) FROM `{$new}feedback`F WHERE F.type='ST');", "SET @stories = (SELECT COUNT(DISTINCT sid) FROM `{$new}stories`S WHERE S.validated > 0 );", "SET @chapters = (SELECT COUNT(DISTINCT chapid) FROM `{$new}chapters`C INNER JOIN `{$new}stories`S ON ( C.sid=S.sid AND S.validated > 0 AND C.validated > 0) );", "SET @words = (SELECT SUM(C.wordcount) FROM `{$new}chapters`C INNER JOIN `{$new}stories`S ON ( C.sid=S.sid AND S.validated > 0 AND C.validated > 0) );", "SET @newmember = (SELECT CONCAT_WS(',', U.uid, U.nickname) FROM `{$new}users`U WHERE U.groups>0 ORDER BY U.registered DESC LIMIT 1);", "SELECT @users as users, @authors as authors, @reviews as reviews, @stories as stories, @chapters as chapters, @words as words, @newmember as newmember;"]; $statsData = $fw->db5->exec($statSQL)[0]; foreach ($statsData as $statKey => $statValue) { $stats[$statKey] = $statKey == "newmember" ? explode(",", $statValue) : $statValue; //->{$statKey} = ($statKey=="newmember") ? json_encode(explode(",",$statValue)) : $statValue; } $mapper->stats = $stats; $mapper->save(); $fw->set('continue', ['message' => 'Configuration file built', 'step' => $fw->get('PARAMS.step') + 1]); return Template::instance()->render('steps.htm'); }