Merge branch 'develop' into eventdispatcher-part3

This commit is contained in:
Art4 2025-05-12 14:32:53 +00:00
commit ea172010f8
91 changed files with 821 additions and 799 deletions

View file

@ -257,6 +257,7 @@ class ConfigFileManager
// map the legacy configuration structure to the current structure
foreach ($htConfigCategories as $htConfigCategory) {
/** @phpstan-ignore-next-line $a->config could be modified after `include $fullName` */
if (is_array($a->config[$htConfigCategory])) {
$keys = array_keys($a->config[$htConfigCategory]);

View file

@ -40,7 +40,7 @@ class Hook
public static function loadHooks()
{
self::$hooks = [];
$stmt = DBA::select('hook', ['hook', 'file', 'function'], [], ['order' => ['priority' => 'desc', 'file']]);
$stmt = DBA::select('hook', ['hook', 'file', 'function'], [], ['order' => ['priority' => 'desc', 'file']]);
while ($hook = DBA::fetch($stmt)) {
self::add($hook['hook'], $hook['file'], $hook['function']);

View file

@ -48,8 +48,8 @@ final class SyslogLoggerFactory implements LoggerFactory
*/
public function createLogger(string $logLevel, string $logChannel): LoggerInterface
{
$logOpts = (string) $this->config->get('system', 'syslog_flags') ?? SyslogLogger::DEFAULT_FLAGS;
$logFacility = (string) $this->config->get('system', 'syslog_facility') ?? SyslogLogger::DEFAULT_FACILITY;
$logOpts = (int) $this->config->get('system', 'syslog_flags') ?? SyslogLogger::DEFAULT_FLAGS;
$logFacility = (int) $this->config->get('system', 'syslog_facility') ?? SyslogLogger::DEFAULT_FACILITY;
if (!array_key_exists($logLevel, SyslogLogger::logLevels)) {
throw new LogLevelException(sprintf('The log level "%s" is not supported by "%s".', $logLevel, SyslogLogger::class));
@ -58,7 +58,7 @@ final class SyslogLoggerFactory implements LoggerFactory
return new SyslogLogger(
$logChannel,
$this->introspection,
(string) SyslogLogger::logLevels[$logLevel],
SyslogLogger::logLevels[$logLevel],
$logOpts,
$logFacility
);

View file

@ -22,21 +22,19 @@ class StreamLogger extends AbstractLogger
/**
* The minimum loglevel at which this logger will be triggered
* @var string
*/
private $logLevel;
private int $logLevel;
/**
* The stream, where the current logger is writing into
* @var resource
* @var resource|null
*/
private $stream;
/**
* The current process ID
* @var int
*/
private $pid;
private int $pid;
/**
* Translates LogLevel log levels to integer values

View file

@ -29,7 +29,7 @@ class SyslogLogger extends AbstractLogger
/**
* Translates LogLevel log levels to syslog log priorities.
* @var array
* @var array<string,int>
*/
public const logLevels = [
LogLevel::DEBUG => LOG_DEBUG,
@ -60,39 +60,33 @@ class SyslogLogger extends AbstractLogger
/**
* Indicates what logging options will be used when generating a log message
* @see http://php.net/manual/en/function.openlog.php#refsect1-function.openlog-parameters
*
* @var int
*/
private $logOpts;
private int $logOpts;
/**
* Used to specify what type of program is logging the message
* @see http://php.net/manual/en/function.openlog.php#refsect1-function.openlog-parameters
*
* @var int
*/
private $logFacility;
private int $logFacility;
/**
* The minimum loglevel at which this logger will be triggered
* @var int
*/
private $logLevel;
private int $logLevel;
/**
* A error message of the current operation
* @var string
*/
private $errorMessage;
private string $errorMessage;
/**
* {@inheritdoc}
*
* @param string $logLevel The minimum loglevel at which this logger will be triggered
* @param string $logOptions
* @param string $logFacility
* @param int $logLevel The minimum loglevel at which this logger will be triggered
* @param int $logOptions
* @param int $logFacility
*/
public function __construct(string $channel, IHaveCallIntrospections $introspection, string $logLevel, string $logOptions, string $logFacility)
public function __construct(string $channel, IHaveCallIntrospections $introspection, int $logLevel, int $logOptions, int $logFacility)
{
parent::__construct($channel, $introspection);
@ -166,7 +160,7 @@ class SyslogLogger extends AbstractLogger
restore_error_handler();
if (!$opened) {
throw new LoggerException(sprintf('Can\'t open syslog for ident "%s" and facility "%s": ' . $this->errorMessage, $this->channel, $this->logFacility));
throw new LoggerException(sprintf('Can\'t open syslog for ident "%s" and facility "%s": ' . $this->errorMessage, $this->channel, (string) $this->logFacility));
}
$this->syslogWrapper($priority, $message);
@ -215,7 +209,7 @@ class SyslogLogger extends AbstractLogger
restore_error_handler();
if (!$written) {
throw new LoggerException(sprintf('Can\'t write into syslog for ident "%s" and facility "%s": ' . $this->errorMessage, $this->channel, $this->logFacility));
throw new LoggerException(sprintf('Can\'t write into syslog for ident "%s" and facility "%s": ' . $this->errorMessage, $this->channel, (string) $this->logFacility));
}
}
}

View file

@ -37,7 +37,7 @@ class PConfig
*/
public function isConnected(): bool
{
return $this->db->isConnected() & !$this->mode->isInstall();
return $this->db->isConnected() && !$this->mode->isInstall();
}
/**

View file

@ -101,7 +101,7 @@ class UserSession implements IHandleUserSessions
public function getUserIDForVisitorContactID(int $cid): int
{
if (empty($this->session->get('remote'))) {
return false;
return 0;
}
return array_search($cid, $this->session->get('remote'));
@ -142,7 +142,7 @@ class UserSession implements IHandleUserSessions
{
return !$this->session->get('authenticated', false);
}
/** {@inheritDoc} */
public function setVisitorsContacts(string $my_url)
{

View file

@ -80,7 +80,7 @@ class Database implements ICanWriteToStorage
throw new StorageException(sprintf('Database storage failed to update %s', $reference), 500, new Exception($this->dba->errorMessage(), $this->dba->errorNo()));
}
return $this->dba->lastInsertId();
return (string) $this->dba->lastInsertId();
}
}

View file

@ -452,19 +452,17 @@ class System
/**
* Returns the current Load of the System
*
* @return integer
*/
public static function currentLoad()
public static function currentLoad(): float
{
if (!function_exists('sys_getloadavg')) {
return false;
return (float) 0;
}
$load_arr = sys_getloadavg();
if (!is_array($load_arr)) {
return false;
return (float) 0;
}
return round(max($load_arr[0], $load_arr[1]), 2);

View file

@ -217,7 +217,7 @@ class Update
->set('system', 'maintenance', false)
->delete('system', 'maintenance_reason')
->commit();
return $r;
return 'Pre update failed';
} else {
DI::logger()->notice('Pre update executed.', ['version' => $version]);
}
@ -262,7 +262,7 @@ class Update
->set('system', 'maintenance', false)
->delete('system', 'maintenance_reason')
->commit();
return $r;
return 'Post update failed';
} else {
DI::config()->set('system', 'build', $version);
DI::logger()->notice('Post update executed.', ['version' => $version]);

View file

@ -272,12 +272,13 @@ class Worker
*
* @param integer $priority The priority that should be checked
*
* @return integer Is there a process running with that priority?
* @return bool Is there a process running with that priority?
* @throws \Exception
*/
private static function processWithPriorityActive(int $priority): int
private static function processWithPriorityActive(int $priority): bool
{
$condition = ["`priority` <= ? AND `pid` != 0 AND NOT `done`", $priority];
return DBA::exists('workerqueue', $condition);
}
@ -956,7 +957,7 @@ class Worker
/**
* Returns the priority of the next workerqueue job
*
* @return string|bool priority or FALSE on failure
* @return int|false priority or FALSE on failure
* @throws \Exception
*/
private static function nextPriority()

View file

@ -8,11 +8,11 @@
namespace Friendica\Core\Worker\Repository;
use Friendica\BaseRepository;
use Friendica\Core\Worker\Entity\Process as ProcessEntity;
use Friendica\Core\Worker\Exception\ProcessPersistenceException;
use Friendica\Core\Worker\Factory\Process as ProcessFactory;
use Friendica\Database\Database;
use Friendica\Util\DateTimeFormat;
use Friendica\Core\Worker\Factory;
use Friendica\Core\Worker\Entity;
use Psr\Log\LoggerInterface;
/**
@ -24,13 +24,13 @@ class Process extends BaseRepository
protected static $table_name = 'process';
/** @var Factory\Process */
/** @var ProcessFactory */
protected $factory;
/** @var string */
private $currentHost;
public function __construct(Database $database, LoggerInterface $logger, Factory\Process $factory, array $server)
public function __construct(Database $database, LoggerInterface $logger, ProcessFactory $factory, array $server)
{
parent::__construct($database, $logger, $factory);
@ -39,13 +39,8 @@ class Process extends BaseRepository
/**
* Starts and Returns the process for a given PID at the current host
*
* @param int $pid
* @param string $command
*
* @return Entity\Process
*/
public function create(int $pid, string $command): Entity\Process
public function create(int $pid, string $command): ProcessEntity
{
// Cleanup inactive process
$this->deleteInactive();
@ -64,7 +59,9 @@ class Process extends BaseRepository
}
}
$result = $this->_selectOne(['pid' => $pid, 'hostname' => $this->currentHost]);
$fields = $this->_selectFirstRowAsArray(['pid' => $pid, 'hostname' => $this->currentHost]);
$result = $this->factory->createFromTableRow($fields);
$this->db->commit();
@ -74,7 +71,7 @@ class Process extends BaseRepository
}
}
public function delete(Entity\Process $process)
public function delete(ProcessEntity $process)
{
try {
if (!$this->db->delete(static::$table_name, [