Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Weimann <mail@michael-weimann.eu>2018-08-04 22:53:50 +0300
committerJohn Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>2018-08-20 16:24:10 +0300
commitc164409ee7f921a96f95e1fe95d86fe07a98963e (patch)
tree42fc9ded3b31d152242258518366da0c145b570d
parent1d2bc9c45ecbbb7521dbf14dba6560d925691f01 (diff)
Adds a memory limit warning for console commands if the limit is below the recommended value
Signed-off-by: Michael Weimann <mail@michael-weimann.eu>
-rw-r--r--console.php8
-rw-r--r--core/js/setupchecks.js2
-rw-r--r--lib/private/Console/Application.php30
-rw-r--r--lib/private/MemoryInfo.php13
-rw-r--r--settings/Controller/CheckSetupController.php12
5 files changed, 51 insertions, 14 deletions
diff --git a/console.php b/console.php
index 67856a17b3b..1d5021edef0 100644
--- a/console.php
+++ b/console.php
@@ -85,7 +85,13 @@ try {
echo "The process control (PCNTL) extensions are required in case you want to interrupt long running commands - see http://php.net/manual/en/book.pcntl.php" . PHP_EOL;
}
- $application = new Application(\OC::$server->getConfig(), \OC::$server->getEventDispatcher(), \OC::$server->getRequest(), \OC::$server->getLogger());
+ $application = new Application(
+ \OC::$server->getConfig(),
+ \OC::$server->getEventDispatcher(),
+ \OC::$server->getRequest(),
+ \OC::$server->getLogger(),
+ \OC::$server->query(\OC\MemoryInfo::class)
+ );
$application->loadCommands(new ArgvInput(), new ConsoleOutput());
$application->run();
} catch (Exception $ex) {
diff --git a/core/js/setupchecks.js b/core/js/setupchecks.js
index f7ee8c73c81..7dabefe9e8f 100644
--- a/core/js/setupchecks.js
+++ b/core/js/setupchecks.js
@@ -316,7 +316,7 @@
type: OC.SetupChecks.MESSAGE_TYPE_WARNING
});
}
- if (!data.isTheMemoryLimitHighEnough) {
+ if (!data.isMemoryLimitSufficient) {
messages.push({
msg: t(
'core',
diff --git a/lib/private/Console/Application.php b/lib/private/Console/Application.php
index 1de5fbd6ca3..422e78ee06f 100644
--- a/lib/private/Console/Application.php
+++ b/lib/private/Console/Application.php
@@ -29,6 +29,7 @@
*/
namespace OC\Console;
+use OC\MemoryInfo;
use OC\NeedsUpdateException;
use OC_App;
use OCP\AppFramework\QueryException;
@@ -52,20 +53,28 @@ class Application {
private $request;
/** @var ILogger */
private $logger;
+ /** @var MemoryInfo */
+ private $memoryInfo;
/**
* @param IConfig $config
* @param EventDispatcherInterface $dispatcher
* @param IRequest $request
* @param ILogger $logger
+ * @param MemoryInfo $memoryInfo
*/
- public function __construct(IConfig $config, EventDispatcherInterface $dispatcher, IRequest $request, ILogger $logger) {
+ public function __construct(IConfig $config,
+ EventDispatcherInterface $dispatcher,
+ IRequest $request,
+ ILogger $logger,
+ MemoryInfo $memoryInfo) {
$defaults = \OC::$server->getThemingDefaults();
$this->config = $config;
$this->application = new SymfonyApplication($defaults->getName(), \OC_Util::getVersionString());
$this->dispatcher = $dispatcher;
$this->request = $request;
$this->logger = $logger;
+ $this->memoryInfo = $memoryInfo;
}
/**
@@ -97,6 +106,11 @@ class Application {
if ($input->getOption('no-warnings')) {
$output->setVerbosity(OutputInterface::VERBOSITY_QUIET);
}
+
+ if ($this->memoryInfo->isMemoryLimitSufficient() === false) {
+ $this->writeMemoryLimitInfo($output);
+ }
+
try {
require_once __DIR__ . '/../../../core/register_command.php';
if ($this->config->getSystemValue('installed', false)) {
@@ -174,6 +188,20 @@ class Application {
}
/**
+ * Write a memory info output if the limit is below the recommended value.
+ *
+ * @param ConsoleOutputInterface $output
+ * @return void
+ */
+ private function writeMemoryLimitInfo(ConsoleOutputInterface $output) {
+ $errOutput = $output->getErrorOutput();
+ $errOutput->writeln(
+ '<comment>The current PHP memory limit ' .
+ 'is below the recommended value of 512MB.</comment>'
+ );
+ }
+
+ /**
* Sets whether to automatically exit after a command execution or not.
*
* @param bool $boolean Whether to automatically exit after a command execution or not
diff --git a/lib/private/MemoryInfo.php b/lib/private/MemoryInfo.php
index 14865ed682e..0501d3fd049 100644
--- a/lib/private/MemoryInfo.php
+++ b/lib/private/MemoryInfo.php
@@ -6,6 +6,19 @@ namespace OC;
* Helper class that covers memory info.
*/
class MemoryInfo {
+
+ const RECOMMENDED_MEMORY_LIMIT = 512 * 1024 * 1024;
+
+ /**
+ * Tests if the memory limit is greater or equal the recommended value.
+ *
+ * @return bool
+ */
+ public function isMemoryLimitSufficient(): bool {
+ $memoryLimit = $this->getMemoryLimit();
+ return $memoryLimit === -1 || $memoryLimit >= self::RECOMMENDED_MEMORY_LIMIT;
+ }
+
/**
* Returns the php memory limit.
*
diff --git a/settings/Controller/CheckSetupController.php b/settings/Controller/CheckSetupController.php
index eca67667471..a64d131648b 100644
--- a/settings/Controller/CheckSetupController.php
+++ b/settings/Controller/CheckSetupController.php
@@ -535,16 +535,6 @@ Raw output
}
/**
- * Tests if the php memory limit is high enough.
- *
- * @return bool True if more than 512 MB available, else false.
- */
- protected function isTheMemoryLimitHighEnough(): bool {
- $memoryLimit = $this->memoryInfo->getMemoryLimit();
- return $memoryLimit === -1 || $memoryLimit >= 512 * 1024 * 1024;
- }
-
- /**
* @return DataResponse
*/
public function check() {
@@ -581,7 +571,7 @@ Raw output
'databaseConversionDocumentation' => $this->urlGenerator->linkToDocs('admin-db-conversion'),
'isPhpMailerUsed' => $this->isPhpMailerUsed(),
'mailSettingsDocumentation' => $this->urlGenerator->getAbsoluteURL('index.php/settings/admin'),
- 'isTheMemoryLimitHighEnough' => $this->isTheMemoryLimitHighEnough(),
+ 'isMemoryLimitSufficient' => $this->memoryInfo->isMemoryLimitSufficient(),
]
);
}