static function saveVariablePermissions($app, $variableId) { if (!v::intVal()->validate($variableId) || !v::key('indestructible')->validate($app->request->post()) || !v::key('locked')->validate($app->request->post())) { // Validate input parameters return $app->render(400, array('msg' => 'Update failed. Check your parameters and try again.')); } $savedConfig = ConfigData::getVariableById($variableId); if (!$savedConfig) { return $app->render(400, array('msg' => 'Variable doesnt seem to exist.')); } $indestructible = $savedConfig->indestructible; // Converting to boolean did not work well, // This allows a wider range of true false values $indestructible = $app->request->post('indestructible') === 1 || $app->request->post('indestructible') === '1' || $app->request->post('indestructible') === true || $app->request->post('indestructible') === 'true' ? 1 : 0; $locked = $savedConfig->locked; // Converting to boolean did not work well, // This allows a wider range of true false values $locked = $app->request->post('locked') === 1 || $app->request->post('locked') === '1' || $app->request->post('locked') === true || $app->request->post('locked') === 'true' ? 1 : 0; // If its locked its also indestructible $data = array(":id" => $variableId, ":indestructible" => $locked ? 1 : $indestructible, ":locked" => $locked, ":last_updated_by" => APIAuth::getUserId()); $config = ConfigData::updateVariablePermissions($data); if ($config) { $config = ConfigData::getVariableById($variableId); return $app->render(200, array('variable' => $config)); } else { return $app->render(400, array('msg' => 'Could not update system config variable permissions.')); } }