Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding some missing asset injection classes #361

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions README_WP.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

Datainjection changes WP:
* cron-schedulable in automatic action, with 2 parameters CSV and Enabled Y/N
* added diskinjection and vm injection
* additional code in SoftwareVersionInjection and Iten_softwareversioninjection to make it work

PHP files changed

Setup: version, register Diskinjection and VMinjection

Hook: db csvfilename, enable_scheduled_injection
Register PluginDatainjectionCron
Disable uninstall with return true;
softwareversionversioninjection: ADD processAfterInsertOrUpdate

model: add getter function getCSVFilename, getEnableScheduledInjection
Rawsearchoptions array_merge, cron forms show, WP -- if (!$webservice && !$unique_filename)

Item_SoftwareVersionInjection: added processAfterInsertOrUpdate

New Files:
+++item_diskinjection+++
+++cron.class+++
+++computervirtualmachineinjection+++


25 changes: 23 additions & 2 deletions hook.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ function plugin_datainjection_install() {
`float_format` tinyint NOT NULL DEFAULT '0',
`port_unicity` tinyint NOT NULL DEFAULT '0',
`step` int NOT NULL DEFAULT '0',
`csvfilename` VARCHAR(255) NOT NULL DEFAULT '',
`enable_scheduled_injection` tinyint NOT NULL DEFAULT 0,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET={$default_charset} COLLATE={$default_collation} ROW_FORMAT=DYNAMIC;";
$DB->queryOrDie($query, $DB->error());
Expand Down Expand Up @@ -193,9 +195,25 @@ function plugin_datainjection_install() {

default :
break;
}
}

// Register crontask DataInjection

return true;
$cron = new CronTask ();

if (! $cron->getFromDBbyName ( 'PluginDatainjectionCron', 'DataInjection' )) {
CronTask::Register ( 'PluginDatainjectionCron', 'DataInjection', DAY_TIMESTAMP, // 86400 sec
[ // 'allowmode', 'comment', 'hourmax', 'hourmin', 'logs_lifetime', 'mode', 'param', 'state'
'state' => CronTask::STATE_DISABLE,
'comment' => 'File injection from CSV with defined models',
'mode' => CronTask::MODE_EXTERNAL,
'hourmin' => '3',
'hourmax' => '8'
] );
}


return true;
}


Expand All @@ -220,6 +238,9 @@ function plugin_datainjection_uninstall() {
}

plugin_init_datainjection();

CronTask::Unregister('PluginDatainjectionCron');

return true;
}

Expand Down
170 changes: 170 additions & 0 deletions inc/computervirtualmachineinjection.class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
<?php

/**
* -------------------------------------------------------------------------
* DataInjection plugin for GLPI
* -------------------------------------------------------------------------
*
* LICENSE
*
* This file is part of DataInjection.
*
* DataInjection is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* DataInjection is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with DataInjection. If not, see <http://www.gnu.org/licenses/>.
* -------------------------------------------------------------------------
@author Wuerth Phoenix
@copyright Copyright (c) 2010-2013 Datainjection plugin team
@copyright Copyright (C) 2017-2022 Wuerth Phoenix, http://www.wuerth-phoenix.com
@license GPLv2+
http://www.gnu.org/licenses/gpl.txt
@link https://forge.indepnet.net/projects/datainjection
@link http://www.glpi-project.org/
@since 2009
---------------------------------------------------------------------- */

if (!defined('GLPI_ROOT')) {
die("Sorry. You can't access directly to this file");
}

class PluginDatainjectionComputerVirtualMachineInjection extends ComputerVirtualMachine //MOMI from Item_Diskinjection !!
implements PluginDatainjectionInjectionInterface {


static function getTable($classname = null) {

$parenttype = get_parent_class();
return $parenttype::getTable();
}


function isPrimaryType() {
return true;
}


function connectedTo() {
return array('Computer');
}

/**
* @see plugins/datainjection/inc/PluginDatainjectionInjectionInterface::getOptions()
**/
function getOptions($primary_type='') {

$tab = Search::getOptions(get_parent_class($this));

#these have to be added here because they are defined only in rawSearchOptionsToAdd!
# -- put id as tab[id] and add linkfield.
$tab[161] = [
'table' => 'glpi_virtualmachinestates',
'field' => 'name',
'name' => __('State'),
'forcegroupby' => true,
'massiveaction' => false,
'datatype' => 'dropdown',
'joinparams' => [
'beforejoin' => [
'table' => self::getTable(),
'joinparams' => [
'jointype' => 'child'
]
]
],
'linkfield' => 'virtualmachinestates_id'
];

$tab[162] = [
'table' => 'glpi_virtualmachinesystems',
'field' => 'name',
'name' => VirtualMachineSystem::getTypeName(1),
'forcegroupby' => true,
'massiveaction' => false,
'datatype' => 'dropdown',
'joinparams' => [
'beforejoin' => [
'table' => self::getTable(),
'joinparams' => [
'jointype' => 'child'
]
]
],
'linkfield' => 'virtualmachinesystems_id'
];

$tab[163] = [
'table' => 'glpi_virtualmachinetypes',
'field' => 'name',
'name' => VirtualMachineType::getTypeName(1),
'datatype' => 'dropdown',
'forcegroupby' => true,
'massiveaction' => false,
'joinparams' => [
'beforejoin' => [
'table' => self::getTable(),
'joinparams' => [
'jointype' => 'child'
]
]
],
'linkfield' => 'virtualmachinetypes_id'
];

//Remove some options because some fields cannot be imported
$blacklist = array();# = PluginDatainjectionCommonInjectionLib::getBlacklistedOptions(get_parent_class($this));
$notimportable = array();

$options['ignore_fields'] = array_merge($blacklist, $notimportable);
$options['displaytype'] = ["dropdown" => [161, 162, 163]];

return PluginDatainjectionCommonInjectionLib::addToSearchOptions($tab, $options, $this);
}

/**
* @param $primary_type
* @param $values
**/
function addSpecificNeededFields($primary_type, $values) {

$fields = [];
if ($primary_type == 'Computer') {
$fields['computers_id'] = $values[$primary_type]['id'];
}
return $fields;
}

/**
* @param $fields_toinject array
* @param $options array
**/
function checkPresent($fields_toinject = [], $options = []) {
if ($options['itemtype'] != 'ComputerVirtualMachine') {
return (" AND `computers_id` = '" . $fields_toinject['Computer']['id'] . "'
AND `name` = '" . $fields_toinject['ComputerVirtualMachine']['name'] . "'");
}
return "";
}

/**
* @param $values
* @param $add (true by default)
* @param $rights array
**/

/**
* @see plugins/datainjection/inc/PluginDatainjectionInjectionInterface::addOrUpdateObject()
**/
function addOrUpdateObject($values = [], $options = []) {
//error_log("THIS IS NEVER EXECUTED BECAUSE A COMPUTER IS ADDED, NOT A VM!!" );
}

}
Loading