Merge remote-tracking branch 'upstream/develop' into diaspora-item
This commit is contained in:
commit
24c32cff0d
99 changed files with 2750 additions and 2500 deletions
|
|
@ -296,8 +296,7 @@ class App
|
|||
*/
|
||||
public function getBasePath(): string
|
||||
{
|
||||
// Don't use the basepath of the config table for basepath (it should always be the config-file one)
|
||||
return $this->config->getCache()->get('system', 'basepath');
|
||||
return $this->config->get('system', 'basepath');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -360,7 +359,7 @@ class App
|
|||
$this->profiler->update($this->config);
|
||||
|
||||
Core\Hook::loadHooks();
|
||||
$loader = (new Config())->createConfigFileLoader($this->getBasePath(), $_SERVER);
|
||||
$loader = (new Config())->createConfigFileManager($this->getBasePath(), $_SERVER);
|
||||
Core\Hook::callAll('load_config', $loader);
|
||||
|
||||
// Hooks are now working, reload the whole definitions with hook enabled
|
||||
|
|
@ -660,7 +659,7 @@ class App
|
|||
$this->baseURL->redirect('install');
|
||||
} else {
|
||||
$this->checkURL();
|
||||
Core\Update::check($this->getBasePath(), false, $this->mode);
|
||||
Core\Update::check($this->getBasePath(), false);
|
||||
Core\Addon::loadAddons();
|
||||
Core\Hook::loadHooks();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -172,53 +172,32 @@ class BaseURL
|
|||
*/
|
||||
public function save($hostname = null, $sslPolicy = null, $urlPath = null): bool
|
||||
{
|
||||
$currHostname = $this->hostname;
|
||||
$currSSLPolicy = $this->sslPolicy;
|
||||
$currURLPath = $this->urlPath;
|
||||
$currUrl = $this->url;
|
||||
|
||||
$configTransaction = $this->config->beginTransaction();
|
||||
|
||||
if (!empty($hostname) && $hostname !== $this->hostname) {
|
||||
if ($this->config->set('config', 'hostname', $hostname)) {
|
||||
$this->hostname = $hostname;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
$configTransaction->set('config', 'hostname', $hostname);
|
||||
$this->hostname = $hostname;
|
||||
}
|
||||
|
||||
if (isset($sslPolicy) && $sslPolicy !== $this->sslPolicy) {
|
||||
if ($this->config->set('system', 'ssl_policy', $sslPolicy)) {
|
||||
$this->sslPolicy = $sslPolicy;
|
||||
} else {
|
||||
$this->hostname = $currHostname;
|
||||
$this->config->set('config', 'hostname', $this->hostname);
|
||||
return false;
|
||||
}
|
||||
$configTransaction->set('system', 'ssl_policy', $sslPolicy);
|
||||
$this->sslPolicy = $sslPolicy;
|
||||
}
|
||||
|
||||
if (isset($urlPath) && $urlPath !== $this->urlPath) {
|
||||
if ($this->config->set('system', 'urlpath', $urlPath)) {
|
||||
$this->urlPath = $urlPath;
|
||||
} else {
|
||||
$this->hostname = $currHostname;
|
||||
$this->sslPolicy = $currSSLPolicy;
|
||||
$this->config->set('config', 'hostname', $this->hostname);
|
||||
$this->config->set('system', 'ssl_policy', $this->sslPolicy);
|
||||
return false;
|
||||
}
|
||||
$configTransaction->set('system', 'urlpath', $urlPath);
|
||||
$this->urlPath = $urlPath;
|
||||
}
|
||||
|
||||
$this->determineBaseUrl();
|
||||
if (!$this->config->set('system', 'url', $this->url)) {
|
||||
$this->hostname = $currHostname;
|
||||
$this->sslPolicy = $currSSLPolicy;
|
||||
$this->urlPath = $currURLPath;
|
||||
$this->determineBaseUrl();
|
||||
|
||||
$this->config->set('config', 'hostname', $this->hostname);
|
||||
$this->config->set('system', 'ssl_policy', $this->sslPolicy);
|
||||
$this->config->set('system', 'urlpath', $this->urlPath);
|
||||
return false;
|
||||
if ($this->url !== $currUrl) {
|
||||
$configTransaction->set('system', 'url', $this->url);
|
||||
}
|
||||
|
||||
$configTransaction->commit();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -149,16 +149,7 @@ class Mode
|
|||
|
||||
$mode |= Mode::DBAVAILABLE;
|
||||
|
||||
if ($database->fetchFirst("SHOW TABLES LIKE 'config'") === false) {
|
||||
return new Mode($mode);
|
||||
}
|
||||
|
||||
$mode |= Mode::DBCONFIGAVAILABLE;
|
||||
|
||||
if (!empty($configCache->get('system', 'maintenance')) ||
|
||||
// Don't use Config or Configuration here because we're possibly BEFORE initializing the Configuration,
|
||||
// so this could lead to a dependency circle
|
||||
!empty($database->selectFirst('config', ['v'], ['cat' => 'system', 'k' => 'maintenance'])['v'])) {
|
||||
if (!empty($configCache->get('system', 'maintenance'))) {
|
||||
return new Mode($mode);
|
||||
}
|
||||
|
||||
|
|
@ -232,14 +223,14 @@ class Mode
|
|||
}
|
||||
|
||||
/**
|
||||
* Install mode is when the local config file is missing or the DB schema hasn't been installed yet.
|
||||
* Install mode is when the local config file is missing or the database isn't available.
|
||||
*
|
||||
* @return bool Whether installation mode is active (local/database configuration files present or not)
|
||||
*/
|
||||
public function isInstall(): bool
|
||||
{
|
||||
return !$this->has(Mode::LOCALCONFIGPRESENT) ||
|
||||
!$this->has(MODE::DBCONFIGAVAILABLE);
|
||||
!$this->has(MODE::DBAVAILABLE);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -251,7 +242,6 @@ class Mode
|
|||
{
|
||||
return $this->has(Mode::LOCALCONFIGPRESENT) &&
|
||||
$this->has(Mode::DBAVAILABLE) &&
|
||||
$this->has(Mode::DBCONFIGAVAILABLE) &&
|
||||
$this->has(Mode::MAINTENANCEDISABLED);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -99,7 +99,7 @@ HELP;
|
|||
$this->out('Options: ' . var_export($this->options, true));
|
||||
}
|
||||
|
||||
if (!$this->appMode->has(App\Mode::DBCONFIGAVAILABLE)) {
|
||||
if (!$this->appMode->has(App\Mode::DBAVAILABLE)) {
|
||||
$this->out('Database isn\'t ready or populated yet, database cache won\'t be available');
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -115,10 +115,6 @@ HELP;
|
|||
throw new CommandArgsException('Too many arguments');
|
||||
}
|
||||
|
||||
if (!$this->appMode->has(App\Mode::DBCONFIGAVAILABLE)) {
|
||||
$this->out('Database isn\'t ready or populated yet, showing file config only');
|
||||
}
|
||||
|
||||
if (count($this->args) == 3) {
|
||||
$cat = $this->getArgument(0);
|
||||
$key = $this->getArgument(1);
|
||||
|
|
@ -157,7 +153,7 @@ HELP;
|
|||
|
||||
if (count($this->args) == 1) {
|
||||
$cat = $this->getArgument(0);
|
||||
$this->config->load($cat);
|
||||
$this->config->reload();
|
||||
$configCache = $this->config->getCache();
|
||||
|
||||
if ($configCache->get($cat) !== null) {
|
||||
|
|
@ -178,11 +174,7 @@ HELP;
|
|||
}
|
||||
|
||||
if (count($this->args) == 0) {
|
||||
$this->config->load();
|
||||
|
||||
if ($this->config->get('system', 'config_adapter') == 'jit' && $this->appMode->has(App\Mode::DBCONFIGAVAILABLE)) {
|
||||
$this->out('Warning: The JIT (Just In Time) Config adapter doesn\'t support loading the entire configuration, showing file config only');
|
||||
}
|
||||
$this->config->reload();
|
||||
|
||||
$config = $this->config->getCache()->getAll();
|
||||
foreach ($config as $cat => $section) {
|
||||
|
|
|
|||
|
|
@ -93,7 +93,7 @@ HELP;
|
|||
$this->out('Options: ' . var_export($this->options, true));
|
||||
}
|
||||
|
||||
if (!$this->appMode->has(App\Mode::DBCONFIGAVAILABLE)) {
|
||||
if (!$this->appMode->has(App\Mode::DBAVAILABLE)) {
|
||||
$this->out('Database isn\'t ready or populated yet, database cache won\'t be available');
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -100,16 +100,20 @@ HELP;
|
|||
|
||||
$enabled = intval($this->getArgument(0));
|
||||
|
||||
$this->config->set('system', 'maintenance', $enabled);
|
||||
$transactionConfig = $this->config->beginTransaction();
|
||||
|
||||
$transactionConfig->set('system', 'maintenance', $enabled);
|
||||
|
||||
$reason = $this->getArgument(1);
|
||||
|
||||
if ($enabled && $this->getArgument(1)) {
|
||||
$this->config->set('system', 'maintenance_reason', $this->getArgument(1));
|
||||
$transactionConfig->set('system', 'maintenance_reason', $this->getArgument(1));
|
||||
} else {
|
||||
$this->config->set('system', 'maintenance_reason', '');
|
||||
$transactionConfig->delete('system', 'maintenance_reason');
|
||||
}
|
||||
|
||||
$transactionConfig->commit();
|
||||
|
||||
if ($enabled) {
|
||||
$mode_str = "maintenance mode";
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -101,9 +101,10 @@ HELP;
|
|||
$old_host = str_replace('http://', '@', Strings::normaliseLink($old_url));
|
||||
|
||||
$this->out('Entering maintenance mode');
|
||||
$this->config->set('system', 'maintenance', true);
|
||||
$this->config->set('system', 'maintenance_reason', 'Relocating node to ' . $new_url);
|
||||
|
||||
$this->config->beginTransaction()
|
||||
->set('system', 'maintenance', true)
|
||||
->set('system', 'maintenance_reason', 'Relocating node to ' . $new_url)
|
||||
->commit();
|
||||
try {
|
||||
if (!$this->database->transaction()) {
|
||||
throw new \Exception('Unable to start a transaction, please retry later.');
|
||||
|
|
@ -189,8 +190,10 @@ HELP;
|
|||
return 1;
|
||||
} finally {
|
||||
$this->out('Leaving maintenance mode');
|
||||
$this->config->set('system', 'maintenance', false);
|
||||
$this->config->set('system', 'maintenance_reason', '');
|
||||
$this->config->beginTransaction()
|
||||
->set('system', 'maintenance', false)
|
||||
->delete('system', 'maintenance_reason')
|
||||
->commit();
|
||||
}
|
||||
|
||||
// send relocate
|
||||
|
|
|
|||
|
|
@ -856,7 +856,7 @@ class Item
|
|||
}
|
||||
|
||||
$user = User::getById($post['uid'], ['allow_cid', 'allow_gid', 'deny_cid', 'deny_gid']);
|
||||
if (!DBA::isResult($user)) {
|
||||
if (!$user) {
|
||||
throw new HTTPException\NotFoundException($this->l10n->t('Unable to locate original post.'));
|
||||
}
|
||||
|
||||
|
|
@ -876,7 +876,7 @@ class Item
|
|||
$post['allow_cid'] .= $this->aclFormatter->toString(Contact::getPublicIdByUserId($post['uid']));
|
||||
}
|
||||
|
||||
if (strlen($post['allow_gid']) || strlen($post['allow_cid']) || strlen($post['deny_gid']) || strlen($post['deny_cid'])) {
|
||||
if ($post['allow_gid'] || $post['allow_cid'] || $post['deny_gid'] || $post['deny_cid']) {
|
||||
$post['private'] = ItemModel::PRIVATE;
|
||||
} elseif ($this->pConfig->get($post['uid'], 'system', 'unlisted')) {
|
||||
$post['private'] = ItemModel::UNLISTED;
|
||||
|
|
@ -898,7 +898,7 @@ class Item
|
|||
if (empty($attachment)) {
|
||||
continue;
|
||||
}
|
||||
if (strlen($post['attach'])) {
|
||||
if ($post['attach']) {
|
||||
$post['attach'] .= ',';
|
||||
}
|
||||
$post['attach'] .= Post\Media::getAttachElement($this->baseURL->get() . '/attach/' . $attachment['id'],
|
||||
|
|
@ -1013,7 +1013,7 @@ class Item
|
|||
|
||||
foreach ($recipients as $recipient) {
|
||||
$address = trim($recipient);
|
||||
if (!strlen($address)) {
|
||||
if (!$address) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -21,7 +21,6 @@
|
|||
|
||||
namespace Friendica\Core;
|
||||
|
||||
use Friendica\Database\DBA;
|
||||
use Friendica\DI;
|
||||
use Friendica\Model\Contact;
|
||||
use Friendica\Util\Strings;
|
||||
|
|
@ -85,15 +84,19 @@ class Addon
|
|||
public static function getAdminList()
|
||||
{
|
||||
$addons_admin = [];
|
||||
$addonsAdminStmt = DBA::select('addon', ['name'], ['plugin_admin' => 1], ['order' => ['name']]);
|
||||
while ($addon = DBA::fetch($addonsAdminStmt)) {
|
||||
$addons_admin[$addon['name']] = [
|
||||
'url' => 'admin/addons/' . $addon['name'],
|
||||
'name' => $addon['name'],
|
||||
$addons = DI::config()->get('addons');
|
||||
ksort($addons);
|
||||
foreach ($addons as $name => $data) {
|
||||
if (empty($data['admin'])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$addons_admin[$name] = [
|
||||
'url' => 'admin/addons/' . $name,
|
||||
'name' => $name,
|
||||
'class' => 'addon'
|
||||
];
|
||||
}
|
||||
DBA::close($addonsAdminStmt);
|
||||
|
||||
return $addons_admin;
|
||||
}
|
||||
|
|
@ -113,8 +116,7 @@ class Addon
|
|||
*/
|
||||
public static function loadAddons()
|
||||
{
|
||||
$installed_addons = DBA::selectToArray('addon', ['name'], ['installed' => true]);
|
||||
self::$addons = array_column($installed_addons, 'name');
|
||||
self::$addons = array_keys(DI::config()->get('addons') ?? []);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -129,7 +131,7 @@ class Addon
|
|||
$addon = Strings::sanitizeFilePathItem($addon);
|
||||
|
||||
Logger::debug("Addon {addon}: {action}", ['action' => 'uninstall', 'addon' => $addon]);
|
||||
DBA::delete('addon', ['name' => $addon]);
|
||||
DI::config()->delete('addons', $addon);
|
||||
|
||||
@include_once('addon/' . $addon . '/' . $addon . '.php');
|
||||
if (function_exists($addon . '_uninstall')) {
|
||||
|
|
@ -168,12 +170,9 @@ class Addon
|
|||
$func(DI::app());
|
||||
}
|
||||
|
||||
DBA::insert('addon', [
|
||||
'name' => $addon,
|
||||
'installed' => true,
|
||||
'timestamp' => $t,
|
||||
'plugin_admin' => function_exists($addon . '_addon_admin'),
|
||||
'hidden' => file_exists('addon/' . $addon . '/.hidden')
|
||||
DI::config()->set('addons', $addon, [
|
||||
'last_update' => $t,
|
||||
'admin' => function_exists($addon . '_addon_admin'),
|
||||
]);
|
||||
|
||||
if (!self::isEnabled($addon)) {
|
||||
|
|
@ -190,20 +189,20 @@ class Addon
|
|||
*/
|
||||
public static function reload()
|
||||
{
|
||||
$addons = DBA::selectToArray('addon', [], ['installed' => true]);
|
||||
$addons = DI::config()->get('addons');
|
||||
|
||||
foreach ($addons as $addon) {
|
||||
$addonname = Strings::sanitizeFilePathItem(trim($addon['name']));
|
||||
foreach ($addons as $name => $data) {
|
||||
$addonname = Strings::sanitizeFilePathItem(trim($name));
|
||||
$addon_file_path = 'addon/' . $addonname . '/' . $addonname . '.php';
|
||||
if (file_exists($addon_file_path) && $addon['timestamp'] == filemtime($addon_file_path)) {
|
||||
if (file_exists($addon_file_path) && $data['last_update'] == filemtime($addon_file_path)) {
|
||||
// Addon unmodified, skipping
|
||||
continue;
|
||||
}
|
||||
|
||||
Logger::debug("Addon {addon}: {action}", ['action' => 'reload', 'addon' => $addon['name']]);
|
||||
Logger::debug("Addon {addon}: {action}", ['action' => 'reload', 'addon' => $name]);
|
||||
|
||||
self::uninstall($addon['name']);
|
||||
self::install($addon['name']);
|
||||
self::uninstall($name);
|
||||
self::install($name);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -313,11 +312,9 @@ class Addon
|
|||
public static function getVisibleList(): array
|
||||
{
|
||||
$visible_addons = [];
|
||||
$stmt = DBA::select('addon', ['name'], ['hidden' => false, 'installed' => true]);
|
||||
if (DBA::isResult($stmt)) {
|
||||
foreach (DBA::toArray($stmt) as $addon) {
|
||||
$visible_addons[] = $addon['name'];
|
||||
}
|
||||
$addons = DI::config()->get('addons');
|
||||
foreach ($addons as $name => $data) {
|
||||
$visible_addons[] = $name;
|
||||
}
|
||||
|
||||
return $visible_addons;
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@
|
|||
namespace Friendica\Core\Config\Capability;
|
||||
|
||||
use Friendica\Core\Config\Exception\ConfigPersistenceException;
|
||||
use Friendica\Core\Config\Util\ConfigFileManager;
|
||||
use Friendica\Core\Config\ValueObject\Cache;
|
||||
|
||||
/**
|
||||
|
|
@ -30,36 +31,46 @@ use Friendica\Core\Config\ValueObject\Cache;
|
|||
interface IManageConfigValues
|
||||
{
|
||||
/**
|
||||
* Loads all configuration values of family into a cached storage.
|
||||
* Reloads all configuration values (from filesystem and environment variables)
|
||||
*
|
||||
* All configuration values of the system are stored in the cache.
|
||||
*
|
||||
* @param string $cat The category of the configuration value
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @throws ConfigPersistenceException In case the persistence layer throws errors
|
||||
*/
|
||||
public function load(string $cat = 'config');
|
||||
public function reload();
|
||||
|
||||
/**
|
||||
* Get a particular user's config variable given the category name
|
||||
* ($cat) and a $key.
|
||||
*
|
||||
* Get a particular config value from the given category ($cat)
|
||||
* and the $key from a cached storage either from the database or from the cache.
|
||||
*
|
||||
* @param string $cat The category of the configuration value
|
||||
* @param string $key The configuration key to query
|
||||
* @param string $cat The category of the configuration value
|
||||
* @param ?string $key The configuration key to query (if null, the whole array at the category will get returned)
|
||||
* @param mixed $default_value Deprecated, use `Config->get($cat, $key, null, $refresh) ?? $default_value` instead
|
||||
* @param boolean $refresh optional, If true the config is loaded from the db and not from the cache (default: false)
|
||||
*
|
||||
* @return mixed Stored value or null if it does not exist
|
||||
*
|
||||
* @throws ConfigPersistenceException In case the persistence layer throws errors
|
||||
*
|
||||
*/
|
||||
public function get(string $cat, string $key, $default_value = null, bool $refresh = false);
|
||||
public function get(string $cat, string $key = null, $default_value = null);
|
||||
|
||||
/**
|
||||
* Load all configuration values from a given cache and saves it back in the configuration node store
|
||||
* @see ConfigFileManager::CONFIG_DATA_FILE
|
||||
*
|
||||
* All configuration values of the system are stored in the cache.
|
||||
*
|
||||
* @param Cache $cache a new cache
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @throws ConfigPersistenceException In case the persistence layer throws errors
|
||||
*/
|
||||
public function load(Cache $cache);
|
||||
|
||||
/**
|
||||
* Sets a configuration value for system config
|
||||
|
|
@ -78,6 +89,15 @@ interface IManageConfigValues
|
|||
*/
|
||||
public function set(string $cat, string $key, $value): bool;
|
||||
|
||||
/**
|
||||
* Creates a transactional config value store, which is used to set a bunch of values at once
|
||||
*
|
||||
* It relies on the current instance, so after save(), the values of this config class will get altered at once too.
|
||||
*
|
||||
* @return ISetConfigValuesTransactionally
|
||||
*/
|
||||
public function beginTransaction(): ISetConfigValuesTransactionally;
|
||||
|
||||
/**
|
||||
* Deletes the given key from the system configuration.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -0,0 +1,64 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2023, the Friendica project
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace Friendica\Core\Config\Capability;
|
||||
|
||||
use Friendica\Core\Config\Exception\ConfigPersistenceException;
|
||||
|
||||
/**
|
||||
* Interface for transactional saving of config values
|
||||
* It buffers every set/delete until "save()" is called
|
||||
*/
|
||||
interface ISetConfigValuesTransactionally
|
||||
{
|
||||
/**
|
||||
* Sets a configuration value for system config
|
||||
*
|
||||
* Stores a config value ($value) in the category ($cat) under the key ($key)
|
||||
*
|
||||
* Note: Please do not store booleans - convert to 0/1 integer values!
|
||||
*
|
||||
* @param string $cat The category of the configuration value
|
||||
* @param string $key The configuration key to set
|
||||
* @param mixed $value The value to store
|
||||
*
|
||||
* @return static the current instance
|
||||
*/
|
||||
public function set(string $cat, string $key, $value): self;
|
||||
|
||||
/**
|
||||
* Deletes the given key from the system configuration.
|
||||
*
|
||||
* @param string $cat The category of the configuration value
|
||||
* @param string $key The configuration key to delete
|
||||
*
|
||||
* @return static the current instance
|
||||
*
|
||||
*/
|
||||
public function delete(string $cat, string $key): self;
|
||||
|
||||
/**
|
||||
* Commits the changes of the current transaction
|
||||
*
|
||||
* @throws ConfigPersistenceException In case the persistence layer throws errors
|
||||
*/
|
||||
public function commit(): void;
|
||||
}
|
||||
|
|
@ -21,12 +21,12 @@
|
|||
|
||||
namespace Friendica\Core\Config\Factory;
|
||||
|
||||
use Friendica\Core\Config\Capability;
|
||||
use Friendica\Core\Config\Repository;
|
||||
use Friendica\Core\Config\Type;
|
||||
use Friendica\Core\Config\Util;
|
||||
use Friendica\Core\Config\ValueObject\Cache;
|
||||
|
||||
/**
|
||||
* The config factory for creating either the cache or the whole model
|
||||
*/
|
||||
class Config
|
||||
{
|
||||
/**
|
||||
|
|
@ -54,9 +54,9 @@ class Config
|
|||
* @param string $basePath The basepath of FRIENDICA
|
||||
* @param array $server The $_SERVER array
|
||||
*
|
||||
* @return Util\ConfigFileLoader
|
||||
* @return Util\ConfigFileManager
|
||||
*/
|
||||
public function createConfigFileLoader(string $basePath, array $server = []): Util\ConfigFileLoader
|
||||
public function createConfigFileManager(string $basePath, array $server = []): Util\ConfigFileManager
|
||||
{
|
||||
if (!empty($server[self::CONFIG_DIR_ENV]) && is_dir($server[self::CONFIG_DIR_ENV])) {
|
||||
$configDir = $server[self::CONFIG_DIR_ENV];
|
||||
|
|
@ -65,37 +65,19 @@ class Config
|
|||
}
|
||||
$staticDir = $basePath . DIRECTORY_SEPARATOR . self::STATIC_DIR;
|
||||
|
||||
return new Util\ConfigFileLoader($basePath, $configDir, $staticDir);
|
||||
return new Util\ConfigFileManager($basePath, $configDir, $staticDir, $server);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Util\ConfigFileLoader $loader The Config Cache loader (INI/config/.htconfig)
|
||||
* @param array $server
|
||||
* @param Util\ConfigFileManager $configFileManager The Config Cache manager (INI/config/.htconfig)
|
||||
*
|
||||
* @return Cache
|
||||
*/
|
||||
public function createCache(Util\ConfigFileLoader $loader, array $server = []): Cache
|
||||
public function createCache(Util\ConfigFileManager $configFileManager): Cache
|
||||
{
|
||||
$configCache = new Cache();
|
||||
$loader->setupCache($configCache, $server);
|
||||
$configFileManager->setupCache($configCache);
|
||||
|
||||
return $configCache;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Cache $configCache The config cache of this adapter
|
||||
* @param Repository\Config $configRepo The configuration repository
|
||||
*
|
||||
* @return Capability\IManageConfigValues
|
||||
*/
|
||||
public function create(Cache $configCache, Repository\Config $configRepo)
|
||||
{
|
||||
if ($configCache->get('system', 'config_adapter') === 'preload') {
|
||||
$configuration = new Type\PreloadConfig($configCache, $configRepo);
|
||||
} else {
|
||||
$configuration = new Type\JitConfig($configCache, $configRepo);
|
||||
}
|
||||
|
||||
return $configuration;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
126
src/Core/Config/Model/Config.php
Normal file
126
src/Core/Config/Model/Config.php
Normal file
|
|
@ -0,0 +1,126 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2023, the Friendica project
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace Friendica\Core\Config\Model;
|
||||
|
||||
use Friendica\Core\Config\Capability\IManageConfigValues;
|
||||
use Friendica\Core\Config\Capability\ISetConfigValuesTransactionally;
|
||||
use Friendica\Core\Config\Exception\ConfigFileException;
|
||||
use Friendica\Core\Config\Exception\ConfigPersistenceException;
|
||||
use Friendica\Core\Config\Util\ConfigFileManager;
|
||||
use Friendica\Core\Config\ValueObject\Cache;
|
||||
|
||||
/**
|
||||
* Configuration model, which manages the whole system configuration
|
||||
*/
|
||||
class Config implements IManageConfigValues
|
||||
{
|
||||
/** @var Cache */
|
||||
protected $configCache;
|
||||
|
||||
/** @var ConfigFileManager */
|
||||
protected $configFileManager;
|
||||
|
||||
/**
|
||||
* @param ConfigFileManager $configFileManager The configuration file manager to save back configs
|
||||
* @param Cache $configCache The configuration cache (based on the config-files)
|
||||
*/
|
||||
public function __construct(ConfigFileManager $configFileManager, Cache $configCache)
|
||||
{
|
||||
$this->configFileManager = $configFileManager;
|
||||
$this->configCache = $configCache;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getCache(): Cache
|
||||
{
|
||||
return $this->configCache;
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public function beginTransaction(): ISetConfigValuesTransactionally
|
||||
{
|
||||
return new ConfigTransaction($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves the current Configuration back into the data config.
|
||||
* @see ConfigFileManager::CONFIG_DATA_FILE
|
||||
*/
|
||||
protected function save()
|
||||
{
|
||||
try {
|
||||
$this->configFileManager->saveData($this->configCache);
|
||||
} catch (ConfigFileException $e) {
|
||||
throw new ConfigPersistenceException('Cannot save config', $e);
|
||||
}
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public function reload()
|
||||
{
|
||||
$configCache = new Cache();
|
||||
|
||||
try {
|
||||
$this->configFileManager->setupCache($configCache);
|
||||
} catch (ConfigFileException $e) {
|
||||
throw new ConfigPersistenceException('Cannot reload config', $e);
|
||||
}
|
||||
$this->configCache = $configCache;
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public function load(Cache $cache)
|
||||
{
|
||||
$this->configCache = $cache;
|
||||
$this->save();
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public function get(string $cat, string $key = null, $default_value = null)
|
||||
{
|
||||
return $this->configCache->get($cat, $key) ?? $default_value;
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public function set(string $cat, string $key, $value): bool
|
||||
{
|
||||
if ($this->configCache->set($cat, $key, $value, Cache::SOURCE_DATA)) {
|
||||
$this->save();
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public function delete(string $cat, string $key): bool
|
||||
{
|
||||
if ($this->configCache->delete($cat, $key, Cache::SOURCE_DATA)) {
|
||||
$this->save();
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
81
src/Core/Config/Model/ConfigTransaction.php
Normal file
81
src/Core/Config/Model/ConfigTransaction.php
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2023, the Friendica project
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace Friendica\Core\Config\Model;
|
||||
|
||||
use Friendica\Core\Config\Capability\IManageConfigValues;
|
||||
use Friendica\Core\Config\Capability\ISetConfigValuesTransactionally;
|
||||
use Friendica\Core\Config\Exception\ConfigPersistenceException;
|
||||
use Friendica\Core\Config\ValueObject\Cache;
|
||||
|
||||
/**
|
||||
* Transaction class for configurations, which sets values into a temporary buffer until "save()" is called
|
||||
*/
|
||||
class ConfigTransaction implements ISetConfigValuesTransactionally
|
||||
{
|
||||
/** @var IManageConfigValues */
|
||||
protected $config;
|
||||
/** @var Cache */
|
||||
protected $cache;
|
||||
/** @var bool field to check if something is to save */
|
||||
protected $changedConfig = false;
|
||||
|
||||
public function __construct(IManageConfigValues $config)
|
||||
{
|
||||
$this->config = $config;
|
||||
$this->cache = clone $config->getCache();
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public function set(string $cat, string $key, $value): ISetConfigValuesTransactionally
|
||||
{
|
||||
$this->cache->set($cat, $key, $value, Cache::SOURCE_DATA);
|
||||
$this->changedConfig = true;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public function delete(string $cat, string $key): ISetConfigValuesTransactionally
|
||||
{
|
||||
$this->cache->delete($cat, $key, Cache::SOURCE_DATA);
|
||||
$this->changedConfig = true;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public function commit(): void
|
||||
{
|
||||
// If nothing changed, just do nothing :)
|
||||
if (!$this->changedConfig) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
$this->config->load($this->cache);
|
||||
$this->cache = clone $this->config->getCache();
|
||||
} catch (\Exception $e) {
|
||||
throw new ConfigPersistenceException('Cannot save config', $e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,191 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2023, the Friendica project
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace Friendica\Core\Config\Repository;
|
||||
|
||||
use Friendica\App\Mode;
|
||||
use Friendica\Core\Config\Exception\ConfigPersistenceException;
|
||||
use Friendica\Core\Config\Util\ValueConversion;
|
||||
use Friendica\Database\Database;
|
||||
|
||||
/**
|
||||
* The Config Repository, which is using the general DB-model backend for configs
|
||||
*/
|
||||
class Config
|
||||
{
|
||||
/** @var Database */
|
||||
protected $db;
|
||||
/** @var Mode */
|
||||
protected $mode;
|
||||
|
||||
public function __construct(Database $db, Mode $mode)
|
||||
{
|
||||
$this->db = $db;
|
||||
$this->mode = $mode;
|
||||
}
|
||||
|
||||
protected static $table_name = 'config';
|
||||
|
||||
/**
|
||||
* Checks if the model is currently connected
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isConnected(): bool
|
||||
{
|
||||
return $this->db->isConnected() && !$this->mode->isInstall();
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads all configuration values and returns the loaded category as an array.
|
||||
*
|
||||
* @param string|null $cat The category of the configuration values to load
|
||||
*
|
||||
* @return array The config array
|
||||
*
|
||||
* @throws ConfigPersistenceException In case the persistence layer throws errors
|
||||
*/
|
||||
public function load(?string $cat = null): array
|
||||
{
|
||||
$return = [];
|
||||
|
||||
try {
|
||||
if (empty($cat)) {
|
||||
$configs = $this->db->select(static::$table_name, ['cat', 'v', 'k']);
|
||||
} else {
|
||||
$configs = $this->db->select(static::$table_name, ['cat', 'v', 'k'], ['cat' => $cat]);
|
||||
}
|
||||
|
||||
while ($config = $this->db->fetch($configs)) {
|
||||
$key = $config['k'];
|
||||
$value = ValueConversion::toConfigValue($config['v']);
|
||||
|
||||
// just save it in case it is set
|
||||
if (isset($value)) {
|
||||
$return[$config['cat']][$key] = $value;
|
||||
}
|
||||
}
|
||||
} catch (\Exception $exception) {
|
||||
throw new ConfigPersistenceException(sprintf('Cannot load config category %s', $cat), $exception);
|
||||
} finally {
|
||||
$this->db->close($configs);
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a particular, system-wide config variable out of the DB with the
|
||||
* given category name ($cat) and a key ($key).
|
||||
*
|
||||
* Note: Boolean variables are defined as 0/1 in the database
|
||||
*
|
||||
* @param string $cat The category of the configuration value
|
||||
* @param string $key The configuration key to query
|
||||
*
|
||||
* @return array|string|null Stored value or null if it does not exist
|
||||
*
|
||||
* @throws ConfigPersistenceException In case the persistence layer throws errors
|
||||
*/
|
||||
public function get(string $cat, string $key)
|
||||
{
|
||||
if (!$this->isConnected()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
$config = $this->db->selectFirst(static::$table_name, ['v'], ['cat' => $cat, 'k' => $key]);
|
||||
if ($this->db->isResult($config)) {
|
||||
$value = ValueConversion::toConfigValue($config['v']);
|
||||
|
||||
// just return it in case it is set
|
||||
if (isset($value)) {
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
} catch (\Exception $exception) {
|
||||
throw new ConfigPersistenceException(sprintf('Cannot get config with category %s and key %s', $cat, $key), $exception);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Stores a config value ($value) in the category ($cat) under the key ($key).
|
||||
*
|
||||
* Note: Please do not store booleans - convert to 0/1 integer values!
|
||||
*
|
||||
* @param string $cat The category of the configuration value
|
||||
* @param string $key The configuration key to set
|
||||
* @param mixed $value The value to store
|
||||
*
|
||||
* @return bool Operation success
|
||||
*
|
||||
* @throws ConfigPersistenceException In case the persistence layer throws errors
|
||||
*/
|
||||
public function set(string $cat, string $key, $value): bool
|
||||
{
|
||||
if (!$this->isConnected()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// We store our setting values in a string variable.
|
||||
// So we have to do the conversion here so that the compare below works.
|
||||
// The exception are array values.
|
||||
$compare_value = (!is_array($value) ? (string)$value : $value);
|
||||
$stored_value = $this->get($cat, $key);
|
||||
|
||||
if (isset($stored_value) && ($stored_value === $compare_value)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$dbValue = ValueConversion::toDbValue($value);
|
||||
|
||||
try {
|
||||
return $this->db->update(static::$table_name, ['v' => $dbValue], ['cat' => $cat, 'k' => $key], true);
|
||||
} catch (\Exception $exception) {
|
||||
throw new ConfigPersistenceException(sprintf('Cannot set config with category %s and key %s', $cat, $key), $exception);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the configured value from the database.
|
||||
*
|
||||
* @param string $cat The category of the configuration value
|
||||
* @param string $key The configuration key to delete
|
||||
*
|
||||
* @return bool Operation success
|
||||
*
|
||||
* @throws ConfigPersistenceException In case the persistence layer throws errors
|
||||
*/
|
||||
public function delete(string $cat, string $key): bool
|
||||
{
|
||||
if (!$this->isConnected()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
return $this->db->delete(static::$table_name, ['cat' => $cat, 'k' => $key]);
|
||||
} catch (\Exception $exception) {
|
||||
throw new ConfigPersistenceException(sprintf('Cannot delete config with category %s and key %s', $cat, $key), $exception);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,63 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2023, the Friendica project
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace Friendica\Core\Config\Type;
|
||||
|
||||
use Friendica\Core\Config\Repository\Config;
|
||||
use Friendica\Core\Config\ValueObject\Cache;
|
||||
use Friendica\Core\Config\Capability\IManageConfigValues;
|
||||
|
||||
/**
|
||||
* This class is responsible for all system-wide configuration values in Friendica
|
||||
* There are two types of storage
|
||||
* - The Config-Files (loaded into the FileCache @see Cache)
|
||||
* - The Config-Repository (per Config-Repository @see Config )
|
||||
*/
|
||||
abstract class AbstractConfig implements IManageConfigValues
|
||||
{
|
||||
/**
|
||||
* @var Cache
|
||||
*/
|
||||
protected $configCache;
|
||||
|
||||
/**
|
||||
* @var Config
|
||||
*/
|
||||
protected $configRepo;
|
||||
|
||||
/**
|
||||
* @param Cache $configCache The configuration cache (based on the config-files)
|
||||
* @param Config $configRepo The configuration repository
|
||||
*/
|
||||
public function __construct(Cache $configCache, Config $configRepo)
|
||||
{
|
||||
$this->configCache = $configCache;
|
||||
$this->configRepo = $configRepo;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getCache(): Cache
|
||||
{
|
||||
return $this->configCache;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,139 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2023, the Friendica project
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace Friendica\Core\Config\Type;
|
||||
|
||||
use Friendica\Core\Config\ValueObject\Cache;
|
||||
use Friendica\Core\Config\Repository\Config;
|
||||
|
||||
/**
|
||||
* This class implements the Just-In-Time configuration, which will cache
|
||||
* config values in a cache, once they are retrieved.
|
||||
*
|
||||
* Default Configuration type.
|
||||
* Provides the best performance for pages loading few configuration variables.
|
||||
*/
|
||||
class JitConfig extends AbstractConfig
|
||||
{
|
||||
/**
|
||||
* @var array Array of already loaded db values (even if there was no value)
|
||||
*/
|
||||
private $db_loaded;
|
||||
|
||||
/**
|
||||
* @param Cache $configCache The configuration cache (based on the config-files)
|
||||
* @param Config $configRepo The configuration model
|
||||
*/
|
||||
public function __construct(Cache $configCache, Config $configRepo)
|
||||
{
|
||||
parent::__construct($configCache, $configRepo);
|
||||
$this->db_loaded = [];
|
||||
|
||||
$this->load();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function load(string $cat = 'config')
|
||||
{
|
||||
// If not connected, do nothing
|
||||
if (!$this->configRepo->isConnected()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$config = $this->configRepo->load($cat);
|
||||
|
||||
if (!empty($config[$cat])) {
|
||||
foreach ($config[$cat] as $key => $value) {
|
||||
$this->db_loaded[$cat][$key] = true;
|
||||
}
|
||||
}
|
||||
|
||||
// load the whole category out of the DB into the cache
|
||||
$this->configCache->load($config, Cache::SOURCE_DB);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function get(string $cat, string $key, $default_value = null, bool $refresh = false)
|
||||
{
|
||||
// if the value isn't loaded or refresh is needed, load it to the cache
|
||||
if ($this->configRepo->isConnected() &&
|
||||
(empty($this->db_loaded[$cat][$key]) ||
|
||||
$refresh)) {
|
||||
$dbValue = $this->configRepo->get($cat, $key);
|
||||
|
||||
if (isset($dbValue)) {
|
||||
$this->configCache->set($cat, $key, $dbValue, Cache::SOURCE_DB);
|
||||
unset($dbValue);
|
||||
}
|
||||
|
||||
$this->db_loaded[$cat][$key] = true;
|
||||
}
|
||||
|
||||
// use the config cache for return
|
||||
$result = $this->configCache->get($cat, $key);
|
||||
|
||||
return (isset($result)) ? $result : $default_value;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function set(string $cat, string $key, $value): bool
|
||||
{
|
||||
// set the cache first
|
||||
$cached = $this->configCache->set($cat, $key, $value, Cache::SOURCE_DB);
|
||||
|
||||
// If there is no connected adapter, we're finished
|
||||
if (!$this->configRepo->isConnected()) {
|
||||
return $cached;
|
||||
}
|
||||
|
||||
$stored = $this->configRepo->set($cat, $key, $value);
|
||||
|
||||
$this->db_loaded[$cat][$key] = $stored;
|
||||
|
||||
return $cached && $stored;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function delete(string $cat, string $key): bool
|
||||
{
|
||||
$cacheRemoved = $this->configCache->delete($cat, $key);
|
||||
|
||||
if (isset($this->db_loaded[$cat][$key])) {
|
||||
unset($this->db_loaded[$cat][$key]);
|
||||
}
|
||||
|
||||
if (!$this->configRepo->isConnected()) {
|
||||
return $cacheRemoved;
|
||||
}
|
||||
|
||||
$storeRemoved = $this->configRepo->delete($cat, $key);
|
||||
|
||||
return $cacheRemoved || $storeRemoved;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,135 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2023, the Friendica project
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace Friendica\Core\Config\Type;
|
||||
|
||||
use Friendica\Core\Config\ValueObject\Cache;
|
||||
use Friendica\Core\Config\Repository\Config;
|
||||
|
||||
/**
|
||||
* This class implements the preload configuration, which will cache
|
||||
* all config values per call in a cache.
|
||||
*
|
||||
* Minimizes the number of database queries to retrieve configuration values at the cost of memory.
|
||||
*/
|
||||
class PreloadConfig extends AbstractConfig
|
||||
{
|
||||
/** @var bool */
|
||||
private $config_loaded;
|
||||
|
||||
/**
|
||||
* @param Cache $configCache The configuration cache (based on the config-files)
|
||||
* @param Config $configRepo The configuration model
|
||||
*/
|
||||
public function __construct(Cache $configCache, Config $configRepo)
|
||||
{
|
||||
parent::__construct($configCache, $configRepo);
|
||||
$this->config_loaded = false;
|
||||
|
||||
$this->load();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* This loads all config values everytime load is called
|
||||
*/
|
||||
public function load(string $cat = 'config')
|
||||
{
|
||||
// Don't load the whole configuration twice
|
||||
if ($this->config_loaded) {
|
||||
return;
|
||||
}
|
||||
|
||||
// If not connected, do nothing
|
||||
if (!$this->configRepo->isConnected()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$config = $this->configRepo->load();
|
||||
$this->config_loaded = true;
|
||||
|
||||
// load the whole category out of the DB into the cache
|
||||
$this->configCache->load($config, Cache::SOURCE_DB);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function get(string $cat, string $key, $default_value = null, bool $refresh = false)
|
||||
{
|
||||
if ($refresh) {
|
||||
if ($this->configRepo->isConnected()) {
|
||||
$config = $this->configRepo->get($cat, $key);
|
||||
if (isset($config)) {
|
||||
$this->configCache->set($cat, $key, $config, Cache::SOURCE_DB);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// use the config cache for return
|
||||
$result = $this->configCache->get($cat, $key);
|
||||
|
||||
return (isset($result)) ? $result : $default_value;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function set(string $cat, string $key, $value): bool
|
||||
{
|
||||
if (!$this->config_loaded) {
|
||||
$this->load();
|
||||
}
|
||||
|
||||
// set the cache first
|
||||
$cached = $this->configCache->set($cat, $key, $value, Cache::SOURCE_DB);
|
||||
|
||||
// If there is no connected adapter, we're finished
|
||||
if (!$this->configRepo->isConnected()) {
|
||||
return $cached;
|
||||
}
|
||||
|
||||
$stored = $this->configRepo->set($cat, $key, $value);
|
||||
|
||||
return $cached && $stored;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function delete(string $cat, string $key): bool
|
||||
{
|
||||
if ($this->config_loaded) {
|
||||
$this->load();
|
||||
}
|
||||
|
||||
$cacheRemoved = $this->configCache->delete($cat, $key);
|
||||
|
||||
if (!$this->configRepo->isConnected()) {
|
||||
return $cacheRemoved;
|
||||
}
|
||||
|
||||
$storeRemoved = $this->configRepo->delete($cat, $key);
|
||||
|
||||
return $cacheRemoved || $storeRemoved;
|
||||
}
|
||||
}
|
||||
|
|
@ -26,22 +26,15 @@ use Friendica\Core\Config\Exception\ConfigFileException;
|
|||
use Friendica\Core\Config\ValueObject\Cache;
|
||||
|
||||
/**
|
||||
* The ConfigFileLoader loads config-files and stores them in a ConfigCache ( @see Cache )
|
||||
* The ConfigFileLoader loads and saves config-files and stores them in a ConfigCache ( @see Cache )
|
||||
*
|
||||
* It is capable of loading the following config files:
|
||||
* - *.config.php (current)
|
||||
* - *.ini.php (deprecated)
|
||||
* - *.htconfig.php (deprecated)
|
||||
*/
|
||||
class ConfigFileLoader
|
||||
class ConfigFileManager
|
||||
{
|
||||
/**
|
||||
* The default name of the user defined ini file
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const CONFIG_INI = 'local';
|
||||
|
||||
/**
|
||||
* The default name of the user defined legacy config file
|
||||
*
|
||||
|
|
@ -49,6 +42,13 @@ class ConfigFileLoader
|
|||
*/
|
||||
const CONFIG_HTCONFIG = 'htconfig';
|
||||
|
||||
/**
|
||||
* The config file, where overrides per admin page/console are saved at
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const CONFIG_DATA_FILE = 'node.config.php';
|
||||
|
||||
/**
|
||||
* The sample string inside the configs, which shouldn't get loaded
|
||||
*
|
||||
|
|
@ -69,16 +69,22 @@ class ConfigFileLoader
|
|||
*/
|
||||
private $staticDir;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $server;
|
||||
|
||||
/**
|
||||
* @param string $baseDir The base
|
||||
* @param string $configDir
|
||||
* @param string $staticDir
|
||||
*/
|
||||
public function __construct(string $baseDir, string $configDir, string $staticDir)
|
||||
public function __construct(string $baseDir, string $configDir, string $staticDir, array $server = [])
|
||||
{
|
||||
$this->baseDir = $baseDir;
|
||||
$this->configDir = $configDir;
|
||||
$this->staticDir = $staticDir;
|
||||
$this->server = $server;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -87,31 +93,33 @@ class ConfigFileLoader
|
|||
* First loads the default value for all the configuration keys, then the legacy configuration files, then the
|
||||
* expected local.config.php
|
||||
*
|
||||
* @param Cache $config The config cache to load to
|
||||
* @param array $server The $_SERVER array
|
||||
* @param bool $raw Setup the raw config format
|
||||
* @param Cache $configCache The config cache to load to
|
||||
* @param bool $raw Set up the raw config format
|
||||
*
|
||||
* @throws ConfigFileException
|
||||
*/
|
||||
public function setupCache(Cache $config, array $server = [], bool $raw = false)
|
||||
public function setupCache(Cache $configCache, bool $raw = false)
|
||||
{
|
||||
// Load static config files first, the order is important
|
||||
$config->load($this->loadStaticConfig('defaults'), Cache::SOURCE_STATIC);
|
||||
$config->load($this->loadStaticConfig('settings'), Cache::SOURCE_STATIC);
|
||||
$configCache->load($this->loadStaticConfig('defaults'), Cache::SOURCE_STATIC);
|
||||
$configCache->load($this->loadStaticConfig('settings'), Cache::SOURCE_STATIC);
|
||||
|
||||
// try to load the legacy config first
|
||||
$config->load($this->loadLegacyConfig('htpreconfig'), Cache::SOURCE_FILE);
|
||||
$config->load($this->loadLegacyConfig('htconfig'), Cache::SOURCE_FILE);
|
||||
$configCache->load($this->loadLegacyConfig('htpreconfig'), Cache::SOURCE_FILE);
|
||||
$configCache->load($this->loadLegacyConfig('htconfig'), Cache::SOURCE_FILE);
|
||||
|
||||
// Now load every other config you find inside the 'config/' directory
|
||||
$this->loadCoreConfig($config);
|
||||
$this->loadCoreConfig($configCache);
|
||||
|
||||
$config->load($this->loadEnvConfig($server), Cache::SOURCE_ENV);
|
||||
// Now load the node.config.php file with the node specific config values (based on admin gui/console actions)
|
||||
$this->loadDataConfig($configCache);
|
||||
|
||||
$configCache->load($this->loadEnvConfig(), Cache::SOURCE_ENV);
|
||||
|
||||
// In case of install mode, add the found basepath (because there isn't a basepath set yet
|
||||
if (!$raw && empty($config->get('system', 'basepath'))) {
|
||||
if (!$raw && empty($configCache->get('system', 'basepath'))) {
|
||||
// Setting at least the basepath we know
|
||||
$config->set('system', 'basepath', $this->baseDir, Cache::SOURCE_FILE);
|
||||
$configCache->set('system', 'basepath', $this->baseDir, Cache::SOURCE_FILE);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -131,7 +139,7 @@ class ConfigFileLoader
|
|||
|
||||
if (file_exists($configName)) {
|
||||
return $this->loadConfigFile($configName);
|
||||
} elseif (file_exists($iniName)) {
|
||||
} else if (file_exists($iniName)) {
|
||||
return $this->loadINIConfigFile($iniName);
|
||||
} else {
|
||||
return [];
|
||||
|
|
@ -141,20 +149,172 @@ class ConfigFileLoader
|
|||
/**
|
||||
* Tries to load the specified core-configuration into the config cache.
|
||||
*
|
||||
* @param Cache $config The Config cache
|
||||
* @param Cache $configCache The Config cache
|
||||
*
|
||||
* @throws ConfigFileException if the configuration file isn't readable
|
||||
*/
|
||||
private function loadCoreConfig(Cache $config)
|
||||
private function loadCoreConfig(Cache $configCache)
|
||||
{
|
||||
// try to load legacy ini-files first
|
||||
foreach ($this->getConfigFiles(true) as $configFile) {
|
||||
$config->load($this->loadINIConfigFile($configFile), Cache::SOURCE_FILE);
|
||||
$configCache->load($this->loadINIConfigFile($configFile), Cache::SOURCE_FILE);
|
||||
}
|
||||
|
||||
// try to load supported config at last to overwrite it
|
||||
foreach ($this->getConfigFiles() as $configFile) {
|
||||
$config->load($this->loadConfigFile($configFile), Cache::SOURCE_FILE);
|
||||
$configCache->load($this->loadConfigFile($configFile), Cache::SOURCE_FILE);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tries to load the data config file with the overridden data
|
||||
*
|
||||
* @param Cache $configCache The Config cache
|
||||
*
|
||||
* @throws ConfigFileException In case the config file isn't loadable
|
||||
*/
|
||||
private function loadDataConfig(Cache $configCache)
|
||||
{
|
||||
$filename = $this->configDir . '/' . self::CONFIG_DATA_FILE;
|
||||
|
||||
if (file_exists($filename)) {
|
||||
|
||||
// The fallback empty return content
|
||||
$content = '<?php return [];';
|
||||
|
||||
/**
|
||||
* This code-block creates a readonly node.config.php content stream (fopen() with "r")
|
||||
* The stream is locked shared (LOCK_SH), so not exclusively, but the OS knows that there's a lock
|
||||
*
|
||||
* Any exclusive locking (LOCK_EX) would need to wait until all LOCK_SHs are unlocked
|
||||
*/
|
||||
$configStream = fopen($filename, 'r');
|
||||
try {
|
||||
if (flock($configStream, LOCK_SH)) {
|
||||
$content = fread($configStream, filesize($filename));
|
||||
if (!$content) {
|
||||
throw new ConfigFileException(sprintf('Couldn\'t read file %s', $filename));
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
// unlock and close the stream for every circumstances
|
||||
flock($configStream, LOCK_UN);
|
||||
fclose($configStream);
|
||||
}
|
||||
|
||||
/**
|
||||
* Evaluate the content string as PHP code
|
||||
*
|
||||
* @see https://www.php.net/manual/en/function.eval.php
|
||||
*
|
||||
* @note
|
||||
* To leave the PHP mode, we have to use the appropriate PHP tags '?>' as prefix.
|
||||
*/
|
||||
$dataArray = eval('?>' . $content);
|
||||
|
||||
if (is_array($dataArray)) {
|
||||
$configCache->load($dataArray, Cache::SOURCE_DATA);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks, if the node.config.php is writable
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function dataIsWritable(): bool
|
||||
{
|
||||
$filename = $this->configDir . '/' . self::CONFIG_DATA_FILE;
|
||||
|
||||
if (file_exists($filename)) {
|
||||
return is_writable($filename);
|
||||
} else {
|
||||
return is_writable($this->configDir);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves overridden config entries back into the data.config.php
|
||||
*
|
||||
* @param Cache $configCache The config cache
|
||||
*
|
||||
* @throws ConfigFileException In case the config file isn't writeable or the data is invalid
|
||||
*/
|
||||
public function saveData(Cache $configCache)
|
||||
{
|
||||
$filename = $this->configDir . '/' . self::CONFIG_DATA_FILE;
|
||||
|
||||
if (file_exists($filename)) {
|
||||
$fileExists = true;
|
||||
} else {
|
||||
$fileExists = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a read-write stream
|
||||
*
|
||||
* @see https://www.php.net/manual/en/function.fopen.php
|
||||
* @note Open the file for reading and writing. If the file does not exist, it is created.
|
||||
* If it exists, it is neither truncated (as opposed to 'w'), nor the call to this function fails
|
||||
* (as is the case with 'x'). The file pointer is positioned on the beginning of the file.
|
||||
*
|
||||
*/
|
||||
if (($configStream = @fopen($filename, 'c+')) === false) {
|
||||
throw new ConfigFileException(sprintf('Cannot open file "%s" in mode c+', $filename));
|
||||
}
|
||||
|
||||
try {
|
||||
// We do want an exclusive lock, so we wait until every LOCK_SH (config reading) is unlocked
|
||||
if (flock($configStream, LOCK_EX)) {
|
||||
|
||||
/**
|
||||
* If the file exists, we read the whole file again to avoid a race condition with concurrent threads that could have modified the file between the first config read of this thread and now
|
||||
* Since we're currently exclusive locked, no other process can now change the config again
|
||||
*/
|
||||
if ($fileExists) {
|
||||
// When reading the config file too fast, we get a wrong filesize, "clearstatcache" prevents that
|
||||
clearstatcache(true, $filename);
|
||||
$content = fread($configStream, filesize($filename));
|
||||
if (!$content) {
|
||||
throw new ConfigFileException(sprintf('Cannot read file %s', $filename));
|
||||
}
|
||||
|
||||
// Event truncating the whole content wouldn't automatically rewind the stream,
|
||||
// so we need to do it manually
|
||||
rewind($configStream);
|
||||
|
||||
$dataArray = eval('?>' . $content);
|
||||
|
||||
// Merge the new content into the existing file based config cache and use it
|
||||
// as the new config cache
|
||||
if (is_array($dataArray)) {
|
||||
$fileConfigCache = new Cache();
|
||||
$fileConfigCache->load($dataArray, Cache::SOURCE_DATA);
|
||||
$configCache = $fileConfigCache->merge($configCache);
|
||||
}
|
||||
}
|
||||
|
||||
// Only SOURCE_DATA is wanted, the rest isn't part of the node.config.php file
|
||||
$data = $configCache->getDataBySource(Cache::SOURCE_DATA);
|
||||
|
||||
$encodedData = ConfigFileTransformer::encode($data);
|
||||
if (!$encodedData) {
|
||||
throw new ConfigFileException('config source cannot get encoded');
|
||||
}
|
||||
|
||||
// Once again to avoid wrong, implicit "filesize" calls during the fwrite() or ftruncate() call
|
||||
clearstatcache(true, $filename);
|
||||
if (!ftruncate($configStream, 0) ||
|
||||
!fwrite($configStream, $encodedData) ||
|
||||
!fflush($configStream)) {
|
||||
throw new ConfigFileException(sprintf('Cannot modify locked file %s', $filename));
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
// unlock and close the stream for every circumstances
|
||||
flock($configStream, LOCK_UN);
|
||||
fclose($configStream);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -172,7 +332,7 @@ class ConfigFileLoader
|
|||
$filepath = $this->baseDir . DIRECTORY_SEPARATOR . // /var/www/html/
|
||||
Addon::DIRECTORY . DIRECTORY_SEPARATOR . // addon/
|
||||
$name . DIRECTORY_SEPARATOR . // openstreetmap/
|
||||
'config'. DIRECTORY_SEPARATOR . // config/
|
||||
'config' . DIRECTORY_SEPARATOR . // config/
|
||||
$name . ".config.php"; // openstreetmap.config.php
|
||||
|
||||
if (file_exists($filepath)) {
|
||||
|
|
@ -185,13 +345,11 @@ class ConfigFileLoader
|
|||
/**
|
||||
* Tries to load environment specific variables, based on the `env.config.php` mapping table
|
||||
*
|
||||
* @param array $server The $_SERVER variable
|
||||
*
|
||||
* @return array The config array (empty if no config was found)
|
||||
*
|
||||
* @throws ConfigFileException if the configuration file isn't readable
|
||||
*/
|
||||
public function loadEnvConfig(array $server): array
|
||||
protected function loadEnvConfig(): array
|
||||
{
|
||||
$filepath = $this->staticDir . DIRECTORY_SEPARATOR . // /var/www/html/static/
|
||||
"env.config.php"; // env.config.php
|
||||
|
|
@ -205,8 +363,8 @@ class ConfigFileLoader
|
|||
$return = [];
|
||||
|
||||
foreach ($envConfig as $envKey => $configStructure) {
|
||||
if (isset($server[$envKey])) {
|
||||
$return[$configStructure[0]][$configStructure[1]] = $server[$envKey];
|
||||
if (isset($this->server[$envKey])) {
|
||||
$return[$configStructure[0]][$configStructure[1]] = $this->server[$envKey];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -231,7 +389,9 @@ class ConfigFileLoader
|
|||
$sampleEnd = self::SAMPLE_END . ($ini ? '.ini.php' : '.config.php');
|
||||
|
||||
foreach ($files as $filename) {
|
||||
if (fnmatch($filePattern, $filename) && substr_compare($filename, $sampleEnd, -strlen($sampleEnd))) {
|
||||
if (fnmatch($filePattern, $filename) &&
|
||||
substr_compare($filename, $sampleEnd, -strlen($sampleEnd)) &&
|
||||
$filename !== self::CONFIG_DATA_FILE) {
|
||||
$found[] = $this->configDir . '/' . $filename;
|
||||
}
|
||||
}
|
||||
|
|
@ -353,12 +513,16 @@ class ConfigFileLoader
|
|||
*/
|
||||
private function loadConfigFile(string $filepath): array
|
||||
{
|
||||
$config = include($filepath);
|
||||
if (file_exists($filepath)) {
|
||||
$config = include $filepath;
|
||||
|
||||
if (!is_array($config)) {
|
||||
throw new ConfigFileException('Error loading config file ' . $filepath);
|
||||
if (!is_array($config)) {
|
||||
throw new ConfigFileException('Error loading config file ' . $filepath);
|
||||
}
|
||||
|
||||
return $config;
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
|
||||
return $config;
|
||||
}
|
||||
}
|
||||
92
src/Core/Config/Util/ConfigFileTransformer.php
Normal file
92
src/Core/Config/Util/ConfigFileTransformer.php
Normal file
|
|
@ -0,0 +1,92 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2023, the Friendica project
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace Friendica\Core\Config\Util;
|
||||
|
||||
/**
|
||||
* Util to transform back the config array into a string
|
||||
*/
|
||||
class ConfigFileTransformer
|
||||
{
|
||||
public static function encode(array $data): string
|
||||
{
|
||||
$dataString = '<?php' . PHP_EOL . PHP_EOL;
|
||||
$dataString .= 'return [' . PHP_EOL;
|
||||
|
||||
$categories = array_keys($data);
|
||||
|
||||
foreach ($categories as $category) {
|
||||
if (is_null($data[$category])) {
|
||||
$dataString .= "\t'$category' => null," . PHP_EOL;
|
||||
continue;
|
||||
}
|
||||
|
||||
$dataString .= "\t'$category' => [" . PHP_EOL;
|
||||
|
||||
if (is_array($data[$category])) {
|
||||
$keys = array_keys($data[$category]);
|
||||
|
||||
foreach ($keys as $key) {
|
||||
$dataString .= static::mapConfigValue($key, $data[$category][$key]);
|
||||
}
|
||||
}
|
||||
$dataString .= "\t]," . PHP_EOL;
|
||||
}
|
||||
|
||||
$dataString .= "];" . PHP_EOL;
|
||||
|
||||
return $dataString;
|
||||
}
|
||||
|
||||
protected static function extractArray(array $config, int $level = 0): string
|
||||
{
|
||||
$string = '';
|
||||
|
||||
foreach ($config as $configKey => $configValue) {
|
||||
$string .= static::mapConfigValue($configKey, $configValue, $level);
|
||||
}
|
||||
|
||||
return $string;
|
||||
}
|
||||
|
||||
protected static function mapConfigValue(string $key, $value, $level = 0): string
|
||||
{
|
||||
$string = str_repeat("\t", $level + 2) . "'$key' => ";
|
||||
|
||||
if (is_null($value)) {
|
||||
$string .= "null,";
|
||||
} elseif (is_array($value)) {
|
||||
$string .= "[" . PHP_EOL;
|
||||
$string .= static::extractArray($value, ++$level);
|
||||
$string .= str_repeat("\t", $level + 1) . '],';
|
||||
} elseif (is_bool($value)) {
|
||||
$string .= ($value ? 'true' : 'false') . ",";
|
||||
} elseif (is_numeric($value)) {
|
||||
$string .= $value . ",";
|
||||
} else {
|
||||
$string .= sprintf('\'%s\',', addcslashes($value, '\'\\'));
|
||||
}
|
||||
|
||||
$string .= PHP_EOL;
|
||||
|
||||
return $string;
|
||||
}
|
||||
}
|
||||
|
|
@ -21,13 +21,13 @@
|
|||
|
||||
namespace Friendica\Core\Config\ValueObject;
|
||||
|
||||
use Friendica\Core\Config\Util\ConfigFileLoader;
|
||||
use Friendica\Core\Config\Util\ConfigFileManager;
|
||||
use ParagonIE\HiddenString\HiddenString;
|
||||
|
||||
/**
|
||||
* The Friendica config cache for the application
|
||||
* Initial, all *.config.php files are loaded into this cache with the
|
||||
* ConfigFileLoader ( @see ConfigFileLoader )
|
||||
* ConfigFileManager ( @see ConfigFileManager )
|
||||
*/
|
||||
class Cache
|
||||
{
|
||||
|
|
@ -35,8 +35,8 @@ class Cache
|
|||
const SOURCE_STATIC = 0;
|
||||
/** @var int Indicates that the cache entry is set by file - Low Priority */
|
||||
const SOURCE_FILE = 1;
|
||||
/** @var int Indicates that the cache entry is set by the DB config table - Middle Priority */
|
||||
const SOURCE_DB = 2;
|
||||
/** @var int Indicates that the cache entry is manually set by the application (per admin page/console) - Middle Priority */
|
||||
const SOURCE_DATA = 2;
|
||||
/** @var int Indicates that the cache entry is set by a server environment variable - High Priority */
|
||||
const SOURCE_ENV = 3;
|
||||
/** @var int Indicates that the cache entry is fixed and must not be changed */
|
||||
|
|
@ -65,7 +65,7 @@ class Cache
|
|||
* @param bool $hidePasswordOutput True, if cache variables should take extra care of password values
|
||||
* @param int $source Sets a source of the initial config values
|
||||
*/
|
||||
public function __construct(array $config = [], bool $hidePasswordOutput = true, $source = self::SOURCE_DEFAULT)
|
||||
public function __construct(array $config = [], bool $hidePasswordOutput = true, int $source = self::SOURCE_DEFAULT)
|
||||
{
|
||||
$this->hidePasswordOutput = $hidePasswordOutput;
|
||||
$this->load($config, $source);
|
||||
|
|
@ -87,11 +87,10 @@ class Cache
|
|||
$keys = array_keys($config[$category]);
|
||||
|
||||
foreach ($keys as $key) {
|
||||
$value = $config[$category][$key];
|
||||
if (isset($value)) {
|
||||
$this->set($category, $key, $value, $source);
|
||||
}
|
||||
$this->set($category, $key, $config[$category][$key] ?? null, $source);
|
||||
}
|
||||
} else {
|
||||
$this->set($category, null, $config[$category], $source);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -128,62 +127,132 @@ class Cache
|
|||
return $this->source[$cat][$key] ?? -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the whole config array based on the given source type
|
||||
*
|
||||
* @param int $source Indicates the source of the config entry
|
||||
*
|
||||
* @return array The config array part of the given source
|
||||
*/
|
||||
public function getDataBySource(int $source): array
|
||||
{
|
||||
$data = [];
|
||||
|
||||
$categories = array_keys($this->source);
|
||||
|
||||
foreach ($categories as $category) {
|
||||
if (is_array($this->source[$category])) {
|
||||
$keys = array_keys($this->source[$category]);
|
||||
|
||||
foreach ($keys as $key) {
|
||||
if ($this->source[$category][$key] === $source) {
|
||||
$data[$category][$key] = $this->config[$category][$key];
|
||||
}
|
||||
}
|
||||
} elseif (is_int($this->source[$category])) {
|
||||
$data[$category] = null;
|
||||
}
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a value in the config cache. Accepts raw output from the config table
|
||||
*
|
||||
* @param string $cat Config category
|
||||
* @param string $key Config key
|
||||
* @param mixed $value Value to set
|
||||
* @param int $source The source of the current config key
|
||||
* @param string $cat Config category
|
||||
* @param ?string $key Config key
|
||||
* @param ?mixed $value Value to set
|
||||
* @param int $source The source of the current config key
|
||||
*
|
||||
* @return bool True, if the value is set
|
||||
*/
|
||||
public function set(string $cat, string $key, $value, int $source = self::SOURCE_DEFAULT): bool
|
||||
public function set(string $cat, string $key = null, $value = null, int $source = self::SOURCE_DEFAULT): bool
|
||||
{
|
||||
if (!isset($this->config[$cat])) {
|
||||
if (!isset($this->config[$cat]) && $key !== null) {
|
||||
$this->config[$cat] = [];
|
||||
$this->source[$cat] = [];
|
||||
}
|
||||
|
||||
if (isset($this->source[$cat][$key]) &&
|
||||
$source < $this->source[$cat][$key]) {
|
||||
if ((isset($this->source[$cat][$key]) && $source < $this->source[$cat][$key]) ||
|
||||
(is_int($this->source[$cat] ?? null) && $source < $this->source[$cat])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($this->hidePasswordOutput &&
|
||||
$key == 'password' &&
|
||||
is_string($value)) {
|
||||
$this->config[$cat][$key] = new HiddenString((string)$value);
|
||||
$this->setCatKeyValueSource($cat, $key, new HiddenString($value), $source);
|
||||
} else if (is_string($value)) {
|
||||
$this->setCatKeyValueSource($cat, $key, self::toConfigValue($value), $source);
|
||||
} else {
|
||||
$this->config[$cat][$key] = $value;
|
||||
$this->setCatKeyValueSource($cat, $key, $value, $source);
|
||||
}
|
||||
|
||||
$this->source[$cat][$key] = $source;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private function setCatKeyValueSource(string $cat, string $key = null, $value = null, int $source = self::SOURCE_DEFAULT)
|
||||
{
|
||||
if (isset($key)) {
|
||||
$this->config[$cat][$key] = $value;
|
||||
$this->source[$cat][$key] = $source;
|
||||
} else {
|
||||
$this->config[$cat] = $value;
|
||||
$this->source[$cat] = $source;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats a DB value to a config value
|
||||
* - null = The db-value isn't set
|
||||
* - bool = The db-value is either '0' or '1'
|
||||
* - array = The db-value is a serialized array
|
||||
* - string = The db-value is a string
|
||||
*
|
||||
* Keep in mind that there aren't any numeric/integer config values in the database
|
||||
*
|
||||
* @param string|null $value
|
||||
*
|
||||
* @return null|array|string
|
||||
*/
|
||||
public static function toConfigValue(?string $value)
|
||||
{
|
||||
if (!isset($value)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (preg_match("|^a:[0-9]+:{.*}$|s", $value)) {
|
||||
return unserialize($value);
|
||||
} else {
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes a value from the config cache.
|
||||
*
|
||||
* @param string $cat Config category
|
||||
* @param string $key Config key
|
||||
* @param string $cat Config category
|
||||
* @param ?string $key Config key (if not set, the whole category will get deleted)
|
||||
* @param int $source The source of the current config key
|
||||
*
|
||||
* @return bool true, if deleted
|
||||
*/
|
||||
public function delete(string $cat, string $key): bool
|
||||
public function delete(string $cat, string $key = null, int $source = self::SOURCE_DEFAULT): bool
|
||||
{
|
||||
if (isset($this->config[$cat][$key])) {
|
||||
unset($this->config[$cat][$key]);
|
||||
unset($this->source[$cat][$key]);
|
||||
if (count($this->config[$cat]) == 0) {
|
||||
unset($this->config[$cat]);
|
||||
unset($this->source[$cat]);
|
||||
$this->config[$cat][$key] = null;
|
||||
$this->source[$cat][$key] = $source;
|
||||
if (empty(array_filter($this->config[$cat], function($value) { return !is_null($value); }))) {
|
||||
$this->config[$cat] = null;
|
||||
$this->source[$cat] = $source;
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
} elseif (isset($this->config[$cat])) {
|
||||
$this->config[$cat] = null;
|
||||
$this->source[$cat] = $source;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -223,4 +292,39 @@ class Cache
|
|||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Merges a new Cache into the existing one and returns the merged Cache
|
||||
*
|
||||
* @param Cache $cache The cache, which should get merged into this Cache
|
||||
*
|
||||
* @return Cache The merged Cache
|
||||
*/
|
||||
public function merge(Cache $cache): Cache
|
||||
{
|
||||
$newConfig = $this->config;
|
||||
$newSource = $this->source;
|
||||
|
||||
$categories = array_keys($cache->config);
|
||||
|
||||
foreach ($categories as $category) {
|
||||
if (is_array($cache->config[$category])) {
|
||||
$keys = array_keys($cache->config[$category]);
|
||||
|
||||
foreach ($keys as $key) {
|
||||
$newConfig[$category][$key] = $cache->config[$category][$key];
|
||||
$newSource[$category][$key] = $cache->source[$category][$key];
|
||||
}
|
||||
} else {
|
||||
$newConfig[$category] = $cache->config[$category];
|
||||
$newSource[$category] = $cache->source[$category];
|
||||
}
|
||||
}
|
||||
|
||||
$newCache = new Cache();
|
||||
$newCache->config = $newConfig;
|
||||
$newCache->source = $newSource;
|
||||
|
||||
return $newCache;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@
|
|||
|
||||
namespace Friendica\Core\KeyValueStorage\Type;
|
||||
|
||||
use Friendica\Core\Config\Util\ValueConversion;
|
||||
use Friendica\Core\PConfig\Util\ValueConversion;
|
||||
use Friendica\Core\KeyValueStorage\Exceptions\KeyValueStoragePersistenceException;
|
||||
use Friendica\Database\Database;
|
||||
|
||||
|
|
|
|||
|
|
@ -85,10 +85,15 @@ class L10n
|
|||
* @var Database
|
||||
*/
|
||||
private $dba;
|
||||
/**
|
||||
* @var IManageConfigValues
|
||||
*/
|
||||
private $config;
|
||||
|
||||
public function __construct(IManageConfigValues $config, Database $dba, IHandleSessions $session, array $server, array $get)
|
||||
{
|
||||
$this->dba = $dba;
|
||||
$this->config = $config;
|
||||
|
||||
$this->loadTranslationTable(L10n::detectLanguage($server, $get, $config->get('system', 'language', self::DEFAULT)));
|
||||
$this->setSessionVariable($session);
|
||||
|
|
@ -157,9 +162,9 @@ class L10n
|
|||
$a->strings = [];
|
||||
|
||||
// load enabled addons strings
|
||||
$addons = $this->dba->select('addon', ['name'], ['installed' => true]);
|
||||
while ($p = $this->dba->fetch($addons)) {
|
||||
$name = Strings::sanitizeFilePathItem($p['name']);
|
||||
$addons = array_keys($this->config->get('addons') ?? []);
|
||||
foreach ($addons as $addon) {
|
||||
$name = Strings::sanitizeFilePathItem($addon);
|
||||
if (file_exists(__DIR__ . "/../../addon/$name/lang/$lang/strings.php")) {
|
||||
include __DIR__ . "/../../addon/$name/lang/$lang/strings.php";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@
|
|||
namespace Friendica\Core\PConfig\Repository;
|
||||
|
||||
use Friendica\App\Mode;
|
||||
use Friendica\Core\Config\Util\ValueConversion;
|
||||
use Friendica\Core\PConfig\Util\ValueConversion;
|
||||
use Friendica\Core\PConfig\Exception\PConfigPersistenceException;
|
||||
use Friendica\Database\Database;
|
||||
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
namespace Friendica\Core\Config\Util;
|
||||
namespace Friendica\Core\PConfig\Util;
|
||||
|
||||
/**
|
||||
* Util class to help to convert from/to (p)config values
|
||||
|
|
@ -63,7 +63,11 @@ class ExternalResource implements ICanReadFromStorage
|
|||
Logger::debug('Got picture', ['Content-Type' => $fetchResult->getHeader('Content-Type'), 'uid' => $data->uid, 'url' => $data->url]);
|
||||
return $fetchResult->getBody();
|
||||
} else {
|
||||
throw new ReferenceStorageException(sprintf('External resource failed to get %s', $reference), $fetchResult->getReturnCode(), new Exception($fetchResult->getBody()));
|
||||
if (empty($fetchResult)) {
|
||||
throw new ReferenceStorageException(sprintf('External resource failed to get %s', $reference));
|
||||
} else {
|
||||
throw new ReferenceStorageException(sprintf('External resource failed to get %s', $reference), $fetchResult->getReturnCode(), new Exception($fetchResult->getBody()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -294,7 +294,7 @@ class System
|
|||
}
|
||||
|
||||
DI::apiResponse()->setType(Response::TYPE_XML);
|
||||
DI::apiResponse()->addContent(XML::fromArray(["result" => $result], $xml));
|
||||
DI::apiResponse()->addContent(XML::fromArray(['result' => $result]));
|
||||
DI::page()->exit(DI::apiResponse()->generate());
|
||||
|
||||
self::exit();
|
||||
|
|
|
|||
|
|
@ -47,22 +47,32 @@ class Update
|
|||
* @return void
|
||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
*/
|
||||
public static function check(string $basePath, bool $via_worker, App\Mode $mode)
|
||||
public static function check(string $basePath, bool $via_worker)
|
||||
{
|
||||
if (!DBA::connected()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Don't check the status if the last update was failed
|
||||
if (DI::config()->get('system', 'update', Update::SUCCESS, true) == Update::FAILED) {
|
||||
if (DI::config()->get('system', 'update', Update::SUCCESS) == Update::FAILED) {
|
||||
return;
|
||||
}
|
||||
|
||||
$build = DI::config()->get('system', 'build');
|
||||
|
||||
if (empty($build)) {
|
||||
DI::config()->set('system', 'build', DB_UPDATE_VERSION - 1);
|
||||
$build = DB_UPDATE_VERSION - 1;
|
||||
// legacy option - check if there's something in the Config table
|
||||
if (DBStructure::existsTable('config')) {
|
||||
$dbConfig = DBA::selectFirst('config', ['v'], ['cat' => 'system', 'k' => 'build']);
|
||||
if (!empty($dbConfig)) {
|
||||
$build = $dbConfig['v'];
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($build)) {
|
||||
DI::config()->set('system', 'build', DB_UPDATE_VERSION - 1);
|
||||
$build = DB_UPDATE_VERSION - 1;
|
||||
}
|
||||
}
|
||||
|
||||
// We don't support upgrading from very old versions anymore
|
||||
|
|
@ -119,11 +129,21 @@ class Update
|
|||
DI::lock()->release('dbupdate', true);
|
||||
}
|
||||
|
||||
$build = DI::config()->get('system', 'build', null, true);
|
||||
$build = DI::config()->get('system', 'build');
|
||||
|
||||
if (empty($build) || ($build > DB_UPDATE_VERSION)) {
|
||||
$build = DB_UPDATE_VERSION - 1;
|
||||
DI::config()->set('system', 'build', $build);
|
||||
if (empty($build)) {
|
||||
// legacy option - check if there's something in the Config table
|
||||
if (DBStructure::existsTable('config')) {
|
||||
$dbConfig = DBA::selectFirst('config', ['v'], ['cat' => 'system', 'k' => 'build']);
|
||||
if (!empty($dbConfig)) {
|
||||
$build = $dbConfig['v'];
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($build) || ($build > DB_UPDATE_VERSION)) {
|
||||
DI::config()->set('system', 'build', DB_UPDATE_VERSION - 1);
|
||||
$build = DB_UPDATE_VERSION - 1;
|
||||
}
|
||||
}
|
||||
|
||||
if ($build != DB_UPDATE_VERSION || $force) {
|
||||
|
|
@ -132,7 +152,7 @@ class Update
|
|||
$stored = intval($build);
|
||||
$current = intval(DB_UPDATE_VERSION);
|
||||
if ($stored < $current || $force) {
|
||||
DI::config()->load('database');
|
||||
DI::config()->reload();
|
||||
|
||||
// Compare the current structure with the defined structure
|
||||
// If the Lock is acquired, never release it automatically to avoid double updates
|
||||
|
|
@ -141,11 +161,21 @@ class Update
|
|||
Logger::notice('Update starting.', ['from' => $stored, 'to' => $current]);
|
||||
|
||||
// Checks if the build changed during Lock acquiring (so no double update occurs)
|
||||
$retryBuild = DI::config()->get('system', 'build', null, true);
|
||||
if ($retryBuild !== $build) {
|
||||
Logger::notice('Update already done.', ['from' => $stored, 'to' => $current]);
|
||||
DI::lock()->release('dbupdate');
|
||||
return '';
|
||||
$retryBuild = DI::config()->get('system', 'build');
|
||||
if ($retryBuild != $build) {
|
||||
// legacy option - check if there's something in the Config table
|
||||
if (DBStructure::existsTable('config')) {
|
||||
$dbConfig = DBA::selectFirst('config', ['v'], ['cat' => 'system', 'k' => 'build']);
|
||||
if (!empty($dbConfig)) {
|
||||
$retryBuild = intval($dbConfig['v']);
|
||||
}
|
||||
}
|
||||
|
||||
if ($retryBuild != $build) {
|
||||
Logger::notice('Update already done.', ['from' => $build, 'retry' => $retryBuild, 'to' => $current]);
|
||||
DI::lock()->release('dbupdate');
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
DI::config()->set('system', 'maintenance', 1);
|
||||
|
|
@ -160,8 +190,10 @@ class Update
|
|||
Logger::warning('Pre update failed', ['version' => $version]);
|
||||
DI::config()->set('system', 'update', Update::FAILED);
|
||||
DI::lock()->release('dbupdate');
|
||||
DI::config()->set('system', 'maintenance', 0);
|
||||
DI::config()->set('system', 'maintenance_reason', '');
|
||||
DI::config()->beginTransaction()
|
||||
->set('system', 'maintenance', false)
|
||||
->delete('system', 'maintenance_reason')
|
||||
->commit();
|
||||
return $r;
|
||||
} else {
|
||||
Logger::notice('Pre update executed.', ['version' => $version]);
|
||||
|
|
@ -181,8 +213,10 @@ class Update
|
|||
Logger::error('Update ERROR.', ['from' => $stored, 'to' => $current, 'retval' => $retval]);
|
||||
DI::config()->set('system', 'update', Update::FAILED);
|
||||
DI::lock()->release('dbupdate');
|
||||
DI::config()->set('system', 'maintenance', 0);
|
||||
DI::config()->set('system', 'maintenance_reason', '');
|
||||
DI::config()->beginTransaction()
|
||||
->set('system', 'maintenance', false)
|
||||
->delete('system', 'maintenance_reason')
|
||||
->commit();
|
||||
return $retval;
|
||||
} else {
|
||||
Logger::notice('Database structure update finished.', ['from' => $stored, 'to' => $current]);
|
||||
|
|
@ -198,8 +232,10 @@ class Update
|
|||
Logger::warning('Post update failed', ['version' => $version]);
|
||||
DI::config()->set('system', 'update', Update::FAILED);
|
||||
DI::lock()->release('dbupdate');
|
||||
DI::config()->set('system', 'maintenance', 0);
|
||||
DI::config()->set('system', 'maintenance_reason', '');
|
||||
DI::config()->beginTransaction()
|
||||
->set('system', 'maintenance', false)
|
||||
->delete('system', 'maintenance_reason')
|
||||
->commit();
|
||||
return $r;
|
||||
} else {
|
||||
DI::config()->set('system', 'build', $version);
|
||||
|
|
@ -210,8 +246,10 @@ class Update
|
|||
DI::config()->set('system', 'build', $current);
|
||||
DI::config()->set('system', 'update', Update::SUCCESS);
|
||||
DI::lock()->release('dbupdate');
|
||||
DI::config()->set('system', 'maintenance', 0);
|
||||
DI::config()->set('system', 'maintenance_reason', '');
|
||||
DI::config()->beginTransaction()
|
||||
->set('system', 'maintenance', false)
|
||||
->delete('system', 'maintenance_reason')
|
||||
->commit();
|
||||
|
||||
Logger::notice('Update success.', ['from' => $stored, 'to' => $current]);
|
||||
if ($sendMail) {
|
||||
|
|
|
|||
|
|
@ -331,7 +331,7 @@ class Worker
|
|||
$mypid = getmypid();
|
||||
|
||||
// Quit when in maintenance
|
||||
if (DI::config()->get('system', 'maintenance', false, true)) {
|
||||
if (DI::config()->get('system', 'maintenance', false)) {
|
||||
Logger::notice('Maintenance mode - quit process', ['pid' => $mypid]);
|
||||
return false;
|
||||
}
|
||||
|
|
@ -1315,8 +1315,8 @@ class Worker
|
|||
return $added;
|
||||
}
|
||||
|
||||
// Quit on daemon mode
|
||||
if (Worker\Daemon::isMode()) {
|
||||
// Quit on daemon mode, except the priority is critical (like for db updates)
|
||||
if (Worker\Daemon::isMode() && $priority !== self::PRIORITY_CRITICAL) {
|
||||
return $added;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -181,6 +181,11 @@ abstract class DI
|
|||
return self::$dice->create(Core\Config\Capability\IManageConfigValues::class);
|
||||
}
|
||||
|
||||
public static function configFileManager(): Core\Config\Util\ConfigFileManager
|
||||
{
|
||||
return self::$dice->create(Core\Config\Util\ConfigFileManager::class);
|
||||
}
|
||||
|
||||
public static function keyValue(): Core\KeyValueStorage\Capabilities\IManageKeyValuePairs
|
||||
{
|
||||
return self::$dice->create(Core\KeyValueStorage\Capabilities\IManageKeyValuePairs::class);
|
||||
|
|
|
|||
|
|
@ -74,7 +74,7 @@ class DBStructure
|
|||
$old_tables = ['fserver', 'gcign', 'gcontact', 'gcontact-relation', 'gfollower' ,'glink', 'item-delivery-data',
|
||||
'item-activity', 'item-content', 'item_id', 'participation', 'poll', 'poll_result', 'queue', 'retriever_rule',
|
||||
'deliverq', 'dsprphotoq', 'ffinder', 'sign', 'spam', 'term', 'user-item', 'thread', 'item', 'challenge',
|
||||
'auth_codes', 'tokens', 'clients', 'profile_check', 'host', 'conversation', 'fcontact'];
|
||||
'auth_codes', 'tokens', 'clients', 'profile_check', 'host', 'conversation', 'fcontact', 'config', 'addon'];
|
||||
|
||||
$tables = DBA::selectToArray('INFORMATION_SCHEMA.TABLES', ['TABLE_NAME'],
|
||||
['TABLE_SCHEMA' => DBA::databaseName(), 'TABLE_TYPE' => 'BASE TABLE']);
|
||||
|
|
@ -176,14 +176,16 @@ class DBStructure
|
|||
public static function performUpdate(bool $enable_maintenance_mode = true, bool $verbose = false): string
|
||||
{
|
||||
if ($enable_maintenance_mode) {
|
||||
DI::config()->set('system', 'maintenance', 1);
|
||||
DI::config()->set('system', 'maintenance', true);
|
||||
}
|
||||
|
||||
$status = self::update($verbose, true);
|
||||
|
||||
if ($enable_maintenance_mode) {
|
||||
DI::config()->set('system', 'maintenance', 0);
|
||||
DI::config()->set('system', 'maintenance_reason', '');
|
||||
DI::config()->beginTransaction()
|
||||
->set('system', 'maintenance', false)
|
||||
->delete('system', 'maintenance_reason')
|
||||
->commit();
|
||||
}
|
||||
|
||||
return $status;
|
||||
|
|
|
|||
|
|
@ -44,7 +44,9 @@ use Friendica\Util\Network;
|
|||
use Friendica\Util\Strings;
|
||||
use Friendica\Util\XML;
|
||||
use Friendica\Network\HTTPException;
|
||||
use Friendica\Worker\UpdateGServer;
|
||||
use GuzzleHttp\Psr7\Uri;
|
||||
use Psr\Http\Message\UriInterface;
|
||||
|
||||
/**
|
||||
* This class handles GServer related functions
|
||||
|
|
@ -99,11 +101,11 @@ class GServer
|
|||
*/
|
||||
public static function add(string $url, bool $only_nodeinfo = false)
|
||||
{
|
||||
if (self::getID($url, false)) {
|
||||
if (self::getID($url)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Worker::add(Worker::PRIORITY_LOW, 'UpdateGServer', $url, $only_nodeinfo);
|
||||
UpdateGServer::add(Worker::PRIORITY_LOW, $url, $only_nodeinfo);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -191,8 +193,9 @@ class GServer
|
|||
return false;
|
||||
} else {
|
||||
if (strtotime($gserver['next_contact']) < time()) {
|
||||
Worker::add(Worker::PRIORITY_LOW, 'UpdateGServer', $gserver['url'], false);
|
||||
UpdateGServer::add(Worker::PRIORITY_LOW, $gserver['url']);
|
||||
}
|
||||
|
||||
return self::isDefunct($gserver);
|
||||
}
|
||||
}
|
||||
|
|
@ -210,8 +213,9 @@ class GServer
|
|||
return true;
|
||||
} else {
|
||||
if (strtotime($gserver['next_contact']) < time()) {
|
||||
Worker::add(Worker::PRIORITY_LOW, 'UpdateGServer', $gserver['url'], false);
|
||||
UpdateGServer::add(Worker::PRIORITY_LOW, $gserver['url']);
|
||||
}
|
||||
|
||||
return !$gserver['failed'] && in_array($gserver['network'], Protocol::FEDERATED);
|
||||
}
|
||||
}
|
||||
|
|
@ -252,7 +256,7 @@ class GServer
|
|||
}
|
||||
|
||||
if (!empty($server) && (empty($gserver) || strtotime($gserver['next_contact']) < time())) {
|
||||
Worker::add(Worker::PRIORITY_LOW, 'UpdateGServer', $server, false);
|
||||
UpdateGServer::add(Worker::PRIORITY_LOW, $server);
|
||||
}
|
||||
|
||||
return $reachable;
|
||||
|
|
@ -375,7 +379,7 @@ class GServer
|
|||
Logger::info('Reset failed status for server', ['url' => $gserver['url']]);
|
||||
|
||||
if (strtotime($gserver['next_contact']) < time()) {
|
||||
Worker::add(Worker::PRIORITY_LOW, 'UpdateGServer', $gserver['url'], false);
|
||||
UpdateGServer::add(Worker::PRIORITY_LOW, $gserver['url']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -393,7 +397,7 @@ class GServer
|
|||
Logger::info('Set failed status for server', ['url' => $gserver['url']]);
|
||||
|
||||
if (strtotime($gserver['next_contact']) < time()) {
|
||||
Worker::add(Worker::PRIORITY_LOW, 'UpdateGServer', $gserver['url'], false);
|
||||
UpdateGServer::add(Worker::PRIORITY_LOW, $gserver['url']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -442,18 +446,41 @@ class GServer
|
|||
*
|
||||
* @return string cleaned URL
|
||||
* @throws Exception
|
||||
* @deprecated since 2023.03 Use cleanUri instead
|
||||
*/
|
||||
public static function cleanURL(string $dirtyUrl): string
|
||||
{
|
||||
try {
|
||||
$url = str_replace('/index.php', '', trim($dirtyUrl, '/'));
|
||||
return (string)(new Uri($url))->withUserInfo('')->withQuery('')->withFragment('');
|
||||
return (string)self::cleanUri(new Uri($dirtyUrl));
|
||||
} catch (\Throwable $e) {
|
||||
Logger::warning('Invalid URL', ['dirtyUrl' => $dirtyUrl, 'url' => $url]);
|
||||
Logger::warning('Invalid URL', ['dirtyUrl' => $dirtyUrl]);
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove unwanted content from the given URI
|
||||
*
|
||||
* @param UriInterface $dirtyUri
|
||||
*
|
||||
* @return UriInterface cleaned URI
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function cleanUri(UriInterface $dirtyUri): string
|
||||
{
|
||||
return $dirtyUri
|
||||
->withUserInfo('')
|
||||
->withQuery('')
|
||||
->withFragment('')
|
||||
->withPath(
|
||||
preg_replace(
|
||||
'#(?:^|/)index\.php#',
|
||||
'',
|
||||
rtrim($dirtyUri->getPath(), '/')
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Detect server data (type, protocol, version number, ...)
|
||||
* The detected data is then updated or inserted in the gserver table.
|
||||
|
|
|
|||
|
|
@ -126,7 +126,7 @@ class Link
|
|||
$timeout = DI::config()->get('system', 'xrd_timeout');
|
||||
|
||||
$curlResult = HTTPSignature::fetchRaw($url, 0, [HttpClientOptions::TIMEOUT => $timeout, HttpClientOptions::ACCEPT_CONTENT => $accept]);
|
||||
if (!$curlResult->isSuccess()) {
|
||||
if (empty($curlResult) || !$curlResult->isSuccess()) {
|
||||
return [];
|
||||
}
|
||||
$fields = ['mimetype' => $curlResult->getHeader('Content-Type')[0]];
|
||||
|
|
|
|||
|
|
@ -48,8 +48,6 @@ class Site extends BaseAdmin
|
|||
|
||||
self::checkFormSecurityTokenRedirectOnError('/admin/site', 'admin_site');
|
||||
|
||||
$a = DI::app();
|
||||
|
||||
if (!empty($_POST['republish_directory'])) {
|
||||
Worker::add(Worker::PRIORITY_LOW, 'Directory');
|
||||
return;
|
||||
|
|
@ -146,9 +144,11 @@ class Site extends BaseAdmin
|
|||
$relay_user_tags = !empty($_POST['relay_user_tags']);
|
||||
$active_panel = (!empty($_POST['active_panel']) ? "#" . trim($_POST['active_panel']) : '');
|
||||
|
||||
$transactionConfig = DI::config()->beginTransaction();
|
||||
|
||||
// Has the directory url changed? If yes, then resubmit the existing profiles there
|
||||
if ($global_directory != DI::config()->get('system', 'directory') && ($global_directory != '')) {
|
||||
DI::config()->set('system', 'directory', $global_directory);
|
||||
$transactionConfig->set('system', 'directory', $global_directory);
|
||||
Worker::add(Worker::PRIORITY_LOW, 'Directory');
|
||||
}
|
||||
|
||||
|
|
@ -194,131 +194,133 @@ class Site extends BaseAdmin
|
|||
);
|
||||
}
|
||||
}
|
||||
DI::config()->set('system', 'ssl_policy' , $ssl_policy);
|
||||
DI::config()->set('system', 'maxloadavg' , $maxloadavg);
|
||||
DI::config()->set('system', 'min_memory' , $min_memory);
|
||||
DI::config()->set('system', 'optimize_tables' , $optimize_tables);
|
||||
DI::config()->set('system', 'contact_discovery' , $contact_discovery);
|
||||
DI::config()->set('system', 'synchronize_directory' , $synchronize_directory);
|
||||
DI::config()->set('system', 'poco_requery_days' , $poco_requery_days);
|
||||
DI::config()->set('system', 'poco_discovery' , $poco_discovery);
|
||||
DI::config()->set('system', 'poco_local_search' , $poco_local_search);
|
||||
DI::config()->set('system', 'nodeinfo' , $nodeinfo);
|
||||
DI::config()->set('config', 'sitename' , $sitename);
|
||||
DI::config()->set('config', 'sender_email' , $sender_email);
|
||||
DI::config()->set('system', 'suppress_tags' , $suppress_tags);
|
||||
DI::config()->set('system', 'shortcut_icon' , $shortcut_icon);
|
||||
DI::config()->set('system', 'touch_icon' , $touch_icon);
|
||||
$transactionConfig->set('system', 'ssl_policy' , $ssl_policy);
|
||||
$transactionConfig->set('system', 'maxloadavg' , $maxloadavg);
|
||||
$transactionConfig->set('system', 'min_memory' , $min_memory);
|
||||
$transactionConfig->set('system', 'optimize_tables' , $optimize_tables);
|
||||
$transactionConfig->set('system', 'contact_discovery' , $contact_discovery);
|
||||
$transactionConfig->set('system', 'synchronize_directory' , $synchronize_directory);
|
||||
$transactionConfig->set('system', 'poco_requery_days' , $poco_requery_days);
|
||||
$transactionConfig->set('system', 'poco_discovery' , $poco_discovery);
|
||||
$transactionConfig->set('system', 'poco_local_search' , $poco_local_search);
|
||||
$transactionConfig->set('system', 'nodeinfo' , $nodeinfo);
|
||||
$transactionConfig->set('config', 'sitename' , $sitename);
|
||||
$transactionConfig->set('config', 'sender_email' , $sender_email);
|
||||
$transactionConfig->set('system', 'suppress_tags' , $suppress_tags);
|
||||
$transactionConfig->set('system', 'shortcut_icon' , $shortcut_icon);
|
||||
$transactionConfig->set('system', 'touch_icon' , $touch_icon);
|
||||
|
||||
if ($banner == "") {
|
||||
DI::config()->delete('system', 'banner');
|
||||
$transactionConfig->delete('system', 'banner');
|
||||
} else {
|
||||
DI::config()->set('system', 'banner', $banner);
|
||||
$transactionConfig->set('system', 'banner', $banner);
|
||||
}
|
||||
|
||||
if (empty($email_banner)) {
|
||||
DI::config()->delete('system', 'email_banner');
|
||||
$transactionConfig->delete('system', 'email_banner');
|
||||
} else {
|
||||
DI::config()->set('system', 'email_banner', $email_banner);
|
||||
$transactionConfig->set('system', 'email_banner', $email_banner);
|
||||
}
|
||||
|
||||
if (empty($additional_info)) {
|
||||
DI::config()->delete('config', 'info');
|
||||
$transactionConfig->delete('config', 'info');
|
||||
} else {
|
||||
DI::config()->set('config', 'info', $additional_info);
|
||||
$transactionConfig->set('config', 'info', $additional_info);
|
||||
}
|
||||
DI::config()->set('system', 'language', $language);
|
||||
DI::config()->set('system', 'theme', $theme);
|
||||
$transactionConfig->set('system', 'language', $language);
|
||||
$transactionConfig->set('system', 'theme', $theme);
|
||||
Theme::install($theme);
|
||||
|
||||
if ($theme_mobile == '---') {
|
||||
DI::config()->delete('system', 'mobile-theme');
|
||||
$transactionConfig->delete('system', 'mobile-theme');
|
||||
} else {
|
||||
DI::config()->set('system', 'mobile-theme', $theme_mobile);
|
||||
$transactionConfig->set('system', 'mobile-theme', $theme_mobile);
|
||||
}
|
||||
if ($singleuser == '---') {
|
||||
DI::config()->delete('system', 'singleuser');
|
||||
$transactionConfig->delete('system', 'singleuser');
|
||||
} else {
|
||||
DI::config()->set('system', 'singleuser', $singleuser);
|
||||
$transactionConfig->set('system', 'singleuser', $singleuser);
|
||||
}
|
||||
if (preg_match('/\d+(?:\s*[kmg])?/i', $maximagesize)) {
|
||||
DI::config()->set('system', 'maximagesize', $maximagesize);
|
||||
$transactionConfig->set('system', 'maximagesize', $maximagesize);
|
||||
} else {
|
||||
DI::sysmsg()->addNotice(DI::l10n()->t('%s is no valid input for maximum image size', $maximagesize));
|
||||
}
|
||||
DI::config()->set('system', 'max_image_length' , $maximagelength);
|
||||
DI::config()->set('system', 'jpeg_quality' , $jpegimagequality);
|
||||
$transactionConfig->set('system', 'max_image_length' , $maximagelength);
|
||||
$transactionConfig->set('system', 'jpeg_quality' , $jpegimagequality);
|
||||
|
||||
DI::config()->set('config', 'register_policy' , $register_policy);
|
||||
DI::config()->set('system', 'max_daily_registrations', $daily_registrations);
|
||||
DI::config()->set('system', 'account_abandon_days' , $abandon_days);
|
||||
DI::config()->set('config', 'register_text' , $register_text);
|
||||
DI::config()->set('system', 'allowed_sites' , $allowed_sites);
|
||||
DI::config()->set('system', 'allowed_email' , $allowed_email);
|
||||
DI::config()->set('system', 'forbidden_nicknames' , $forbidden_nicknames);
|
||||
DI::config()->set('system', 'system_actor_name' , $system_actor_name);
|
||||
DI::config()->set('system', 'no_oembed_rich_content' , $no_oembed_rich_content);
|
||||
DI::config()->set('system', 'allowed_oembed' , $allowed_oembed);
|
||||
DI::config()->set('system', 'block_public' , $block_public);
|
||||
DI::config()->set('system', 'publish_all' , $force_publish);
|
||||
DI::config()->set('system', 'newuser_private' , $newuser_private);
|
||||
DI::config()->set('system', 'enotify_no_content' , $enotify_no_content);
|
||||
DI::config()->set('system', 'disable_embedded' , $disable_embedded);
|
||||
DI::config()->set('system', 'allow_users_remote_self', $allow_users_remote_self);
|
||||
DI::config()->set('system', 'explicit_content' , $explicit_content);
|
||||
DI::config()->set('system', 'proxify_content' , $proxify_content);
|
||||
DI::config()->set('system', 'cache_contact_avatar' , $cache_contact_avatar);
|
||||
DI::config()->set('system', 'check_new_version_url' , $check_new_version_url);
|
||||
$transactionConfig->set('config', 'register_policy' , $register_policy);
|
||||
$transactionConfig->set('system', 'max_daily_registrations', $daily_registrations);
|
||||
$transactionConfig->set('system', 'account_abandon_days' , $abandon_days);
|
||||
$transactionConfig->set('config', 'register_text' , $register_text);
|
||||
$transactionConfig->set('system', 'allowed_sites' , $allowed_sites);
|
||||
$transactionConfig->set('system', 'allowed_email' , $allowed_email);
|
||||
$transactionConfig->set('system', 'forbidden_nicknames' , $forbidden_nicknames);
|
||||
$transactionConfig->set('system', 'system_actor_name' , $system_actor_name);
|
||||
$transactionConfig->set('system', 'no_oembed_rich_content' , $no_oembed_rich_content);
|
||||
$transactionConfig->set('system', 'allowed_oembed' , $allowed_oembed);
|
||||
$transactionConfig->set('system', 'block_public' , $block_public);
|
||||
$transactionConfig->set('system', 'publish_all' , $force_publish);
|
||||
$transactionConfig->set('system', 'newuser_private' , $newuser_private);
|
||||
$transactionConfig->set('system', 'enotify_no_content' , $enotify_no_content);
|
||||
$transactionConfig->set('system', 'disable_embedded' , $disable_embedded);
|
||||
$transactionConfig->set('system', 'allow_users_remote_self', $allow_users_remote_self);
|
||||
$transactionConfig->set('system', 'explicit_content' , $explicit_content);
|
||||
$transactionConfig->set('system', 'proxify_content' , $proxify_content);
|
||||
$transactionConfig->set('system', 'cache_contact_avatar' , $cache_contact_avatar);
|
||||
$transactionConfig->set('system', 'check_new_version_url' , $check_new_version_url);
|
||||
|
||||
DI::config()->set('system', 'block_extended_register', !$enable_multi_reg);
|
||||
DI::config()->set('system', 'no_openid' , !$enable_openid);
|
||||
DI::config()->set('system', 'no_regfullname' , !$enable_regfullname);
|
||||
DI::config()->set('system', 'register_notification' , $register_notification);
|
||||
DI::config()->set('system', 'community_page_style' , $community_page_style);
|
||||
DI::config()->set('system', 'max_author_posts_community_page', $max_author_posts_community_page);
|
||||
DI::config()->set('system', 'verifyssl' , $verifyssl);
|
||||
DI::config()->set('system', 'proxyuser' , $proxyuser);
|
||||
DI::config()->set('system', 'proxy' , $proxy);
|
||||
DI::config()->set('system', 'curl_timeout' , $timeout);
|
||||
DI::config()->set('system', 'imap_disabled' , !$mail_enabled && function_exists('imap_open'));
|
||||
DI::config()->set('system', 'ostatus_disabled' , !$ostatus_enabled);
|
||||
DI::config()->set('system', 'diaspora_enabled' , $diaspora_enabled);
|
||||
$transactionConfig->set('system', 'block_extended_register', !$enable_multi_reg);
|
||||
$transactionConfig->set('system', 'no_openid' , !$enable_openid);
|
||||
$transactionConfig->set('system', 'no_regfullname' , !$enable_regfullname);
|
||||
$transactionConfig->set('system', 'register_notification' , $register_notification);
|
||||
$transactionConfig->set('system', 'community_page_style' , $community_page_style);
|
||||
$transactionConfig->set('system', 'max_author_posts_community_page', $max_author_posts_community_page);
|
||||
$transactionConfig->set('system', 'verifyssl' , $verifyssl);
|
||||
$transactionConfig->set('system', 'proxyuser' , $proxyuser);
|
||||
$transactionConfig->set('system', 'proxy' , $proxy);
|
||||
$transactionConfig->set('system', 'curl_timeout' , $timeout);
|
||||
$transactionConfig->set('system', 'imap_disabled' , !$mail_enabled && function_exists('imap_open'));
|
||||
$transactionConfig->set('system', 'ostatus_disabled' , !$ostatus_enabled);
|
||||
$transactionConfig->set('system', 'diaspora_enabled' , $diaspora_enabled);
|
||||
|
||||
DI::config()->set('config', 'private_addons' , $private_addons);
|
||||
$transactionConfig->set('config', 'private_addons' , $private_addons);
|
||||
|
||||
DI::config()->set('system', 'force_ssl' , $force_ssl);
|
||||
DI::config()->set('system', 'hide_help' , !$show_help);
|
||||
$transactionConfig->set('system', 'force_ssl' , $force_ssl);
|
||||
$transactionConfig->set('system', 'hide_help' , !$show_help);
|
||||
|
||||
DI::config()->set('system', 'dbclean' , $dbclean);
|
||||
DI::config()->set('system', 'dbclean-expire-days' , $dbclean_expire_days);
|
||||
DI::config()->set('system', 'dbclean_expire_conversation', $dbclean_expire_conv);
|
||||
$transactionConfig->set('system', 'dbclean' , $dbclean);
|
||||
$transactionConfig->set('system', 'dbclean-expire-days' , $dbclean_expire_days);
|
||||
$transactionConfig->set('system', 'dbclean_expire_conversation', $dbclean_expire_conv);
|
||||
|
||||
if ($dbclean_unclaimed == 0) {
|
||||
$dbclean_unclaimed = $dbclean_expire_days;
|
||||
}
|
||||
|
||||
DI::config()->set('system', 'dbclean-expire-unclaimed', $dbclean_unclaimed);
|
||||
$transactionConfig->set('system', 'dbclean-expire-unclaimed', $dbclean_unclaimed);
|
||||
|
||||
DI::config()->set('system', 'max_comments', $max_comments);
|
||||
DI::config()->set('system', 'max_display_comments', $max_display_comments);
|
||||
$transactionConfig->set('system', 'max_comments', $max_comments);
|
||||
$transactionConfig->set('system', 'max_display_comments', $max_display_comments);
|
||||
|
||||
if ($temppath != '') {
|
||||
$temppath = BasePath::getRealPath($temppath);
|
||||
}
|
||||
|
||||
DI::config()->set('system', 'temppath', $temppath);
|
||||
$transactionConfig->set('system', 'temppath', $temppath);
|
||||
|
||||
DI::config()->set('system', 'only_tag_search' , $only_tag_search);
|
||||
DI::config()->set('system', 'compute_group_counts', $compute_group_counts);
|
||||
$transactionConfig->set('system', 'only_tag_search' , $only_tag_search);
|
||||
$transactionConfig->set('system', 'compute_group_counts', $compute_group_counts);
|
||||
|
||||
DI::config()->set('system', 'worker_queues' , $worker_queues);
|
||||
DI::config()->set('system', 'worker_fastlane' , $worker_fastlane);
|
||||
$transactionConfig->set('system', 'worker_queues' , $worker_queues);
|
||||
$transactionConfig->set('system', 'worker_fastlane' , $worker_fastlane);
|
||||
|
||||
DI::config()->set('system', 'relay_directly' , $relay_directly);
|
||||
DI::config()->set('system', 'relay_scope' , $relay_scope);
|
||||
DI::config()->set('system', 'relay_server_tags', $relay_server_tags);
|
||||
DI::config()->set('system', 'relay_deny_tags' , $relay_deny_tags);
|
||||
DI::config()->set('system', 'relay_user_tags' , $relay_user_tags);
|
||||
$transactionConfig->set('system', 'relay_directly' , $relay_directly);
|
||||
$transactionConfig->set('system', 'relay_scope' , $relay_scope);
|
||||
$transactionConfig->set('system', 'relay_server_tags', $relay_server_tags);
|
||||
$transactionConfig->set('system', 'relay_deny_tags' , $relay_deny_tags);
|
||||
$transactionConfig->set('system', 'relay_user_tags' , $relay_user_tags);
|
||||
|
||||
$transactionConfig->commit();
|
||||
|
||||
DI::baseUrl()->redirect('admin/site' . $active_panel);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ namespace Friendica\Module\Admin;
|
|||
|
||||
use Friendica\App;
|
||||
use Friendica\Core\Addon;
|
||||
use Friendica\Core\Config\Util\ConfigFileManager;
|
||||
use Friendica\Core\Config\ValueObject\Cache;
|
||||
use Friendica\Core\Logger;
|
||||
use Friendica\Core\Renderer;
|
||||
|
|
@ -114,6 +115,10 @@ class Summary extends BaseAdmin
|
|||
$warningtext[] = DI::l10n()->t('Friendica\'s configuration now is stored in config/local.config.php, please copy config/local-sample.config.php and move your config from <code>config/local.ini.php</code>. See <a href="%s">the Config help page</a> for help with the transition.', DI::baseUrl()->get() . '/help/Config');
|
||||
}
|
||||
|
||||
if (!DI::configFileManager()->dataIsWritable()) {
|
||||
$warningtext[] = DI::l10n()->t('Friendica\'s configuration store "%s" isn\'t writable. Until then database updates won\'t be applied automatically, admin settings and console configuration changes won\'t be saved.', ConfigFileManager::CONFIG_DATA_FILE);
|
||||
}
|
||||
|
||||
// Check server vitality
|
||||
if (!self::checkSelfHostMeta()) {
|
||||
$well_known = DI::baseUrl()->get() . Probe::HOST_META;
|
||||
|
|
@ -154,7 +159,7 @@ class Summary extends BaseAdmin
|
|||
}
|
||||
|
||||
// check legacy basepath settings
|
||||
$configLoader = (new Config())->createConfigFileLoader($a->getBasePath(), $_SERVER);
|
||||
$configLoader = (new Config())->createConfigFileManager($a->getBasePath(), $_SERVER);
|
||||
$configCache = new Cache();
|
||||
$configLoader->setupCache($configCache);
|
||||
$confBasepath = $configCache->get('system', 'basepath');
|
||||
|
|
|
|||
|
|
@ -99,7 +99,7 @@ class ApiResponse extends Response
|
|||
|
||||
$data3 = [$root_element => $data2];
|
||||
|
||||
return XML::fromArray($data3, $xml, false, $namespaces);
|
||||
return XML::fromArray($data3, $dummy, false, $namespaces);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -157,7 +157,7 @@ class Friendica extends BaseModule
|
|||
|
||||
$visible_addons = Addon::getVisibleList();
|
||||
|
||||
$config->load('feature_lock');
|
||||
$config->reload();
|
||||
$locked_features = [];
|
||||
$featureLocks = $config->get('config', 'feature_lock');
|
||||
if (isset($featureLocks)) {
|
||||
|
|
|
|||
|
|
@ -43,8 +43,6 @@ class OpenSearch extends BaseModule
|
|||
$baseUrl = DI::baseUrl()->get();
|
||||
|
||||
/** @var DOMDocument $xml */
|
||||
$xml = null;
|
||||
|
||||
XML::fromArray([
|
||||
'OpenSearchDescription' => [
|
||||
'@attributes' => [
|
||||
|
|
|
|||
|
|
@ -34,7 +34,6 @@ class ReallySimpleDiscovery extends BaseModule
|
|||
{
|
||||
protected function rawContent(array $request = [])
|
||||
{
|
||||
$xml = null;
|
||||
$content = XML::fromArray([
|
||||
'rsd' => [
|
||||
'@attributes' => [
|
||||
|
|
@ -67,7 +66,7 @@ class ReallySimpleDiscovery extends BaseModule
|
|||
],
|
||||
],
|
||||
],
|
||||
], $xml);
|
||||
]);
|
||||
System::httpExit($content, Response::TYPE_XML);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -79,7 +79,6 @@ class Display extends BaseSettings
|
|||
$first_day_of_week = !empty($request['first_day_of_week']) ? intval($request['first_day_of_week']) : 0;
|
||||
$calendar_default_view = !empty($request['calendar_default_view']) ? trim($request['calendar_default_view']) : 'month';
|
||||
$infinite_scroll = !empty($request['infinite_scroll']) ? intval($request['infinite_scroll']) : 0;
|
||||
$no_auto_update = !empty($request['no_auto_update']) ? intval($request['no_auto_update']) : 0;
|
||||
$enable_smart_threading = !empty($request['enable_smart_threading']) ? intval($request['enable_smart_threading']) : 0;
|
||||
$enable_dislike = !empty($request['enable_dislike']) ? intval($request['enable_dislike']) : 0;
|
||||
$display_resharer = !empty($request['display_resharer']) ? intval($request['display_resharer']) : 0;
|
||||
|
|
@ -113,7 +112,6 @@ class Display extends BaseSettings
|
|||
$this->pConfig->set($uid, 'system', 'itemspage_network' , $itemspage_network);
|
||||
$this->pConfig->set($uid, 'system', 'itemspage_mobile_network', $itemspage_mobile_network);
|
||||
$this->pConfig->set($uid, 'system', 'update_interval' , $browser_update);
|
||||
$this->pConfig->set($uid, 'system', 'no_auto_update' , $no_auto_update);
|
||||
$this->pConfig->set($uid, 'system', 'no_smilies' , !$enable_smile);
|
||||
$this->pConfig->set($uid, 'system', 'infinite_scroll' , $infinite_scroll);
|
||||
$this->pConfig->set($uid, 'system', 'no_smart_threading' , !$enable_smart_threading);
|
||||
|
|
@ -202,7 +200,6 @@ class Display extends BaseSettings
|
|||
$browser_update = (($browser_update == 0) ? 40 : $browser_update / 1000); // default if not set: 40 seconds
|
||||
}
|
||||
|
||||
$no_auto_update = $this->pConfig->get($uid, 'system', 'no_auto_update', 0);
|
||||
$enable_smile = !$this->pConfig->get($uid, 'system', 'no_smilies', 0);
|
||||
$infinite_scroll = $this->pConfig->get($uid, 'system', 'infinite_scroll', 0);
|
||||
$enable_smart_threading = !$this->pConfig->get($uid, 'system', 'no_smart_threading', 0);
|
||||
|
|
@ -265,7 +262,6 @@ class Display extends BaseSettings
|
|||
'$itemspage_network' => ['itemspage_network' , $this->t('Number of items to display per page:'), $itemspage_network, $this->t('Maximum of 100 items')],
|
||||
'$itemspage_mobile_network' => ['itemspage_mobile_network', $this->t('Number of items to display per page when viewed from mobile device:'), $itemspage_mobile_network, $this->t('Maximum of 100 items')],
|
||||
'$ajaxint' => ['browser_update' , $this->t('Update browser every xx seconds'), $browser_update, $this->t('Minimum of 10 seconds. Enter -1 to disable it.')],
|
||||
'$no_auto_update' => ['no_auto_update' , $this->t('Automatic updates only at the top of the post stream pages'), $no_auto_update, $this->t('Auto update may add new posts at the top of the post stream pages, which can affect the scroll position and perturb normal reading if it happens anywhere else the top of the page.')],
|
||||
'$enable_smile' => ['enable_smile' , $this->t('Display emoticons'), $enable_smile, $this->t('When enabled, emoticons are replaced with matching symbols.')],
|
||||
'$infinite_scroll' => ['infinite_scroll' , $this->t('Infinite scroll'), $infinite_scroll, $this->t('Automatic fetch new items when reaching the page end.')],
|
||||
'$enable_smart_threading' => ['enable_smart_threading' , $this->t('Enable Smart Threading'), $enable_smart_threading, $this->t('Enable the automatic suppression of extraneous thread indentation.')],
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ class Community extends CommunityModule
|
|||
$this->parseRequest();
|
||||
|
||||
$o = '';
|
||||
if (!empty($_GET['force']) || !DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'system', 'no_auto_update')) {
|
||||
if (!empty($request['force'])) {
|
||||
$o = DI::conversation()->create(self::getItems(), 'community', true, false, 'commented', DI::userSession()->getLocalUserId());
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -31,53 +31,55 @@ class Network extends NetworkModule
|
|||
{
|
||||
protected function rawContent(array $request = [])
|
||||
{
|
||||
if (!isset($_GET['p']) || !isset($_GET['item'])) {
|
||||
if (!isset($request['p']) || !isset($request['item'])) {
|
||||
System::exit();
|
||||
}
|
||||
|
||||
$this->parseRequest($_GET);
|
||||
$this->parseRequest($request);
|
||||
|
||||
$profile_uid = intval($_GET['p']);
|
||||
$profile_uid = intval($request['p']);
|
||||
|
||||
$o = '';
|
||||
|
||||
if (!DI::pConfig()->get($profile_uid, 'system', 'no_auto_update') || ($_GET['force'] == 1)) {
|
||||
if (!empty($_GET['item'])) {
|
||||
$item = Post::selectFirst(['parent'], ['id' => $_GET['item']]);
|
||||
$parent = $item['parent'] ?? 0;
|
||||
} else {
|
||||
$parent = 0;
|
||||
}
|
||||
|
||||
$conditionFields = [];
|
||||
if (!empty($parent)) {
|
||||
// Load only a single thread
|
||||
$conditionFields['parent'] = $parent;
|
||||
} elseif (self::$order === 'received') {
|
||||
// Only load new toplevel posts
|
||||
$conditionFields['unseen'] = true;
|
||||
$conditionFields['gravity'] = Item::GRAVITY_PARENT;
|
||||
} else {
|
||||
// Load all unseen items
|
||||
$conditionFields['unseen'] = true;
|
||||
}
|
||||
|
||||
$params = ['limit' => 100];
|
||||
$table = 'network-item-view';
|
||||
|
||||
$items = self::getItems($table, $params, $conditionFields);
|
||||
|
||||
if (self::$order === 'received') {
|
||||
$ordering = '`received`';
|
||||
} elseif (self::$order === 'created') {
|
||||
$ordering = '`created`';
|
||||
} else {
|
||||
$ordering = '`commented`';
|
||||
}
|
||||
|
||||
$o = DI::conversation()->create($items, 'network', $profile_uid, false, $ordering, DI::userSession()->getLocalUserId());
|
||||
if (empty($request['force'])) {
|
||||
System::htmlUpdateExit($o);
|
||||
}
|
||||
|
||||
if (!empty($request['item'])) {
|
||||
$item = Post::selectFirst(['parent'], ['id' => $request['item']]);
|
||||
$parent = $item['parent'] ?? 0;
|
||||
} else {
|
||||
$parent = 0;
|
||||
}
|
||||
|
||||
$conditionFields = [];
|
||||
if (!empty($parent)) {
|
||||
// Load only a single thread
|
||||
$conditionFields['parent'] = $parent;
|
||||
} elseif (self::$order === 'received') {
|
||||
// Only load new toplevel posts
|
||||
$conditionFields['unseen'] = true;
|
||||
$conditionFields['gravity'] = Item::GRAVITY_PARENT;
|
||||
} else {
|
||||
// Load all unseen items
|
||||
$conditionFields['unseen'] = true;
|
||||
}
|
||||
|
||||
$params = ['limit' => 100];
|
||||
$table = 'network-item-view';
|
||||
|
||||
$items = self::getItems($table, $params, $conditionFields);
|
||||
|
||||
if (self::$order === 'received') {
|
||||
$ordering = '`received`';
|
||||
} elseif (self::$order === 'created') {
|
||||
$ordering = '`created`';
|
||||
} else {
|
||||
$ordering = '`commented`';
|
||||
}
|
||||
|
||||
$o = DI::conversation()->create($items, 'network', $profile_uid, false, $ordering, DI::userSession()->getLocalUserId());
|
||||
|
||||
System::htmlUpdateExit($o);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ class Profile extends BaseModule
|
|||
$a = DI::app();
|
||||
|
||||
// Ensure we've got a profile owner if updating.
|
||||
$a->setProfileOwner((int)($_GET['p'] ?? 0));
|
||||
$a->setProfileOwner((int)($request['p'] ?? 0));
|
||||
|
||||
if (DI::config()->get('system', 'block_public') && !DI::userSession()->getLocalUserId() && !DI::userSession()->getRemoteContactID($a->getProfileOwner())) {
|
||||
throw new ForbiddenException();
|
||||
|
|
@ -58,7 +58,7 @@ class Profile extends BaseModule
|
|||
|
||||
$o = '';
|
||||
|
||||
if (empty($_GET['force']) && DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'system', 'no_auto_update')) {
|
||||
if (empty($request['force'])) {
|
||||
System::htmlUpdateExit($o);
|
||||
}
|
||||
|
||||
|
|
@ -73,9 +73,9 @@ class Profile extends BaseModule
|
|||
AND `visible` AND (NOT `deleted` OR `gravity` = ?)
|
||||
AND `wall` " . $sql_extra, $a->getProfileOwner(), Item::GRAVITY_ACTIVITY];
|
||||
|
||||
if ($_GET['force'] && !empty($_GET['item'])) {
|
||||
if ($request['force'] && !empty($request['item'])) {
|
||||
// When the parent is provided, we only fetch this
|
||||
$condition = DBA::mergeConditions($condition, ['parent' => $_GET['item']]);
|
||||
$condition = DBA::mergeConditions($condition, ['parent' => $request['item']]);
|
||||
} elseif ($is_owner || !$last_updated) {
|
||||
// If the page user is the owner of the page we should query for unseen
|
||||
// items. Otherwise use a timestamp of the last succesful update request.
|
||||
|
|
|
|||
|
|
@ -48,7 +48,6 @@ class HostMeta extends BaseModule
|
|||
|
||||
$domain = DI::baseUrl()->get();
|
||||
|
||||
$xml = null;
|
||||
XML::fromArray([
|
||||
'XRD' => [
|
||||
'@attributes' => [
|
||||
|
|
@ -81,13 +80,6 @@ class HostMeta extends BaseModule
|
|||
'href' => $domain . '/amcd'
|
||||
]
|
||||
],
|
||||
'5:link' => [
|
||||
'@attributes' => [
|
||||
'rel' => 'http://oexchange.org/spec/0.8/rel/resident-target',
|
||||
'type' => 'application/xrd+xml',
|
||||
'href' => $domain . '/oexchange/xrd'
|
||||
]
|
||||
],
|
||||
'Property' => [
|
||||
'@attributes' => [
|
||||
'type' => 'http://salmon-protocol.org/ns/magic-key',
|
||||
|
|
|
|||
|
|
@ -230,9 +230,7 @@ class Xrd extends BaseModule
|
|||
{
|
||||
$baseURL = $this->baseUrl->get();
|
||||
|
||||
$xml = null;
|
||||
|
||||
XML::fromArray([
|
||||
$xmlString = XML::fromArray([
|
||||
'XRD' => [
|
||||
'@attributes' => [
|
||||
'xmlns' => 'http://docs.oasis-open.org/ns/xri/xrd-1.0',
|
||||
|
|
@ -319,10 +317,10 @@ class Xrd extends BaseModule
|
|||
]
|
||||
],
|
||||
],
|
||||
], $xml);
|
||||
]);
|
||||
|
||||
header('Access-Control-Allow-Origin: *');
|
||||
|
||||
System::httpExit($xml->saveXML(), Response::TYPE_XML, 'application/xrd+xml');
|
||||
System::httpExit($xmlString, Response::TYPE_XML, 'application/xrd+xml');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -50,11 +50,11 @@ class Subscription extends BaseDataTransferObject
|
|||
$this->id = (string)$subscription['id'];
|
||||
$this->endpoint = $subscription['endpoint'];
|
||||
$this->alerts = [
|
||||
Notification::TYPE_FOLLOW => $subscription[Notification::TYPE_FOLLOW],
|
||||
Notification::TYPE_LIKE => $subscription[Notification::TYPE_LIKE],
|
||||
Notification::TYPE_RESHARE => $subscription[Notification::TYPE_RESHARE],
|
||||
Notification::TYPE_MENTION => $subscription[Notification::TYPE_MENTION],
|
||||
Notification::TYPE_POLL => $subscription[Notification::TYPE_POLL],
|
||||
Notification::TYPE_FOLLOW => (bool)$subscription[Notification::TYPE_FOLLOW],
|
||||
Notification::TYPE_LIKE => (bool)$subscription[Notification::TYPE_LIKE],
|
||||
Notification::TYPE_RESHARE => (bool)$subscription[Notification::TYPE_RESHARE],
|
||||
Notification::TYPE_MENTION => (bool)$subscription[Notification::TYPE_MENTION],
|
||||
Notification::TYPE_POLL => (bool)$subscription[Notification::TYPE_POLL],
|
||||
];
|
||||
|
||||
$this->server_key = $vapid;
|
||||
|
|
|
|||
|
|
@ -2855,7 +2855,7 @@ class Diaspora
|
|||
|
||||
$namespaces = ['me' => ActivityNamespace::SALMON_ME];
|
||||
|
||||
return XML::fromArray($xmldata, $xml, false, $namespaces);
|
||||
return XML::fromArray($xmldata, $dummy, false, $namespaces);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -2974,12 +2974,11 @@ class Diaspora
|
|||
* @param array $message The message data
|
||||
*
|
||||
* @return string The post XML
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function buildPostXml(string $type, array $message): string
|
||||
{
|
||||
$data = [$type => $message];
|
||||
|
||||
return XML::fromArray($data, $xml);
|
||||
return XML::fromArray([$type => $message]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -160,7 +160,7 @@ class Salmon
|
|||
|
||||
$namespaces = ['me' => ActivityNamespace::SALMON_ME];
|
||||
|
||||
$salmon = XML::fromArray($xmldata, $xml, false, $namespaces);
|
||||
$salmon = XML::fromArray($xmldata, $dummy, false, $namespaces);
|
||||
|
||||
// slap them
|
||||
$postResult = DI::httpClient()->post($url, $salmon, [
|
||||
|
|
@ -187,9 +187,7 @@ class Salmon
|
|||
]
|
||||
];
|
||||
|
||||
$namespaces = ['me' => ActivityNamespace::SALMON_ME];
|
||||
|
||||
$salmon = XML::fromArray($xmldata, $xml, false, $namespaces);
|
||||
$salmon = XML::fromArray($xmldata, $dummy, false, $namespaces);
|
||||
|
||||
// slap them
|
||||
$postResult = DI::httpClient()->post($url, $salmon, [
|
||||
|
|
@ -214,9 +212,7 @@ class Salmon
|
|||
]
|
||||
];
|
||||
|
||||
$namespaces = ['me' => ActivityNamespace::SALMON_ME];
|
||||
|
||||
$salmon = XML::fromArray($xmldata, $xml, false, $namespaces);
|
||||
$salmon = XML::fromArray($xmldata, $dummy, false, $namespaces);
|
||||
|
||||
// slap them
|
||||
$postResult = DI::httpClient()->post($url, $salmon, [
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ use Friendica\Network\HTTPClient\Client\HttpClientAccept;
|
|||
use Friendica\Network\HTTPClient\Client\HttpClientOptions;
|
||||
use Friendica\Network\HTTPException\NotModifiedException;
|
||||
use GuzzleHttp\Psr7\Uri;
|
||||
use Psr\Http\Message\UriInterface;
|
||||
|
||||
class Network
|
||||
{
|
||||
|
|
@ -177,11 +178,28 @@ class Network
|
|||
* @param string $url The url to check the domain from
|
||||
*
|
||||
* @return boolean
|
||||
*
|
||||
* @deprecated since 2023.03 Use isUriBlocked instead
|
||||
*/
|
||||
public static function isUrlBlocked(string $url): bool
|
||||
{
|
||||
$host = @parse_url($url, PHP_URL_HOST);
|
||||
if (!$host) {
|
||||
try {
|
||||
return self::isUriBlocked(new Uri($url));
|
||||
} catch (\Throwable $e) {
|
||||
Logger::warning('Invalid URL', ['url' => $url]);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the provided URI domain is on the domain blocklist.
|
||||
*
|
||||
* @param UriInterface $uri
|
||||
* @return boolean
|
||||
*/
|
||||
public static function isUriBlocked(UriInterface $uri): bool
|
||||
{
|
||||
if (!$uri->getHost()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -191,7 +209,7 @@ class Network
|
|||
}
|
||||
|
||||
foreach ($domain_blocklist as $domain_block) {
|
||||
if (fnmatch(strtolower($domain_block['domain']), strtolower($host))) {
|
||||
if (fnmatch(strtolower($domain_block['domain']), strtolower($uri->getHost()))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,14 +37,15 @@ class XML
|
|||
/**
|
||||
* Creates an XML structure out of a given array
|
||||
*
|
||||
* @param array $array The array of the XML structure that will be generated
|
||||
* @param object $xml The created XML will be returned by reference
|
||||
* @param bool $remove_header Should the XML header be removed or not?
|
||||
* @param array $namespaces List of namespaces
|
||||
* @param bool $root interally used parameter. Mustn't be used from outside.
|
||||
* @param array $array The array of the XML structure that will be generated
|
||||
* @param object|null $xml The created XML will be returned by reference
|
||||
* @param bool $remove_header Should the XML header be removed or not?
|
||||
* @param array $namespaces List of namespaces
|
||||
* @param bool $root interally used parameter. Mustn't be used from outside.
|
||||
* @return string
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function fromArray(array $array, &$xml, bool $remove_header = false, array $namespaces = [], bool $root = true): string
|
||||
public static function fromArray(array $array, object &$xml = null, bool $remove_header = false, array $namespaces = [], bool $root = true): string
|
||||
{
|
||||
if ($root) {
|
||||
foreach ($array as $key => $value) {
|
||||
|
|
@ -125,7 +126,7 @@ class XML
|
|||
|
||||
if (!is_array($value)) {
|
||||
$element = $xml->addChild($key, self::escape($value ?? ''), $namespace);
|
||||
} elseif (is_array($value)) {
|
||||
} else {
|
||||
$element = $xml->addChild($key, null, $namespace);
|
||||
self::fromArray($value, $element, $remove_header, $namespaces, false);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ class DBUpdate
|
|||
public static function execute()
|
||||
{
|
||||
// Just in case the last update wasn't failed
|
||||
if (DI::config()->get('system', 'update', Update::SUCCESS, true) != Update::FAILED) {
|
||||
if (DI::config()->get('system', 'update', Update::SUCCESS) != Update::FAILED) {
|
||||
Update::run(DI::app()->getBasePath());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ use Friendica\Core\Logger;
|
|||
use Friendica\Core\Worker;
|
||||
use Friendica\Model\Contact;
|
||||
use Friendica\Network\HTTPException\InternalServerErrorException;
|
||||
use Friendica\Util\Network;
|
||||
|
||||
class UpdateContact
|
||||
{
|
||||
|
|
@ -38,6 +39,11 @@ class UpdateContact
|
|||
*/
|
||||
public static function execute(int $contact_id)
|
||||
{
|
||||
// Silently dropping the task if the contact is blocked
|
||||
if (Contact::isBlocked($contact_id)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$success = Contact::updateFromProbe($contact_id);
|
||||
|
||||
Logger::info('Updated from probe', ['id' => $contact_id, 'success' => $success]);
|
||||
|
|
@ -55,6 +61,11 @@ class UpdateContact
|
|||
throw new \InvalidArgumentException('Invalid value provided for contact_id');
|
||||
}
|
||||
|
||||
// Dropping the task if the contact is blocked
|
||||
if (Contact::isBlocked($contact_id)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return Worker::add($run_parameters, 'UpdateContact', $contact_id);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,9 +22,14 @@
|
|||
namespace Friendica\Worker;
|
||||
|
||||
use Friendica\Core\Logger;
|
||||
use Friendica\Core\Worker;
|
||||
use Friendica\Database\DBA;
|
||||
use Friendica\Model\GServer;
|
||||
use Friendica\Network\HTTPException\InternalServerErrorException;
|
||||
use Friendica\Util\Network;
|
||||
use Friendica\Util\Strings;
|
||||
use GuzzleHttp\Psr7\Uri;
|
||||
use Psr\Http\Message\UriInterface;
|
||||
|
||||
class UpdateGServer
|
||||
{
|
||||
|
|
@ -34,8 +39,9 @@ class UpdateGServer
|
|||
* @param string $server_url Server URL
|
||||
* @param boolean $only_nodeinfo Only use nodeinfo for server detection
|
||||
* @return void
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function execute(string $server_url, bool $only_nodeinfo = false)
|
||||
public static function execute(string $server_url, bool $only_nodeinfo)
|
||||
{
|
||||
if (empty($server_url)) {
|
||||
return;
|
||||
|
|
@ -47,6 +53,11 @@ class UpdateGServer
|
|||
return;
|
||||
}
|
||||
|
||||
// Silently dropping the worker task if the server domain is blocked
|
||||
if (Network::isUrlBlocked($filtered)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (($filtered != $server_url) && DBA::exists('gserver', ['nurl' => Strings::normaliseLink($server_url)])) {
|
||||
GServer::setFailureByUrl($server_url);
|
||||
return;
|
||||
|
|
@ -61,4 +72,23 @@ class UpdateGServer
|
|||
$ret = GServer::check($filtered, '', true, $only_nodeinfo);
|
||||
Logger::info('Updated gserver', ['url' => $filtered, 'result' => $ret]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array|int $run_parameters Priority constant or array of options described in Worker::add
|
||||
* @param string $serverUrl
|
||||
* @param bool $onlyNodeInfo Only use NodeInfo for server detection
|
||||
* @return int
|
||||
* @throws InternalServerErrorException
|
||||
*/
|
||||
public static function add($run_parameters, string $serverUrl, bool $onlyNodeInfo = false): int
|
||||
{
|
||||
// Dropping the worker task if the server domain is blocked
|
||||
if (Network::isUrlBlocked($serverUrl)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// We have to convert the Uri back to string because worker parameters are saved in JSON format which
|
||||
// doesn't allow for structured objects.
|
||||
return Worker::add($run_parameters, 'UpdateGServer', $serverUrl, $onlyNodeInfo);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ use Friendica\Database\DBA;
|
|||
use Friendica\DI;
|
||||
use Friendica\Util\DateTimeFormat;
|
||||
use Friendica\Util\Strings;
|
||||
use GuzzleHttp\Psr7\Uri;
|
||||
|
||||
class UpdateGServers
|
||||
{
|
||||
|
|
@ -63,12 +64,12 @@ class UpdateGServers
|
|||
// There are duplicated "url" but not "nurl". So we check both addresses instead of just overwriting them,
|
||||
// since that would mean loosing data.
|
||||
if (!empty($gserver['url'])) {
|
||||
if (Worker::add(Worker::PRIORITY_LOW, 'UpdateGServer', $gserver['url'])) {
|
||||
if (UpdateGServer::add(Worker::PRIORITY_LOW, $gserver['url'])) {
|
||||
$count++;
|
||||
}
|
||||
}
|
||||
if (!empty($gserver['nurl']) && ($gserver['nurl'] != Strings::normaliseLink($gserver['url']))) {
|
||||
if (Worker::add(Worker::PRIORITY_LOW, 'UpdateGServer', $gserver['nurl'])) {
|
||||
if (UpdateGServer::add(Worker::PRIORITY_LOW, $gserver['nurl'])) {
|
||||
$count++;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue