Commit 7b87532f authored by Ana Rute Mendes's avatar Ana Rute Mendes 🌈
Browse files

CCU: handle snipe-IT exceptions and ticket transactions

After creating items in Snipe-It we need to save in the ticket
(maniphest task) the created ids and tags. So instead of receiving only
the ids list, the SnipeIt extension will return transactions or
validation errors.

If it returns an errror, append it to the list. If not, it's
an array of transactions so add them to the results array to update the
purchasing request.
parent 21ff5f9b
......@@ -387,7 +387,7 @@ final class ManiphestTransactionEditor
$is_open = !$object->isClosed();
$asset_id = null;
$asset_transactions = [];
$new_status = null;
foreach ($xactions as $xaction) {
switch ($xaction->getTransactionType()) {
......@@ -395,12 +395,12 @@ final class ManiphestTransactionEditor
$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"
// its status was changed to "resolved" (Closed)
if (!$this->getIsNewObject()) {
try {
$asset_id = $snipe_api->createAssetItem($new_status, $object, $xactions);
$asset_transactions = $snipe_api->createAssetItem($new_status, $object, $xactions);
} catch (Exception $e) {
$asset_id = null;
$asset_transactions = [];
......@@ -600,27 +600,30 @@ 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())
->setMetadataValue('customfield:key', 'std:maniphest:purchasing:asset-id')
// CCU: if there were assets created in snipe-IT, update the ticket with
// their IDs and tags
if ($asset_transactions) {
if ($asset_transactions instanceof PhabricatorApplicationTransactionValidationError) {
$this->moreValidationErrors[] = $asset_transactions;
} else {
foreach ($asset_transactions as $transaction) {
$results[] = $transaction;
// CCU: if it's a Shipping Request, check if it has an asset item
// in Snipe-IT and automatically fill in some fields.
if ($subtype == 'shipping') {
try {
$transactions = $snipe_api->fetchAssetItem($object, $xactions);
$snipe_api->fetchAssetItem($object, $xactions);
} catch (Exception $e) {
$transactions = [];
foreach ($transactions as $transaction) {
$results[] = $transaction;
$this->moreValidationErrors[] = new PhabricatorApplicationTransactionValidationError(
pht('An error ocurred while editing the item in Snipe-IT, please talk with the tools team.'),
Supports Markdown
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