Skip to content

Commit

Permalink
feat: drop comaptibility with GLPI 9.4
Browse files Browse the repository at this point in the history
Signed-off-by: Thierry Bugier <tbugier@teclib.com>
  • Loading branch information
btry committed Dec 1, 2020
1 parent 0bc3565 commit 7c48d03
Show file tree
Hide file tree
Showing 10 changed files with 23 additions and 238 deletions.
7 changes: 1 addition & 6 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,9 @@ jobs:
runs-on: "ubuntu-latest"
strategy:
matrix:
php-versions: [5.6, 7.4]
php-versions: [7.4]
env:
- { GLPI_BRANCH: 9.4/bugfixes, SKIP_FUNCTIONAL_TESTS: true }
- { GLPI_BRANCH: 9.5/bugfixes, SKIP_FUNCTIONAL_TESTS: false }
exclude:
- php-versions: 5.6
env:
GLPI_BRANCH: 9.5/bugfixes
services:
db:
image: mariadb:10.1
Expand Down
10 changes: 4 additions & 6 deletions inc/category.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,10 @@ public static function getCategoryTree($rootId = 0, $helpdeskHome = false) {
'faq' => '1',
'contains' => ''
]);
if (version_compare(GLPI_VERSION, "9.5") >= 0) {
// GLPI 9.5 returns an array
$subQuery = new DBMysqlIterator($DB);
$subQuery->buildQuery($query_faqs);
$query_faqs = $subQuery->getSQL();
}
// GLPI 9.5 returns an array
$subQuery = new DBMysqlIterator($DB);
$subQuery->buildQuery($query_faqs);
$query_faqs = $subQuery->getSQL();

$dbUtils = new DbUtils();
$entityRestrict = $dbUtils->getEntitiesRestrictCriteria($form_table, "", "", true, false);
Expand Down
13 changes: 1 addition & 12 deletions inc/common.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,7 @@ public static function getEnumValues($table, $field) {

$enum = [];
if ($res = $DB->query( "SHOW COLUMNS FROM `$table` WHERE Field = '$field'" )) {
if (version_compare(GLPI_VERSION, '9.5') >= 0) {
$fa = 'fetchArray';
} else {
$fa = 'fetch_array';
}
$data = $DB->$fa($res);
$data = $DB->fetchArray($res);
$type = $data['Type'];
$matches = null;
preg_match("/^enum\(\'(.*)\'\)$/", $type, $matches);
Expand Down Expand Up @@ -169,12 +164,6 @@ public static function getFontAwesomePictoNames() {
* @return string
*/
public static function getPictoFilename($version) {
if (version_compare($version, '9.4') < 0) {
return 'data/font-awesome_9.3.php';
}
if (version_compare($version, '9.5') < 0) {
return 'data/font-awesome_9.4.php';
}
if (version_compare($version, '9.6') < 0) {
return 'data/font-awesome_9.5.php';
}
Expand Down
16 changes: 0 additions & 16 deletions inc/field/textareafield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,6 @@ public function getRenderedHtml($canEdit = true) {
'enable_fileupload' => false,
'uploads' => $this->uploads,
]);
if (PLUGIN_FORMCREATOR_TEXTAREA_FIX && version_compare(GLPI_VERSION, '9.5.0-dev') < 0) {
// for GLPI 9.4 without patch https://github.com/glpi-project/glpi/pull/6936
$html .= '<div class="fileupload_info"></div>';
}
$html .= Html::scriptBlock("$(function() {
pluginFormcreatorInitializeTextarea('$fieldName', '$rand');
});");
Expand Down Expand Up @@ -162,18 +158,6 @@ public function hasInput($input) {
}

public function parseAnswerValues($input, $nonDestructive = false) {
if (PLUGIN_FORMCREATOR_TEXTAREA_FIX && version_compare(GLPI_VERSION, '9.5.0-dev') < 0) {
$input = $this->question->addFiles(
$input,
[
'force_update' => true,
'content_field' => 'formcreator_field_' . $this->question->getID(),
]
);

return parent::parseAnswerValues($input, $nonDestructive);
}

parent::parseAnswerValues($input, $nonDestructive);
$key = 'formcreator_field_' . $this->question->getID();
if (isset($input['_tag_' . $key]) && isset($input['_' . $key]) && isset($input['_prefix_' . $key])) {
Expand Down
179 changes: 11 additions & 168 deletions inc/field/timefield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,21 +58,12 @@ public function getDesignSpecializationField() {
$additions .= '</td>';
$additions .= '<td>';
$value = Html::entities_deep($this->question->fields['default_values']);
if (version_compare(GLPI_VERSION, '9.5') >= 0) {
$additions .= Html::showTimeField('default_values', [
'type' => 'text',
'id' => 'default_values',
'value' => $value,
'display' => false,
]);
} else {
$additions .= static::showTimeField('default_values', [
'type' => 'text',
'id' => 'default_values',
'value' => $value,
'display' => false,
]);
}
$additions .= Html::showTimeField('default_values', [
'type' => 'text',
'id' => 'default_values',
'value' => $value,
'display' => false,
]);
$additions .= '</td>';
$additions .= '<td></td>';
$additions .= '<td></td>';
Expand All @@ -99,20 +90,11 @@ public function getRenderedHtml($canEdit = true) {
$id = $this->question->getID();
$rand = mt_rand();
$fieldName = 'formcreator_field_' . $id;
if (version_compare(GLPI_VERSION, '9.5') >= 0) {
$html .= Html::showTimeField($fieldName, [
'value' => (strtotime($this->value) != '') ? $this->value : '',
'rand' => $rand,
'display' => false,
]);
} else {
// TODO : drop when GLPI 9.4 compatibility is dropped
$html .= static::showTimeField($fieldName, [
'value' => (strtotime($this->value) != '') ? $this->value : '',
'rand' => $rand,
'display' => false,
]);
}
$html .= Html::showTimeField($fieldName, [
'value' => (strtotime($this->value) != '') ? $this->value : '',
'rand' => $rand,
'display' => false,
]);
$html .= Html::scriptBlock("$(function() {
pluginFormcreatorInitializeTime('$fieldName', '$rand');
});");
Expand Down Expand Up @@ -221,145 +203,6 @@ public function isAnonymousFormCompatible() {
return true;
}

/**
* Display TimeField form
* @see Html::dateTime()
*
* @param string $name
* @param array $options
* - value : default value to display (default '')
* - timestep : step for time in minute (-1 use default config) (default -1)
* - maybeempty : may be empty ? (true by default)
* - canedit : could not modify element (true by default)
* - mintime : minimum allowed time (default '')
* - maxtime : maximum allowed time (default '')
* - display : boolean display or get string (default true)
* - rand : specific random value (default generated one)
* - required : required field (will add required attribute)
* @return void
*/
protected static function showTimeField($name, $options = []) {
global $CFG_GLPI;

$p = [];
$p['value'] = '';
$p['maybeempty'] = true;
$p['canedit'] = true;
$p['mintime'] = '';
$p['maxtime'] = '';
$p['timestep'] = -1;
$p['display'] = true;
$p['rand'] = mt_rand();
$p['required'] = false;

foreach ($options as $key => $val) {
if (isset($p[$key])) {
$p[$key] = $val;
}
}

if ($p['timestep'] < 0) {
$p['timestep'] = $CFG_GLPI['time_step'];
}

// Those vars are set but not used ...
// check Hml::showDateTimeField()

// $minHour = 0;
// $maxHour = 23;
// $minMinute = 0;
// $maxMinute = 59;

$hour_value = '';
if (!empty($p['value'])) {
$hour_value = $p['value'];
}

if (!empty($p['mintime'])) {
// list($minHour, $minMinute) = explode(':', $p['mintime']);
// $minMinute = 0;

// Check time in interval
if (!empty($hour_value) && ($hour_value < $p['mintime'])) {
$hour_value = $p['mintime'];
}
}

if (!empty($p['maxtime'])) {
// list($maxHour, $maxMinute) = explode(':', $p['maxtime']);
// $maxMinute = 59;

// Check time in interval
if (!empty($hour_value) && ($hour_value > $p['maxtime'])) {
$hour_value = $p['maxtime'];
}
}

// reconstruct value to be valid
if (!empty($hour_value)) {
$p['value'] = $hour_value;
}

$output = "<span class='no-wrap'>";
$output .= "<input id='showtime".$p['rand']."' type='text' name='_$name' value='".
trim($p['value'])."'";
if ($p['required'] == true) {
$output .= " required='required'";
}
$output .= ">";
$output .= Html::hidden($name, ['value' => $p['value'], 'id' => "hiddentime".$p['rand']]);
if ($p['maybeempty'] && $p['canedit']) {
$output .= "<span class='fa fa-times-circle pointer' title='".__s('Clear').
"' id='resettime".$p['rand']."'>" .
"<span class='sr-only'>" . __('Clear') . "</span></span>";
}
$output .= "</span>";

$js = "$(function(){";
if ($p['maybeempty'] && $p['canedit']) {
$js .= "$('#resettime".$p['rand']."').click(function(){
$('#showtime".$p['rand']."').val('');
$('#hiddentime".$p['rand']."').val('');
});";
}

$js .= "$( '#showtime".$p['rand']."' ).timepicker({
altField: '#hiddentime".$p['rand']."',
altFormat: 'yy-mm-dd',
altTimeFormat: 'HH:mm:ss',
pickerTimeFormat : 'HH:mm',
altFieldTimeOnly: false,
firstDay: 1,
parse: 'loose',
showAnim: '',
stepMinute: ".$p['timestep'].",
showSecond: false,
showOtherMonths: true,
selectOtherMonths: true,
showButtonPanel: true,
changeMonth: true,
changeYear: true,
showOn: 'both',
showWeek: true,
controlType: 'select',
buttonText: '<i class=\'far fa-calendar-alt\'></i>'";

if (!$p['canedit']) {
$js .= ",disabled: true";
}

$js .= ",timeFormat: 'HH:mm'";
$js .= "}).next('.ui-datepicker-trigger').addClass('pointer');";
$js .= "});";
$output .= Html::scriptBlock($js);

if ($p['display']) {
echo $output;
return $p['rand'];
}
return $output;
}

public function getHtmlIcon() {
return '<i class="fa fa-clock" aria-hidden="true"></i>';
}
Expand Down
8 changes: 3 additions & 5 deletions inc/form.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -944,11 +944,9 @@ public function showFormList($rootCategory = 0, $keywords = '', $helpdeskHome =
'faq' => '1',
'contains' => $keywords
]);
if (version_compare(GLPI_VERSION, "9.4") > 0) {
$subQuery = new DBMysqlIterator($DB);
$subQuery->buildQuery($query_faqs);
$query_faqs = '(' . $subQuery->getSQL() . ')';
}
$subQuery = new DBMysqlIterator($DB);
$subQuery->buildQuery($query_faqs);
$query_faqs = '(' . $subQuery->getSQL() . ')';

$query_faqs = [
'SELECT' => ['faqs' => '*'],
Expand Down
7 changes: 1 addition & 6 deletions inc/issue.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -215,12 +215,7 @@ public static function syncIssues() {
return 0;
}

if (version_compare(GLPI_VERSION, '9.5') < 0) {
$fa = 'fetch_assoc';
} else {
$fa = 'fetchAssoc';
}
$count = $DB->$fa($result);
$count = $DB->fetchAssoc($result);
$table = static::getTable();
if (countElementsInTable($table) == $count['cpt']) {
return 0;
Expand Down
2 changes: 1 addition & 1 deletion setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
define('PLUGIN_FORMCREATOR_IS_OFFICIAL_RELEASE', false);

// Minimal GLPI version, inclusive
define ('PLUGIN_FORMCREATOR_GLPI_MIN_VERSION', '9.4');
define ('PLUGIN_FORMCREATOR_GLPI_MIN_VERSION', '9.5');
// Maximum GLPI version, exclusive (ignored if PLUGIN_FORMCREATOR_IS_OFFICIAL_RELEASE == false)
define ('PLUGIN_FORMCREATOR_GLPI_MAX_VERSION', '9.6');

Expand Down
12 changes: 0 additions & 12 deletions tests/3-unit/PluginFormcreatorCommon.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,18 +64,6 @@ public function testSetNotification() {

public function providerGetPictoFilename() {
return [
[
'version' => '9.3.0',
'expected' => 'data/font-awesome_9.3.php',
],
[
'version' => '9.3.1',
'expected' => 'data/font-awesome_9.3.php',
],
[
'version' => '9.4.0',
'expected' => 'data/font-awesome_9.4.php',
],
[
'version' => '9.5.0',
'expected' => 'data/font-awesome_9.5.php',
Expand Down
7 changes: 1 addition & 6 deletions tests/5-uninstall/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,7 @@ public function testUninstallPlugin() {
// Check all plugin's tables are dropped
$tables = [];
$result = $DB->query("SHOW TABLES LIKE 'glpi_plugin_" . $pluginName . "_%'");
if (version_compare(GLPI_VERSION, '9.5') < 0) {
$fa = 'fetch_assoc';
} else {
$fa = 'fetchAssoc';
}
while ($row = $DB->$fa($result)) {
while ($row = $DB->fetchAssoc($result)) {
$tables[] = array_pop($row);
}
$this->integer(count($tables))->isEqualTo(0, "not deleted tables \n" . json_encode($tables, JSON_PRETTY_PRINT));
Expand Down

0 comments on commit 7c48d03

Please sign in to comment.