mirror of
https://github.com/friendica/friendica
synced 2024-12-22 23:20:16 +00:00
Fix errors in Core namespace
This commit is contained in:
parent
6ad1dd72d6
commit
496f0755b1
15 changed files with 79 additions and 75 deletions
|
@ -7,7 +7,10 @@
|
||||||
|
|
||||||
namespace Friendica\Content\Text;
|
namespace Friendica\Content\Text;
|
||||||
|
|
||||||
use \HTMLPurifier_URIScheme;
|
use HTMLPurifier_Config;
|
||||||
|
use HTMLPurifier_Context;
|
||||||
|
use HTMLPurifier_URI;
|
||||||
|
use HTMLPurifier_URIScheme;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Validates content-id ("cid") as used in multi-part MIME messages, as defined by RFC 2392
|
* Validates content-id ("cid") as used in multi-part MIME messages, as defined by RFC 2392
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
|
|
||||||
namespace Friendica\Core;
|
namespace Friendica\Core;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
use Friendica\App\Page;
|
use Friendica\App\Page;
|
||||||
use Friendica\Database\DBA;
|
use Friendica\Database\DBA;
|
||||||
use Friendica\DI;
|
use Friendica\DI;
|
||||||
|
|
|
@ -18,7 +18,7 @@ interface ICanCache
|
||||||
/**
|
/**
|
||||||
* Lists all cache keys
|
* Lists all cache keys
|
||||||
*
|
*
|
||||||
* @param string|null prefix optional a prefix to search
|
* @param string|null $prefix optional a prefix to search
|
||||||
*
|
*
|
||||||
* @return array Empty if it isn't supported by the cache driver
|
* @return array Empty if it isn't supported by the cache driver
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -7,7 +7,6 @@
|
||||||
|
|
||||||
namespace Friendica\Core\Config\Model;
|
namespace Friendica\Core\Config\Model;
|
||||||
|
|
||||||
use Friendica\Core\Config\Capability\IManageConfigValues;
|
|
||||||
use Friendica\Core\Config\Capability\ISetConfigValuesTransactionally;
|
use Friendica\Core\Config\Capability\ISetConfigValuesTransactionally;
|
||||||
use Friendica\Core\Config\Exception\ConfigPersistenceException;
|
use Friendica\Core\Config\Exception\ConfigPersistenceException;
|
||||||
use Friendica\Core\Config\ValueObject\Cache;
|
use Friendica\Core\Config\ValueObject\Cache;
|
||||||
|
@ -17,7 +16,7 @@ use Friendica\Core\Config\ValueObject\Cache;
|
||||||
*/
|
*/
|
||||||
class ConfigTransaction implements ISetConfigValuesTransactionally
|
class ConfigTransaction implements ISetConfigValuesTransactionally
|
||||||
{
|
{
|
||||||
/** @var IManageConfigValues */
|
/** @var DatabaseConfig */
|
||||||
protected $config;
|
protected $config;
|
||||||
/** @var Cache */
|
/** @var Cache */
|
||||||
protected $setCache;
|
protected $setCache;
|
||||||
|
|
|
@ -345,10 +345,6 @@ class L10n
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provide a fallback which will not collide with a function defined in any language file
|
* Provide a fallback which will not collide with a function defined in any language file
|
||||||
*
|
|
||||||
* @param int $n
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*/
|
*/
|
||||||
private function stringPluralSelectDefault(float $n): bool
|
private function stringPluralSelectDefault(float $n): bool
|
||||||
{
|
{
|
||||||
|
|
|
@ -65,7 +65,7 @@ interface ICanLock
|
||||||
/**
|
/**
|
||||||
* Lists all locks
|
* Lists all locks
|
||||||
*
|
*
|
||||||
* @param string prefix optional a prefix to search
|
* @param string $prefix optional a prefix to search
|
||||||
*
|
*
|
||||||
* @return string[] Empty if it isn't supported by the cache driver
|
* @return string[] Empty if it isn't supported by the cache driver
|
||||||
*
|
*
|
||||||
|
|
|
@ -16,12 +16,14 @@ use Friendica\Core\Lock\Exception\LockPersistenceException;
|
||||||
class CacheLock extends AbstractLock
|
class CacheLock extends AbstractLock
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @var string The static prefix of all locks inside the cache
|
* The static prefix of all locks inside the cache
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
*/
|
*/
|
||||||
const CACHE_PREFIX = 'lock:';
|
const CACHE_PREFIX = 'lock:';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var ICanCache;
|
* @var ICanCacheInMemory
|
||||||
*/
|
*/
|
||||||
private $cache;
|
private $cache;
|
||||||
|
|
||||||
|
|
|
@ -18,20 +18,24 @@ use Psr\Log\LogLevel;
|
||||||
class Logger
|
class Logger
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @var LoggerInterface The default Logger type
|
* LoggerInterface The default Logger type
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
*/
|
*/
|
||||||
const TYPE_LOGGER = LoggerInterface::class;
|
const TYPE_LOGGER = LoggerInterface::class;
|
||||||
/**
|
/**
|
||||||
* @var WorkerLogger A specific worker logger type, which can be enabled
|
* WorkerLogger A specific worker logger type, which can be enabled
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
*/
|
*/
|
||||||
const TYPE_WORKER = WorkerLogger::class;
|
const TYPE_WORKER = WorkerLogger::class;
|
||||||
/**
|
/**
|
||||||
* @var LoggerInterface The current logger type
|
* @var string $type LoggerInterface The current logger type
|
||||||
*/
|
*/
|
||||||
private static $type = self::TYPE_LOGGER;
|
private static $type = self::TYPE_LOGGER;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return LoggerInterface
|
* @return LoggerInterface|WorkerLogger
|
||||||
*/
|
*/
|
||||||
private static function getInstance()
|
private static function getInstance()
|
||||||
{
|
{
|
||||||
|
@ -52,7 +56,7 @@ class Logger
|
||||||
public static function enableWorker(string $functionName)
|
public static function enableWorker(string $functionName)
|
||||||
{
|
{
|
||||||
self::$type = self::TYPE_WORKER;
|
self::$type = self::TYPE_WORKER;
|
||||||
self::getInstance()->setFunctionName($functionName);
|
DI::workerLogger()->setFunctionName($functionName);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -55,7 +55,7 @@ class StreamLogger extends AbstractLogger
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
* @param string $level The minimum loglevel at which this logger will be triggered
|
* @param int $logLevel The minimum loglevel at which this logger will be triggered
|
||||||
*
|
*
|
||||||
* @throws LoggerException
|
* @throws LoggerException
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -17,7 +17,7 @@ class LoggerSettingsCheck implements ICheckLoggerSettings
|
||||||
{
|
{
|
||||||
/** @var IManageConfigValues */
|
/** @var IManageConfigValues */
|
||||||
protected $config;
|
protected $config;
|
||||||
/** @var $fileSystem */
|
/** @var FileSystem */
|
||||||
protected $fileSystem;
|
protected $fileSystem;
|
||||||
/** @var L10n */
|
/** @var L10n */
|
||||||
protected $l10n;
|
protected $l10n;
|
||||||
|
@ -38,10 +38,8 @@ class LoggerSettingsCheck implements ICheckLoggerSettings
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$stream = $this->fileSystem->createStream($file);
|
$stream = $this->fileSystem->createStream($file);
|
||||||
|
} catch (LoggerUnusableException $exception) {
|
||||||
if (!isset($stream)) {
|
throw new LoggerUnusableException('Stream is null.', $exception);
|
||||||
throw new LoggerUnusableException('Stream is null.');
|
|
||||||
}
|
|
||||||
} catch (\Throwable $exception) {
|
} catch (\Throwable $exception) {
|
||||||
return $this->l10n->t('The logfile \'%s\' is not usable. No logging possible (error: \'%s\')', $file, $exception->getMessage());
|
return $this->l10n->t('The logfile \'%s\' is not usable. No logging possible (error: \'%s\')', $file, $exception->getMessage());
|
||||||
}
|
}
|
||||||
|
@ -57,16 +55,14 @@ class LoggerSettingsCheck implements ICheckLoggerSettings
|
||||||
if ($this->config->get('system', 'debugging')) {
|
if ($this->config->get('system', 'debugging')) {
|
||||||
$file = $this->config->get('system', 'dlogfile');
|
$file = $this->config->get('system', 'dlogfile');
|
||||||
|
|
||||||
if (empty($file)) {
|
if ($file === null || $file === '') {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$stream = $this->fileSystem->createStream($file);
|
$stream = $this->fileSystem->createStream($file);
|
||||||
|
} catch (LoggerUnusableException $exception) {
|
||||||
if (!isset($stream)) {
|
throw new LoggerUnusableException('Stream is null.', $exception);
|
||||||
throw new LoggerUnusableException('Stream is null.');
|
|
||||||
}
|
|
||||||
} catch (\Throwable $exception) {
|
} catch (\Throwable $exception) {
|
||||||
return $this->l10n->t('The debug logfile \'%s\' is not usable. No logging possible (error: \'%s\')', $file, $exception->getMessage());
|
return $this->l10n->t('The debug logfile \'%s\' is not usable. No logging possible (error: \'%s\')', $file, $exception->getMessage());
|
||||||
}
|
}
|
||||||
|
|
|
@ -274,8 +274,11 @@ class StorageManager
|
||||||
*/
|
*/
|
||||||
public function register(string $class): bool
|
public function register(string $class): bool
|
||||||
{
|
{
|
||||||
if (is_subclass_of($class, ICanReadFromStorage::class)) {
|
if (!is_subclass_of($class, ICanReadFromStorage::class)) {
|
||||||
/** @var ICanReadFromStorage $class */
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @var class-string<ICanReadFromStorage> $class */
|
||||||
if ($this->isValidBackend($class::getName(), $this->validBackends)) {
|
if ($this->isValidBackend($class::getName(), $this->validBackends)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -286,13 +289,10 @@ class StorageManager
|
||||||
if ($this->config->set('storage', 'backends', $backends)) {
|
if ($this->config->set('storage', 'backends', $backends)) {
|
||||||
$this->validBackends = $backends;
|
$this->validBackends = $backends;
|
||||||
return true;
|
return true;
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unregister a storage backend class
|
* Unregister a storage backend class
|
||||||
|
@ -305,31 +305,32 @@ class StorageManager
|
||||||
*/
|
*/
|
||||||
public function unregister(string $class): bool
|
public function unregister(string $class): bool
|
||||||
{
|
{
|
||||||
if (is_subclass_of($class, ICanReadFromStorage::class)) {
|
if (!is_subclass_of($class, ICanReadFromStorage::class)) {
|
||||||
/** @var ICanReadFromStorage $class */
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @var class-string<ICanReadFromStorage> $class */
|
||||||
if ($this->currentBackend::getName() == $class::getName()) {
|
if ($this->currentBackend::getName() == $class::getName()) {
|
||||||
throw new StorageException(sprintf('Cannot unregister %s, because it\'s currently active.', $class::getName()));
|
throw new StorageException(sprintf('Cannot unregister %s, because it\'s currently active.', $class::getName()));
|
||||||
}
|
}
|
||||||
|
|
||||||
$key = array_search($class::getName(), $this->validBackends);
|
$key = array_search($class::getName(), $this->validBackends);
|
||||||
|
|
||||||
if ($key !== false) {
|
if ($key === false) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
$backends = $this->validBackends;
|
$backends = $this->validBackends;
|
||||||
unset($backends[$key]);
|
unset($backends[$key]);
|
||||||
$backends = array_values($backends);
|
$backends = array_values($backends);
|
||||||
|
|
||||||
if ($this->config->set('storage', 'backends', $backends)) {
|
if ($this->config->set('storage', 'backends', $backends)) {
|
||||||
$this->validBackends = $backends;
|
$this->validBackends = $backends;
|
||||||
return true;
|
return true;
|
||||||
} else {
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Move up to 5000 resources to storage $dest
|
* Move up to 5000 resources to storage $dest
|
||||||
|
|
|
@ -8,10 +8,8 @@
|
||||||
namespace Friendica\Core;
|
namespace Friendica\Core;
|
||||||
|
|
||||||
use Friendica\Content\Text\BBCode;
|
use Friendica\Content\Text\BBCode;
|
||||||
use Friendica\Content\Text\HTML;
|
|
||||||
use Friendica\Core\Config\Capability\IManageConfigValues;
|
use Friendica\Core\Config\Capability\IManageConfigValues;
|
||||||
use Friendica\DI;
|
use Friendica\DI;
|
||||||
use Friendica\Model\User;
|
|
||||||
use Friendica\Module\Response;
|
use Friendica\Module\Response;
|
||||||
use Friendica\Network\HTTPException\FoundException;
|
use Friendica\Network\HTTPException\FoundException;
|
||||||
use Friendica\Network\HTTPException\InternalServerErrorException;
|
use Friendica\Network\HTTPException\InternalServerErrorException;
|
||||||
|
@ -325,7 +323,7 @@ class System
|
||||||
/**
|
/**
|
||||||
* Send HTTP status header and exit.
|
* Send HTTP status header and exit.
|
||||||
*
|
*
|
||||||
* @param integer $val HTTP status result value
|
* @param integer $httpCode HTTP status result value
|
||||||
* @param string $message Error message. Optional.
|
* @param string $message Error message. Optional.
|
||||||
* @param string $content Response body. Optional.
|
* @param string $content Response body. Optional.
|
||||||
* @throws \Exception
|
* @throws \Exception
|
||||||
|
|
|
@ -824,7 +824,11 @@ class Worker
|
||||||
$max_idletime = DI::config()->get('system', 'worker_max_idletime');
|
$max_idletime = DI::config()->get('system', 'worker_max_idletime');
|
||||||
$last_check = DI::cache()->get(self::LAST_CHECK);
|
$last_check = DI::cache()->get(self::LAST_CHECK);
|
||||||
$last_date = $last_check ? date('c', $last_check) : '';
|
$last_date = $last_check ? date('c', $last_check) : '';
|
||||||
if (($max_idletime > 0) && (time() > $last_check + $max_idletime) && !DBA::exists('workerqueue', ["`done` AND `executed` > ?", DateTimeFormat::utc('now - ' . $max_idletime . ' second')])) {
|
if (
|
||||||
|
($max_idletime > 0)
|
||||||
|
&& (time() > (int) $last_check + (int) $max_idletime)
|
||||||
|
&& !DBA::exists('workerqueue', ["`done` AND `executed` > ?", DateTimeFormat::utc('now - ' . $max_idletime . ' second')])
|
||||||
|
) {
|
||||||
DI::cache()->set(self::LAST_CHECK, time(), Duration::HOUR);
|
DI::cache()->set(self::LAST_CHECK, time(), Duration::HOUR);
|
||||||
Logger::info('The last worker execution had been too long ago.', ['last' => $last_check, 'last-check' => $last_date, 'seconds' => $max_idletime, 'load' => $load, 'max_load' => $maxsysload, 'active_worker' => $active, 'max_worker' => $maxqueues]);
|
Logger::info('The last worker execution had been too long ago.', ['last' => $last_check, 'last-check' => $last_date, 'seconds' => $max_idletime, 'load' => $load, 'max_load' => $maxsysload, 'active_worker' => $active, 'max_worker' => $maxqueues]);
|
||||||
return false;
|
return false;
|
||||||
|
@ -1211,7 +1215,7 @@ class Worker
|
||||||
/**
|
/**
|
||||||
* Adds tasks to the worker queue
|
* Adds tasks to the worker queue
|
||||||
*
|
*
|
||||||
* @param (integer|array) priority or parameter array, strings are deprecated and are ignored
|
* @param integer|array $args priority or parameter array, strings are deprecated and are ignored
|
||||||
*
|
*
|
||||||
* next args are passed as $cmd command line
|
* next args are passed as $cmd command line
|
||||||
* or: Worker::add(Worker::PRIORITY_HIGH, 'Notifier', Delivery::DELETION, $drop_id);
|
* or: Worker::add(Worker::PRIORITY_HIGH, 'Notifier', Delivery::DELETION, $drop_id);
|
||||||
|
|
|
@ -81,7 +81,7 @@ class Process extends BaseRepository
|
||||||
'pid' => $process->pid,
|
'pid' => $process->pid,
|
||||||
'hostname' => $this->currentHost,
|
'hostname' => $this->currentHost,
|
||||||
])) {
|
])) {
|
||||||
throw new ProcessPersistenceException(sprintf('The process with PID %s doesn\'t exists.', $process->pi));
|
throw new ProcessPersistenceException(sprintf('The process with PID %d doesn\'t exists.', $process->pid));
|
||||||
}
|
}
|
||||||
} catch (\Exception $exception) {
|
} catch (\Exception $exception) {
|
||||||
throw new ProcessPersistenceException(sprintf('Cannot delete process with PID %s.', $process->pid), $exception);
|
throw new ProcessPersistenceException(sprintf('Cannot delete process with PID %s.', $process->pid), $exception);
|
||||||
|
|
|
@ -312,7 +312,7 @@ abstract class DI
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return LoggerInterface
|
* @return \Friendica\Core\Logger\Type\WorkerLogger
|
||||||
*/
|
*/
|
||||||
public static function workerLogger()
|
public static function workerLogger()
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue