<commit_before><?php

final class ConpherenceColumnViewController extends
  ConpherenceController {

  public function handleRequest(AphrontRequest $request) {
    $user = $request->getUser();

    $latest_conpherences = array();
    $latest_participant = id(new ConpherenceParticipantQuery())
      ->withParticipantPHIDs(array($user->getPHID()))
      ->setLimit(6)
      ->execute();
    if ($latest_participant) {
      $conpherence_phids = mpull($latest_participant, 'getConpherencePHID');
      $latest_conpherences = id(new ConpherenceThreadQuery())
        ->setViewer($user)
        ->withPHIDs($conpherence_phids)
        ->needParticipantCache(true)
        ->execute();
      $latest_conpherences = mpull($latest_conpherences, null, 'getPHID');
      $latest_conpherences = array_select_keys(
        $latest_conpherences,
        $conpherence_phids);
    }

    $conpherence = null;
    $should_404 = false;
    if ($request->getInt('id')) {
      $conpherence = id(new ConpherenceThreadQuery())
        ->setViewer($user)
        ->withIDs(array($request->getInt('id')))
        ->needTransactions(true)
        ->setTransactionLimit(ConpherenceThreadQuery::TRANSACTION_LIMIT)
        ->executeOne();
      $should_404 = true;
    } else if ($latest_participant) {
      $participant = head($latest_participant);
      $conpherence = id(new ConpherenceThreadQuery())
        ->setViewer($user)
        ->withPHIDs(array($participant->getConpherencePHID()))
        ->needTransactions(true)
        ->setTransactionLimit(ConpherenceThreadQuery::TRANSACTION_LIMIT)
        ->executeOne();
      $should_404 = true;
    }

    $durable_column = id(new ConpherenceDurableColumnView())
      ->setUser($user)
      ->setVisible(true);
    if (!$conpherence) {
      if ($should_404) {
        return new Aphront404Response();
      }

      $conpherence_id = null;
      $conpherence_phid = null;
      $latest_transaction_id = null;

    } else {
      $this->setConpherence($conpherence);

      $participant = $conpherence->getParticipant($user->getPHID());
      $transactions = $conpherence->getTransactions();
      $latest_transaction = head($transactions);
      $write_guard = AphrontWriteGuard::beginScopedUnguardedWrites();
      $participant->markUpToDate($conpherence, $latest_transaction);
      unset($write_guard);

      $draft = PhabricatorDraft::newFromUserAndKey(
        $user,
        $conpherence->getPHID());

      $durable_column
        ->setDraft($draft)
        ->setSelectedConpherence($conpherence)
        ->setConpherences($latest_conpherences);
      $conpherence_id = $conpherence->getID();
      $conpherence_phid = $conpherence->getPHID();
      $latest_transaction_id = $latest_transaction->getID();
    }

    $response = array(
      'content' => hsprintf('%s', $durable_column),
      'threadID' => $conpherence_id,
      'threadPHID' => $conpherence_phid,
      'latestTransactionID' => $latest_transaction_id,
      'canEdit' => PhabricatorPolicyFilter::hasCapability(
        $user,
        $conpherence,
        PhabricatorPolicyCapability::CAN_EDIT),
    );

    return id(new AphrontAjaxResponse())->setContent($response);<commit_msg>Conpherence - fix possible fatal<commit_after><?php

final class ConpherenceColumnViewController extends
  ConpherenceController {

  public function handleRequest(AphrontRequest $request) {
    $user = $request->getUser();

    $latest_conpherences = array();
    $latest_participant = id(new ConpherenceParticipantQuery())
      ->withParticipantPHIDs(array($user->getPHID()))
      ->setLimit(6)
      ->execute();
    if ($latest_participant) {
      $conpherence_phids = mpull($latest_participant, 'getConpherencePHID');
      $latest_conpherences = id(new ConpherenceThreadQuery())
        ->setViewer($user)
        ->withPHIDs($conpherence_phids)
        ->needParticipantCache(true)
        ->execute();
      $latest_conpherences = mpull($latest_conpherences, null, 'getPHID');
      $latest_conpherences = array_select_keys(
        $latest_conpherences,
        $conpherence_phids);
    }

    $conpherence = null;
    $should_404 = false;
    if ($request->getInt('id')) {
      $conpherence = id(new ConpherenceThreadQuery())
        ->setViewer($user)
        ->withIDs(array($request->getInt('id')))
        ->needTransactions(true)
        ->setTransactionLimit(ConpherenceThreadQuery::TRANSACTION_LIMIT)
        ->executeOne();
      $should_404 = true;
    } else if ($latest_participant) {
      $participant = head($latest_participant);
      $conpherence = id(new ConpherenceThreadQuery())
        ->setViewer($user)
        ->withPHIDs(array($participant->getConpherencePHID()))
        ->needTransactions(true)
        ->setTransactionLimit(ConpherenceThreadQuery::TRANSACTION_LIMIT)
        ->executeOne();
      $should_404 = true;
    }

    $durable_column = id(new ConpherenceDurableColumnView())
      ->setUser($user)
      ->setVisible(true);
    if (!$conpherence) {
      if ($should_404) {
        return new Aphront404Response();
      }

      $conpherence_id = null;
      $conpherence_phid = null;
      $latest_transaction_id = null;
      $can_edit = false;

    } else {
      $this->setConpherence($conpherence);

      $participant = $conpherence->getParticipant($user->getPHID());
      $transactions = $conpherence->getTransactions();
      $latest_transaction = head($transactions);
      $write_guard = AphrontWriteGuard::beginScopedUnguardedWrites();
      $participant->markUpToDate($conpherence, $latest_transaction);
      unset($write_guard);

      $draft = PhabricatorDraft::newFromUserAndKey(
        $user,
        $conpherence->getPHID());

      $durable_column
        ->setDraft($draft)
        ->setSelectedConpherence($conpherence)
        ->setConpherences($latest_conpherences);
      $conpherence_id = $conpherence->getID();
      $conpherence_phid = $conpherence->getPHID();
      $latest_transaction_id = $latest_transaction->getID();
      $can_edit = PhabricatorPolicyFilter::hasCapability(
        $user,
        $conpherence,
        PhabricatorPolicyCapability::CAN_EDIT);
    }

    $response = array(
      'content' => hsprintf('%s', $durable_column),
      'threadID' => $conpherence_id,
      'threadPHID' => $conpherence_phid,
      'latestTransactionID' => $latest_transaction_id,
      'canEdit' => $can_edit,
    );

    return id(new AphrontAjaxResponse())->setContent($response);
{'fraction_non_alphanumeric': 0.133271346660468, 'fraction_numerical': 0.004958933829226716, 'mean_word_length': 3.4205479452054797, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 87, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6543534', 'n_tokens_mistral': 2064, 'n_tokens_neox': 2005, 'n_words': 276}