re-add App::isBackend()
This commit is contained in:
parent
0af9747c6c
commit
4089e17f85
29
src/App.php
29
src/App.php
|
@ -100,8 +100,6 @@ class App
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var bool true, if the call is from an backend node (f.e. worker)
|
* @var bool true, if the call is from an backend node (f.e. worker)
|
||||||
*
|
|
||||||
* @deprecated 2019.09 - use App\Module->isBackend() instead
|
|
||||||
*/
|
*/
|
||||||
private $isBackend;
|
private $isBackend;
|
||||||
|
|
||||||
|
@ -287,7 +285,7 @@ class App
|
||||||
$this->logger = $logger;
|
$this->logger = $logger;
|
||||||
$this->l10n = $l10n;
|
$this->l10n = $l10n;
|
||||||
$this->args = $args;
|
$this->args = $args;
|
||||||
$this->isBackend = $module->isBackend();
|
$this->isBackend = $this->checkBackend($module);
|
||||||
|
|
||||||
$this->profiler->reset();
|
$this->profiler->reset();
|
||||||
|
|
||||||
|
@ -575,6 +573,29 @@ class App
|
||||||
$this->getBaseURL();
|
$this->getBaseURL();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if the site is called via a backend process
|
||||||
|
*
|
||||||
|
* @param Module $module The pre-loaded module (just name, not class!)
|
||||||
|
|
||||||
|
* @return bool True, if the call is a backend call
|
||||||
|
*/
|
||||||
|
private function checkBackend(Module $module)
|
||||||
|
{
|
||||||
|
return basename(($_SERVER['PHP_SELF'] ?? ''), '.php') !== 'index' ||
|
||||||
|
$module->isBackend();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true, if the call is from a backend node (f.e. from a worker)
|
||||||
|
*
|
||||||
|
* @return bool Is it a known backend?
|
||||||
|
*/
|
||||||
|
public function isBackend()
|
||||||
|
{
|
||||||
|
return $this->isBackend;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Checks if the maximum number of database processes is reached
|
* @brief Checks if the maximum number of database processes is reached
|
||||||
*
|
*
|
||||||
|
@ -668,7 +689,7 @@ class App
|
||||||
*/
|
*/
|
||||||
public function isMaxLoadReached()
|
public function isMaxLoadReached()
|
||||||
{
|
{
|
||||||
if ($this->isBackend) {
|
if ($this->isBackend()) {
|
||||||
$process = 'backend';
|
$process = 'backend';
|
||||||
$maxsysload = intval($this->config->get('system', 'maxloadavg'));
|
$maxsysload = intval($this->config->get('system', 'maxloadavg'));
|
||||||
if ($maxsysload < 1) {
|
if ($maxsysload < 1) {
|
||||||
|
|
|
@ -15,7 +15,7 @@ use Psr\Log\LoggerInterface;
|
||||||
*/
|
*/
|
||||||
class Module
|
class Module
|
||||||
{
|
{
|
||||||
const DEFAULT = 'home';
|
const DEFAULT = 'home';
|
||||||
const DEFAULT_CLASS = Home::class;
|
const DEFAULT_CLASS = Home::class;
|
||||||
/**
|
/**
|
||||||
* A list of modules, which are backend methods
|
* A list of modules, which are backend methods
|
||||||
|
@ -87,7 +87,8 @@ class Module
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return bool
|
* @return bool True, if the current module is a backend module
|
||||||
|
* @see Module::BACKEND_MODULES for a list
|
||||||
*/
|
*/
|
||||||
public function isBackend()
|
public function isBackend()
|
||||||
{
|
{
|
||||||
|
@ -96,9 +97,9 @@ class Module
|
||||||
|
|
||||||
public function __construct(string $module = self::DEFAULT, string $moduleClass = self::DEFAULT_CLASS, bool $isBackend = false, bool $printNotAllowedAddon = false)
|
public function __construct(string $module = self::DEFAULT, string $moduleClass = self::DEFAULT_CLASS, bool $isBackend = false, bool $printNotAllowedAddon = false)
|
||||||
{
|
{
|
||||||
$this->module = $module;
|
$this->module = $module;
|
||||||
$this->module_class = $moduleClass;
|
$this->module_class = $moduleClass;
|
||||||
$this->isBackend = $isBackend;
|
$this->isBackend = $isBackend;
|
||||||
$this->printNotAllowedAddon = $printNotAllowedAddon;
|
$this->printNotAllowedAddon = $printNotAllowedAddon;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -124,7 +125,7 @@ class Module
|
||||||
$module = "login";
|
$module = "login";
|
||||||
}
|
}
|
||||||
|
|
||||||
$isBackend = $this->checkBackend($module, $server);
|
$isBackend = in_array($module, Module::BACKEND_MODULES);;
|
||||||
|
|
||||||
return new Module($module, $this->module_class, $isBackend, $this->printNotAllowedAddon);
|
return new Module($module, $this->module_class, $isBackend, $this->printNotAllowedAddon);
|
||||||
}
|
}
|
||||||
|
@ -190,16 +191,16 @@ class Module
|
||||||
/**
|
/**
|
||||||
* Run the determined module class and calls all hooks applied to
|
* Run the determined module class and calls all hooks applied to
|
||||||
*
|
*
|
||||||
* @param Core\L10n\L10n $l10n The L10n instance
|
* @param Core\L10n\L10n $l10n The L10n instance
|
||||||
* @param App $app The whole Friendica app (for method arguments)
|
* @param App $app The whole Friendica app (for method arguments)
|
||||||
* @param LoggerInterface $logger The Friendica logger
|
* @param LoggerInterface $logger The Friendica logger
|
||||||
* @param string $currentTheme The chosen theme
|
* @param string $currentTheme The chosen theme
|
||||||
* @param array $server The $_SERVER variable
|
* @param array $server The $_SERVER variable
|
||||||
* @param array $post The $_POST variables
|
* @param array $post The $_POST variables
|
||||||
*
|
*
|
||||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||||
*/
|
*/
|
||||||
public function run(Core\L10n\L10n $l10n, App $app, LoggerInterface $logger, string $currentTheme, array $server, array $post)
|
public function run(Core\L10n\L10n $l10n, App $app, LoggerInterface $logger, string $currentTheme, array $server, array $post)
|
||||||
{
|
{
|
||||||
if ($this->printNotAllowedAddon) {
|
if ($this->printNotAllowedAddon) {
|
||||||
info($l10n->t("You must be logged in to use addons. "));
|
info($l10n->t("You must be logged in to use addons. "));
|
||||||
|
@ -258,22 +259,4 @@ class Module
|
||||||
Core\Hook::callAll($this->module . '_mod_afterpost', $placeholder);
|
Core\Hook::callAll($this->module . '_mod_afterpost', $placeholder);
|
||||||
call_user_func([$this->module_class, 'afterpost']);
|
call_user_func([$this->module_class, 'afterpost']);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Checks if the site is called via a backend process
|
|
||||||
*
|
|
||||||
* This isn't a perfect solution. But we need this check very early.
|
|
||||||
* So we cannot wait until the modules are loaded.
|
|
||||||
*
|
|
||||||
* @param string $module The determined module
|
|
||||||
* @param array $server The $_SERVER variable
|
|
||||||
*
|
|
||||||
* @return bool True, if the current module is called at backend
|
|
||||||
*/
|
|
||||||
private function checkBackend($module, array $server)
|
|
||||||
{
|
|
||||||
// Check if current module is in backend or backend flag is set
|
|
||||||
return basename(($server['PHP_SELF'] ?? ''), '.php') !== 'index' &&
|
|
||||||
in_array($module, Module::BACKEND_MODULES);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue