Merge remote-tracking branch 'upstream/develop' into server-detection
This commit is contained in:
commit
8b7cb5d9ef
328 changed files with 13242 additions and 10211 deletions
|
@ -124,7 +124,7 @@ class Addon
|
|||
* @return void
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function uninstall($addon)
|
||||
public static function uninstall(string $addon)
|
||||
{
|
||||
$addon = Strings::sanitizeFilePathItem($addon);
|
||||
|
||||
|
@ -149,7 +149,7 @@ class Addon
|
|||
* @return bool
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function install($addon)
|
||||
public static function install(string $addon): bool
|
||||
{
|
||||
$addon = Strings::sanitizeFilePathItem($addon);
|
||||
|
||||
|
@ -185,6 +185,8 @@ class Addon
|
|||
|
||||
/**
|
||||
* reload all updated addons
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function reload()
|
||||
{
|
||||
|
@ -222,7 +224,7 @@ class Addon
|
|||
* @return array with the addon information
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function getInfo($addon)
|
||||
public static function getInfo(string $addon): array
|
||||
{
|
||||
$addon = Strings::sanitizeFilePathItem($addon);
|
||||
|
||||
|
@ -287,7 +289,7 @@ class Addon
|
|||
* @param string $addon
|
||||
* @return boolean
|
||||
*/
|
||||
public static function isEnabled($addon)
|
||||
public static function isEnabled(string $addon): bool
|
||||
{
|
||||
return in_array($addon, self::$addons);
|
||||
}
|
||||
|
@ -297,7 +299,7 @@ class Addon
|
|||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getEnabledList()
|
||||
public static function getEnabledList(): array
|
||||
{
|
||||
return self::$addons;
|
||||
}
|
||||
|
@ -308,7 +310,7 @@ class Addon
|
|||
* @return array
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function getVisibleList()
|
||||
public static function getVisibleList(): array
|
||||
{
|
||||
$visible_addons = [];
|
||||
$stmt = DBA::select('addon', ['name'], ['hidden' => false, 'installed' => true]);
|
||||
|
|
|
@ -68,6 +68,17 @@ class MemcacheCache extends AbstractCache implements ICanCacheInMemory
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Memcache doesn't allow spaces in keys
|
||||
*
|
||||
* @param string $key
|
||||
* @return string
|
||||
*/
|
||||
protected function getCacheKey(string $key): string
|
||||
{
|
||||
return str_replace(' ', '_', parent::getCacheKey($key));
|
||||
}
|
||||
|
||||
/**
|
||||
* (@inheritdoc)
|
||||
*/
|
||||
|
|
|
@ -93,6 +93,17 @@ class MemcachedCache extends AbstractCache implements ICanCacheInMemory
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Memcached doesn't allow spaces in keys
|
||||
*
|
||||
* @param string $key
|
||||
* @return string
|
||||
*/
|
||||
protected function getCacheKey(string $key): string
|
||||
{
|
||||
return str_replace(' ', '_', parent::getCacheKey($key));
|
||||
}
|
||||
|
||||
/**
|
||||
* (@inheritdoc)
|
||||
*/
|
||||
|
|
|
@ -121,7 +121,7 @@ HELP;
|
|||
$this->dice = $dice;
|
||||
}
|
||||
|
||||
protected function doExecute()
|
||||
protected function doExecute(): int
|
||||
{
|
||||
if ($this->getOption('v')) {
|
||||
$this->out('Executable: ' . $this->executable);
|
||||
|
|
|
@ -49,6 +49,8 @@ class Hook
|
|||
|
||||
/**
|
||||
* Load hooks
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function loadHooks()
|
||||
{
|
||||
|
@ -69,8 +71,9 @@ class Hook
|
|||
* @param string $hook
|
||||
* @param string $file
|
||||
* @param string $function
|
||||
* @return void
|
||||
*/
|
||||
public static function add($hook, $file, $function)
|
||||
public static function add(string $hook, string $file, string $function)
|
||||
{
|
||||
if (!array_key_exists($hook, self::$hooks)) {
|
||||
self::$hooks[$hook] = [];
|
||||
|
@ -90,7 +93,7 @@ class Hook
|
|||
* @return mixed|bool
|
||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
*/
|
||||
public static function register($hook, $file, $function, $priority = 0)
|
||||
public static function register(string $hook, string $file, string $function, int $priority = 0)
|
||||
{
|
||||
$file = str_replace(DI::app()->getBasePath() . DIRECTORY_SEPARATOR, '', $file);
|
||||
|
||||
|
@ -111,7 +114,7 @@ class Hook
|
|||
* @return boolean
|
||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
*/
|
||||
public static function unregister($hook, $file, $function)
|
||||
public static function unregister(string $hook, string $file, string $function): bool
|
||||
{
|
||||
$relative_file = str_replace(DI::app()->getBasePath() . DIRECTORY_SEPARATOR, '', $file);
|
||||
|
||||
|
@ -120,8 +123,8 @@ class Hook
|
|||
self::delete($condition);
|
||||
|
||||
$condition = ['hook' => $hook, 'file' => $relative_file, 'function' => $function];
|
||||
$result = self::delete($condition);
|
||||
return $result;
|
||||
|
||||
return self::delete($condition);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -130,7 +133,7 @@ class Hook
|
|||
* @param string $name Name of the hook
|
||||
* @return array
|
||||
*/
|
||||
public static function getByName($name)
|
||||
public static function getByName(string $name): array
|
||||
{
|
||||
$return = [];
|
||||
|
||||
|
@ -149,9 +152,10 @@ class Hook
|
|||
* @param integer $priority of the hook
|
||||
* @param string $name of the hook to call
|
||||
* @param mixed $data to transmit to the callback handler
|
||||
* @return void
|
||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
*/
|
||||
public static function fork($priority, $name, $data = null)
|
||||
public static function fork(int $priority, string $name, $data = null)
|
||||
{
|
||||
if (array_key_exists($name, self::$hooks)) {
|
||||
foreach (self::$hooks[$name] as $hook) {
|
||||
|
@ -184,9 +188,10 @@ class Hook
|
|||
*
|
||||
* @param string $name of the hook to call
|
||||
* @param string|array &$data to transmit to the callback handler
|
||||
* @return void
|
||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
*/
|
||||
public static function callAll($name, &$data = null)
|
||||
public static function callAll(string $name, &$data = null)
|
||||
{
|
||||
if (array_key_exists($name, self::$hooks)) {
|
||||
foreach (self::$hooks[$name] as $hook) {
|
||||
|
@ -202,9 +207,10 @@ class Hook
|
|||
* @param string $name of the hook to call
|
||||
* @param array $hook Hook data
|
||||
* @param string|array &$data to transmit to the callback handler
|
||||
* @return void
|
||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
*/
|
||||
public static function callSingle(App $a, $name, $hook, &$data = null)
|
||||
public static function callSingle(App $a, string $name, array $hook, &$data = null)
|
||||
{
|
||||
// Don't run a theme's hook if the user isn't using the theme
|
||||
if (strpos($hook[0], 'view/theme/') !== false && strpos($hook[0], 'view/theme/' . $a->getCurrentTheme()) === false) {
|
||||
|
@ -229,7 +235,7 @@ class Hook
|
|||
* @param string $name Name of the addon
|
||||
* @return boolean
|
||||
*/
|
||||
public static function isAddonApp($name)
|
||||
public static function isAddonApp(string $name): bool
|
||||
{
|
||||
$name = Strings::sanitizeFilePathItem($name);
|
||||
|
||||
|
@ -253,7 +259,7 @@ class Hook
|
|||
* @return bool
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function delete(array $condition)
|
||||
public static function delete(array $condition): bool
|
||||
{
|
||||
$result = DBA::delete('hook', $condition);
|
||||
|
||||
|
@ -273,7 +279,7 @@ class Hook
|
|||
* @return bool
|
||||
* @throws \Exception
|
||||
*/
|
||||
private static function insert(array $condition)
|
||||
private static function insert(array $condition): bool
|
||||
{
|
||||
$result = DBA::insert('hook', $condition);
|
||||
|
||||
|
|
|
@ -189,14 +189,12 @@ class Installer
|
|||
/***
|
||||
* Installs the DB-Scheme for Friendica
|
||||
*
|
||||
* @param string $basePath The base path of this application
|
||||
*
|
||||
* @return bool true if the installation was successful, otherwise false
|
||||
* @throws Exception
|
||||
*/
|
||||
public function installDatabase($basePath)
|
||||
public function installDatabase(): bool
|
||||
{
|
||||
$result = DBStructure::install($basePath);
|
||||
$result = DBStructure::install();
|
||||
|
||||
if ($result) {
|
||||
$txt = DI::l10n()->t('You may need to import the file "database.sql" manually using phpmyadmin or mysql.') . EOL;
|
||||
|
@ -656,7 +654,7 @@ class Installer
|
|||
* @return bool true if the check was successful, otherwise false
|
||||
* @throws Exception
|
||||
*/
|
||||
public function checkDB(Database $dba)
|
||||
public function checkDB(Database $dba): bool
|
||||
{
|
||||
$dba->reconnect();
|
||||
|
||||
|
|
|
@ -128,7 +128,7 @@ class L10n
|
|||
private function setLangFromSession(IHandleSessions $session)
|
||||
{
|
||||
if ($session->get('language') !== $this->lang) {
|
||||
$this->loadTranslationTable($session->get('language'));
|
||||
$this->loadTranslationTable($session->get('language') ?? $this->lang);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -140,10 +140,10 @@ class L10n
|
|||
* Uses an App object shim since all the strings files refer to $a->strings
|
||||
*
|
||||
* @param string $lang language code to load
|
||||
*
|
||||
* @return void
|
||||
* @throws \Exception
|
||||
*/
|
||||
private function loadTranslationTable($lang)
|
||||
private function loadTranslationTable(string $lang)
|
||||
{
|
||||
$lang = Strings::sanitizeFilePathItem($lang);
|
||||
|
||||
|
@ -183,7 +183,7 @@ class L10n
|
|||
*
|
||||
* @return string The two-letter language code
|
||||
*/
|
||||
public static function detectLanguage(array $server, array $get, string $sysLang = self::DEFAULT)
|
||||
public static function detectLanguage(array $server, array $get, string $sysLang = self::DEFAULT): string
|
||||
{
|
||||
$lang_variable = $server['HTTP_ACCEPT_LANGUAGE'] ?? null;
|
||||
|
||||
|
@ -269,7 +269,7 @@ class L10n
|
|||
*
|
||||
* @return string
|
||||
*/
|
||||
public function t($s, ...$vars)
|
||||
public function t(string $s, ...$vars): string
|
||||
{
|
||||
if (empty($s)) {
|
||||
return '';
|
||||
|
@ -307,7 +307,7 @@ class L10n
|
|||
* @return string
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function tt(string $singular, string $plural, int $count)
|
||||
public function tt(string $singular, string $plural, int $count): string
|
||||
{
|
||||
$s = null;
|
||||
|
||||
|
@ -352,7 +352,7 @@ class L10n
|
|||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function stringPluralSelectDefault($n)
|
||||
private function stringPluralSelectDefault(int $n): bool
|
||||
{
|
||||
return $n != 1;
|
||||
}
|
||||
|
@ -369,7 +369,7 @@ class L10n
|
|||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getAvailableLanguages()
|
||||
public static function getAvailableLanguages(): array
|
||||
{
|
||||
$langs = [];
|
||||
$strings_file_paths = glob('view/lang/*/strings.php');
|
||||
|
@ -391,10 +391,9 @@ class L10n
|
|||
* Translate days and months names.
|
||||
*
|
||||
* @param string $s String with day or month name.
|
||||
*
|
||||
* @return string Translated string.
|
||||
*/
|
||||
public function getDay($s)
|
||||
public function getDay(string $s): string
|
||||
{
|
||||
$ret = str_replace(['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'],
|
||||
[$this->t('Monday'), $this->t('Tuesday'), $this->t('Wednesday'), $this->t('Thursday'), $this->t('Friday'), $this->t('Saturday'), $this->t('Sunday')],
|
||||
|
@ -411,10 +410,9 @@ class L10n
|
|||
* Translate short days and months names.
|
||||
*
|
||||
* @param string $s String with short day or month name.
|
||||
*
|
||||
* @return string Translated string.
|
||||
*/
|
||||
public function getDayShort($s)
|
||||
public function getDayShort(string $s): string
|
||||
{
|
||||
$ret = str_replace(['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
|
||||
[$this->t('Mon'), $this->t('Tue'), $this->t('Wed'), $this->t('Thu'), $this->t('Fri'), $this->t('Sat'), $this->t('Sun')],
|
||||
|
@ -435,7 +433,7 @@ class L10n
|
|||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
* @hook poke_verbs pokes array
|
||||
*/
|
||||
public function getPokeVerbs()
|
||||
public function getPokeVerbs(): array
|
||||
{
|
||||
// index is present tense verb
|
||||
// value is array containing past tense verb, translation of present, translation of past
|
||||
|
@ -461,7 +459,7 @@ class L10n
|
|||
* @return static A new L10n instance
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function withLang(string $lang)
|
||||
public function withLang(string $lang): L10n
|
||||
{
|
||||
// Don't create a new instance for same language
|
||||
if ($lang === $this->lang) {
|
||||
|
|
|
@ -47,7 +47,7 @@ class Logger
|
|||
/**
|
||||
* @return LoggerInterface
|
||||
*/
|
||||
private static function getWorker()
|
||||
private static function getInstance()
|
||||
{
|
||||
if (self::$type === self::TYPE_LOGGER) {
|
||||
return DI::logger();
|
||||
|
@ -66,7 +66,7 @@ class Logger
|
|||
public static function enableWorker(string $functionName)
|
||||
{
|
||||
self::$type = self::TYPE_WORKER;
|
||||
self::getWorker()->setFunctionName($functionName);
|
||||
self::getInstance()->setFunctionName($functionName);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -82,15 +82,14 @@ class Logger
|
|||
*
|
||||
* @see LoggerInterface::emergency()
|
||||
*
|
||||
* @param string $message
|
||||
* @param array $context
|
||||
*
|
||||
* @param string $message Message to log
|
||||
* @param array $context Optional variables
|
||||
* @return void
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function emergency($message, $context = [])
|
||||
public static function emergency(string $message, array $context = [])
|
||||
{
|
||||
self::getWorker()->emergency($message, $context);
|
||||
self::getInstance()->emergency($message, $context);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -100,15 +99,14 @@ class Logger
|
|||
* Example: Entire website down, database unavailable, etc. This should
|
||||
* trigger the SMS alerts and wake you up.
|
||||
*
|
||||
* @param string $message
|
||||
* @param array $context
|
||||
*
|
||||
* @param string $message Message to log
|
||||
* @param array $context Optional variables
|
||||
* @return void
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function alert($message, $context = [])
|
||||
public static function alert(string $message, array $context = [])
|
||||
{
|
||||
self::getWorker()->alert($message, $context);
|
||||
self::getInstance()->alert($message, $context);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -117,15 +115,14 @@ class Logger
|
|||
*
|
||||
* Example: Application component unavailable, unexpected exception.
|
||||
*
|
||||
* @param string $message
|
||||
* @param array $context
|
||||
*
|
||||
* @param string $message Message to log
|
||||
* @param array $context Optional variables
|
||||
* @return void
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function critical($message, $context = [])
|
||||
public static function critical(string $message, array $context = [])
|
||||
{
|
||||
self::getWorker()->critical($message, $context);
|
||||
self::getInstance()->critical($message, $context);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -133,15 +130,14 @@ class Logger
|
|||
* be logged and monitored.
|
||||
* @see LoggerInterface::error()
|
||||
*
|
||||
* @param string $message
|
||||
* @param array $context
|
||||
*
|
||||
* @param string $message Message to log
|
||||
* @param array $context Optional variables
|
||||
* @return void
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function error($message, $context = [])
|
||||
public static function error(string $message, array $context = [])
|
||||
{
|
||||
self::getWorker()->error($message, $context);
|
||||
self::getInstance()->error($message, $context);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -151,30 +147,28 @@ class Logger
|
|||
* Example: Use of deprecated APIs, poor use of an API, undesirable things
|
||||
* that are not necessarily wrong.
|
||||
*
|
||||
* @param string $message
|
||||
* @param array $context
|
||||
*
|
||||
* @param string $message Message to log
|
||||
* @param array $context Optional variables
|
||||
* @return void
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function warning($message, $context = [])
|
||||
public static function warning(string $message, array $context = [])
|
||||
{
|
||||
self::getWorker()->warning($message, $context);
|
||||
self::getInstance()->warning($message, $context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Normal but significant events.
|
||||
* @see LoggerInterface::notice()
|
||||
*
|
||||
* @param string $message
|
||||
* @param array $context
|
||||
*
|
||||
* @param string $message Message to log
|
||||
* @param array $context Optional variables
|
||||
* @return void
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function notice($message, $context = [])
|
||||
public static function notice(string $message, array $context = [])
|
||||
{
|
||||
self::getWorker()->notice($message, $context);
|
||||
self::getInstance()->notice($message, $context);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -189,24 +183,23 @@ class Logger
|
|||
* @return void
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function info($message, $context = [])
|
||||
public static function info(string $message, array $context = [])
|
||||
{
|
||||
self::getWorker()->info($message, $context);
|
||||
self::getInstance()->info($message, $context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Detailed debug information.
|
||||
* @see LoggerInterface::debug()
|
||||
*
|
||||
* @param string $message
|
||||
* @param array $context
|
||||
*
|
||||
* @param string $message Message to log
|
||||
* @param array $context Optional variables
|
||||
* @return void
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function debug($message, $context = [])
|
||||
public static function debug(string $message, array $context = [])
|
||||
{
|
||||
self::getWorker()->debug($message, $context);
|
||||
self::getInstance()->debug($message, $context);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -216,12 +209,13 @@ class Logger
|
|||
* to isolate particular elements they are targetting
|
||||
* personally without background noise
|
||||
*
|
||||
* @param string $msg
|
||||
* @param string $level
|
||||
* @param string $message Message to log
|
||||
* @param string $level Logging level
|
||||
* @return void
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function devLog($msg, $level = LogLevel::DEBUG)
|
||||
public static function devLog(string $message, string $level = LogLevel::DEBUG)
|
||||
{
|
||||
DI::devLogger()->log($level, $msg);
|
||||
DI::devLogger()->log($level, $message);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
|
||||
namespace Friendica\Core\Logger\Type\Monolog;
|
||||
|
||||
use Friendica\App\Request;
|
||||
use Monolog\Handler;
|
||||
use Monolog\Logger;
|
||||
|
||||
|
@ -38,15 +39,22 @@ class DevelopHandler extends Handler\AbstractHandler
|
|||
private $developerIp;
|
||||
|
||||
/**
|
||||
* @param string $developerIp The IP of the developer who wants to debug
|
||||
* @param int $level The minimum logging level at which this handler will be triggered
|
||||
* @param bool $bubble Whether the messages that are handled can bubble up the stack or not
|
||||
* @var string The IP of the current request
|
||||
*/
|
||||
public function __construct($developerIp, $level = Logger::DEBUG, bool $bubble = true)
|
||||
private $remoteAddress;
|
||||
|
||||
/**
|
||||
* @param Request $request The current http request
|
||||
* @param string $developerIp The IP of the developer who wants to debug
|
||||
* @param int $level The minimum logging level at which this handler will be triggered
|
||||
* @param bool $bubble Whether the messages that are handled can bubble up the stack or not
|
||||
*/
|
||||
public function __construct(Request $request, $developerIp, int $level = Logger::DEBUG, bool $bubble = true)
|
||||
{
|
||||
parent::__construct($level, $bubble);
|
||||
|
||||
$this->developerIp = $developerIp;
|
||||
$this->developerIp = $developerIp;
|
||||
$this->remoteAddress = $request->getRemoteAddress();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -59,7 +67,7 @@ class DevelopHandler extends Handler\AbstractHandler
|
|||
}
|
||||
|
||||
/// Just in case the remote IP is the same as the developer IP log the output
|
||||
if (!is_null($this->developerIp) && $_SERVER['REMOTE_ADDR'] != $this->developerIp) {
|
||||
if (!is_null($this->developerIp) && $this->remoteAddress != $this->developerIp) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -71,7 +71,7 @@ class Renderer
|
|||
* @return string
|
||||
* @throws ServiceUnavailableException
|
||||
*/
|
||||
public static function replaceMacros(string $template, array $vars = [])
|
||||
public static function replaceMacros(string $template, array $vars = []): string
|
||||
{
|
||||
DI::profiler()->startRecording('rendering');
|
||||
|
||||
|
|
|
@ -441,6 +441,12 @@ class System
|
|||
*
|
||||
* @param string $url The new Location to redirect
|
||||
* @param int $code The redirection code, which is used (Default is 302)
|
||||
*
|
||||
* @throws FoundException
|
||||
* @throws MovedPermanentlyException
|
||||
* @throws TemporaryRedirectException
|
||||
*
|
||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
*/
|
||||
public static function externalRedirect($url, $code = 302)
|
||||
{
|
||||
|
|
|
@ -32,7 +32,7 @@ require_once 'boot.php';
|
|||
*/
|
||||
class Theme
|
||||
{
|
||||
public static function getAllowedList()
|
||||
public static function getAllowedList(): array
|
||||
{
|
||||
$allowed_themes_str = DI::config()->get('system', 'allowed_themes');
|
||||
$allowed_themes_raw = explode(',', str_replace(' ', '', $allowed_themes_str));
|
||||
|
@ -69,7 +69,7 @@ class Theme
|
|||
* @param string $theme the name of the theme
|
||||
* @return array
|
||||
*/
|
||||
public static function getInfo($theme)
|
||||
public static function getInfo(string $theme): array
|
||||
{
|
||||
$theme = Strings::sanitizeFilePathItem($theme);
|
||||
|
||||
|
@ -133,7 +133,7 @@ class Theme
|
|||
* @return string
|
||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
*/
|
||||
public static function getScreenshot($theme)
|
||||
public static function getScreenshot(string $theme): string
|
||||
{
|
||||
$theme = Strings::sanitizeFilePathItem($theme);
|
||||
|
||||
|
@ -146,7 +146,13 @@ class Theme
|
|||
return DI::baseUrl() . '/images/blank.png';
|
||||
}
|
||||
|
||||
public static function uninstall($theme)
|
||||
/**
|
||||
* Uninstalls given theme name
|
||||
*
|
||||
* @param string $theme Name of theme
|
||||
* @return bool true on success
|
||||
*/
|
||||
public static function uninstall(string $theme)
|
||||
{
|
||||
$theme = Strings::sanitizeFilePathItem($theme);
|
||||
|
||||
|
@ -167,10 +173,18 @@ class Theme
|
|||
if ($key !== false) {
|
||||
unset($allowed_themes[$key]);
|
||||
Theme::setAllowedList($allowed_themes);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function install($theme)
|
||||
/**
|
||||
* Installs given theme name
|
||||
*
|
||||
* @param string $theme Name of theme
|
||||
* @return bool true on success
|
||||
*/
|
||||
public static function install(string $theme): bool
|
||||
{
|
||||
$theme = Strings::sanitizeFilePathItem($theme);
|
||||
|
||||
|
@ -208,7 +222,7 @@ class Theme
|
|||
* @return string Path to the file or empty string if the file isn't found
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function getPathForFile($file)
|
||||
public static function getPathForFile(string $file): string
|
||||
{
|
||||
$a = DI::app();
|
||||
|
||||
|
@ -237,10 +251,9 @@ class Theme
|
|||
* Provide a sane default if nothing is chosen or the specified theme does not exist.
|
||||
*
|
||||
* @param string $theme Theme name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getStylesheetPath($theme)
|
||||
public static function getStylesheetPath(string $theme): string
|
||||
{
|
||||
$theme = Strings::sanitizeFilePathItem($theme);
|
||||
|
||||
|
@ -263,10 +276,10 @@ class Theme
|
|||
/**
|
||||
* Returns the path of the provided theme
|
||||
*
|
||||
* @param $theme
|
||||
* @param string $theme Theme name
|
||||
* @return string|null
|
||||
*/
|
||||
public static function getConfigFile($theme)
|
||||
public static function getConfigFile(string $theme)
|
||||
{
|
||||
$theme = Strings::sanitizeFilePathItem($theme);
|
||||
|
||||
|
@ -285,11 +298,11 @@ class Theme
|
|||
/**
|
||||
* Returns the background color of the provided theme if available.
|
||||
*
|
||||
* @param string $theme
|
||||
* @param string $theme Theme name
|
||||
* @param int|null $uid Current logged-in user id
|
||||
* @return string|null
|
||||
*/
|
||||
public static function getBackgroundColor(string $theme, $uid = null)
|
||||
public static function getBackgroundColor(string $theme, int $uid = null)
|
||||
{
|
||||
$theme = Strings::sanitizeFilePathItem($theme);
|
||||
|
||||
|
|
|
@ -41,7 +41,7 @@ class Update
|
|||
* @param string $basePath The base path of this application
|
||||
* @param boolean $via_worker Is the check run via the worker?
|
||||
* @param App\Mode $mode The current app mode
|
||||
*
|
||||
* @return void
|
||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
*/
|
||||
public static function check(string $basePath, bool $via_worker, App\Mode $mode)
|
||||
|
@ -73,7 +73,7 @@ class Update
|
|||
}
|
||||
|
||||
// The postupdate has to completed version 1288 for the new post views to take over
|
||||
$postupdate = DI::config()->get("system", "post_update_version", NEW_TABLE_STRUCTURE_VERSION);
|
||||
$postupdate = DI::config()->get('system', 'post_update_version', NEW_TABLE_STRUCTURE_VERSION);
|
||||
if ($postupdate < NEW_TABLE_STRUCTURE_VERSION) {
|
||||
$error = DI::l10n()->t('Updates from postupdate version %s are not supported. Please update at least to version 2021.01 and wait until the postupdate finished version 1383.', $postupdate);
|
||||
if (DI::mode()->getExecutor() == Mode::INDEX) {
|
||||
|
@ -85,9 +85,11 @@ class Update
|
|||
|
||||
if ($build < DB_UPDATE_VERSION) {
|
||||
if ($via_worker) {
|
||||
// Calling the database update directly via the worker enables us to perform database changes to the workerqueue table itself.
|
||||
// This is a fallback, since normally the database update will be performed by a worker job.
|
||||
// This worker job doesn't work for changes to the "workerqueue" table itself.
|
||||
/*
|
||||
* Calling the database update directly via the worker enables us to perform database changes to the workerqueue table itself.
|
||||
* This is a fallback, since normally the database update will be performed by a worker job.
|
||||
* This worker job doesn't work for changes to the "workerqueue" table itself.
|
||||
*/
|
||||
self::run($basePath);
|
||||
} else {
|
||||
Worker::add(PRIORITY_CRITICAL, 'DBUpdate');
|
||||
|
@ -103,11 +105,10 @@ class Update
|
|||
* @param bool $override Overrides any running/stuck updates
|
||||
* @param bool $verbose Run the Update-Check verbose
|
||||
* @param bool $sendMail Sends a Mail to the administrator in case of success/failure
|
||||
*
|
||||
* @return string Empty string if the update is successful, error messages otherwise
|
||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
*/
|
||||
public static function run(string $basePath, bool $force = false, bool $override = false, bool $verbose = false, bool $sendMail = true)
|
||||
public static function run(string $basePath, bool $force = false, bool $override = false, bool $verbose = false, bool $sendMail = true): string
|
||||
{
|
||||
// In force mode, we release the dbupdate lock first
|
||||
// Necessary in case of an stuck update
|
||||
|
@ -228,11 +229,10 @@ class Update
|
|||
* @param int $version the DB version number of the function
|
||||
* @param string $prefix the prefix of the function (update, pre_update)
|
||||
* @param bool $sendMail whether to send emails on success/failure
|
||||
|
||||
* @return bool true, if the update function worked
|
||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
*/
|
||||
public static function runUpdateFunction(int $version, string $prefix, bool $sendMail = true)
|
||||
public static function runUpdateFunction(int $version, string $prefix, bool $sendMail = true): bool
|
||||
{
|
||||
$funcname = $prefix . '_' . $version;
|
||||
|
||||
|
@ -284,6 +284,7 @@ class Update
|
|||
*
|
||||
* @param int $update_id number of failed update
|
||||
* @param string $error_message error message
|
||||
* @return void
|
||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
*/
|
||||
private static function updateFailed(int $update_id, string $error_message) {
|
||||
|
|
|
@ -86,7 +86,7 @@ class UserImport
|
|||
* @return array|bool
|
||||
* @throws \Exception
|
||||
*/
|
||||
private static function dbImportAssoc($table, $arr)
|
||||
private static function dbImportAssoc(string $table, array $arr)
|
||||
{
|
||||
if (isset($arr['id'])) {
|
||||
unset($arr['id']);
|
||||
|
@ -105,10 +105,11 @@ class UserImport
|
|||
* Import account file exported from mod/uexport
|
||||
*
|
||||
* @param array $file array from $_FILES
|
||||
* @return void
|
||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
* @throws \ImagickException
|
||||
*/
|
||||
public static function importAccount($file)
|
||||
public static function importAccount(array $file)
|
||||
{
|
||||
Logger::notice("Start user import from " . $file['tmp_name']);
|
||||
/*
|
||||
|
|
|
@ -60,7 +60,7 @@ class Worker
|
|||
* @return void
|
||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
*/
|
||||
public static function processQueue($run_cron, Process $process)
|
||||
public static function processQueue(bool $run_cron, Process $process)
|
||||
{
|
||||
self::$up_start = microtime(true);
|
||||
|
||||
|
@ -169,7 +169,7 @@ class Worker
|
|||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public static function isReady()
|
||||
public static function isReady(): bool
|
||||
{
|
||||
// Count active workers and compare them with a maximum value that depends on the load
|
||||
if (self::tooMuchWorkers()) {
|
||||
|
@ -204,7 +204,7 @@ class Worker
|
|||
* @return boolean Returns "true" if tasks are existing
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function entriesExists()
|
||||
public static function entriesExists(): bool
|
||||
{
|
||||
$stamp = (float)microtime(true);
|
||||
$exists = DBA::exists('workerqueue', ["NOT `done` AND `pid` = 0 AND `next_try` < ?", DateTimeFormat::utcNow()]);
|
||||
|
@ -218,7 +218,7 @@ class Worker
|
|||
* @return integer Number of deferred entries in the worker queue
|
||||
* @throws \Exception
|
||||
*/
|
||||
private static function deferredEntries()
|
||||
private static function deferredEntries(): int
|
||||
{
|
||||
$stamp = (float)microtime(true);
|
||||
$count = DBA::count('workerqueue', ["NOT `done` AND `pid` = 0 AND `retrial` > ?", 0]);
|
||||
|
@ -233,7 +233,7 @@ class Worker
|
|||
* @return integer Number of non executed entries in the worker queue
|
||||
* @throws \Exception
|
||||
*/
|
||||
private static function totalEntries()
|
||||
private static function totalEntries(): int
|
||||
{
|
||||
$stamp = (float)microtime(true);
|
||||
$count = DBA::count('workerqueue', ['done' => false, 'pid' => 0]);
|
||||
|
@ -248,7 +248,7 @@ class Worker
|
|||
* @return integer Number of active worker processes
|
||||
* @throws \Exception
|
||||
*/
|
||||
private static function highestPriority()
|
||||
private static function highestPriority(): int
|
||||
{
|
||||
$stamp = (float)microtime(true);
|
||||
$condition = ["`pid` = 0 AND NOT `done` AND `next_try` < ?", DateTimeFormat::utcNow()];
|
||||
|
@ -269,7 +269,7 @@ class Worker
|
|||
* @return integer Is there a process running with that priority?
|
||||
* @throws \Exception
|
||||
*/
|
||||
private static function processWithPriorityActive($priority)
|
||||
private static function processWithPriorityActive(int $priority): int
|
||||
{
|
||||
$condition = ["`priority` <= ? AND `pid` != 0 AND NOT `done`", $priority];
|
||||
return DBA::exists('workerqueue', $condition);
|
||||
|
@ -281,7 +281,7 @@ class Worker
|
|||
* @param mixed $file
|
||||
* @return bool
|
||||
*/
|
||||
private static function validateInclude(&$file)
|
||||
private static function validateInclude(&$file): bool
|
||||
{
|
||||
$orig_file = $file;
|
||||
|
||||
|
@ -321,7 +321,7 @@ class Worker
|
|||
* @return boolean "true" if further processing should be stopped
|
||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
*/
|
||||
public static function execute($queue)
|
||||
public static function execute(array $queue): bool
|
||||
{
|
||||
$mypid = getmypid();
|
||||
|
||||
|
@ -454,7 +454,7 @@ class Worker
|
|||
* @return void
|
||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
*/
|
||||
private static function execFunction($queue, $funcname, $argv, $method_call)
|
||||
private static function execFunction(array $queue, string $funcname, array $argv, bool $method_call)
|
||||
{
|
||||
$a = DI::app();
|
||||
|
||||
|
@ -543,7 +543,7 @@ class Worker
|
|||
* @return bool Are more than 3/4 of the maximum connections used?
|
||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
*/
|
||||
private static function maxConnectionsReached()
|
||||
private static function maxConnectionsReached(): bool
|
||||
{
|
||||
// Fetch the max value from the config. This is needed when the system cannot detect the correct value by itself.
|
||||
$max = DI::config()->get("system", "max_connections");
|
||||
|
@ -627,7 +627,7 @@ class Worker
|
|||
* @return bool Are there too much workers running?
|
||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
*/
|
||||
private static function tooMuchWorkers()
|
||||
private static function tooMuchWorkers(): bool
|
||||
{
|
||||
$queues = DI::config()->get("system", "worker_queues", 10);
|
||||
|
||||
|
@ -751,7 +751,7 @@ class Worker
|
|||
* @return integer Number of active worker processes
|
||||
* @throws \Exception
|
||||
*/
|
||||
private static function activeWorkers()
|
||||
private static function activeWorkers(): int
|
||||
{
|
||||
$stamp = (float)microtime(true);
|
||||
$count = DI::process()->countCommand('Worker.php');
|
||||
|
@ -766,7 +766,7 @@ class Worker
|
|||
* @return array List of worker process ids
|
||||
* @throws \Exception
|
||||
*/
|
||||
private static function getWorkerPIDList()
|
||||
private static function getWorkerPIDList(): array
|
||||
{
|
||||
$ids = [];
|
||||
$stamp = (float)microtime(true);
|
||||
|
@ -787,7 +787,7 @@ class Worker
|
|||
/**
|
||||
* Returns waiting jobs for the current process id
|
||||
*
|
||||
* @return array waiting workerqueue jobs
|
||||
* @return array|bool waiting workerqueue jobs or FALSE on failture
|
||||
* @throws \Exception
|
||||
*/
|
||||
private static function getWaitingJobForPID()
|
||||
|
@ -809,7 +809,7 @@ class Worker
|
|||
* @return array array with next jobs
|
||||
* @throws \Exception
|
||||
*/
|
||||
private static function nextProcess(int $limit)
|
||||
private static function nextProcess(int $limit): array
|
||||
{
|
||||
$priority = self::nextPriority();
|
||||
if (empty($priority)) {
|
||||
|
@ -844,7 +844,7 @@ class Worker
|
|||
/**
|
||||
* Returns the priority of the next workerqueue job
|
||||
*
|
||||
* @return string priority
|
||||
* @return string|bool priority or FALSE on failure
|
||||
* @throws \Exception
|
||||
*/
|
||||
private static function nextPriority()
|
||||
|
@ -915,7 +915,7 @@ class Worker
|
|||
/**
|
||||
* Find and claim the next worker process for us
|
||||
*
|
||||
* @return boolean Have we found something?
|
||||
* @return void
|
||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
*/
|
||||
private static function findWorkerProcesses()
|
||||
|
@ -993,7 +993,7 @@ class Worker
|
|||
* @return array worker processes
|
||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
*/
|
||||
public static function workerProcess()
|
||||
public static function workerProcess(): array
|
||||
{
|
||||
// There can already be jobs for us in the queue.
|
||||
$waiting = self::getWaitingJobForPID();
|
||||
|
@ -1003,7 +1003,7 @@ class Worker
|
|||
|
||||
$stamp = (float)microtime(true);
|
||||
if (!DI::lock()->acquire(self::LOCK_PROCESS)) {
|
||||
return false;
|
||||
return [];
|
||||
}
|
||||
self::$lock_duration += (microtime(true) - $stamp);
|
||||
|
||||
|
@ -1011,7 +1011,9 @@ class Worker
|
|||
|
||||
DI::lock()->release(self::LOCK_PROCESS);
|
||||
|
||||
return self::getWaitingJobForPID();
|
||||
// Prevents "Return value of Friendica\Core\Worker::workerProcess() must be of the type array, bool returned"
|
||||
$process = self::getWaitingJobForPID();
|
||||
return (is_array($process) ? $process : []);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1097,7 +1099,7 @@ class Worker
|
|||
* @return void
|
||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
*/
|
||||
public static function spawnWorker($do_cron = false)
|
||||
public static function spawnWorker(bool $do_cron = false)
|
||||
{
|
||||
if (Worker\Daemon::isMode() && DI::config()->get('system', 'worker_fork')) {
|
||||
self::forkProcess($do_cron);
|
||||
|
@ -1231,7 +1233,7 @@ class Worker
|
|||
return $added;
|
||||
}
|
||||
|
||||
public static function countWorkersByCommand(string $command)
|
||||
public static function countWorkersByCommand(string $command): int
|
||||
{
|
||||
return DBA::count('workerqueue', ['done' => false, 'pid' => 0, 'command' => $command]);
|
||||
}
|
||||
|
@ -1244,7 +1246,7 @@ class Worker
|
|||
* @param integer $max_level maximum retrial level
|
||||
* @return integer the next retrial level value
|
||||
*/
|
||||
private static function getNextRetrial($queue, $max_level)
|
||||
private static function getNextRetrial(array $queue, int $max_level): int
|
||||
{
|
||||
$created = strtotime($queue['created']);
|
||||
$retrial_time = time() - $created;
|
||||
|
@ -1314,9 +1316,10 @@ class Worker
|
|||
/**
|
||||
* Check if the system is inside the defined maintenance window
|
||||
*
|
||||
* @param bool $check_last_execution Whether check last execution
|
||||
* @return boolean
|
||||
*/
|
||||
public static function isInMaintenanceWindow(bool $check_last_execution = false)
|
||||
public static function isInMaintenanceWindow(bool $check_last_execution = false): bool
|
||||
{
|
||||
// Calculate the seconds of the start end end of the maintenance window
|
||||
$start = strtotime(DI::config()->get('system', 'maintenance_start')) % 86400;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue