From a804e2b5cc46e976af75c661c20dd1ec6cc83a41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Anne?= Date: Thu, 21 Apr 2022 10:47:05 +0200 Subject: [PATCH] GLPI 10.0 compatibility * Permit installation on GLPI 10.0.x * Remove dead code referencing removed method * Fix showForm() signature * Use same PHP minimal version as GLPI core; upgrade build libs * Remove deprecated usage of integer display width * Use default GLPI charset/collation during install/update * Force database dynamic row format * Fix files mode * Update compatibility in XML * Use default sign on primary/foreign keys --- AUTHORS.txt | 0 composer.json | 4 ++-- config.php | 0 example.xml | 2 +- front/example.php | 0 hook.php | 53 +++++++++++++++++++++++-------------------- inc/example.class.php | 2 +- setup.php | 4 ++-- 8 files changed, 34 insertions(+), 31 deletions(-) mode change 100755 => 100644 AUTHORS.txt mode change 100755 => 100644 config.php mode change 100755 => 100644 front/example.php mode change 100755 => 100644 setup.php diff --git a/AUTHORS.txt b/AUTHORS.txt old mode 100755 new mode 100644 diff --git a/composer.json b/composer.json index 3638ad6..80f27e8 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "require": { - "php": "^7.2" + "php": ">=7.4" }, "require-dev": { "glpi-project/tools": "^0.4" @@ -8,7 +8,7 @@ "config": { "optimize-autoloader": true, "platform": { - "php": "7.2.0" + "php": "7.4.0" }, "sort-packages": true } diff --git a/config.php b/config.php old mode 100755 new mode 100644 diff --git a/example.xml b/example.xml index 3142e81..583311c 100644 --- a/example.xml +++ b/example.xml @@ -26,7 +26,7 @@ 0.0.1 - 9.5 + ~10.0.0 diff --git a/front/example.php b/front/example.php old mode 100755 new mode 100644 diff --git a/hook.php b/hook.php index 85e557a..197ee2d 100644 --- a/hook.php +++ b/hook.php @@ -295,7 +295,6 @@ function plugin_example_MassiveActionsFieldsDisplay($options = []) { switch ($table.".".$field) { case 'glpi_plugin_example_examples.serial' : echo __("Not really specific - Just for example", 'example'); - //Html::autocompletionTextField($linkfield,$table,$field); // Dropdown::showYesNo($linkfield); // Need to return true if specific display return true; @@ -471,17 +470,21 @@ function plugin_example_install() { ProfileRight::addProfileRights(['example:read']); + $default_charset = DBConnection::getDefaultCharset(); + $default_collation = DBConnection::getDefaultCollation(); + $default_key_sign = DBConnection::getDefaultPrimaryKeySignOption(); + if (!$DB->tableExists("glpi_plugin_example_examples")) { $query = "CREATE TABLE `glpi_plugin_example_examples` ( - `id` int(11) NOT NULL auto_increment, - `name` varchar(255) collate utf8_unicode_ci default NULL, - `serial` varchar(255) collate utf8_unicode_ci NOT NULL, - `plugin_example_dropdowns_id` int(11) NOT NULL default '0', - `is_deleted` tinyint(1) NOT NULL default '0', - `is_template` tinyint(1) NOT NULL default '0', - `template_name` varchar(255) collate utf8_unicode_ci default NULL, + `id` int {$default_key_sign} NOT NULL auto_increment, + `name` varchar(255) default NULL, + `serial` varchar(255) NOT NULL, + `plugin_example_dropdowns_id` int NOT NULL default '0', + `is_deleted` tinyint NOT NULL default '0', + `is_template` tinyint NOT NULL default '0', + `template_name` varchar(255) default NULL, PRIMARY KEY (`id`) - ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci"; + ) ENGINE=InnoDB DEFAULT CHARSET={$default_charset} COLLATE={$default_collation} ROW_FORMAT=DYNAMIC;"; $DB->query($query) or die("error creating glpi_plugin_example_examples ". $DB->error()); @@ -496,12 +499,12 @@ function plugin_example_install() { if (!$DB->tableExists("glpi_plugin_example_dropdowns")) { $query = "CREATE TABLE `glpi_plugin_example_dropdowns` ( - `id` int(11) NOT NULL auto_increment, - `name` varchar(255) collate utf8_unicode_ci default NULL, - `comment` text collate utf8_unicode_ci, + `id` int {$default_key_sign} NOT NULL auto_increment, + `name` varchar(255) default NULL, + `comment` text, PRIMARY KEY (`id`), KEY `name` (`name`) - ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci"; + ) ENGINE=InnoDB DEFAULT CHARSET={$default_charset} COLLATE={$default_collation} ROW_FORMAT=DYNAMIC;"; $DB->query($query) or die("error creating glpi_plugin_example_dropdowns". $DB->error()); @@ -516,32 +519,32 @@ function plugin_example_install() { if (!$DB->tableExists('glpi_plugin_example_devicecameras')) { $query = "CREATE TABLE `glpi_plugin_example_devicecameras` ( - `id` int(11) NOT NULL AUTO_INCREMENT, - `designation` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, - `comment` text COLLATE utf8_unicode_ci, - `manufacturers_id` int(11) NOT NULL DEFAULT '0', + `id` int {$default_key_sign} NOT NULL AUTO_INCREMENT, + `designation` varchar(255) DEFAULT NULL, + `comment` text, + `manufacturers_id` int {$default_key_sign} NOT NULL DEFAULT '0', PRIMARY KEY (`id`), KEY `designation` (`designation`), KEY `manufacturers_id` (`manufacturers_id`) - ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci"; + ) ENGINE=InnoDB DEFAULT CHARSET={$default_charset} COLLATE={$default_collation} ROW_FORMAT=DYNAMIC;"; $DB->query($query) or die("error creating glpi_plugin_example_examples ". $DB->error()); } if (!$DB->tableExists('glpi_plugin_example_items_devicecameras')) { $query = "CREATE TABLE `glpi_plugin_example_items_devicecameras` ( - `id` int(11) NOT NULL AUTO_INCREMENT, - `items_id` int(11) NOT NULL DEFAULT '0', - `itemtype` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, - `plugin_example_devicecameras_id` int(11) NOT NULL DEFAULT '0', - `is_deleted` tinyint(1) NOT NULL DEFAULT '0', - `is_dynamic` tinyint(1) NOT NULL DEFAULT '0', + `id` int {$default_key_sign} NOT NULL AUTO_INCREMENT, + `items_id` int {$default_key_sign} NOT NULL DEFAULT '0', + `itemtype` varchar(255) DEFAULT NULL, + `plugin_example_devicecameras_id` int {$default_key_sign} NOT NULL DEFAULT '0', + `is_deleted` tinyint NOT NULL DEFAULT '0', + `is_dynamic` tinyint NOT NULL DEFAULT '0', PRIMARY KEY (`id`), KEY `computers_id` (`items_id`), KEY `plugin_example_devicecameras_id` (`plugin_example_devicecameras_id`), KEY `is_deleted` (`is_deleted`), KEY `is_dynamic` (`is_dynamic`) - ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci"; + ) ENGINE=InnoDB DEFAULT CHARSET={$default_charset} COLLATE={$default_collation} ROW_FORMAT=DYNAMIC;"; $DB->query($query) or die("error creating glpi_plugin_example_examples ". $DB->error()); } diff --git a/inc/example.class.php b/inc/example.class.php index db7690c..c7b9016 100644 --- a/inc/example.class.php +++ b/inc/example.class.php @@ -94,7 +94,7 @@ class PluginExampleExample extends CommonDBTM { return $ong; } - function showForm($ID, $options = []) { + function showForm($ID, array $options = []) { global $CFG_GLPI; $this->initForm($ID, $options); diff --git a/setup.php b/setup.php old mode 100755 new mode 100644 index 66af1a4..33f5ae9 --- a/setup.php +++ b/setup.php @@ -33,9 +33,9 @@ use Glpi\Plugin\Hooks; define('PLUGIN_EXAMPLE_VERSION', '0.0.1'); // Minimal GLPI version, inclusive -define('PLUGIN_EXAMPLE_MIN_GLPI', '9.5.0'); +define('PLUGIN_EXAMPLE_MIN_GLPI', '10.0.0'); // Maximum GLPI version, exclusive -define('PLUGIN_EXAMPLE_MAX_GLPI', '9.5.99'); +define('PLUGIN_EXAMPLE_MAX_GLPI', '10.0.99'); /** * Init hooks of the plugin.