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

@ -40,9 +40,9 @@ DROP TABLE IF EXISTS `ol_layers`;
--
CREATE TABLE `users` (
`id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
`login` varchar(15) CHARACTER SET latin1 NOT NULL UNIQUE,
`password` varchar(255) CHARACTER SET latin1 NOT NULL DEFAULT ''
`id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
`login` varchar(15) CHARACTER SET latin1 NOT NULL UNIQUE,
`password` varchar(255) CHARACTER SET latin1 NOT NULL DEFAULT ''
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- --------------------------------------------------------
@ -52,12 +52,12 @@ CREATE TABLE `users` (
--
CREATE TABLE `tracks` (
`id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
`user_id` int(11) NOT NULL,
`name` varchar(255) DEFAULT NULL,
`comment` varchar(1024) DEFAULT NULL,
INDEX `idx_user_id` (`user_id`),
FOREIGN KEY(`user_id`) REFERENCES `users`(`id`)
`id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
`user_id` int(11) NOT NULL,
`name` varchar(255) DEFAULT NULL,
`comment` varchar(1024) DEFAULT NULL,
INDEX `idx_user_id` (`user_id`),
FOREIGN KEY(`user_id`) REFERENCES `users`(`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- --------------------------------------------------------
@ -67,21 +67,21 @@ CREATE TABLE `tracks` (
--
CREATE TABLE `positions` (
`id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
`time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`user_id` int(11) NOT NULL,
`track_id` int(11) NOT NULL,
`latitude` double NOT NULL,
`longitude` double NOT NULL,
`altitude` double DEFAULT NULL,
`speed` double DEFAULT NULL,
`bearing` double DEFAULT NULL,
`accuracy` int(11) DEFAULT NULL,
`provider` varchar(100) DEFAULT NULL,
`comment` varchar(255) DEFAULT NULL,
`image_id` int(11) DEFAULT NULL,
INDEX `idx_ptrack_id` (`track_id`),
INDEX `index_puser_id` (`user_id`),
FOREIGN KEY(`user_id`) REFERENCES `users`(`id`),
FOREIGN KEY(`track_id`) REFERENCES `tracks`(`id`)
`id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
`time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`user_id` int(11) NOT NULL,
`track_id` int(11) NOT NULL,
`latitude` double NOT NULL,
`longitude` double NOT NULL,
`altitude` double DEFAULT NULL,
`speed` double DEFAULT NULL,
`bearing` double DEFAULT NULL,
`accuracy` int(11) DEFAULT NULL,
`provider` varchar(100) DEFAULT NULL,
`comment` varchar(255) DEFAULT NULL,
`image_id` int(11) DEFAULT NULL,
INDEX `idx_ptrack_id` (`track_id`),
INDEX `index_puser_id` (`user_id`),
FOREIGN KEY(`user_id`) REFERENCES `users`(`id`),
FOREIGN KEY(`track_id`) REFERENCES `tracks`(`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

View File

@ -40,9 +40,9 @@ DROP TABLE IF EXISTS ol_layers;
--
CREATE TABLE users (
id serial PRIMARY KEY,
login varchar(15) NOT NULL UNIQUE,
password varchar(255) NOT NULL DEFAULT ''
id serial PRIMARY KEY,
login varchar(15) NOT NULL UNIQUE,
password varchar(255) NOT NULL DEFAULT ''
);
-- --------------------------------------------------------
@ -52,11 +52,11 @@ CREATE TABLE users (
--
CREATE TABLE tracks (
id serial PRIMARY KEY,
user_id int NOT NULL,
name varchar(255) DEFAULT NULL,
comment varchar(1024) DEFAULT NULL,
FOREIGN KEY(user_id) REFERENCES users(id)
id serial PRIMARY KEY,
user_id int NOT NULL,
name varchar(255) DEFAULT NULL,
comment varchar(1024) DEFAULT NULL,
FOREIGN KEY(user_id) REFERENCES users(id)
);
CREATE INDEX idx_user_id ON tracks(user_id);
@ -68,21 +68,21 @@ CREATE INDEX idx_user_id ON tracks(user_id);
--
CREATE TABLE positions (
id serial PRIMARY KEY,
time timestamp(0) NOT NULL DEFAULT CURRENT_TIMESTAMP,
user_id int NOT NULL,
track_id int NOT NULL,
latitude double precision NOT NULL,
longitude double precision NOT NULL,
altitude double precision DEFAULT NULL,
speed double precision DEFAULT NULL,
bearing double precision DEFAULT NULL,
accuracy int DEFAULT NULL,
provider varchar(100) DEFAULT NULL,
comment varchar(255) DEFAULT NULL,
image_id int DEFAULT NULL,
FOREIGN KEY(user_id) REFERENCES users(id),
FOREIGN KEY(track_id) REFERENCES tracks(id)
id serial PRIMARY KEY,
time timestamp(0) NOT NULL DEFAULT CURRENT_TIMESTAMP,
user_id int NOT NULL,
track_id int NOT NULL,
latitude double precision NOT NULL,
longitude double precision NOT NULL,
altitude double precision DEFAULT NULL,
speed double precision DEFAULT NULL,
bearing double precision DEFAULT NULL,
accuracy int DEFAULT NULL,
provider varchar(100) DEFAULT NULL,
comment varchar(255) DEFAULT NULL,
image_id int DEFAULT NULL,
FOREIGN KEY(user_id) REFERENCES users(id),
FOREIGN KEY(track_id) REFERENCES tracks(id)
);
CREATE INDEX idx_ptrack_id ON positions(track_id);

View File

@ -40,9 +40,9 @@ DROP TABLE IF EXISTS `ol_layers`;
--
CREATE TABLE `users` (
`id` integer PRIMARY KEY AUTOINCREMENT,
`login` varchar(15) NOT NULL UNIQUE,
`password` varchar(255) NOT NULL DEFAULT ''
`id` integer PRIMARY KEY AUTOINCREMENT,
`login` varchar(15) NOT NULL UNIQUE,
`password` varchar(255) NOT NULL DEFAULT ''
);
-- --------------------------------------------------------
@ -52,11 +52,11 @@ CREATE TABLE `users` (
--
CREATE TABLE `tracks` (
`id` integer PRIMARY KEY AUTOINCREMENT,
`user_id` integer NOT NULL,
`name` varchar(255) DEFAULT NULL,
`comment` varchar(1024) DEFAULT NULL,
FOREIGN KEY(`user_id`) REFERENCES `users`(`id`)
`id` integer PRIMARY KEY AUTOINCREMENT,
`user_id` integer NOT NULL,
`name` varchar(255) DEFAULT NULL,
`comment` varchar(1024) DEFAULT NULL,
FOREIGN KEY(`user_id`) REFERENCES `users`(`id`)
);
CREATE INDEX `idx_user_id` ON `tracks`(`user_id`);
@ -67,21 +67,21 @@ CREATE INDEX `idx_user_id` ON `tracks`(`user_id`);
--
CREATE TABLE `positions` (
`id` integer PRIMARY KEY AUTOINCREMENT,
`time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`user_id` integer NOT NULL,
`track_id` integer NOT NULL,
`latitude` double NOT NULL,
`longitude` double NOT NULL,
`altitude` double DEFAULT NULL,
`speed` double DEFAULT NULL,
`bearing` double DEFAULT NULL,
`accuracy` integer DEFAULT NULL,
`provider` varchar(100) DEFAULT NULL,
`comment` varchar(255) DEFAULT NULL,
`image_id` integer DEFAULT NULL,
FOREIGN KEY(`user_id`) REFERENCES `users`(`id`),
FOREIGN KEY(`track_id`) REFERENCES `tracks`(`id`)
`id` integer PRIMARY KEY AUTOINCREMENT,
`time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`user_id` integer NOT NULL,
`track_id` integer NOT NULL,
`latitude` double NOT NULL,
`longitude` double NOT NULL,
`altitude` double DEFAULT NULL,
`speed` double DEFAULT NULL,
`bearing` double DEFAULT NULL,
`accuracy` integer DEFAULT NULL,
`provider` varchar(100) DEFAULT NULL,
`comment` varchar(255) DEFAULT NULL,
`image_id` integer DEFAULT NULL,
FOREIGN KEY(`user_id`) REFERENCES `users`(`id`),
FOREIGN KEY(`track_id`) REFERENCES `tracks`(`id`)
);
CREATE INDEX `idx_ptrack_id` ON `positions`(`track_id`);
CREATE INDEX `idx_puser_id` ON `positions`(`user_id`);

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,9 +428,17 @@ 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;');
-- --------------------------------------------------------