Add spacePHID infrastructure and implement in Paste

Summary:
Ref T8424. I'm using Paste as a testbed application because Spaces make some degree of sense for it but it's also flat/simple.

This doesn't do anything interesting or useful and mostly just making the next (more interesting) diff smaller.

Test Plan:
  - Ran `bin/storage upgrade -f`.
  - Browsed pastes.
  - Created a paste.

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: epriestley

Maniphest Tasks: T8424

Differential Revision: https://secure.phabricator.com/D13154
This commit is contained in:
epriestley
2015-06-04 17:45:24 -07:00
parent 52a29be70d
commit 763b63a0fb
6 changed files with 50 additions and 14 deletions

View File

@@ -0,0 +1,2 @@
ALTER TABLE {$NAMESPACE}_pastebin.pastebin_paste
ADD spacePHID VARBINARY(64);

View File

@@ -5615,6 +5615,7 @@ phutil_register_library_map(array(
'PhabricatorProjectInterface', 'PhabricatorProjectInterface',
'PhabricatorDestructibleInterface', 'PhabricatorDestructibleInterface',
'PhabricatorApplicationTransactionInterface', 'PhabricatorApplicationTransactionInterface',
'PhabricatorSpacesInterface',
), ),
'PhabricatorPasteApplication' => 'PhabricatorApplication', 'PhabricatorPasteApplication' => 'PhabricatorApplication',
'PhabricatorPasteCommentController' => 'PhabricatorPasteController', 'PhabricatorPasteCommentController' => 'PhabricatorPasteController',

View File

@@ -96,61 +96,59 @@ final class PhabricatorPasteQuery
return $pastes; return $pastes;
} }
protected function buildWhereClause(AphrontDatabaseConnection $conn_r) { protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
$where = array(); $where = parent::buildWhereClauseParts($conn);
$where[] = $this->buildPagingClause($conn_r);
if ($this->ids) { if ($this->ids) {
$where[] = qsprintf( $where[] = qsprintf(
$conn_r, $conn,
'id IN (%Ld)', 'id IN (%Ld)',
$this->ids); $this->ids);
} }
if ($this->phids) { if ($this->phids) {
$where[] = qsprintf( $where[] = qsprintf(
$conn_r, $conn,
'phid IN (%Ls)', 'phid IN (%Ls)',
$this->phids); $this->phids);
} }
if ($this->authorPHIDs) { if ($this->authorPHIDs) {
$where[] = qsprintf( $where[] = qsprintf(
$conn_r, $conn,
'authorPHID IN (%Ls)', 'authorPHID IN (%Ls)',
$this->authorPHIDs); $this->authorPHIDs);
} }
if ($this->parentPHIDs) { if ($this->parentPHIDs) {
$where[] = qsprintf( $where[] = qsprintf(
$conn_r, $conn,
'parentPHID IN (%Ls)', 'parentPHID IN (%Ls)',
$this->parentPHIDs); $this->parentPHIDs);
} }
if ($this->languages) { if ($this->languages) {
$where[] = qsprintf( $where[] = qsprintf(
$conn_r, $conn,
'language IN (%Ls)', 'language IN (%Ls)',
$this->languages); $this->languages);
} }
if ($this->dateCreatedAfter) { if ($this->dateCreatedAfter) {
$where[] = qsprintf( $where[] = qsprintf(
$conn_r, $conn,
'dateCreated >= %d', 'dateCreated >= %d',
$this->dateCreatedAfter); $this->dateCreatedAfter);
} }
if ($this->dateCreatedBefore) { if ($this->dateCreatedBefore) {
$where[] = qsprintf( $where[] = qsprintf(
$conn_r, $conn,
'dateCreated <= %d', 'dateCreated <= %d',
$this->dateCreatedBefore); $this->dateCreatedBefore);
} }
return $this->formatWhereClause($where); return $where;
} }
private function getContentCacheKey(PhabricatorPaste $paste) { private function getContentCacheKey(PhabricatorPaste $paste) {

View File

@@ -9,7 +9,8 @@ final class PhabricatorPaste extends PhabricatorPasteDAO
PhabricatorPolicyInterface, PhabricatorPolicyInterface,
PhabricatorProjectInterface, PhabricatorProjectInterface,
PhabricatorDestructibleInterface, PhabricatorDestructibleInterface,
PhabricatorApplicationTransactionInterface { PhabricatorApplicationTransactionInterface,
PhabricatorSpacesInterface {
protected $title; protected $title;
protected $authorPHID; protected $authorPHID;
@@ -19,6 +20,7 @@ final class PhabricatorPaste extends PhabricatorPasteDAO
protected $viewPolicy; protected $viewPolicy;
protected $editPolicy; protected $editPolicy;
protected $mailKey; protected $mailKey;
protected $spacePHID;
private $content = self::ATTACHABLE; private $content = self::ATTACHABLE;
private $rawContent = self::ATTACHABLE; private $rawContent = self::ATTACHABLE;
@@ -206,4 +208,12 @@ final class PhabricatorPaste extends PhabricatorPasteDAO
return $timeline; return $timeline;
} }
/* -( PhabricatorSpacesInterface )----------------------------------------- */
public function getSpacePHID() {
return $this->spacePHID;
}
} }

View File

@@ -1,3 +1,18 @@
<?php <?php
interface PhabricatorSpacesInterface extends PhabricatorPHIDInterface {} interface PhabricatorSpacesInterface extends PhabricatorPHIDInterface {
public function getSpacePHID();
}
// TEMPLATE IMPLEMENTATION /////////////////////////////////////////////////////
/* -( PhabricatorSpacesInterface )----------------------------------------- */
/*
public function getSpacePHID() {
return $this->spacePHID;
}
*/

View File

@@ -1897,6 +1897,11 @@ abstract class LiskDAO {
continue; continue;
} }
if ($property === 'spacePHID') {
$map[$property] = 'phid?';
continue;
}
// If the column is named `somethingPHID`, infer it is a PHID. // If the column is named `somethingPHID`, infer it is a PHID.
if (preg_match('/[a-z]PHID$/', $property)) { if (preg_match('/[a-z]PHID$/', $property)) {
$map[$property] = 'phid'; $map[$property] = 'phid';
@@ -1937,6 +1942,11 @@ abstract class LiskDAO {
'unique' => true, 'unique' => true,
); );
break; break;
case 'spacePHID':
$default_map['key_space'] = array(
'columns' => array('spacePHID'),
);
break;
} }
} }