Skip to content

Commit

Permalink
Merge install and uninstall in deploy package. references fusioninven…
Browse files Browse the repository at this point in the history
…tory#1823

Fix unit tests

Fix update script + other fixes

Reorder update script + fix deploy

Fix unit test
  • Loading branch information
David Durieux committed May 27, 2016
1 parent 9f83395 commit e0d7696
Show file tree
Hide file tree
Showing 17 changed files with 4,221 additions and 4,488 deletions.
16 changes: 8 additions & 8 deletions ajax/deploypackage_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,36 +63,36 @@
exit;
}

if ( !isset($_REQUEST['orders_id']) && !isset($_REQUEST['rand']) && !isset($_REQUEST['subtype'])) {
if ( !isset($_REQUEST['packages_id']) && !isset($_REQUEST['rand']) && !isset($_REQUEST['subtype'])) {
exit;
}

if ( !is_numeric($_REQUEST['orders_id']) ) {
if ( !is_numeric($_REQUEST['packages_id']) ) {
Toolbox::logDebug("Error: orders_id in request is not an integer");
Toolbox::logDebug(var_dump($_REQUEST['orders_id']) );
exit;
}

$order = new PluginFusioninventoryDeployOrder();
$pfDeployPackage = new PluginFusioninventoryDeployPackage();

$order->getFromDB($_REQUEST['orders_id']);
$pfDeployPackage->getFromDB($_REQUEST['packages_id']);


//TODO: In the displayForm function, $_REQUEST is somewhat too much for the '$datas' parameter
// I think we could use only $order -- Kevin 'kiniou' Roy
switch ($_REQUEST['subtype']) {
case 'check':
PluginFusioninventoryDeployCheck::displayForm($order, $_REQUEST, $_REQUEST['rand'], $_POST['mode']);
PluginFusioninventoryDeployCheck::displayForm($pfDeployPackage, $_REQUEST, $_REQUEST['rand'], $_POST['mode']);
break;
case 'file':
PluginFusioninventoryDeployFile::displayForm($order, $_REQUEST, $_REQUEST['rand'], $_POST['mode']);
PluginFusioninventoryDeployFile::displayForm($pfDeployPackage, $_REQUEST, $_REQUEST['rand'], $_POST['mode']);
break;
case 'action':
PluginFusioninventoryDeployAction::displayForm($order, $_REQUEST, $_REQUEST['rand'], $_POST['mode']);
PluginFusioninventoryDeployAction::displayForm($pfDeployPackage, $_REQUEST, $_REQUEST['rand'], $_POST['mode']);
break;
case 'package_json_debug':
if ( isset($order->fields['json']) ) {
PluginFusioninventoryDeployPackage::display_json_debug($order);
$pfDeployPackage->display_json_debug();
} else {
echo "{}";
}
Expand Down
9 changes: 2 additions & 7 deletions b/deploy/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@

$taskjobstates = $pfTask->getTaskjobstatesForAgent(
$agent['id'],
array('deployinstall', 'deployuninstall')
array('deployinstall')
);
if (!$pfAgentModule->isAgentCanDo("DEPLOY", $agent['id'])) {
foreach($taskjobstates as $taskjobstate) {
Expand Down Expand Up @@ -167,12 +167,7 @@
}
}
if (is_array($params['msg']) ) {

if (version_compare(PHP_VERSION, '5.4.0') >= 0) {
$htmlspecialchars_flags = ENT_SUBSTITUTE | ENT_DISALLOWED;
} else {
$htmlspecialchars_flags = NULL;
}
$htmlspecialchars_flags = ENT_SUBSTITUTE | ENT_DISALLOWED;

$tmp_msg = implode("\n", $params['msg']);
$flags = NULL;
Expand Down
7 changes: 2 additions & 5 deletions front/deploypackage.form.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,13 @@
include ("../../../inc/includes.php");
Session::checkLoginUser();


$package = new PluginFusioninventoryDeployPackage();
if (isset($_POST['update_json'])) {
$order = new PluginFusioninventoryDeployOrder();

$json_clean = stripcslashes($_POST['json']);

$json = json_decode($json_clean,TRUE);

$ret = PluginFusioninventoryDeployOrder::updateOrderJson($_POST['orders_id'], $json);
$ret = PluginFusioninventoryDeployPackage::updateOrderJson($_POST['packages_id'], $json);
Html::back();
exit;
} elseif (isset($_POST['add_item'])) {
Expand All @@ -71,7 +69,6 @@
//$data = Toolbox::stripslashes_deep($_POST);
$data = $_POST;

$package = new PluginFusioninventoryDeployPackage();
//general form
if (isset ($data["add"])) {
Session::checkRight('plugin_fusioninventory_package', CREATE);
Expand Down
52 changes: 21 additions & 31 deletions inc/deployaction.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,7 @@ static function getType($type) {



static function displayForm($order, $request_data, $rand, $mode) {
global $CFG_GLPI;
static function displayForm(PluginFusioninventoryDeployPackage $package, $request_data, $rand, $mode) {

/*
* Get element config in 'edit' mode
Expand All @@ -93,7 +92,7 @@ static function displayForm($order, $request_data, $rand, $mode) {
*/
echo "<input type='hidden' name='index' value='".$request_data['index']."' />";

$c = $order->getSubElement( 'actions', $request_data['index'] );
$c = $package->getSubElement( 'actions', $request_data['index'] );
if ( is_array( $c ) && count( $c ) == 1 ) {
reset( $c );
$t = key( $c );
Expand Down Expand Up @@ -127,7 +126,7 @@ static function displayForm($order, $request_data, $rand, $mode) {
if ( in_array( $mode, array('create', 'edit'), TRUE ) ) {
echo "<span id='show_action_value{$rand}'>";
if ( $mode === 'edit' ) {
self::displayAjaxValues( $config, $request_data, $rand, $mode );
self::displayAjaxValues($config, $request_data, $rand, $mode);
}
echo "</span>";
}
Expand All @@ -143,17 +142,14 @@ static function displayForm($order, $request_data, $rand, $mode) {



static function displayList(PluginFusioninventoryDeployOrder $order, $datas, $rand) {
static function displayList(PluginFusioninventoryDeployPackage $package, $datas, $rand) {
global $CFG_GLPI;

$pfDeployPackage = new PluginFusioninventoryDeployPackage();
$pfDeployPackage->getFromDB($order->fields['plugin_fusioninventory_deploypackages_id']);

echo "<table class='tab_cadrehov package_item_list' id='table_action_$rand'>";
$i=0;
foreach ($datas['jobs']['actions'] as $action) {
echo Search::showNewLine(Search::HTML_OUTPUT, ($i%2));
if ($pfDeployPackage->can($pfDeployPackage->getID(), UPDATE)) {
if ($package->can($package->getID(), UPDATE)) {
echo "<td class='control'>";
Html::showCheckbox(array('name' => 'action_entries[]'));
echo "</td>";
Expand All @@ -162,7 +158,7 @@ static function displayList(PluginFusioninventoryDeployOrder $order, $datas, $ra
$action_type = array_shift($keys);
echo "<td>";
echo "<a class='edit' ".
"onclick=\"edit_subtype('action', {$order->fields['id']}, $rand, this)\">";
"onclick=\"edit_subtype('action', {$package->fields['id']}, $rand, this)\">";
echo PluginFusioninventoryDeployAction::getType($action_type);
echo "</a><br />";

Expand Down Expand Up @@ -203,20 +199,20 @@ static function displayList(PluginFusioninventoryDeployOrder $order, $datas, $ra
}
echo "</td>";
echo "</td>";
if ($pfDeployPackage->can($pfDeployPackage->getID(), UPDATE)) {
if ($package->can($package->getID(), UPDATE)) {
echo "<td class='rowhandler control' title='".__('drag', 'fusioninventory').
"'><div class='drag row'></div></td>";
}
echo "</tr>";
$i++;
}
if ($pfDeployPackage->can($pfDeployPackage->getID(), UPDATE)) {
if ($package->can($package->getID(), UPDATE)) {
echo "<tr><th>";
Html::checkAllAsCheckbox("actionsList$rand", mt_rand());
echo "</th><th colspan='3' class='mark'></th></tr>";
}
echo "</table>";
if ($pfDeployPackage->can($pfDeployPackage->getID(), UPDATE)) {
if ($package->can($package->getID(), UPDATE)) {
echo "&nbsp;&nbsp;<img src='".$CFG_GLPI["root_doc"]."/pics/arrow-left.png' alt=''>";
echo "<input type='submit' name='delete' value=\"".
__('Delete', 'fusioninventory')."\" class='submit'>";
Expand Down Expand Up @@ -291,11 +287,8 @@ static function displayAjaxValues($config, $request_data, $rand, $mode) {
global $CFG_GLPI;

$pfDeployPackage = new PluginFusioninventoryDeployPackage();
$pfDeployOrder = new PluginFusioninventoryDeployOrder();

if (isset($request_data['orders_id'])) {
$pfDeployOrder->getFromDB($request_data['orders_id']);
$pfDeployPackage->getFromDB($pfDeployOrder->fields['plugin_fusioninventory_deploypackages_id']);
if (isset($request_data['packages_id'])) {
$pfDeployPackage->getFromDB($request_data['packages_id']);
} else {
$pfDeployPackage->getEmpty();
}
Expand Down Expand Up @@ -399,11 +392,8 @@ static function displayAjaxValues($config, $request_data, $rand, $mode) {
}
echo "<span id='retchecks' style='display:block'>";



if ( is_array( $retChecks )
&& count( $retChecks )
) {
if (is_array($retChecks)
&& count($retChecks)) {
foreach ($retChecks as $retcheck) {
echo "<table class='table_retchecks'>";
echo "<tr>";
Expand Down Expand Up @@ -494,13 +484,13 @@ static function add_item($params) {
$new_entry[ $params['deploy_actiontype']] = $tmp;

//get current order json
$data = json_decode(PluginFusioninventoryDeployOrder::getJson($params['orders_id']), TRUE);
$data = json_decode(PluginFusioninventoryDeployPackage::getJson($params['id']), TRUE);

//add new entry
$data['jobs']['actions'][] = $new_entry;

//update order
PluginFusioninventoryDeployOrder::updateOrderJson($params['orders_id'], $data);
PluginFusioninventoryDeployPackage::updateOrderJson($params['id'], $data);
}


Expand Down Expand Up @@ -537,7 +527,7 @@ static function save_item($params) {
$entry[ $params['deploy_actiontype']] = $tmp;

//get current order json
$data = json_decode(PluginFusioninventoryDeployOrder::getJson($params['orders_id']), TRUE);
$data = json_decode(PluginFusioninventoryDeployPackage::getJson($params['id']), TRUE);

//unset index
unset($data['jobs']['actions'][$params['index']]);
Expand All @@ -547,7 +537,7 @@ static function save_item($params) {
array_splice($data['jobs']['actions'], $params['index'], 0, array($entry));

//update order
PluginFusioninventoryDeployOrder::updateOrderJson($params['orders_id'], $data);
PluginFusioninventoryDeployPackage::updateOrderJson($params['id'], $data);
}


Expand All @@ -558,7 +548,7 @@ static function remove_item($params) {
}

//get current order json
$datas = json_decode(PluginFusioninventoryDeployOrder::getJson($params['orders_id']), TRUE);
$datas = json_decode(PluginFusioninventoryDeployPackage::getJson($params['id']), TRUE);

//remove selected checks
foreach ($params['action_entries'] as $index => $checked) {
Expand All @@ -572,14 +562,14 @@ static function remove_item($params) {
$datas['jobs']['actions'] = array_values($datas['jobs']['actions']);

//update order
PluginFusioninventoryDeployOrder::updateOrderJson($params['orders_id'], $datas);
PluginFusioninventoryDeployPackage::updateOrderJson($params['id'], $datas);
}



static function move_item($params) {
//get current order json
$datas = json_decode(PluginFusioninventoryDeployOrder::getJson($params['orders_id']), TRUE);
$datas = json_decode(PluginFusioninventoryDeployPackage::getJson($params['id']), TRUE);

//get data on old index
$moved_check = $datas['jobs']['actions'][$params['old_index']];
Expand All @@ -591,7 +581,7 @@ static function move_item($params) {
array_splice($datas['jobs']['actions'], $params['new_index'], 0, array($moved_check));

//update order
PluginFusioninventoryDeployOrder::updateOrderJson($params['orders_id'], $datas);
PluginFusioninventoryDeployPackage::updateOrderJson($params['id'], $datas);
}
}

Expand Down
Loading

0 comments on commit e0d7696

Please sign in to comment.