Fix new config value in tests

This commit is contained in:
Bartek Fabiszewski 2020-06-04 21:08:17 +02:00
parent 74eef23492
commit 55e5319f19
11 changed files with 93 additions and 86 deletions

View File

@ -22,6 +22,6 @@
<config name="stroke_opacity" value="d:0;" />
<config name="stroke_weight" value="i:0;" />
<config name="units" value="s:6:&quot;metric&quot;;" />
<config name="upload_maxsize" value="i:0;" />
<config name="upload_maxsize" value="i:5242880;" />
<ol_layers />
</dataset>

View File

@ -81,7 +81,7 @@ class MigrateTest extends UloggerDatabaseTestCase {
["name" => "stroke_opacity", "value" => "i:1;"],
["name" => "stroke_weight", "value" => "i:22;"],
["name" => "units", "value" => "s:8:\"imperial\";"],
["name" => "upload_maxsize", "value" => "i:0;"]
["name" => "upload_maxsize", "value" => "i:5242880;"]
]];
$actual = $this->getConnection()->createQueryTable(
"config",

View File

@ -135,10 +135,9 @@ class uConfig {
* @var int Maximum size of uploaded files in bytes.
* Will be adjusted to system maximum upload size
*/
public $uploadMaxSize;
public $uploadMaxSize = 5242880;
public function __construct($useDatabase = true) {
$this->uploadMaxSize = uUtils::getUploadMaxSize();
if ($useDatabase) {
$this->setFromDatabase();
}
@ -227,10 +226,10 @@ class uConfig {
WHEN 'color_start' THEN $placeholder
WHEN 'color_stop' THEN $placeholder
WHEN 'google_key' THEN $placeholder
WHEN 'interval_seconds' THEN $placeholder
WHEN 'lang' THEN $placeholder
WHEN 'latitude' THEN $placeholder
WHEN 'longitude' THEN $placeholder
WHEN 'interval_seconds' THEN $placeholder
WHEN 'lang' THEN $placeholder
WHEN 'map_api' THEN $placeholder
WHEN 'pass_lenmin' THEN $placeholder
WHEN 'pass_strength' THEN $placeholder
@ -429,10 +428,18 @@ class uConfig {
}
if (isset($arr['upload_maxsize']) && is_numeric($arr['upload_maxsize'])) {
$this->uploadMaxSize = (int) $arr['upload_maxsize'];
if ($this->uploadMaxSize === 0 || $this->uploadMaxSize > uUtils::getUploadMaxSize()) {
$this->uploadMaxSize = uUtils::getUploadMaxSize();
$this->setUploadLimit();
}
}
/**
* Adjust uploadMaxSize to system limits
*/
private function setUploadLimit() {
$limit = uUtils::getSystemUploadLimit();
if ($this->uploadMaxSize <= 0 || $this->uploadMaxSize > $limit) {
$this->uploadMaxSize = $limit;
}
}
}

View File

@ -141,7 +141,7 @@ class uUpload {
$file = NULL;
$fileError = isset($fileMeta[self::META_ERROR]) ? $fileMeta[self::META_ERROR] : UPLOAD_ERR_OK;
if ($fileMeta[self::META_SIZE] > uUtils::getUploadMaxSize() && $fileError == UPLOAD_ERR_OK) {
if ($fileMeta[self::META_SIZE] > uUtils::getSystemUploadLimit() && $fileError == UPLOAD_ERR_OK) {
$fileError = UPLOAD_ERR_FORM_SIZE;
}
if ($fileError == UPLOAD_ERR_OK) {

View File

@ -28,7 +28,7 @@
*
* @return int Number of bytes
*/
public static function getUploadMaxSize() {
public static function getSystemUploadLimit() {
$upload_max_filesize = self::iniGetBytes('upload_max_filesize');
$post_max_size = self::iniGetBytes('post_max_size');
// post_max_size = 0 means unlimited size

View File

@ -106,7 +106,7 @@ INSERT INTO `config` (`name`, `value`) VALUES
('stroke_opacity', 'd:1;'),
('stroke_weight', 'i:2;'),
('units', 's:6:"metric";'),
('upload_maxsize', 'i:0;');
('upload_maxsize', 'i:5242880;');
-- --------------------------------------------------------

View File

@ -108,7 +108,7 @@ INSERT INTO config (name, value) VALUES
('stroke_opacity', 'd:1;'),
('stroke_weight', 'i:2;'),
('units', 's:6:"metric";'),
('upload_maxsize', 'i:0;');
('upload_maxsize', 'i:5242880;');
-- --------------------------------------------------------

View File

@ -103,7 +103,7 @@ INSERT INTO `config` (`name`, `value`) VALUES
('stroke_opacity', 'd:1;'),
('stroke_weight', 'i:2;'),
('units', 's:6:"metric";'),
('upload_maxsize', 'i:0;');
('upload_maxsize', 'i:5242880;');
-- --------------------------------------------------------