Skip to content

Commit

Permalink
Compatible with GLPI 9.4
Browse files Browse the repository at this point in the history
  • Loading branch information
tomolimo committed Aug 9, 2019
1 parent 3fca030 commit 9d560b4
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 24 deletions.
12 changes: 6 additions & 6 deletions hook.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,22 +82,22 @@ function plugin_timezones_install() {
return true;
}


/**
* Summary of convertDB
* @param mixed $echo
* @return boolean true if success, else will die
*/
function convertDB($echo = false) {
function convertDB($echo = false, $res = null) {
global $DB;

$now = date('Y-m-d H:i:s' );

// we are going to update datetime, date and time (?) types to timestamp type
$query = "SELECT DISTINCT( `INFORMATION_SCHEMA`.`COLUMNS`.`TABLE_NAME` ), TABLE_TYPE from `INFORMATION_SCHEMA`.`COLUMNS`
JOIN `INFORMATION_SCHEMA`.`TABLES` ON `INFORMATION_SCHEMA`.`TABLES`.`TABLE_NAME` = `INFORMATION_SCHEMA`.`COLUMNS`.`TABLE_NAME` AND `INFORMATION_SCHEMA`.`TABLES`.`TABLE_TYPE` = 'BASE TABLE'
WHERE `INFORMATION_SCHEMA`.`COLUMNS`.TABLE_SCHEMA = '".$DB->dbdefault."' AND `INFORMATION_SCHEMA`.`COLUMNS`.`COLUMN_TYPE` IN ('DATETIME') ; ";
if (!$res) {
$res = needConvert();
}

foreach ($DB->request($query) as $table) {
foreach ($res as $table) {
$tablealter = $tablebackup = ''; // init by default

// get table create code to get accurate table definition for backup purpose
Expand Down
7 changes: 5 additions & 2 deletions inc/user.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,11 @@ static function getTimezones() {
$tz = []; //default $tz is empty
$phpTimezones = DateTimeZone::listIdentifiers();
$now = new DateTime;
$query = "SELECT Name FROM mysql.time_zone_name";
foreach ($DB->request( $query ) as $mySQLTimezone) {
$res = $DB->request([
'SELECT' => 'Name',
'FROM' => 'mysql.time_zone_name'
]);
foreach ($res as $mySQLTimezone) {
if (in_array( $mySQLTimezone['Name'], $phpTimezones )) {
$now->setTimezone( new DateTimeZone( $mySQLTimezone['Name'] ) );
$tz[ $mySQLTimezone['Name'] ] = $mySQLTimezone['Name'] . $now->format( " (T P)" );
Expand Down
3 changes: 3 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ GLPI: 9.2 | PHP: 5, 7 | locales: en, fr, ru, cs
Version 2.4.0
GLPI: 9.3 | PHP: 5, 7 | locales: en, fr, ru, cs

Version 2.5.0
GLPI: 9.4 | PHP: 5, 7 | locales: en, fr, ru, cs

## Installation procedure:
Like any other GLPI plugin: you must copy the package to the plugins folder.

Expand Down
22 changes: 17 additions & 5 deletions scripts/migratetasks.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,26 @@
// it has to be done only for 'on call' tasks

// first we need to get the sons of Task Category 'on call' which has ID == 2 in order to build SQL query
$query = "SELECT sons_cache from glpi_taskcategories where id=2;";
$res = $DB->query( $query );
if ($res && $DB->numrows( $res ) > 0) {
$row = $DB->fetch_assoc( $res );
$res = $DB->request([
'SELECT' => 'sons_cache',
'FROM' => 'glpi_taskcategories',
'WHERE' => ['id' => 2]
]);
//$query = "SELECT sons_cache from glpi_taskcategories where id=2;";
//$res = $DB->query( $query );
//if ($res && $DB->numrows( $res ) > 0) {
if ($res && $res->numrows() > 0) {
//$row = $DB->fetch_assoc( $res );
$row = $res->next();
$cat = importArrayFromDB($row['sons_cache']);

// then build query to get 'On call' tasks
$query = "SELECT * FROM glpi_tickettasks WHERE taskcategories_id IN ( ".implode(',', $cat)." );";
//$query = "SELECT * FROM glpi_tickettasks WHERE taskcategories_id IN ( ".implode(',', $cat)." );";
$res = $DB->request(
'glpi_tickettasks',
[
'taskcategories' => $cat
]);
//TODO
}

Expand Down
36 changes: 25 additions & 11 deletions setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
// Original Author of file: Olivier Moron
// Purpose of file: to setup time zone management plugin to GLPI
// ----------------------------------------------------------------------
define ("PLUGIN_TIMEZONES_VERSION", "2.4.1");
define ("PLUGIN_TIMEZONES_VERSION", "2.5.1");

/**
* Summary of plugin_init_timezones
Expand Down Expand Up @@ -115,6 +115,28 @@ function plugin_timezones_check_prerequisites() {
}


/**
* Summary of needConvert
* @return boolean|DBmysqlIterator
*/
function needConvert() {
global $DB;
$query = "SELECT `INFORMATION_SCHEMA`.`COLUMNS`.`COLUMN_NAME` from `INFORMATION_SCHEMA`.`COLUMNS`
WHERE `INFORMATION_SCHEMA`.`COLUMNS`.TABLE_SCHEMA = '".$DB->dbdefault."' AND `INFORMATION_SCHEMA`.`COLUMNS`.`COLUMN_TYPE` IN ('DATETIME') ;";
$res = $DB->request( $query );
if ($res->numrows() > 0) {
$query = "SELECT DISTINCT( `INFORMATION_SCHEMA`.`COLUMNS`.`TABLE_NAME` ), TABLE_TYPE from `INFORMATION_SCHEMA`.`COLUMNS`
JOIN `INFORMATION_SCHEMA`.`TABLES` ON `INFORMATION_SCHEMA`.`TABLES`.`TABLE_NAME` = `INFORMATION_SCHEMA`.`COLUMNS`.`TABLE_NAME` AND `INFORMATION_SCHEMA`.`TABLES`.`TABLE_TYPE` = 'BASE TABLE'
WHERE `INFORMATION_SCHEMA`.`COLUMNS`.TABLE_SCHEMA = '".$DB->dbdefault."' AND `INFORMATION_SCHEMA`.`COLUMNS`.`COLUMN_TYPE` IN ('DATETIME') ; ";
$res = $DB->request( $query );
if ($res->numrows() > 0) {
return $res;
}
}
return false;
}


/**
* Summary of plugin_timezones_check_config
* @param mixed $verbose
Expand All @@ -126,18 +148,10 @@ function plugin_timezones_check_config($verbose = false) {
$plug = new Plugin;
if ($plug->isActivated('timezones')) {
// check if all datetime fields of the glpi db have been converted to timestamp otherwise, timezone management can't be done correctly
$query = "SELECT DISTINCT( `INFORMATION_SCHEMA`.`COLUMNS`.`TABLE_NAME` ), TABLE_TYPE from `INFORMATION_SCHEMA`.`COLUMNS`
JOIN `INFORMATION_SCHEMA`.`TABLES` ON `INFORMATION_SCHEMA`.`TABLES`.`TABLE_NAME` = `INFORMATION_SCHEMA`.`COLUMNS`.`TABLE_NAME` AND `INFORMATION_SCHEMA`.`TABLES`.`TABLE_TYPE` = 'BASE TABLE'
WHERE `INFORMATION_SCHEMA`.`COLUMNS`.TABLE_SCHEMA = '".$DB->dbdefault."' AND `INFORMATION_SCHEMA`.`COLUMNS`.`COLUMN_TYPE` IN ('DATETIME') ; ";
$res = $DB->query( $query );
if ($DB->numrows( $res ) > 0) {
if ($res = needConvert()) {
// will convert during GLPI execution any DATETIME fields that may have been added
include_once 'hook.php';
convertDB($verbose);
//if ($verbose) {
// echo $LANG['timezones']['dbnotconverted'];
//}
//return false;
convertDB($verbose, $res);
}
}

Expand Down
4 changes: 4 additions & 0 deletions timezones.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@
<author>Olivier Moron</author>
</authors>
<versions>
<version>
<num>2.5.1</num>
<compatibility>9.4</compatibility>
</version>
<version>
<num>2.4.1</num>
<compatibility>9.3</compatibility>
Expand Down

0 comments on commit 9d560b4

Please sign in to comment.