mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-07-25 06:44:33 +02:00
Respect php.ini limits when exporting to PDF
This commit is contained in:
parent
a95e645236
commit
87da1e76cd
@ -8,6 +8,7 @@ use Dompdf\Dompdf;
|
|||||||
use Dompdf\Options;
|
use Dompdf\Options;
|
||||||
use Icinga\Application\Icinga;
|
use Icinga\Application\Icinga;
|
||||||
use Icinga\Exception\ProgrammingError;
|
use Icinga\Exception\ProgrammingError;
|
||||||
|
use Icinga\Util\Format;
|
||||||
use Icinga\Web\Hook;
|
use Icinga\Web\Hook;
|
||||||
use Icinga\Web\Url;
|
use Icinga\Web\Url;
|
||||||
|
|
||||||
@ -45,8 +46,17 @@ class Pdf
|
|||||||
public function renderControllerAction($controller)
|
public function renderControllerAction($controller)
|
||||||
{
|
{
|
||||||
$this->assertNoHeadersSent();
|
$this->assertNoHeadersSent();
|
||||||
ini_set('memory_limit', '384M');
|
|
||||||
ini_set('max_execution_time', 300);
|
$memLimit = 512 * 1024 ** 2;
|
||||||
|
if (Format::unpackShorthandBytes(ini_get('memory_limit')) < $memLimit) {
|
||||||
|
ini_set('memory_limit', $memLimit);
|
||||||
|
}
|
||||||
|
|
||||||
|
$maxExecTime = 300;
|
||||||
|
if ((int) ini_get('max_execution_time') < $maxExecTime) {
|
||||||
|
ini_set('max_execution_time', $maxExecTime);
|
||||||
|
}
|
||||||
|
|
||||||
$viewRenderer = $controller->getHelper('viewRenderer');
|
$viewRenderer = $controller->getHelper('viewRenderer');
|
||||||
$controller->render(
|
$controller->render(
|
||||||
$viewRenderer->getScriptAction(),
|
$viewRenderer->getScriptAction(),
|
||||||
|
@ -4,8 +4,6 @@
|
|||||||
namespace Icinga\Util;
|
namespace Icinga\Util;
|
||||||
|
|
||||||
use DateTime;
|
use DateTime;
|
||||||
use Icinga\Date\DateFormatter;
|
|
||||||
use Icinga\Exception\ProgrammingError;
|
|
||||||
|
|
||||||
class Format
|
class Format
|
||||||
{
|
{
|
||||||
@ -141,4 +139,37 @@ class Format
|
|||||||
|
|
||||||
return $dt->format('L') == 1;
|
return $dt->format('L') == 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unpack shorthand bytes PHP directives to bytes
|
||||||
|
*
|
||||||
|
* @param string $subject
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public static function unpackShorthandBytes($subject)
|
||||||
|
{
|
||||||
|
$base = (int) $subject;
|
||||||
|
|
||||||
|
if ($base <= -1) {
|
||||||
|
return INF;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (strtoupper($subject[strlen($subject) - 1])) {
|
||||||
|
case 'K':
|
||||||
|
$multiplier = 1024;
|
||||||
|
break;
|
||||||
|
case 'M':
|
||||||
|
$multiplier = 1024 ** 2;
|
||||||
|
break;
|
||||||
|
case 'G':
|
||||||
|
$multiplier = 1024 ** 3;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
$multiplier = 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $base * $multiplier;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user