@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.)
hq.recaptime.dev/wiki/Phorge
phorge
phabricator
1<?php
2
3final class HarbormasterString
4 extends HarbormasterDAO {
5
6 protected $stringIndex;
7 protected $stringValue;
8
9 protected function getConfiguration() {
10 return array(
11 self::CONFIG_TIMESTAMPS => false,
12 self::CONFIG_COLUMN_SCHEMA => array(
13 'stringIndex' => 'bytes12',
14 'stringValue' => 'text',
15 ),
16 self::CONFIG_KEY_SCHEMA => array(
17 'key_string' => array(
18 'columns' => array('stringIndex'),
19 'unique' => true,
20 ),
21 ),
22 ) + parent::getConfiguration();
23 }
24
25 public static function newIndex($string) {
26 $index = PhabricatorHash::digestForIndex($string);
27
28 $table = new self();
29 $conn = $table->establishConnection('w');
30
31 queryfx(
32 $conn,
33 'INSERT IGNORE INTO %R (stringIndex, stringValue) VALUES (%s, %s)',
34 $table,
35 $index,
36 $string);
37
38 return $index;
39 }
40
41 public static function newIndexMap(array $indexes) {
42 $table = new self();
43 $conn = $table->establishConnection('r');
44
45 $rows = queryfx_all(
46 $conn,
47 'SELECT stringIndex, stringValue FROM %R WHERE stringIndex IN (%Ls)',
48 $table,
49 $indexes);
50
51 return ipull($rows, 'stringValue', 'stringIndex');
52 }
53
54}