/** * Executes the current command. * * @param InputInterface $input An InputInterface instance * @param OutputInterface $output An OutputInterface instance * @return null|int null or 0 if everything went fine, or an error code */ protected function execute(InputInterface $input, OutputInterface $output) { $configNames = $input->getArgument('name'); $configName = array_shift($configNames); $defaultValue = $input->getOption('default-value'); if (!in_array($configName, $this->systemConfig->getKeys()) && !$input->hasParameterOption('--default-value')) { return 1; } if (!in_array($configName, $this->systemConfig->getKeys())) { $configValue = $defaultValue; } else { $configValue = $this->systemConfig->getValue($configName); if (!empty($configNames)) { foreach ($configNames as $configName) { if (isset($configValue[$configName])) { $configValue = $configValue[$configName]; } else { if (!$input->hasParameterOption('--default-value')) { return 1; } else { $configValue = $defaultValue; break; } } } } } $this->writeMixedInOutputFormat($input, $output, $configValue); return 0; }
protected function execute(InputInterface $input, OutputInterface $output) { $configName = $input->getArgument('name'); if ($input->hasParameterOption('--error-if-not-exists') && !in_array($configName, $this->systemConfig->getKeys())) { $output->writeln('<error>System config ' . $configName . ' could not be deleted because it did not exist</error>'); return 1; } $this->systemConfig->deleteValue($configName); $output->writeln('<info>System config value ' . $configName . ' deleted</info>'); return 0; }
protected function execute(InputInterface $input, OutputInterface $output) { $configName = $input->getArgument('name'); if (!in_array($configName, $this->systemConfig->getKeys()) && $input->hasParameterOption('--update-only')) { $output->writeln('<comment>Config value ' . $configName . ' not updated, as it has not been set before.</comment>'); return 1; } $configValue = $input->getOption('value'); $this->systemConfig->setValue($configName, $configValue); $output->writeln('<info>System config value ' . $configName . ' set to ' . $configValue . '</info>'); return 0; }
/** * Get the system configs * * @param bool $noSensitiveValues * @return array */ protected function getSystemConfigs($noSensitiveValues) { $keys = $this->systemConfig->getKeys(); $configs = []; foreach ($keys as $key) { if ($noSensitiveValues && in_array($key, $this->sensitiveValues)) { continue; } $value = $this->systemConfig->getValue($key, serialize(null)); if ($value !== 'N;') { $configs[$key] = $value; } } return $configs; }
/** * Executes the current command. * * @param InputInterface $input An InputInterface instance * @param OutputInterface $output An OutputInterface instance * @return null|int null or 0 if everything went fine, or an error code */ protected function execute(InputInterface $input, OutputInterface $output) { $configName = $input->getArgument('name'); $defaultValue = $input->getOption('default-value'); if (!in_array($configName, $this->systemConfig->getKeys()) && !$input->hasParameterOption('--default-value')) { return 1; } if (!in_array($configName, $this->systemConfig->getKeys())) { $configValue = $defaultValue; } else { $configValue = $this->systemConfig->getValue($configName); } $this->writeMixedInOutputFormat($input, $output, $configValue); return 0; }
/** * Get the system configs * * @param bool $noSensitiveValues * @return array */ protected function getSystemConfigs($noSensitiveValues) { $keys = $this->systemConfig->getKeys(); $configs = []; foreach ($keys as $key) { $value = $this->systemConfig->getValue($key, serialize(null)); if ($noSensitiveValues && isset($this->sensitiveValues[$key])) { $value = $this->removeSensitiveValue($this->sensitiveValues[$key], $value); } if ($value !== 'N;') { $configs[$key] = $value; } } return $configs; }
/** * Get the system configs * * @param bool $noSensitiveValues * @return array */ protected function getSystemConfigs($noSensitiveValues) { $keys = $this->systemConfig->getKeys(); $configs = []; foreach ($keys as $key) { if ($noSensitiveValues) { $value = $this->systemConfig->getFilteredValue($key, serialize(null)); } else { $value = $this->systemConfig->getValue($key, serialize(null)); } if ($value !== 'N;') { $configs[$key] = $value; } } return $configs; }
/** * Logs with an arbitrary level. * * @param mixed $level * @param string $message * @param array $context * @return void */ public function log($level, $message, array $context = array()) { $minLevel = min($this->config->getValue('loglevel', Util::WARN), Util::ERROR); $logCondition = $this->config->getValue('log.condition', []); array_walk($context, [$this->normalizer, 'format']); if (isset($context['app'])) { $app = $context['app']; /** * check log condition based on the context of each log message * once this is met -> change the required log level to debug */ if (!empty($logCondition) && isset($logCondition['apps']) && in_array($app, $logCondition['apps'], true)) { $minLevel = Util::DEBUG; } } else { $app = 'no app in context'; } // interpolate $message as defined in PSR-3 $replace = array(); foreach ($context as $key => $val) { $replace['{' . $key . '}'] = $val; } // interpolate replacement values into the message and return $message = strtr($message, $replace); /** * check for a special log condition - this enables an increased log on * a per request/user base */ if ($this->logConditionSatisfied === null) { // default to false to just process this once per request $this->logConditionSatisfied = false; if (!empty($logCondition)) { // check for secret token in the request if (isset($logCondition['shared_secret'])) { $request = \OC::$server->getRequest(); // if token is found in the request change set the log condition to satisfied if ($request && hash_equals($logCondition['shared_secret'], $request->getParam('log_secret'))) { $this->logConditionSatisfied = true; } } // check for user if (isset($logCondition['users'])) { $user = \OC::$server->getUserSession()->getUser(); // if the user matches set the log condition to satisfied if ($user !== null && in_array($user->getUID(), $logCondition['users'], true)) { $this->logConditionSatisfied = true; } } } } // if log condition is satisfied change the required log level to DEBUG if ($this->logConditionSatisfied) { $minLevel = Util::DEBUG; } if ($level >= $minLevel) { $logger = $this->logger; call_user_func(array($logger, 'write'), $app, $message, $level); } }
protected function execute(InputInterface $input, OutputInterface $output) { $configNames = $input->getArgument('name'); $configName = $configNames[0]; $configValue = $this->castValue($input->getOption('value'), $input->getOption('type')); $updateOnly = $input->getOption('update-only'); if (sizeof($configNames) > 1) { $existingValue = $this->systemConfig->getValue($configName); $newValue = $this->mergeArrayValue(array_slice($configNames, 1), $existingValue, $configValue['value'], $updateOnly); $this->systemConfig->setValue($configName, $newValue); } else { if ($updateOnly && !in_array($configName, $this->systemConfig->getKeys(), true)) { throw new \UnexpectedValueException('Config parameter does not exist'); } $this->systemConfig->setValue($configName, $configValue['value']); } $output->writeln('<info>System config value ' . implode(' => ', $configNames) . ' set to ' . $configValue['readable-value'] . '</info>'); return 0; }
protected function execute(InputInterface $input, OutputInterface $output) { $configNames = $input->getArgument('name'); $configName = $configNames[0]; if (sizeof($configNames) > 1) { if ($input->hasParameterOption('--error-if-not-exists') && !in_array($configName, $this->systemConfig->getKeys())) { $output->writeln('<error>System config ' . implode(' => ', $configNames) . ' could not be deleted because it did not exist</error>'); return 1; } $value = $this->systemConfig->getValue($configName); try { $value = $this->removeSubValue(array_slice($configNames, 1), $value, $input->hasParameterOption('--error-if-not-exists')); } catch (\UnexpectedValueException $e) { $output->writeln('<error>System config ' . implode(' => ', $configNames) . ' could not be deleted because it did not exist</error>'); return 1; } $this->systemConfig->setValue($configName, $value); $output->writeln('<info>System config value ' . implode(' => ', $configNames) . ' deleted</info>'); return 0; } else { if ($input->hasParameterOption('--error-if-not-exists') && !in_array($configName, $this->systemConfig->getKeys())) { $output->writeln('<error>System config ' . $configName . ' could not be deleted because it did not exist</error>'); return 1; } $this->systemConfig->deleteValue($configName); $output->writeln('<info>System config value ' . $configName . ' deleted</info>'); return 0; } }
/** * Create the connection parameters for the config * * @param \OC\SystemConfig $config * @return array */ public function createConnectionParams($config) { $type = $config->getValue('dbtype', 'sqlite'); $connectionParams = array('user' => $config->getValue('dbuser', ''), 'password' => $config->getValue('dbpassword', '')); $name = $config->getValue('dbname', 'owncloud'); if ($this->normalizeType($type) === 'sqlite3') { $dataDir = $config->getValue("datadirectory", \OC::$SERVERROOT . '/data'); $connectionParams['path'] = $dataDir . '/' . $name . '.db'; } else { $host = $config->getValue('dbhost', ''); if (strpos($host, ':')) { // Host variable may carry a port or socket. list($host, $portOrSocket) = explode(':', $host, 2); if (ctype_digit($portOrSocket)) { $connectionParams['port'] = $portOrSocket; } else { $connectionParams['unix_socket'] = $portOrSocket; } } $connectionParams['host'] = $host; $connectionParams['dbname'] = $name; } $connectionParams['tablePrefix'] = $config->getValue('dbtableprefix', 'oc_'); $connectionParams['sqlite.journal_mode'] = $config->getValue('sqlite.journal_mode', 'WAL'); //additional driver options, eg. for mysql ssl $driverOptions = $config->getValue('dbdriveroptions', null); if ($driverOptions) { $connectionParams['driverOptions'] = $driverOptions; } return $connectionParams; }
/** * Delete a system wide defined value * * @param string $key the key of the value, under which it was saved */ public function deleteSystemValue($key) { $this->systemConfig->deleteValue($key); }