Changeset View
Changeset View
Standalone View
Standalone View
src/applications/fact/engine/PhabricatorManiphestTaskFactEngine.php
- This file was moved from src/applications/fact/engine/PhabricatorFactManiphestTaskEngine.php.
<?php | <?php | ||||
final class PhabricatorFactManiphestTaskEngine | final class PhabricatorManiphestTaskFactEngine | ||||
extends PhabricatorFactEngine { | extends PhabricatorTransactionFactEngine { | ||||
public function newFacts() { | public function newFacts() { | ||||
return array( | return array( | ||||
id(new PhabricatorCountFact()) | id(new PhabricatorCountFact()) | ||||
->setKey('tasks.count.create'), | ->setKey('tasks.count.create'), | ||||
id(new PhabricatorCountFact()) | id(new PhabricatorCountFact()) | ||||
->setKey('tasks.open-count.create'), | ->setKey('tasks.open-count.create'), | ||||
▲ Show 20 Lines • Show All 55 Lines • ▼ Show 20 Lines | return array( | ||||
->setKey('tasks.points.assign.owner'), | ->setKey('tasks.points.assign.owner'), | ||||
id(new PhabricatorPointsFact()) | id(new PhabricatorPointsFact()) | ||||
->setKey('tasks.points.score.owner'), | ->setKey('tasks.points.score.owner'), | ||||
id(new PhabricatorPointsFact()) | id(new PhabricatorPointsFact()) | ||||
->setKey('tasks.open-points.create.owner'), | ->setKey('tasks.open-points.create.owner'), | ||||
id(new PhabricatorPointsFact()) | id(new PhabricatorPointsFact()) | ||||
->setKey('tasks.open-points.status.owner'), | ->setKey('tasks.open-points.status.owner'), | ||||
id(new PhabricatorPointsFact()) | id(new PhabricatorPointsFact()) | ||||
->setKey('tasks.open-points.score.project'), | ->setKey('tasks.open-points.score.owner'), | ||||
id(new PhabricatorPointsFact()) | id(new PhabricatorPointsFact()) | ||||
->setKey('tasks.open-points.assign.owner'), | ->setKey('tasks.open-points.assign.owner'), | ||||
); | ); | ||||
} | } | ||||
public function supportsDatapointsForObject(PhabricatorLiskDAO $object) { | public function supportsDatapointsForObject(PhabricatorLiskDAO $object) { | ||||
return ($object instanceof ManiphestTask); | return ($object instanceof ManiphestTask); | ||||
} | } | ||||
public function newDatapointsForObject(PhabricatorLiskDAO $object) { | public function newDatapointsForObject(PhabricatorLiskDAO $object) { | ||||
$viewer = $this->getViewer(); | $xaction_groups = $this->newTransactionGroupsForObject($object); | ||||
$xaction_query = PhabricatorApplicationTransactionQuery::newQueryForObject( | |||||
$object); | |||||
$xactions = $xaction_query | |||||
->setViewer($viewer) | |||||
->withObjectPHIDs(array($object->getPHID())) | |||||
->execute(); | |||||
$xactions = msortv($xactions, 'newChronologicalSortVector'); | |||||
$old_open = false; | $old_open = false; | ||||
$old_points = 0; | $old_points = 0; | ||||
$old_owner = null; | $old_owner = null; | ||||
$project_map = array(); | $project_map = array(); | ||||
$object_phid = $object->getPHID(); | $object_phid = $object->getPHID(); | ||||
$is_create = true; | $is_create = true; | ||||
$specs = array(); | $specs = array(); | ||||
$datapoints = array(); | $datapoints = array(); | ||||
foreach ($xactions as $xaction_group) { | foreach ($xaction_groups as $xaction_group) { | ||||
$add_projects = array(); | $add_projects = array(); | ||||
$rem_projects = array(); | $rem_projects = array(); | ||||
$new_open = $old_open; | $new_open = $old_open; | ||||
$new_points = $old_points; | $new_points = $old_points; | ||||
$new_owner = $old_owner; | $new_owner = $old_owner; | ||||
// TODO: Actually group concurrent transactions. | if ($is_create) { | ||||
$xaction_group = array($xaction_group); | // Assume tasks start open. | ||||
// TODO: This might be a questionable assumption? | |||||
$new_open = true; | |||||
} | |||||
$group_epoch = last($xaction_group)->getDateCreated(); | $group_epoch = last($xaction_group)->getDateCreated(); | ||||
foreach ($xaction_group as $xaction) { | foreach ($xaction_group as $xaction) { | ||||
$old_value = $xaction->getOldValue(); | $old_value = $xaction->getOldValue(); | ||||
$new_value = $xaction->getNewValue(); | $new_value = $xaction->getNewValue(); | ||||
switch ($xaction->getTransactionType()) { | switch ($xaction->getTransactionType()) { | ||||
case ManiphestTaskStatusTransaction::TRANSACTIONTYPE: | case ManiphestTaskStatusTransaction::TRANSACTIONTYPE: | ||||
$new_open = !ManiphestTaskStatus::isClosedStatus($new_value); | $new_open = !ManiphestTaskStatus::isClosedStatus($new_value); | ||||
Show All 37 Lines | foreach ($xaction_groups as $xaction_group) { | ||||
'phids' => $add_projects, | 'phids' => $add_projects, | ||||
'scale' => 1, | 'scale' => 1, | ||||
), | ), | ||||
); | ); | ||||
if ($is_create) { | if ($is_create) { | ||||
$action = 'create'; | $action = 'create'; | ||||
$action_points = $new_points; | $action_points = $new_points; | ||||
$include_open = $new_open; | |||||
} else { | } else { | ||||
$action = 'assign'; | $action = 'assign'; | ||||
$action_points = $old_points; | $action_points = $old_points; | ||||
$include_open = $old_open; | |||||
} | } | ||||
foreach ($project_sets as $project_set) { | foreach ($project_sets as $project_set) { | ||||
$scale = $project_set['scale']; | $scale = $project_set['scale']; | ||||
foreach ($project_set['phids'] as $project_phid) { | foreach ($project_set['phids'] as $project_phid) { | ||||
if ($old_open) { | if ($include_open) { | ||||
$specs[] = array( | $specs[] = array( | ||||
"tasks.open-count.{$action}.project", | "tasks.open-count.{$action}.project", | ||||
1 * $scale, | 1 * $scale, | ||||
$project_phid, | $project_phid, | ||||
); | ); | ||||
$specs[] = array( | $specs[] = array( | ||||
"tasks.open-points.{$action}.project", | "tasks.open-points.{$action}.project", | ||||
Show All 35 Lines | foreach ($xaction_groups as $xaction_group) { | ||||
); | ); | ||||
foreach ($owner_sets as $owner_set) { | foreach ($owner_sets as $owner_set) { | ||||
$owner_phid = $owner_set['phid']; | $owner_phid = $owner_set['phid']; | ||||
if ($owner_phid === null) { | if ($owner_phid === null) { | ||||
continue; | continue; | ||||
} | } | ||||
if ($old_open) { | $scale = $owner_set['scale']; | ||||
if ($old_open != $new_open) { | |||||
$specs[] = array( | $specs[] = array( | ||||
"tasks.open-count.{$action}.owner", | "tasks.open-count.{$action}.owner", | ||||
1 * $scale, | 1 * $scale, | ||||
$owner_phid, | $owner_phid, | ||||
); | ); | ||||
$specs[] = array( | $specs[] = array( | ||||
"tasks.open-points.{$action}.owner", | "tasks.open-points.{$action}.owner", | ||||
$action_points * $scale, | $action_points * $scale, | ||||
$owner_phid, | $owner_phid, | ||||
); | ); | ||||
} | } | ||||
$specs[] = array( | $specs[] = array( | ||||
"tasks.count.{$action}.owner", | "tasks.count.{$action}.owner", | ||||
1 * $scale, | 1 * $scale, | ||||
$owner_phid, | $owner_phid, | ||||
); | ); | ||||
if ($action_points) { | |||||
$specs[] = array( | $specs[] = array( | ||||
"tasks.points.{$action}.owner", | "tasks.points.{$action}.owner", | ||||
$action_points * $scale, | $action_points * $scale, | ||||
$owner_phid, | $owner_phid, | ||||
); | ); | ||||
} | } | ||||
} | |||||
$old_owner = $new_owner; | |||||
} | } | ||||
if ($is_create) { | if ($is_create) { | ||||
$specs[] = array( | $specs[] = array( | ||||
'tasks.count.create', | 'tasks.count.create', | ||||
1, | 1, | ||||
); | ); | ||||
$specs[] = array( | $specs[] = array( | ||||
'tasks.points.create', | 'tasks.points.create', | ||||
$new_points, | $new_points, | ||||
); | ); | ||||
if ($new_open) { | if ($new_open) { | ||||
$specs[] = array( | $specs[] = array( | ||||
'tasks.open-count.create', | 'tasks.open-count.create', | ||||
Show All 38 Lines | foreach ($xaction_groups as $xaction_group) { | ||||
$specs[] = array( | $specs[] = array( | ||||
'tasks.open-count.status.project', | 'tasks.open-count.status.project', | ||||
1 * $scale, | 1 * $scale, | ||||
$project_phid, | $project_phid, | ||||
); | ); | ||||
$specs[] = array( | $specs[] = array( | ||||
'tasks.open-points.status.project', | 'tasks.open-points.status.project', | ||||
$action_points * $scale, | $action_points * $scale, | ||||
$new_owner, | $project_phid, | ||||
); | ); | ||||
} | } | ||||
$old_open = $new_open; | |||||
} | } | ||||
// The "score" facts only apply to rescoring tasks which already | // The "score" facts only apply to rescoring tasks which already | ||||
// exist, so we skip them if the task is being created. | // exist, so we skip them if the task is being created. | ||||
if (($new_points !== $old_points) && !$is_create) { | if (($new_points !== $old_points) && !$is_create) { | ||||
$delta = ($new_points - $old_points); | $delta = ($new_points - $old_points); | ||||
$specs[] = array( | $specs[] = array( | ||||
Show All 34 Lines | foreach ($xaction_groups as $xaction_group) { | ||||
} | } | ||||
if ($old_open && $new_open) { | if ($old_open && $new_open) { | ||||
$specs[] = array( | $specs[] = array( | ||||
'tasks.open-points.score', | 'tasks.open-points.score', | ||||
$delta, | $delta, | ||||
); | ); | ||||
} | } | ||||
} | |||||
$old_points = $new_points; | $old_points = $new_points; | ||||
} | $old_open = $new_open; | ||||
$old_owner = $new_owner; | |||||
foreach ($specs as $spec) { | foreach ($specs as $spec) { | ||||
$spec_key = $spec[0]; | $spec_key = $spec[0]; | ||||
$spec_value = $spec[1]; | $spec_value = $spec[1]; | ||||
// Don't write any facts with a value of 0. The "count" facts never | |||||
// have a value of 0, and the "points" facts aren't meaningful if | |||||
// they have a value of 0. | |||||
if ($spec_value == 0) { | |||||
continue; | |||||
} | |||||
$datapoint = $this->getFact($spec_key) | $datapoint = $this->getFact($spec_key) | ||||
->newDatapoint(); | ->newDatapoint(); | ||||
$datapoint | $datapoint | ||||
->setObjectPHID($object_phid) | ->setObjectPHID($object_phid) | ||||
->setValue($spec_value) | ->setValue($spec_value) | ||||
->setEpoch($group_epoch); | ->setEpoch($group_epoch); | ||||
if (isset($spec[2])) { | if (isset($spec[2])) { | ||||
$datapoint->setDimensionPHID($spec[2]); | $datapoint->setDimensionPHID($spec[2]); | ||||
} | } | ||||
$datapoints[] = $datapoint; | $datapoints[] = $datapoint; | ||||
} | } | ||||
$specs = array(); | $specs = array(); | ||||
$is_create = false; | $is_create = false; | ||||
} | } | ||||
return $datapoints; | return $datapoints; | ||||
} | } | ||||
} | } |