public function renderModuleStatus(AphrontRequest $request)
 {
     $viewer = $request->getViewer();
     $types = PhabricatorEdgeType::getAllTypes();
     $types = msort($types, 'getEdgeConstant');
     $rows = array();
     foreach ($types as $key => $type) {
         $rows[] = array($type->getEdgeConstant(), $type->getInverseEdgeConstant(), get_class($type));
     }
     return id(new AphrontTableView($rows))->setHeaders(array(pht('Constant'), pht('Inverse'), pht('Class')))->setColumnClasses(array(null, null, 'pri wide'));
 }
 private function applyExternalEffects(PhabricatorLiskDAO $object, PhabricatorApplicationTransaction $xaction)
 {
     switch ($xaction->getTransactionType()) {
         case PhabricatorTransactions::TYPE_BUILDABLE:
         case PhabricatorTransactions::TYPE_TOKEN:
             return;
         case PhabricatorTransactions::TYPE_SUBSCRIBERS:
             $subeditor = id(new PhabricatorSubscriptionsEditor())->setObject($object)->setActor($this->requireActor());
             $old_map = array_fuse($xaction->getOldValue());
             $new_map = array_fuse($xaction->getNewValue());
             $subeditor->unsubscribe(array_keys(array_diff_key($old_map, $new_map)));
             $subeditor->subscribeExplicit(array_keys(array_diff_key($new_map, $old_map)));
             $subeditor->save();
             // for the rest of these edits, subscribers should include those just
             // added as well as those just removed.
             $subscribers = array_unique(array_merge($this->subscribers, $xaction->getOldValue(), $xaction->getNewValue()));
             $this->subscribers = $subscribers;
             break;
         case PhabricatorTransactions::TYPE_EDGE:
             if ($this->getIsInverseEdgeEditor()) {
                 // If we're writing an inverse edge transaction, don't actually
                 // do anything. The initiating editor on the other side of the
                 // transaction will take care of the edge writes.
                 break;
             }
             $old = $xaction->getOldValue();
             $new = $xaction->getNewValue();
             $src = $object->getPHID();
             $const = $xaction->getMetadataValue('edge:type');
             $type = PhabricatorEdgeType::getByConstant($const);
             if ($type->shouldWriteInverseTransactions()) {
                 $this->applyInverseEdgeTransactions($object, $xaction, $type->getInverseEdgeConstant());
             }
             foreach ($new as $dst_phid => $edge) {
                 $new[$dst_phid]['src'] = $src;
             }
             $editor = new PhabricatorEdgeEditor();
             foreach ($old as $dst_phid => $edge) {
                 if (!empty($new[$dst_phid])) {
                     if ($old[$dst_phid]['data'] === $new[$dst_phid]['data']) {
                         continue;
                     }
                 }
                 $editor->removeEdge($src, $const, $dst_phid);
             }
             foreach ($new as $dst_phid => $edge) {
                 if (!empty($old[$dst_phid])) {
                     if ($old[$dst_phid]['data'] === $new[$dst_phid]['data']) {
                         continue;
                     }
                 }
                 $data = array('data' => $edge['data']);
                 $editor->addEdge($src, $const, $dst_phid, $data);
             }
             $editor->save();
             break;
         case PhabricatorTransactions::TYPE_CUSTOMFIELD:
             $field = $this->getCustomFieldForTransaction($object, $xaction);
             return $field->applyApplicationTransactionExternalEffects($xaction);
     }
     return $this->applyCustomExternalTransaction($object, $xaction);
 }
 public function getTitleForFeed()
 {
     $author_phid = $this->getAuthorPHID();
     $object_phid = $this->getObjectPHID();
     $old = $this->getOldValue();
     $new = $this->getNewValue();
     switch ($this->getTransactionType()) {
         case PhabricatorTransactions::TYPE_CREATE:
             return pht('%s created %s.', $this->renderHandleLink($author_phid), $this->renderHandleLink($object_phid));
         case PhabricatorTransactions::TYPE_COMMENT:
             return pht('%s added a comment to %s.', $this->renderHandleLink($author_phid), $this->renderHandleLink($object_phid));
         case PhabricatorTransactions::TYPE_VIEW_POLICY:
             return pht('%s changed the visibility for %s.', $this->renderHandleLink($author_phid), $this->renderHandleLink($object_phid));
         case PhabricatorTransactions::TYPE_EDIT_POLICY:
             return pht('%s changed the edit policy for %s.', $this->renderHandleLink($author_phid), $this->renderHandleLink($object_phid));
         case PhabricatorTransactions::TYPE_JOIN_POLICY:
             return pht('%s changed the join policy for %s.', $this->renderHandleLink($author_phid), $this->renderHandleLink($object_phid));
         case PhabricatorTransactions::TYPE_SUBSCRIBERS:
             return pht('%s updated subscribers of %s.', $this->renderHandleLink($author_phid), $this->renderHandleLink($object_phid));
         case PhabricatorTransactions::TYPE_SPACE:
             return pht('%s shifted %s from the %s space to the %s space.', $this->renderHandleLink($author_phid), $this->renderHandleLink($object_phid), $this->renderHandleLink($old), $this->renderHandleLink($new));
         case PhabricatorTransactions::TYPE_EDGE:
             $new = ipull($new, 'dst');
             $old = ipull($old, 'dst');
             $add = array_diff($new, $old);
             $rem = array_diff($old, $new);
             $type = $this->getMetadata('edge:type');
             $type = head($type);
             $type_obj = PhabricatorEdgeType::getByConstant($type);
             if ($add && $rem) {
                 return $type_obj->getFeedEditString($this->renderHandleLink($author_phid), $this->renderHandleLink($object_phid), new PhutilNumber(count($add) + count($rem)), phutil_count($add), $this->renderHandleList($add), phutil_count($rem), $this->renderHandleList($rem));
             } else {
                 if ($add) {
                     return $type_obj->getFeedAddString($this->renderHandleLink($author_phid), $this->renderHandleLink($object_phid), phutil_count($add), $this->renderHandleList($add));
                 } else {
                     if ($rem) {
                         return $type_obj->getFeedRemoveString($this->renderHandleLink($author_phid), $this->renderHandleLink($object_phid), phutil_count($rem), $this->renderHandleList($rem));
                     } else {
                         return pht('%s edited edge metadata for %s.', $this->renderHandleLink($author_phid), $this->renderHandleLink($object_phid));
                     }
                 }
             }
         case PhabricatorTransactions::TYPE_CUSTOMFIELD:
             $field = $this->getTransactionCustomField();
             if ($field) {
                 return $field->getApplicationTransactionTitleForFeed($this);
             } else {
                 return pht('%s edited a custom field on %s.', $this->renderHandleLink($author_phid), $this->renderHandleLink($object_phid));
             }
         case PhabricatorTransactions::TYPE_BUILDABLE:
             switch ($this->getNewValue()) {
                 case HarbormasterBuildable::STATUS_BUILDING:
                     return pht('%s started building %s for %s.', $this->renderHandleLink($author_phid), $this->renderHandleLink($this->getMetadataValue('harbormaster:buildablePHID')), $this->renderHandleLink($object_phid));
                 case HarbormasterBuildable::STATUS_PASSED:
                     return pht('%s completed building %s for %s.', $this->renderHandleLink($author_phid), $this->renderHandleLink($this->getMetadataValue('harbormaster:buildablePHID')), $this->renderHandleLink($object_phid));
                 case HarbormasterBuildable::STATUS_FAILED:
                     return pht('%s failed to build %s for %s.', $this->renderHandleLink($author_phid), $this->renderHandleLink($this->getMetadataValue('harbormaster:buildablePHID')), $this->renderHandleLink($object_phid));
                 default:
                     return null;
             }
         case PhabricatorTransactions::TYPE_COLUMNS:
             $moves = $this->getInterestingMoves($new);
             if (count($moves) == 1) {
                 $move = head($moves);
                 $from_columns = $move['fromColumnPHIDs'];
                 $to_column = $move['columnPHID'];
                 $board_phid = $move['boardPHID'];
                 if (count($from_columns) == 1) {
                     return pht('%s moved %s from %s to %s on the %s board.', $this->renderHandleLink($author_phid), $this->renderHandleLink($object_phid), $this->renderHandleLink(head($from_columns)), $this->renderHandleLink($to_column), $this->renderHandleLink($board_phid));
                 } else {
                     return pht('%s moved %s to %s on the %s board.', $this->renderHandleLink($author_phid), $this->renderHandleLink($object_phid), $this->renderHandleLink($to_column), $this->renderHandleLink($board_phid));
                 }
             } else {
                 $fragments = array();
                 foreach ($moves as $move) {
                     $fragments[] = pht('%s (%s)', $this->renderHandleLink($board_phid), $this->renderHandleLink($to_column));
                 }
                 return pht('%s moved %s on %s board(s): %s.', $this->renderHandleLink($author_phid), $this->renderHandleLink($object_phid), phutil_count($moves), phutil_implode_html(', ', $fragments));
             }
             break;
     }
     return $this->getTitle();
 }
 public function getTitleForFeed()
 {
     $author_phid = $this->getAuthorPHID();
     $object_phid = $this->getObjectPHID();
     $old = $this->getOldValue();
     $new = $this->getNewValue();
     switch ($this->getTransactionType()) {
         case PhabricatorTransactions::TYPE_COMMENT:
             return pht('%s added a comment to %s.', $this->renderHandleLink($author_phid), $this->renderHandleLink($object_phid));
         case PhabricatorTransactions::TYPE_VIEW_POLICY:
             return pht('%s changed the visibility for %s.', $this->renderHandleLink($author_phid), $this->renderHandleLink($object_phid));
         case PhabricatorTransactions::TYPE_EDIT_POLICY:
             return pht('%s changed the edit policy for %s.', $this->renderHandleLink($author_phid), $this->renderHandleLink($object_phid));
         case PhabricatorTransactions::TYPE_JOIN_POLICY:
             return pht('%s changed the join policy for %s.', $this->renderHandleLink($author_phid), $this->renderHandleLink($object_phid));
         case PhabricatorTransactions::TYPE_SUBSCRIBERS:
             return pht('%s updated subscribers of %s.', $this->renderHandleLink($author_phid), $this->renderHandleLink($object_phid));
         case PhabricatorTransactions::TYPE_SPACE:
             return pht('%s shifted %s from the %s space to the %s space.', $this->renderHandleLink($author_phid), $this->renderHandleLink($object_phid), $this->renderHandleLink($old), $this->renderHandleLink($new));
         case PhabricatorTransactions::TYPE_EDGE:
             $new = ipull($new, 'dst');
             $old = ipull($old, 'dst');
             $add = array_diff($new, $old);
             $rem = array_diff($old, $new);
             $type = $this->getMetadata('edge:type');
             $type = head($type);
             $type_obj = PhabricatorEdgeType::getByConstant($type);
             if ($add && $rem) {
                 return $type_obj->getFeedEditString($this->renderHandleLink($author_phid), $this->renderHandleLink($object_phid), new PhutilNumber(count($add) + count($rem)), new PhutilNumber(count($add)), $this->renderHandleList($add), new PhutilNumber(count($rem)), $this->renderHandleList($rem));
             } else {
                 if ($add) {
                     return $type_obj->getFeedAddString($this->renderHandleLink($author_phid), $this->renderHandleLink($object_phid), new PhutilNumber(count($add)), $this->renderHandleList($add));
                 } else {
                     if ($rem) {
                         return $type_obj->getFeedRemoveString($this->renderHandleLink($author_phid), $this->renderHandleLink($object_phid), new PhutilNumber(count($rem)), $this->renderHandleList($rem));
                     } else {
                         return pht('%s edited edge metadata for %s.', $this->renderHandleLink($author_phid), $this->renderHandleLink($object_phid));
                     }
                 }
             }
         case PhabricatorTransactions::TYPE_CUSTOMFIELD:
             $field = $this->getTransactionCustomField();
             if ($field) {
                 return $field->getApplicationTransactionTitleForFeed($this);
             } else {
                 return pht('%s edited a custom field on %s.', $this->renderHandleLink($author_phid), $this->renderHandleLink($object_phid));
             }
         case PhabricatorTransactions::TYPE_BUILDABLE:
             switch ($this->getNewValue()) {
                 case HarbormasterBuildable::STATUS_BUILDING:
                     return pht('%s started building %s for %s.', $this->renderHandleLink($author_phid), $this->renderHandleLink($this->getMetadataValue('harbormaster:buildablePHID')), $this->renderHandleLink($object_phid));
                 case HarbormasterBuildable::STATUS_PASSED:
                     return pht('%s completed building %s for %s.', $this->renderHandleLink($author_phid), $this->renderHandleLink($this->getMetadataValue('harbormaster:buildablePHID')), $this->renderHandleLink($object_phid));
                 case HarbormasterBuildable::STATUS_FAILED:
                     return pht('%s failed to build %s for %s.', $this->renderHandleLink($author_phid), $this->renderHandleLink($this->getMetadataValue('harbormaster:buildablePHID')), $this->renderHandleLink($object_phid));
                 default:
                     return null;
             }
     }
     return $this->getTitle();
 }
 /**
  * See @{method::applyBuiltinInternalTransaction}.
  */
 protected function applyBuiltinExternalTransaction(PhabricatorLiskDAO $object, PhabricatorApplicationTransaction $xaction)
 {
     switch ($xaction->getTransactionType()) {
         case PhabricatorTransactions::TYPE_EDGE:
             if ($this->getIsInverseEdgeEditor()) {
                 // If we're writing an inverse edge transaction, don't actually
                 // do anything. The initiating editor on the other side of the
                 // transaction will take care of the edge writes.
                 break;
             }
             $old = $xaction->getOldValue();
             $new = $xaction->getNewValue();
             $src = $object->getPHID();
             $const = $xaction->getMetadataValue('edge:type');
             $type = PhabricatorEdgeType::getByConstant($const);
             if ($type->shouldWriteInverseTransactions()) {
                 $this->applyInverseEdgeTransactions($object, $xaction, $type->getInverseEdgeConstant());
             }
             foreach ($new as $dst_phid => $edge) {
                 $new[$dst_phid]['src'] = $src;
             }
             $editor = new PhabricatorEdgeEditor();
             foreach ($old as $dst_phid => $edge) {
                 if (!empty($new[$dst_phid])) {
                     if ($old[$dst_phid]['data'] === $new[$dst_phid]['data']) {
                         continue;
                     }
                 }
                 $editor->removeEdge($src, $const, $dst_phid);
             }
             foreach ($new as $dst_phid => $edge) {
                 if (!empty($old[$dst_phid])) {
                     if ($old[$dst_phid]['data'] === $new[$dst_phid]['data']) {
                         continue;
                     }
                 }
                 $data = array('data' => $edge['data']);
                 $editor->addEdge($src, $const, $dst_phid, $data);
             }
             $editor->save();
             $this->updateWorkboardColumns($object, $const, $old, $new);
             break;
         case PhabricatorTransactions::TYPE_VIEW_POLICY:
         case PhabricatorTransactions::TYPE_SPACE:
             $this->scrambleFileSecrets($object);
             break;
     }
 }
Ejemplo n.º 6
0
 /**
  * Get a list of all edge types which are being added, and which we should
  * prevent cycles on.
  *
  * @return list<const> List of edge types which should have cycles prevented.
  * @task cycle
  */
 private function getPreventCyclesEdgeTypes()
 {
     $edge_types = array();
     foreach ($this->addEdges as $edge) {
         $edge_types[$edge['type']] = true;
     }
     foreach ($edge_types as $type => $ignored) {
         $type_obj = PhabricatorEdgeType::getByConstant($type);
         if (!$type_obj->shouldPreventCycles()) {
             unset($edge_types[$type]);
         }
     }
     return array_keys($edge_types);
 }
 public function testGetAllTypes()
 {
     PhabricatorEdgeType::getAllTypes();
     $this->assertTrue(true);
 }