diff --git a/inc/policybase.class.php b/inc/policybase.class.php index 75d14230..f3851272 100644 --- a/inc/policybase.class.php +++ b/inc/policybase.class.php @@ -70,6 +70,7 @@ abstract class PluginFlyvemdmPolicyBase implements PluginFlyvemdmPolicyInterface /** * get common task statuses + * * @return array */ public static final function getEnumBaseTaskStatus() { @@ -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() { @@ -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) { @@ -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) { @@ -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) { @@ -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) { @@ -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) { @@ -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; @@ -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) { @@ -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) { @@ -229,6 +247,7 @@ public function showValueInput($value = '', $itemType = '', $itemId = 0) { /** * @param PluginFlyvemdmTask $task + * * @return mixed */ public function showValue(PluginFlyvemdmTask $task) { @@ -237,6 +256,7 @@ public function showValue(PluginFlyvemdmTask $task) { /** * @param array $input + * * @return array */ public function preprocessFormData($input) { @@ -245,6 +265,7 @@ public function preprocessFormData($input) { /** * @param $status + * * @return mixed */ public function filterStatus($status) { @@ -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( diff --git a/inc/policydeployapplication.class.php b/inc/policydeployapplication.class.php index 53041b85..0be63c63 100644 --- a/inc/policydeployapplication.class.php +++ b/inc/policydeployapplication.class.php @@ -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 @@ -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 !== '') { diff --git a/inc/policydeployfile.class.php b/inc/policydeployfile.class.php index 8b9550b5..f97ce20d 100644 --- a/inc/policydeployfile.class.php +++ b/inc/policydeployfile.class.php @@ -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 @@ -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 diff --git a/inc/policyinterface.class.php b/inc/policyinterface.class.php index 53c090a9..5eaf2af4 100644 --- a/inc/policyinterface.class.php +++ b/inc/policyinterface.class.php @@ -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 @@ -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 diff --git a/inc/task.class.php b/inc/task.class.php index 86cc4029..f9171240 100644 --- a/inc/task.class.php +++ b/inc/task.class.php @@ -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'])) { @@ -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); @@ -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); } /**