<?php

final class DiffusionRepositoryURIsIndexEngineExtension
  extends PhabricatorIndexEngineExtension {

  const EXTENSIONKEY = 'diffusion.repositories.uri';

  public function getExtensionName() {
    return pht('Repository URIs');
  }

  public function shouldIndexObject($object) {
    return ($object instanceof PhabricatorRepository);
  }

  public function indexObject(
    PhabricatorIndexEngine $engine,
    $object) {
    $object->updateURIIndex();
  }

}

<?php

final class DiffusionRepositoryURIsIndexEngineExtension
  extends PhabricatorIndexEngineExtension {

  const EXTENSIONKEY = 'diffusion.repositories.uri';

  public function getExtensionName() {
    return pht('Repository URIs');
  }

  public function shouldIndexObject($object) {
    return ($object instanceof PhabricatorRepository);
  }

  public function indexObject(
    PhabricatorIndexEngine $engine,
    $object) {

    // Reload the repository to pick up URIs, which we need in order to update
    // the URI index.
    $object = id(new PhabricatorRepositoryQuery())
      ->setViewer(PhabricatorUser::getOmnipotentUser())
      ->withPHIDs(array($object->getPHID()))
      ->needURIs(true)
      ->executeOne();
    if (!$object) {
      return;
    }

    $object->updateURIIndex();
  }

}

Fix an issue with URI index updates from the daemons
Fix an issue with URI index updates from the daemons

Summary:
Ref T10923. This extension needs to load a little more data (with `needURIs`) to function correctly now.

(There's a recent migration does this, so indexes got updated correctly when it ran, so it hasn't been obvious that they weren't getting updated properly after that.)

Test Plan: Made an arbitrary edit to a repository, observed no more error in daemon logs.

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T10923

Differential Revision: https://secure.phabricator.com/D15908
