1
0
Fork 0

Merge remote-tracking branch 'origin/develop' into install_config

This commit is contained in:
Philipp Holzer 2018-04-21 14:23:49 +02:00
commit 334d392154
90 changed files with 59497 additions and 56448 deletions

View file

@ -50,7 +50,7 @@ class MemcachedCacheDriver extends BaseObject implements ICacheDriver
{
// We store with the hostname as key to avoid problems with other applications
return $this->memcached->set(
self::getApp()->get_hostname() . ":" . $key,
self::getApp()->get_hostname() . ':' . $key,
$value,
time() + $duration
);
@ -58,7 +58,9 @@ class MemcachedCacheDriver extends BaseObject implements ICacheDriver
public function delete($key)
{
return $this->memcached->delete($key);
$return = $this->memcached->delete(self::getApp()->get_hostname() . ':' . $key);
return $return;
}
public function clear()

View file

@ -32,6 +32,10 @@ class PreloadPConfigAdapter extends BaseObject implements IPConfigAdapter
return;
}
if (empty($uid)) {
return;
}
$pconfigs = dba::select('pconfig', ['cat', 'v', 'k'], ['uid' => $uid]);
while ($pconfig = dba::fetch($pconfigs)) {
self::getApp()->setPConfigValue($uid, $pconfig['cat'], $pconfig['k'], $pconfig['v']);
@ -43,6 +47,10 @@ class PreloadPConfigAdapter extends BaseObject implements IPConfigAdapter
public function get($uid, $cat, $k, $default_value = null, $refresh = false)
{
if (!$this->config_loaded) {
$this->load($uid, $cat);
}
if ($refresh) {
$config = dba::selectFirst('pconfig', ['v'], ['uid' => $uid, 'cat' => $cat, 'k' => $k]);
if (DBM::is_result($config)) {
@ -59,6 +67,9 @@ class PreloadPConfigAdapter extends BaseObject implements IPConfigAdapter
public function set($uid, $cat, $k, $value)
{
if (!$this->config_loaded) {
$this->load($uid, $cat);
}
// We store our setting values as strings.
// So we have to do the conversion here so that the compare below works.
// The exception are array values.
@ -83,6 +94,10 @@ class PreloadPConfigAdapter extends BaseObject implements IPConfigAdapter
public function delete($uid, $cat, $k)
{
if (!$this->config_loaded) {
$this->load($uid, $cat);
}
self::getApp()->deletePConfigValue($uid, $cat, $k);
$result = dba::delete('pconfig', ['uid' => $uid, 'cat' => $cat, 'k' => $k]);

View file

@ -21,6 +21,7 @@ class Console extends \Asika\SimpleConsole\Console
'extract' => __NAMESPACE__ . '\Console\Extract',
'globalcommunityblock' => __NAMESPACE__ . '\Console\GlobalCommunityBlock',
'globalcommunitysilence' => __NAMESPACE__ . '\Console\GlobalCommunitySilence',
'autoinstall' => __NAMESPACE__ . '\Console\AutomaticInstallation',
'maintenance' => __NAMESPACE__ . '\Console\Maintenance',
'newpassword' => __NAMESPACE__ . '\Console\NewPassword',
'php2po' => __NAMESPACE__ . '\Console\PhpToPo',
@ -42,6 +43,7 @@ Commands:
globalcommunityblock Block remote profile from interacting with this node
globalcommunitysilence Silence remote profile from global community page
help Show help about a command, e.g (bin/console help config)
autoinstall Starts automatic installation of friendica based on values from htconfig.php
maintenance Set maintenance mode for this node
newpassword Set a new password for a given user
php2po Generate a messages.po file from a strings.php file

View file

@ -0,0 +1,164 @@
<?php
namespace Friendica\Core\Console;
use Asika\SimpleConsole\Console;
use dba;
use Friendica\App;
require_once 'mod/install.php';
require_once 'include/dba.php';
class AutomaticInstallation extends Console
{
protected function getHelp()
{
return <<<HELP
Installation - Install Friendica automatically
Synopsis
bin/console autoinstall [-h|--help|-?] [-v] [-a]
Description
Installs Friendica with data based on the htconfig.php file
Notes:
Not checking .htaccess/URL-Rewrite during CLI installation.
Options
-h|--help|-? Show help information
-v Show more debug information.
-a All setup checks are required (except .htaccess)
HELP;
}
protected function doExecute()
{
// Initialise the app
$this->out("Initializing setup...\n");
$a = get_app();
$db_host = '';
$db_user = '';
$db_pass = '';
$db_data = '';
require_once 'htconfig.php';
$this->out(" Complete!\n\n");
// Check basic setup
$this->out("Checking basic setup...\n");
$checkResults = [];
$checkResults['basic'] = $this->runBasicChecks($a);
$errorMessage = $this->extractErrors($checkResults['basic']);
if ($errorMessage !== '') {
throw new \RuntimeException($errorMessage);
}
$this->out(" Complete!\n\n");
// Check database connection
$this->out("Checking database...\n");
$checkResults['db'] = array();
$checkResults['db'][] = $this->runDatabaseCheck($db_host, $db_user, $db_pass, $db_data);
$errorMessage = $this->extractErrors($checkResults['db']);
if ($errorMessage !== '') {
throw new \RuntimeException($errorMessage);
}
$this->out(" Complete!\n\n");
// Install database
$this->out("Inserting data into database...\n");
$checkResults['data'] = load_database();
if ($checkResults['data'] !== '') {
throw new \RuntimeException("ERROR: DB Database creation error. Is the DB empty?\n");
}
$this->out(" Complete!\n\n");
// Copy config file
$this->out("Saving config file...\n");
if (!copy('htconfig.php', '.htconfig.php')) {
throw new \RuntimeException("ERROR: Saving config file failed. Please copy .htautoinstall.php to .htconfig.php manually.\n");
}
$this->out(" Complete!\n\n");
$this->out("\nInstallation is finished\n");
return 0;
}
/**
* @param App $app
* @return array
*/
private function runBasicChecks($app)
{
$checks = [];
check_funcs($checks);
check_imagik($checks);
check_htconfig($checks);
check_smarty3($checks);
check_keys($checks);
if (!empty($app->config['php_path'])) {
check_php($app->config['php_path'], $checks);
} else {
throw new \RuntimeException(" ERROR: The php_path is not set in the config. Please check the file .htconfig.php.\n");
}
$this->out(" NOTICE: Not checking .htaccess/URL-Rewrite during CLI installation.\n");
return $checks;
}
/**
* @param $db_host
* @param $db_user
* @param $db_pass
* @param $db_data
* @return array
*/
private function runDatabaseCheck($db_host, $db_user, $db_pass, $db_data)
{
$result = array(
'title' => 'MySQL Connection',
'required' => true,
'status' => true,
'help' => '',
);
if (!dba::connect($db_host, $db_user, $db_pass, $db_data, true)) {
$result['status'] = false;
$result['help'] = 'Failed, please check your MySQL settings and credentials.';
}
return $result;
}
/**
* @param array $results
* @return string
*/
private function extractErrors($results)
{
$errorMessage = '';
$allChecksRequired = $this->getOption('a') !== null;
foreach ($results as $result) {
if (($allChecksRequired || $result['required'] === true) && $result['status'] === false) {
$errorMessage .= "--------\n";
$errorMessage .= $result['title'] . ': ' . $result['help'] . "\n";
}
}
return $errorMessage;
}
}

View file

@ -27,7 +27,7 @@ class NewPassword extends \Asika\SimpleConsole\Console
$help = <<<HELP
console newpassword - Creates a new password for a given user
Usage
bin/console newpassword <nickname> <password> [-h|--help|-?] [-v]
bin/console newpassword <nickname> [<password>] [-h|--help|-?] [-v]
Description
Creates a new password for a user without using the "forgot password" functionality.
@ -67,13 +67,22 @@ HELP;
}
$nick = $this->getArgument(0);
$password = $this->getArgument(1);
$user = dba::selectFirst('user', ['uid'], ['nickname' => $nick]);
if (!DBM::is_result($user)) {
throw new \RuntimeException(L10n::t('User not found'));
}
$password = $this->getArgument(1);
if (is_null($password)) {
$this->out(L10n::t('Enter new password: '), false);
$password = \Seld\CliPrompt\CliPrompt::hiddenPrompt(true);
}
if (!$password) {
throw new \RuntimeException(L10n::t('Password can\'t be empty'));
}
if (!Config::get('system', 'disable_password_exposed', false) && User::isPasswordExposed($password)) {
throw new \RuntimeException(L10n::t('The new password has been exposed in a public data dump, please choose another.'));
}

View file

@ -24,7 +24,7 @@ class CacheSessionHandler extends BaseObject implements SessionHandlerInterface
public function read($session_id)
{
if (!x($session_id)) {
if (empty($session_id)) {
return '';
}
@ -58,9 +58,9 @@ class CacheSessionHandler extends BaseObject implements SessionHandlerInterface
return true;
}
Cache::set('session:' . $session_id, $session_data, Session::$expire);
$return = Cache::set('session:' . $session_id, $session_data, Session::$expire);
return true;
return $return;
}
public function close()
@ -70,8 +70,9 @@ class CacheSessionHandler extends BaseObject implements SessionHandlerInterface
public function destroy($id)
{
Cache::delete('session:' . $id);
return true;
$return = Cache::delete('session:' . $id);
return $return;
}
public function gc($maxlifetime)

View file

@ -60,12 +60,12 @@ class System extends BaseObject
$previous = ['class' => '', 'function' => ''];
// The ignore list contains all functions that are only wrapper functions
$ignore = ['fetchUrl'];
$ignore = ['fetchUrl', 'call_user_func_array'];
while ($func = array_pop($trace)) {
if (!empty($func['class'])) {
// Don't show multiple calls from the same function (mostly used for "dba" class)
if (($previous['class'] != $func['class']) && ($previous['function'] != 'q')) {
// Don't show multiple calls from the "dba" class to show the essential parts of the callstack
if ((($previous['class'] != $func['class']) || ($func['class'] != 'dba')) && ($previous['function'] != 'q')) {
$classparts = explode("\\", $func['class']);
$callstack[] = array_pop($classparts).'::'.$func['function'];
$previous = $func;