From c025914999d6e2aa308ed72040d6ec3b29be8e71 Mon Sep 17 00:00:00 2001 From: Johan Cwiklinski Date: Thu, 28 Mar 2024 13:45:32 +0100 Subject: [PATCH] Use bigint for disks size (#16845) * Use bigint for disks size closes #16844 * Add unit sizes --- .../update_10.0.4_to_10.0.5/items_disks.php | 41 +++++++++++++++++++ install/mysql/glpi-empty.sql | 4 +- src/Toolbox.php | 2 +- tests/functional/Toolbox.php | 13 +++--- 4 files changed, 52 insertions(+), 8 deletions(-) create mode 100644 install/migrations/update_10.0.4_to_10.0.5/items_disks.php diff --git a/install/migrations/update_10.0.4_to_10.0.5/items_disks.php b/install/migrations/update_10.0.4_to_10.0.5/items_disks.php new file mode 100644 index 00000000000..caa27093836 --- /dev/null +++ b/install/migrations/update_10.0.4_to_10.0.5/items_disks.php @@ -0,0 +1,41 @@ +. + * + * --------------------------------------------------------------------- + */ + +/** + * @var \Migration $migration + */ + +$migration->changeField('glpi_items_disks', 'totalsize', 'totalsize', 'bigint NOT NULL DEFAULT "0"'); +$migration->changeField('glpi_items_disks', 'freesize', 'freesize', 'bigint NOT NULL DEFAULT "0"'); diff --git a/install/mysql/glpi-empty.sql b/install/mysql/glpi-empty.sql index de86c586085..038c9250085 100644 --- a/install/mysql/glpi-empty.sql +++ b/install/mysql/glpi-empty.sql @@ -900,8 +900,8 @@ CREATE TABLE `glpi_items_disks` ( `device` varchar(255) DEFAULT NULL, `mountpoint` varchar(255) DEFAULT NULL, `filesystems_id` int unsigned NOT NULL DEFAULT '0', - `totalsize` int NOT NULL DEFAULT '0', - `freesize` int NOT NULL DEFAULT '0', + `totalsize` bigint NOT NULL DEFAULT '0', + `freesize` bigint NOT NULL DEFAULT '0', `is_deleted` tinyint NOT NULL DEFAULT '0', `is_dynamic` tinyint NOT NULL DEFAULT '0', `encryption_status` int NOT NULL DEFAULT '0', diff --git a/src/Toolbox.php b/src/Toolbox.php index 9dcd1e5ac58..6f7f74b9148 100644 --- a/src/Toolbox.php +++ b/src/Toolbox.php @@ -974,7 +974,7 @@ public static function getSize($size) { //TRANS: list of unit (o for octet) - $bytes = [__('o'), __('Kio'), __('Mio'), __('Gio'), __('Tio')]; + $bytes = [__('o'), __('Kio'), __('Mio'), __('Gio'), __('Tio'), __('Pio'), __('Eio'), __('Zio'), __('Yio')]; foreach ($bytes as $val) { if ($size > 1024) { $size = $size / 1024; diff --git a/tests/functional/Toolbox.php b/tests/functional/Toolbox.php index f91b5a84741..911af81e74c 100644 --- a/tests/functional/Toolbox.php +++ b/tests/functional/Toolbox.php @@ -144,11 +144,14 @@ public function testFilename($name, $expected) public function dataGetSize() { return [ - [1, '1 o'], - [1025, '1 Kio'], - [1100000, '1.05 Mio'], - [1100000000, '1.02 Gio'], - [1100000000000, '1 Tio'], + [1, '1 o'], + [1025, '1 Kio'], + [1100000, '1.05 Mio'], + [1100000000, '1.02 Gio'], + [1100000000000, '1 Tio'], + [1100000000000 * 1024, '1 Pio'], + [1100000000000 * 1024 * 1024, '1 Eio'], + [1100000000000 * 1024 * 1024 * 1024, '1 Zio'], ]; }