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.'; } }
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 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'); }