<?php

final class PhabricatorRepositoryArcanistProject
  extends PhabricatorRepositoryDAO {

  protected $name;
  protected $phid;
  protected $repositoryID;

  protected $symbolIndexLanguages = array();
  protected $symbolIndexProjects  = array();

  public function getConfiguration() {
    return array(
      self::CONFIG_AUX_PHID   => true,
      self::CONFIG_TIMESTAMPS => false,
      self::CONFIG_SERIALIZATION => array(
        'symbolIndexLanguages' => self::SERIALIZATION_JSON,
        'symbolIndexProjects'  => self::SERIALIZATION_JSON,
      ),
    ) + parent::getConfiguration();
  }

  public function generatePHID() {
    return PhabricatorPHID::generateNewPHID('APRJ');
  }

  public function loadRepository() {
    if (!$this->getRepositoryID()) {
      return null;
    }
    return id(new PhabricatorRepository())->load($this->getRepositoryID());
  }

  public function delete() {
    $this->openTransaction();
      $conn_w = $this->establishConnection('w');

      $symbols = id(new PhabricatorRepositorySymbol())->loadAllWhere(
        'arcanistProjectID = %d',
        $this->getID()
      );
      foreach ($symbols as $symbol) {
        $symbol->delete();
      }

      $result = parent::delete();
    $this->saveTransaction();
    return $result;
  }

}

<?php

final class PhabricatorRepositoryArcanistProject
  extends PhabricatorRepositoryDAO {

  protected $name;
  protected $phid;
  protected $repositoryID;

  protected $symbolIndexLanguages = array();
  protected $symbolIndexProjects  = array();

  public function getConfiguration() {
    return array(
      self::CONFIG_AUX_PHID   => true,
      self::CONFIG_TIMESTAMPS => false,
      self::CONFIG_SERIALIZATION => array(
        'symbolIndexLanguages' => self::SERIALIZATION_JSON,
        'symbolIndexProjects'  => self::SERIALIZATION_JSON,
      ),
    ) + parent::getConfiguration();
  }

  public function generatePHID() {
    return PhabricatorPHID::generateNewPHID('APRJ');
  }

  public function loadRepository() {
    if (!$this->getRepositoryID()) {
      return null;
    }
    return id(new PhabricatorRepository())->load($this->getRepositoryID());
  }

  public function delete() {
    $this->openTransaction();

      queryfx(
        $this->establishConnection('w'),
        'DELETE FROM %T WHERE arcanistProjectID = %d',
        id(new PhabricatorRepositorySymbol())->getTableName(),
        $this->getID());

      $result = parent::delete();
    $this->saveTransaction();
    return $result;
  }

}

Clean up repositories with symbols correctly
Clean up repositories with symbols correctly

Summary: We currently try to delete symbols by ID, but the table has a multipart primary key and no `id` column.

Test Plan: Ran query locally; had @JThramer verify fix in his environment.

Reviewers: btrahan

Reviewed By: btrahan

CC: JThramer, aran

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