function main() { $PARAMS = array_merge($_GET, $_POST); switch (@$PARAMS['cmd']) { case 'config': update_loader_js(); break; case 'listview': jsondb_views($PARAMS['db_name'], $PARAMS['table_name'], true); break; case 'reset': if (RESET_KEY === @$PARAMS['key']) { jsondb_reset(@$PARAMS['db_name'], @$PARAMS['table_name']); } break; case 'debug': data_idlist('grep-datas', 'historys', 33, false); break; } jsonp_echo(['status' => 'ok']); exit; }
function set_data($db_name, $table_name, $mapper_key, $data) { //检查是否合法 $merged_data = flat_fields($data); $ID = @$merged_data['ID']; if (empty($ID)) { return false; } //(1)更新映射片段 $mappers = data_mapper($db_name, $table_name, $data); if ($mapper_key) { if (!array_key_exists($mapper_key, $mappers)) { $mappers[] = $mapper_key; } } $map_str = ''; foreach ($mappers as $mapper_name) { $map_str .= "\"{$mapper_name}\":{$ID},"; } data_object($db_name, $table_name, $ID . '.map.json', $map_str, false); //(2)更新新的视图片段 $data_view = data_view($db_name, $table_name, $data); $data_str = json_encode($data_view) . ','; data_object($db_name, $table_name, $ID . '.view.json', $data_str, false); //(3)更新ID列表 data_idlist($db_name, $table_name, $ID); return data_object($db_name, $table_name, $ID . '.json', $data); }