Skip to content
This repository has been archived by the owner on Aug 9, 2021. It is now read-only.

Commit

Permalink
fix(policy): reorder cascaded task creation
Browse files Browse the repository at this point in the history
Signed-off-by: Thierry Bugier <tbugier@teclib.com>
  • Loading branch information
btry authored and DIOHz0r committed May 11, 2018
1 parent fb3a8b5 commit 868b26d
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 14 deletions.
24 changes: 23 additions & 1 deletion inc/policybase.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ abstract class PluginFlyvemdmPolicyBase implements PluginFlyvemdmPolicyInterface

/**
* get common task statuses
*
* @return array
*/
public static final function getEnumBaseTaskStatus() {
Expand All @@ -91,6 +92,7 @@ public static final function getEnumBaseTaskStatus() {
/**
* get specific task statuses
* To be overriden in child class
*
* @return array
*/
public static function getEnumSpecificStatus() {
Expand All @@ -109,6 +111,7 @@ public function __construct(PluginFlyvemdmPolicy $policy) {
* JSON decode properties for the policy and merges them with default values
* @param string $properties
* @param array $defaultProperties
*
* @return array
*/
protected function jsonDecodeProperties($properties, array $defaultProperties) {
Expand All @@ -130,6 +133,7 @@ protected function jsonDecodeProperties($properties, array $defaultProperties) {
* @param mixed $itemtype
* @param integer $itemId
* @param PluginFlyvemdmNotifiableInterface $notifiable
*
* @return bool
*/
public function canApply($value, $itemtype, $itemId, PluginFlyvemdmNotifiableInterface $notifiable) {
Expand All @@ -141,6 +145,7 @@ public function canApply($value, $itemtype, $itemId, PluginFlyvemdmNotifiableInt
* @param mixed $itemtype
* @param integer $itemId
* @param PluginFlyvemdmNotifiableInterface $notifiable
*
* @return boolean
*/
public function unicityCheck($value, $itemtype, $itemId, PluginFlyvemdmNotifiableInterface $notifiable) {
Expand All @@ -161,6 +166,7 @@ public function unicityCheck($value, $itemtype, $itemId, PluginFlyvemdmNotifiabl
* @param mixed $itemtype
* @param integer $itemId
* @param PluginFlyvemdmNotifiableInterface $notifiable
*
* @return boolean
*/
public function conflictCheck($value, $itemtype, $itemId, PluginFlyvemdmNotifiableInterface $notifiable) {
Expand All @@ -171,6 +177,7 @@ public function conflictCheck($value, $itemtype, $itemId, PluginFlyvemdmNotifiab
* @param mixed $value
* @param mixed $itemtype
* @param integer $itemId
*
* @return bool
*/
public function integrityCheck($value, $itemtype, $itemId) {
Expand All @@ -195,8 +202,9 @@ public function getGroup() {
* @param mixed $value
* @param mixed $itemtype
* @param integer $itemId
* @return bool
* @param PluginFlyvemdmNotifiableInterface $notifiable
*
* @return bool
*/
public function pre_apply($value, $itemtype, $itemId, PluginFlyvemdmNotifiableInterface $notifiable) {
return true;
Expand All @@ -207,6 +215,7 @@ public function pre_apply($value, $itemtype, $itemId, PluginFlyvemdmNotifiableIn
* @param mixed $itemtype
* @param integer $itemId
* @param PluginFlyvemdmNotifiableInterface $notifiable
*
* @return bool
*/
public function pre_unapply($value, $itemtype, $itemId, PluginFlyvemdmNotifiableInterface $notifiable) {
Expand All @@ -215,10 +224,19 @@ public function pre_unapply($value, $itemtype, $itemId, PluginFlyvemdmNotifiable
return true;
}

/**
* @param mixed $value
* @param mixed $itemtype
* @param integer $itemId
* @param PluginFlyvemdmNotifiableInterface $notifiable
*/
public function post_unapply($value, $itemtype, $itemId, PluginFlyvemdmNotifiableInterface $notifiable) {}

/**
* @param string $value value of the task
* @param string $itemType type of the item linked to the task
* @param integer $itemId ID of the item
*
* @return string
*/
public function showValueInput($value = '', $itemType = '', $itemId = 0) {
Expand All @@ -229,6 +247,7 @@ public function showValueInput($value = '', $itemType = '', $itemId = 0) {

/**
* @param PluginFlyvemdmTask $task
*
* @return mixed
*/
public function showValue(PluginFlyvemdmTask $task) {
Expand All @@ -237,6 +256,7 @@ public function showValue(PluginFlyvemdmTask $task) {

/**
* @param array $input
*
* @return array
*/
public function preprocessFormData($input) {
Expand All @@ -245,6 +265,7 @@ public function preprocessFormData($input) {

/**
* @param $status
*
* @return mixed
*/
public function filterStatus($status) {
Expand All @@ -268,6 +289,7 @@ public function getPolicyData() {
*
* @param string $mode add or update
* @param array $_input values for update
*
* @return string html
*/
public function formGenerator(
Expand Down
15 changes: 10 additions & 5 deletions inc/policydeployapplication.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@
*/
class PluginFlyvemdmPolicyDeployapplication extends PluginFlyvemdmPolicyBase implements PluginFlyvemdmPolicyInterface {

/** @var array $postUnapplyTask task to add after unapplying the policy */
private $postUnapplyTask = null;

/**
* PluginFlyvemdmPolicyDeployapplication constructor.
* @param PluginFlyvemdmPolicy $policy
Expand Down Expand Up @@ -208,19 +211,21 @@ public function pre_unapply($value, $itemtype, $itemId, PluginFlyvemdmNotifiable
return false;
}

$task = new PluginFlyvemdmTask();
if (!$task->add([
$this->postUnapplyTask = [
'itemtype_applied' => $notifiable->getType(),
'items_id_applied' => $notifiable->getID(),
'plugin_flyvemdm_policies_id' => $policyData->getID(),
'value' => $package->getField('package_name'),
])) {
return false;
}
];

return true;
}

public function post_unapply($value, $itemtype, $itemId, PluginFlyvemdmNotifiableInterface $notifiable) {
$task = new PluginFlyvemdmTask();
$task->add($this->postUnapplyTask);
}

public function showValueInput($value = '', $itemType = '', $itemId = 0) {
$itemtype = PluginFlyvemdmPackage::class;
if ($value !== '') {
Expand Down
15 changes: 11 additions & 4 deletions inc/policydeployfile.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@
*/
class PluginFlyvemdmPolicyDeployfile extends PluginFlyvemdmPolicyBase implements PluginFlyvemdmPolicyInterface {

/** @var array $postUnapplyTask task to add after unapplying the policy */
private $postUnapplyTask = null;

/**
* @param PluginFlyvemdmPolicy $policy
* @internal param string $properties
Expand Down Expand Up @@ -240,18 +243,22 @@ public function pre_unapply($value, $itemtype, $itemId, PluginFlyvemdmNotifiable
if (strrpos($value['destination'], '/') != strlen($value['destination']) - 1) {
$value['destination'] .= '/';
}
if (!$task->add([

$this->postUnapplyTask = [
'itemtype_applied' => $notifiable->getType(),
'items_id_applied' => $notifiable->getID(),
'plugin_flyvemdm_policies_id' => $policyData->getID(),
'value' => $value['destination'] . $file->getField('name'),
])) {
return false;
}
];

return true;
}

public function post_unapply($value, $itemtype, $itemId, PluginFlyvemdmNotifiableInterface $notifiable) {
$task = new PluginFlyvemdmTask();
$task->add($this->postUnapplyTask);
}

/**
* @param string $value
* @param string $itemType
Expand Down
12 changes: 11 additions & 1 deletion inc/policyinterface.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public function getGroup();
public function pre_apply($value, $itemtype, $itemId, PluginFlyvemdmNotifiableInterface $notifiable);

/**
* Actions done after a policy is unapplied to a notifiable
* Actions done before a policy is unapplied to a notifiable
*
* @param mixed $value
* @param mixed $itemtype
Expand All @@ -124,6 +124,16 @@ public function pre_apply($value, $itemtype, $itemId, PluginFlyvemdmNotifiableIn
public function pre_unapply($value, $itemtype, $itemId, PluginFlyvemdmNotifiableInterface $notifiable);

/**
* Actions done after a policy is unapplied to a notifiable
*
* @param mixed $value
* @param mixed $itemtype
* @param integer $itemId
* @param PluginFlyvemdmNotifiableInterface $notifiable
*/
public function post_unapply($value, $itemtype, $itemId, PluginFlyvemdmNotifiableInterface $notifiable);

/**
* return HTML input to set policy value
* @param string $value value of the task
* @param string $itemType type of the item linked to the task
Expand Down
7 changes: 4 additions & 3 deletions inc/task.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ public function prepareInputForUpdate($input) {
$itemId = $input['items_id'];
}

//Check the fleet exists
//Check the notifiable exists
$notifiableType = $this->fields['itemtype_applied'];
$notifiableId = $this->fields['items_id_applied'];
if (isset($input['items_id_applied'])) {
Expand All @@ -283,7 +283,7 @@ public function prepareInputForUpdate($input) {
return false;
}

// Check the policy may be applied to the fleet and the value is matches requirements
// Check the policy may be applied to the notifiable and the value matches requirements
if (!$this->policy->integrityCheck($value, $itemtype, $itemId)) {
Session::addMessageAfterRedirect(__('Incorrect value for this policy', 'flyvemdm'), false,
ERROR);
Expand Down Expand Up @@ -347,9 +347,10 @@ public function pre_deleteItem() {
* @see CommonDBTM::post_deleteItem()
*/
public function post_purgeItem() {
//$this->updateQueue($this->notifiable, [$this->policy->getGroup()]);
$this->unpublishPolicy($this->notifiable);
$this->deleteTaskStatuses();
$this->policy->post_unapply($this->fields['value'], $this->fields['itemtype'],
$this->fields['items_id'], $this->notifiable);
}

/**
Expand Down

0 comments on commit 868b26d

Please sign in to comment.