This repository has been archived by the owner on Dec 16, 2020. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #249 from wmde/snapshots-20
Stop using Phabricator's JSON data structure in snapshots (and internally)
- Loading branch information
Showing
66 changed files
with
2,675 additions
and
1,109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
<?php | ||
|
||
namespace App\Console\Commands\Lib; | ||
|
||
use Phragile\Domain\Task; | ||
use Phragile\TaskRawDataProcessor; | ||
|
||
class SnapshotTaskDataConverter { | ||
|
||
public function convert(array $taskData) | ||
{ | ||
if ($this->taskDataIsInManiphestQueryFormat($taskData)) | ||
{ | ||
return array_values(array_map([$this, 'convertTaskInManiphestQueryFormat'], $taskData)); | ||
} | ||
if (!$this->taskDataIsInManiphestSearchFormat($taskData)) | ||
{ | ||
return $taskData; | ||
} | ||
$processor = new TaskRawDataProcessor(); | ||
return array_map( | ||
function(Task $task) | ||
{ | ||
return $task->getData(); | ||
}, | ||
$processor->process($taskData) | ||
); | ||
} | ||
|
||
public function needsConversion(array $taskData) | ||
{ | ||
return $this->taskDataIsInManiphestSearchFormat($taskData) || $this->taskDataIsInManiphestQueryFormat($taskData); | ||
} | ||
|
||
private function taskDataIsInManiphestSearchFormat(array $taskData) | ||
{ | ||
return array_keys($taskData) === range(0, count($taskData) - 1) && is_array($taskData[0]) && | ||
array_key_exists('fields', $taskData[0]) && array_key_exists('attachments', $taskData[0]); | ||
} | ||
|
||
private function taskDataIsInManiphestQueryFormat(array $taskData) | ||
{ | ||
// task array in maniphest.query response is PHID-indexed | ||
return array_keys($taskData) !== range(0, count($taskData) - 1); | ||
} | ||
|
||
private function convertTaskInManiphestQueryFormat(array $task) | ||
{ | ||
$points = isset( | ||
$task['auxiliary'][env('MANIPHEST_STORY_POINTS_FIELD')] | ||
) ? $task['auxiliary'][env('MANIPHEST_STORY_POINTS_FIELD')] : 0; | ||
|
||
return [ | ||
'id' => (int)$task['id'], | ||
'title' => $task['title'], | ||
'priority' => $task['priority'], | ||
'status' => $task['status'], | ||
'points' => $points, | ||
'projectPHIDs' => $task['projectPHIDs'], | ||
'assigneePHID' => $task['ownerPHID'], | ||
'customFields' => $this->convertManiphestQueryCustomFields($task) | ||
]; | ||
} | ||
|
||
private function convertManiphestQueryCustomFields(array $task) | ||
{ | ||
$fields = []; | ||
|
||
foreach ($task['auxiliary'] as $name => $value) | ||
{ | ||
$fields[$this->extractFieldName($name)] = $value; | ||
} | ||
|
||
return $fields; | ||
} | ||
|
||
/** | ||
* Format of old custom field was e.g. std:maniphest:WMDE:story_points or isdc:sprint:storypoints. | ||
* Equivalent new format would be custom.WMDE_story_points or custom.storypoints. | ||
* @param string $s | ||
* @return string | ||
*/ | ||
private function extractFieldName($s) | ||
{ | ||
if (count(explode(':', $s)) < 3) | ||
{ | ||
return $s; | ||
} | ||
return implode(':', | ||
array_slice(explode(':', $s), 2) | ||
); | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
app/Console/Commands/lib/SnapshotTransactionDataConverter.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
|
||
namespace App\Console\Commands\Lib; | ||
|
||
use Phragile\Domain\Transaction; | ||
use Phragile\TransactionRawDataProcessor; | ||
|
||
class SnapshotTransactionDataConverter { | ||
|
||
public function convert(array $transactionData) | ||
{ | ||
if (!$this->transactionDataIsInPhabricatorFormat($transactionData)) | ||
{ | ||
return $transactionData; | ||
} | ||
return $this->convertPhabricatorTransactionData($transactionData); | ||
} | ||
|
||
private function convertPhabricatorTransactionData(array $transactionData) | ||
{ | ||
$processor = new TransactionRawDataProcessor(); | ||
return array_map( | ||
function(array $taskTransactions) | ||
{ | ||
return array_map( | ||
function(Transaction $transaction) | ||
{ | ||
return $transaction->getData(); | ||
}, | ||
$taskTransactions | ||
); | ||
}, | ||
$processor->process($transactionData) | ||
); | ||
} | ||
public function needsConversion(array $transactionData) | ||
{ | ||
return $this->transactionDataIsInPhabricatorFormat($transactionData); | ||
} | ||
|
||
private function transactionDataIsInPhabricatorFormat(array $transactionData) | ||
{ | ||
$taskId = array_keys($transactionData)[0]; | ||
if (!is_array($transactionData[$taskId])) | ||
{ | ||
return false; | ||
} | ||
$transaction = array_values($transactionData[$taskId])[0]; | ||
return array_key_exists('taskID', $transaction) && array_key_exists('dateCreated', $transaction) && | ||
array_key_exists('transactionType', $transaction) && array_key_exists('oldValue', $transaction) && | ||
array_key_exists('newValue', $transaction); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.