Changeset View
Changeset View
Standalone View
Standalone View
src/applications/maniphest/editor/ManiphestTransactionEditor.php
Show First 20 Lines • Show All 673 Lines • ▼ Show 20 Lines | public static function getAdjacentSubpriority( | ||||
$base = $dst->getSubpriority(); | $base = $dst->getSubpriority(); | ||||
$step = (double)(2 << 32); | $step = (double)(2 << 32); | ||||
// If we find an adjacent task, we average the two subpriorities and | // If we find an adjacent task, we average the two subpriorities and | ||||
// return the result. | // return the result. | ||||
if ($adjacent) { | if ($adjacent) { | ||||
// If the adjacent task has a subpriority that is identical or very | // If the adjacent task has a subpriority that is identical or very | ||||
// close to the task we're looking at, we're going to move it a little | // close to the task we're looking at, we're going to move it and all | ||||
// farther down the subpriority list. | // tasks with the same subpriority a little farther down the subpriority | ||||
// scale. | |||||
if (abs($adjacent->getSubpriority() - $base) < 0.01) { | if (abs($adjacent->getSubpriority() - $base) < 0.01) { | ||||
$conn_w = $adjacent->establishConnection('w'); | |||||
// Get all of the tasks with the same subpriority as the adjacent | |||||
// task, including the adjacent task itself. | |||||
$shift_base = $adjacent->getSubpriority(); | |||||
$shift_all = id(new ManiphestTaskQuery()) | |||||
->setViewer(PhabricatorUser::getOmnipotentUser()) | |||||
->setOrderBy(ManiphestTaskQuery::ORDER_PRIORITY) | |||||
->withPriorities(array($adjacent->getPriority())) | |||||
->withSubpriorities(array($shift_base)) | |||||
->setReversePaging(!$is_after) | |||||
->execute(); | |||||
$shift_last = last($shift_all); | |||||
// Find the subpriority before or after the task at the end of the | |||||
// block. | |||||
list($shift_pri, $shift_sub) = self::getAdjacentSubpriority( | list($shift_pri, $shift_sub) = self::getAdjacentSubpriority( | ||||
$adjacent, | $shift_last, | ||||
$is_after); | $is_after); | ||||
$delta = ($shift_sub - $shift_base); | |||||
$count = count($shift_all); | |||||
$shift = array(); | |||||
$cursor = 1; | |||||
foreach ($shift_all as $shift_task) { | |||||
$shift_target = $shift_base + (($cursor / $count) * $delta); | |||||
$cursor++; | |||||
queryfx( | queryfx( | ||||
$adjacent->establishConnection('r'), | $conn_w, | ||||
'UPDATE %T SET subpriority = %f WHERE id = %d', | 'UPDATE %T SET subpriority = %f WHERE id = %d', | ||||
$adjacent->getTableName(), | $adjacent->getTableName(), | ||||
$shift_sub, | $shift_target, | ||||
$adjacent->getID()); | $shift_task->getID()); | ||||
// If we're shifting the adjacent task, update it. | |||||
if ($shift_task->getID() == $adjacent->getID()) { | |||||
$adjacent->setSubpriority($shift_target); | |||||
} | |||||
$adjacent->setSubpriority($shift_sub); | // If we're shifting the original target task, update the base | ||||
// subpriority. | |||||
if ($shift_task->getID() == $dst->getID()) { | |||||
$base = $shift_target; | |||||
} | |||||
} | |||||
} | } | ||||
$sub = ($adjacent->getSubpriority() + $base) / 2; | $sub = ($adjacent->getSubpriority() + $base) / 2; | ||||
} else { | } else { | ||||
// Otherwise, we take a step away from the target's subpriority and | // Otherwise, we take a step away from the target's subpriority and | ||||
// use that. | // use that. | ||||
if ($is_after) { | if ($is_after) { | ||||
$sub = ($base - $step); | $sub = ($base - $step); | ||||
Show All 10 Lines |