Path: blob/master/src/applications/differential/customfield/DifferentialHarbormasterField.php
12256 views
<?php12abstract class DifferentialHarbormasterField3extends DifferentialCustomField {45abstract protected function getDiffPropertyKeys();6abstract protected function loadHarbormasterTargetMessages(7array $target_phids);8abstract protected function getLegacyProperty();9abstract protected function newModernMessage(array $message);10abstract protected function renderHarbormasterStatus(11DifferentialDiff $diff,12array $messages);13abstract protected function newHarbormasterMessageView(array $messages);1415public function renderDiffPropertyViewValue(DifferentialDiff $diff) {16// TODO: This load is slightly inefficient, but most of this is moving17// to Harbormaster and this simplifies the transition. Eat 1-2 extra18// queries for now.19$keys = $this->getDiffPropertyKeys();2021$properties = id(new DifferentialDiffProperty())->loadAllWhere(22'diffID = %d AND name IN (%Ls)',23$diff->getID(),24$keys);25$properties = mpull($properties, 'getData', 'getName');2627foreach ($keys as $key) {28$diff->attachProperty($key, idx($properties, $key));29}3031$target_phids = $diff->getBuildTargetPHIDs();32if ($target_phids) {33$messages = $this->loadHarbormasterTargetMessages($target_phids);34} else {35$messages = array();36}3738if (!$messages) {39// No Harbormaster messages, so look for legacy messages and make them40// look like modern messages.41$legacy_messages = $diff->getProperty($this->getLegacyProperty());42if ($legacy_messages) {43// Show the top 100 legacy lint messages. Previously, we showed some44// by default and let the user toggle the rest. With modern messages,45// we can send the user to the Harbormaster detail page. Just show46// "a lot" of messages in legacy cases to try to strike a balance47// between implementation simplicity and compatibility.48$legacy_messages = array_slice($legacy_messages, 0, 100);4950foreach ($legacy_messages as $message) {51try {52$modern = $this->newModernMessage($message);53$messages[] = $modern;54} catch (Exception $ex) {55// Ignore any poorly formatted messages.56}57}58}59}6061$status = $this->renderHarbormasterStatus($diff, $messages);6263if ($messages) {64$path_map = mpull($diff->loadChangesets(), 'getID', 'getFilename');65foreach ($path_map as $path => $id) {66$href = '#C'.$id.'NL';6768// TODO: When the diff is not the right-hand-size diff, we should69// ideally adjust this URI to be absolute.7071$path_map[$path] = $href;72}7374$view = $this->newHarbormasterMessageView($messages);75if ($view) {76$view->setPathURIMap($path_map);77}78} else {79$view = null;80}8182if ($view) {83$view = phutil_tag(84'div',85array(86'class' => 'differential-harbormaster-table-view',87),88$view);89}9091return array(92$status,93$view,94);95}9697}9899100