Skip to content

Commit

Permalink
feat(ticket): remove pending status from follow-up/task
Browse files Browse the repository at this point in the history
  • Loading branch information
Rom1-B authored Sep 26, 2022
1 parent 832bd50 commit d1f6316
Show file tree
Hide file tree
Showing 5 changed files with 186 additions and 153 deletions.
45 changes: 2 additions & 43 deletions src/CommonITILTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
/// TODO extends it from CommonDBChild
abstract class CommonITILTask extends CommonDBTM implements CalDAVCompatibleItemInterface
{
use Glpi\Features\ParentStatus;
use Glpi\Features\PlanningEvent;
use VobjectConverterTrait;

Expand Down Expand Up @@ -620,49 +621,7 @@ public function post_addItem()
$this->input["_job"]->updateActionTime($this->input[$this->input["_job"]->getForeignKeyField()]);
}

// Set pending reason data on parent and self
if ($this->input['pending'] ?? 0) {
PendingReason_Item::createForItem($this->input["_job"], [
'pendingreasons_id' => $this->input['pendingreasons_id'],
'followup_frequency' => $this->input['followup_frequency'] ?? 0,
'followups_before_resolution' => $this->input['followups_before_resolution'] ?? 0,
]);
PendingReason_Item::createForItem($this, [
'pendingreasons_id' => $this->input['pendingreasons_id'],
'followup_frequency' => $this->input['followup_frequency'] ?? 0,
'followups_before_resolution' => $this->input['followups_before_resolution'] ?? 0,
]);

// Set parent status to pending
$this->input['_status'] = CommonITILObject::WAITING;
}

//change status only if input change
if (
isset($this->input['_status'])
&& ($this->input['_status'] != $this->input['_job']->fields['status'])
) {
$update = [
'status' => $this->input['_status'],
'id' => $this->input['_job']->fields['id'],
'_disablenotif' => true
];
$this->input['_job']->update($update);
}

if (
!empty($this->fields['begin'])
&& $this->input["_job"]->isStatusExists(CommonITILObject::PLANNED)
&& (($this->input["_job"]->fields["status"] == CommonITILObject::INCOMING)
|| ($this->input["_job"]->fields["status"] == CommonITILObject::ASSIGNED))
) {
$input2 = [
'id' => $this->input["_job"]->getID(),
'status' => CommonITILObject::PLANNED,
'_disablenotif' => true,
];
$this->input["_job"]->update($input2);
}
$this->updateParentStatus($this->input['_job'], $this->input);

if ($donotif) {
$options = ['task_id' => $this->fields["id"],
Expand Down
169 changes: 169 additions & 0 deletions src/Features/ParentStatus.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
<?php

/**
* ---------------------------------------------------------------------
*
* GLPI - Gestionnaire Libre de Parc Informatique
*
* http://glpi-project.org
*
* @copyright 2015-2022 Teclib' and contributors.
* @copyright 2003-2014 by the INDEPNET Development Team.
* @licence https://www.gnu.org/licenses/gpl-3.0.html
*
* ---------------------------------------------------------------------
*
* LICENSE
*
* This file is part of GLPI.
*
* This program 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 3 of the License, or
* (at your option) any later version.
*
* This program 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 this program. If not, see <https://www.gnu.org/licenses/>.
*
* ---------------------------------------------------------------------
*/

namespace Glpi\Features;

use CommonITILActor;
use CommonITILObject;
use PendingReason_Item;
use Session;

/**
* ParentStatus
*
* @since 10.0.4
*/
trait ParentStatus
{
public function updateParentStatus(CommonITILObject $parentitem, array $input): void
{
$needupdateparent = false;

// Set pending reason data on parent and self
if ($input['pending'] ?? 0) {
PendingReason_Item::createForItem($parentitem, [
'pendingreasons_id' => $input['pendingreasons_id'] ?? 0,
'followup_frequency' => $input['followup_frequency'] ?? 0,
'followups_before_resolution' => $input['followups_before_resolution'] ?? 0,
]);
PendingReason_Item::createForItem($this, [
'pendingreasons_id' => $input['pendingreasons_id'] ?? 0,
'followup_frequency' => $input['followup_frequency'] ?? 0,
'followups_before_resolution' => $input['followups_before_resolution'] ?? 0,
]);
}

if (
isset($input["_close"])
&& $input["_close"]
&& ($parentitem->isSolved())
) {
$update = [
'id' => $parentitem->fields['id'],
'status' => CommonITILObject::CLOSED,
'closedate' => $_SESSION["glpi_currenttime"],
'_accepted' => true,
];

// Use update method for history
$parentitem->update($update);
}

// Set parent status to pending
if ($input['pending'] ?? 0) {
$input['_status'] = CommonITILObject::WAITING;
} elseif ($parentitem->fields["status"] == CommonITILObject::WAITING) {
$input["_reopen"] = true;
}

//manage reopening of ITILObject
$reopened = false;
if (!isset($input['_status'])) {
$input['_status'] = $parentitem->fields["status"];
}
// if reopen set (from followup form or mailcollector)
// and status is reopenable and not changed in form
$is_set_pending = $input['pending'] ?? 0;
if (
isset($input["_reopen"])
&& $input["_reopen"]
&& in_array($parentitem->fields["status"], $parentitem::getReopenableStatusArray())
&& $input['_status'] == $parentitem->fields["status"]
&& !$is_set_pending
) {
if (
isset($parentitem::getAllStatusArray($parentitem->getType())[CommonITILObject::ASSIGNED])
&& (
($parentitem->countUsers(CommonITILActor::ASSIGN) > 0)
|| ($parentitem->countGroups(CommonITILActor::ASSIGN) > 0)
|| ($parentitem->countSuppliers(CommonITILActor::ASSIGN) > 0)
)
) {
//check if lifecycle allowed new status
if (
Session::isCron()
|| Session::getCurrentInterface() == "helpdesk"
|| $parentitem::isAllowedStatus($parentitem->fields["status"], CommonITILObject::ASSIGNED)
) {
$needupdateparent = true;
$update['status'] = CommonITILObject::ASSIGNED;
}
} else {
//check if lifecycle allowed new status
if (
Session::isCron()
|| Session::getCurrentInterface() == "helpdesk"
|| $parentitem::isAllowedStatus($parentitem->fields["status"], CommonITILObject::INCOMING)
) {
$needupdateparent = true;
$update['status'] = CommonITILObject::INCOMING;
}
}

if ($needupdateparent) {
$update['id'] = $parentitem->fields['id'];

// Use update method for history
$parentitem->update($update);
$reopened = true;
}
}

if (
!empty($this->fields['begin'])
&& $parentitem->isStatusExists(CommonITILObject::PLANNED)
&& (($parentitem->fields["status"] == CommonITILObject::INCOMING)
|| ($parentitem->fields["status"] == CommonITILObject::ASSIGNED)
|| $needupdateparent)
) {
$input['_status'] = CommonITILObject::PLANNED;
}

//change ITILObject status only if imput change
if (
!$reopened
&& $input['_status'] != $parentitem->fields['status']
) {
$update['status'] = $input['_status'];
$update['id'] = $parentitem->fields['id'];

// don't notify on ITILObject - update event
$update['_disablenotif'] = true;

// Use update method for history
$parentitem->update($update);
}
}
}
107 changes: 3 additions & 104 deletions src/ITILFollowup.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
*/
class ITILFollowup extends CommonDBChild
{
use Glpi\Features\ParentStatus;

// From CommonDBTM
public $auto_message_on_action = false;
public static $rightname = 'followup';
Expand Down Expand Up @@ -251,110 +253,7 @@ public function post_addItem()
$this->input["users_id"]
);

// Set pending reason data on parent and self
if ($this->input['pending'] ?? 0) {
PendingReason_Item::createForItem($parentitem, [
'pendingreasons_id' => $this->input['pendingreasons_id'] ?? 0,
'followup_frequency' => $this->input['followup_frequency'] ?? 0,
'followups_before_resolution' => $this->input['followups_before_resolution'] ?? 0,
]);
PendingReason_Item::createForItem($this, [
'pendingreasons_id' => $this->input['pendingreasons_id'] ?? 0,
'followup_frequency' => $this->input['followup_frequency'] ?? 0,
'followups_before_resolution' => $this->input['followups_before_resolution'] ?? 0,
]);
}

if (
isset($this->input["_close"])
&& $this->input["_close"]
&& ($parentitem->isSolved())
) {
$update = [
'id' => $parentitem->fields['id'],
'status' => CommonITILObject::CLOSED,
'closedate' => $_SESSION["glpi_currenttime"],
'_accepted' => true,
];

// Use update method for history
$this->input["_job"]->update($update);
$donotif = false; // Done for ITILObject update (new status)
}

// Set parent status to pending
if ($this->input['pending'] ?? 0) {
$this->input['_status'] = CommonITILObject::WAITING;
}

//manage reopening of ITILObject
$reopened = false;
if (!isset($this->input['_status'])) {
$this->input['_status'] = $parentitem->fields["status"];
}
// if reopen set (from followup form or mailcollector)
// and status is reopenable and not changed in form
$is_set_pending = $this->input['pending'] ?? 0;
if (
isset($this->input["_reopen"])
&& $this->input["_reopen"]
&& in_array($parentitem->fields["status"], $parentitem::getReopenableStatusArray())
&& $this->input['_status'] == $parentitem->fields["status"]
&& !$is_set_pending
) {
$needupdateparent = false;
if (
isset($parentitem::getAllStatusArray($parentitem->getType())[CommonITILObject::ASSIGNED])
&& (
($parentitem->countUsers(CommonITILActor::ASSIGN) > 0)
|| ($parentitem->countGroups(CommonITILActor::ASSIGN) > 0)
|| ($parentitem->countSuppliers(CommonITILActor::ASSIGN) > 0)
)
) {
//check if lifecycle allowed new status
if (
Session::isCron()
|| Session::getCurrentInterface() == "helpdesk"
|| $parentitem::isAllowedStatus($parentitem->fields["status"], CommonITILObject::ASSIGNED)
) {
$needupdateparent = true;
$update['status'] = CommonITILObject::ASSIGNED;
}
} else {
//check if lifecycle allowed new status
if (
Session::isCron()
|| Session::getCurrentInterface() == "helpdesk"
|| $parentitem::isAllowedStatus($parentitem->fields["status"], CommonITILObject::INCOMING)
) {
$needupdateparent = true;
$update['status'] = CommonITILObject::INCOMING;
}
}

if ($needupdateparent) {
$update['id'] = $parentitem->fields['id'];

// Use update method for history
$parentitem->update($update);
$reopened = true;
}
}

//change ITILObject status only if imput change
if (
!$reopened
&& $this->input['_status'] != $parentitem->fields['status']
) {
$update['status'] = $this->input['_status'];
$update['id'] = $parentitem->fields['id'];

// don't notify on ITILObject - update event
$update['_disablenotif'] = true;

// Use update method for history
$parentitem->update($update);
}
$this->updateParentStatus($this->input['_job'], $this->input);

if ($donotif) {
$options = ['followup_id' => $this->fields["id"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,13 +223,16 @@
<input type="checkbox" name="pending" value="1" class="form-check-input"
id="enable-pending-reasons-{{ rand }}"
role="button"
{{ item.fields['status'] == constant('CommonITILObject::WAITING') ? 'checked' : '' }}
data-bs-toggle="collapse" data-bs-target="#pending-reasons-setup-{{ rand }}" />
</label>
</span>

<div class="collapse ps-2 py-1 flex-fill" id="pending-reasons-setup-{{ rand }}">
{{ include('components/itilobject/timeline/pending_reasons.html.twig') }}
</div>
{% if item.fields['status'] != constant('CommonITILObject::WAITING') %}
<div class="collapse ps-2 py-1 flex-fill" id="pending-reasons-setup-{{ rand }}">
{{ include('components/itilobject/timeline/pending_reasons.html.twig') }}
</div>
{% endif %}
</span>
{% endif %}
</div>
Expand Down
9 changes: 6 additions & 3 deletions templates/components/itilobject/timeline/form_task.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -392,13 +392,16 @@
<input type="checkbox" name="pending" value="1" class="form-check-input"
id="enable-pending-reasons-{{ rand }}"
role="button"
{{ item.fields['status'] == constant('CommonITILObject::WAITING') ? 'checked' : '' }}
data-bs-toggle="collapse" data-bs-target="#pending-reasons-setup-{{ rand }}" />
</label>
</span>

<div class="collapse ps-2 py-1 flex-fill" id="pending-reasons-setup-{{ rand }}">
{{ include('components/itilobject/timeline/pending_reasons.html.twig') }}
</div>
{% if item.fields['status'] != constant('CommonITILObject::WAITING') %}
<div class="collapse ps-2 py-1 flex-fill" id="pending-reasons-setup-{{ rand }}">
{{ include('components/itilobject/timeline/pending_reasons.html.twig') }}
</div>
{% endif %}
</span>
</div>
{% else %}
Expand Down

0 comments on commit d1f6316

Please sign in to comment.