Commit 6f8f0e14 authored by Ana Rute Mendes's avatar Ana Rute Mendes 🌈

LOCAL: Maniphest: trigger asset item creation

When a Purchasing Request changes status to "To Relase" an asset
must be created in the inventory system, external from Phabricator.

Trigger the create asset method that is placed in the extensions folder.
parent 5996c6a9
......@@ -386,11 +386,19 @@ final class ManiphestTransactionEditor
$is_open = !$object->isClosed();
$asset_id = null;
$new_status = null;
foreach ($xactions as $xaction) {
switch ($xaction->getTransactionType()) {
case ManiphestTaskStatusTransaction::TRANSACTIONTYPE:
$new_status = $xaction->getNewValue();
// CCU: create Item in the inventory system if it's a Purchase request and
// its status was changed to "to release"
if (!$this->getIsNewObject()) {
$snipe_api = new SnipeItHelper();
$asset_id = $snipe_api->createAssetItem($new_status, $object, $xactions);
}
break;
}
}
......@@ -444,8 +452,8 @@ final class ManiphestTransactionEditor
foreach ($xactions as $xaction) {
switch ($xaction->getTransactionType()) {
case PhabricatorTransactions::TYPE_SUBTYPE:
$subtype = $xaction->getNewValue();
break;
$subtype = $xaction->getNewValue();
break;
case PhabricatorTransactions::TYPE_CUSTOMFIELD:
switch ($xaction->getMetadataValue('customfield:key')) {
......@@ -579,6 +587,17 @@ final class ManiphestTransactionEditor
}
}
// CCU: if there were an asset created in the process, refer it in the
// purchase request.
if ($asset_id) {
$results[] = id(new ManiphestTransaction())
->setTransactionType(PhabricatorTransactions::TYPE_CUSTOMFIELD)
->attachObject($object)
->attachViewer($this->getActor())
->setMetadataValue('customfield:key', 'std:maniphest:purchasing:asset-id')
->setNewValue($asset_id);
}
return $results;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment