diff --git a/src/customfields/ReleaseDetailsCustomField.php b/src/customfields/ReleaseDetailsCustomField.php index 0829c8a..42d784a 100644 --- a/src/customfields/ReleaseDetailsCustomField.php +++ b/src/customfields/ReleaseDetailsCustomField.php @@ -1,237 +1,238 @@ textproxy = id(new PhabricatorStandardCustomFieldText()) ->setFieldKey($this->getFieldKey()) ->setApplicationField($this) ->setFieldConfig(array( 'name' => $this->getFieldName(), 'description' => $this->getFieldDescription(), )); $this->setProxy($this->textproxy); } public function getFieldKey() { return 'wmf:releasedetails'; } public function getModernFieldKey() { return 'releasedetails'; } public function getFieldName() { return 'Release Details'; } public function shouldAppearInApplicationSearch() { return true; } public function shouldAppearInPropertyView() { - //$task = $this->getObject(); - //$subtype = $task->getSubtype(); - //phlog($subtype); - return true; + $task = $this->getObject(); + if (!$task) { + return false; + } + return $task->getSubtype() == 'release'; } public function shouldAppearInEditView() { return true; } public function getFieldValue() { return $this->textproxy->getFieldValue(); } public function renderPropertyViewLabel() { return ""; } public function getStyleForPropertyView() { return 'block'; } public function getStandardCustomFieldNamespace() { return 'maniphest'; } public function renderEditControl(array $handles) { return id(new PhabricatorRemarkupControl()) ->setUser($this->getViewer()) ->setLabel($this->getFieldName()) ->setName($this->getFieldKey()) ->setValue($this->getFieldValue()); } public function renderPropertyViewValue(array $handles) { $obj = $this->getObject(); $fields = $obj->getCustomFields(); $field_list = $fields->getCustomFieldList('view'); $fields = $field_list->getFields(); $date = new DateTime(); $version = ""; $fieldIndex = null; foreach($fields as $key => $field) { $val = $field->getValueForStorage(); if ($key == 'std:maniphest:release.date' && $val) { $date->setTimestamp((int)$val); } else if ($key == 'std:maniphest:release.version' && $val) { $fieldIndex = $field->getFieldIndex(); $version = $val; } } // if this task doesn't have a release.version assigned then it isn't part // of a release series so we should not render anything: if (!isset($fieldIndex)) { return ""; } // Format dates related to this task based on the release.date custom field $year = $date->format("Y"); $week = $date->format("W"); $weekdaynum = $date->format('N'); if ($weekdaynum > 1) { // if release.date is after monday, subtract days the preceeding monday: $subtract_days = $weekdaynum-1; $interval = new DateInterval('P'.$subtract_days."D"); $date->sub($interval); } $weekday = $date->format("l"); $month = $date->format("F"); $monthday = $date->format("jS"); $oneday = new DateInterval('P1D'); $date->add($oneday); $tue = $date->format('F jS'); $date->add($oneday); $wed = $date->format('F jS'); $date->add($oneday); $thu = $date->format('F jS'); list($major, $wmfnum) = explode("-", $version); $major = explode('.', $major); $major = $major[0] . '.' . $major[1]; // look up prev/next task monograms: $series = $this->getSeries($fieldIndex, $version); // vars to pass to template: $vars = compact("major", "wmfnum", "year", "week", "weekday", "month", "monthday", "tue", "wed", "thu", "series"); // render template to remarkupL $remarkup = $this->renderTrainDeployDetails($vars); $viewer = $this->getViewer(); // RemarkupView based on the template markup: return new PHUIRemarkupView($viewer, $remarkup); } private function renderTrainDeployDetails($vars) { extract($vars); return << 1) { $prev = $minor-1; $prev = join('.', array($v[0],$v[1],$v[2],$prev)); $versions[] = $prev; } else { $prev = '...'; } $next = $v[3]+1; $next = join('.', array($v[0],$v[1],$v[2],$next)); $versions[] = $next; $storage = $this->newStorageObject(); $conn = $storage->establishConnection('r'); $indexes = array($fieldIndex); // dirty manual query of the custom field storage table to get the value // for the release.version field for the previous and next version in this // series $rows = queryfx_all( $conn, 'SELECT objectPHID, fieldIndex, fieldValue FROM %T WHERE fieldIndex IN (%Ls) AND fieldValue in (%Ls)', $storage->getTableName(), $indexes, $versions); // now save the versions and phids $versions = array(); $phids = array(); foreach($rows as $row) { $phid = $row['objectPHID']; $taskVersion = $row['fieldValue']; $phids[] = $phid; $versions[$phid] = $taskVersion; } // now look up the monograms for the phids we found $query = id(new ManiphestTaskQuery()) ->setViewer($this->getViewer()) ->withPHIDs($phids); $tasks = $query->execute(); $res = array('prev' => '...', 'next' => '...'); foreach ($tasks as $id => $task) { $monogram = $task->getMonogram(); $phid = $task->getPHID(); $version = $versions[$phid]; if ($version == $prev) { $res['prev'] = '{'.$monogram.'}'; } else if ($version == $next) { $res['next'] = '{'.$monogram.'}'; } } return $res; } } \ No newline at end of file