Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/harbormaster/storage/HarbormasterString.php
12256 views
1
<?php
2
3
final 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
}
55
56