Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F102218677
PhabricatorFactDimension.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Tue, Feb 18, 09:40
Size
2 KB
Mime Type
text/x-php
Expires
Thu, Feb 20, 09:40 (2 d)
Engine
blob
Format
Raw Data
Handle
24309137
Attached To
rPH Phabricator
PhabricatorFactDimension.php
View Options
<?php
abstract
class
PhabricatorFactDimension
extends
PhabricatorFactDAO
{
abstract
protected
function
getDimensionColumnName
();
final
public
function
newDimensionID
(
$key
,
$create
=
false
)
{
$map
=
$this
->
newDimensionMap
(
array
(
$key
),
$create
);
return
idx
(
$map
,
$key
);
}
final
public
function
newDimensionUnmap
(
array
$ids
)
{
if
(!
$ids
)
{
return
array
();
}
$conn
=
$this
->
establishConnection
(
'r'
);
$column
=
$this
->
getDimensionColumnName
();
$rows
=
queryfx_all
(
$conn
,
'SELECT id, %C FROM %T WHERE id IN (%Ld)'
,
$column
,
$this
->
getTableName
(),
$ids
);
$rows
=
ipull
(
$rows
,
$column
,
'id'
);
return
$rows
;
}
final
public
function
newDimensionMap
(
array
$keys
,
$create
=
false
)
{
if
(!
$keys
)
{
return
array
();
}
$conn
=
$this
->
establishConnection
(
'r'
);
$column
=
$this
->
getDimensionColumnName
();
$rows
=
queryfx_all
(
$conn
,
'SELECT id, %C FROM %T WHERE %C IN (%Ls)'
,
$column
,
$this
->
getTableName
(),
$column
,
$keys
);
$rows
=
ipull
(
$rows
,
'id'
,
$column
);
$map
=
array
();
$need
=
array
();
foreach
(
$keys
as
$key
)
{
if
(
isset
(
$rows
[
$key
]))
{
$map
[
$key
]
=
(
int
)
$rows
[
$key
];
}
else
{
$need
[]
=
$key
;
}
}
if
(!
$need
)
{
return
$map
;
}
if
(!
$create
)
{
return
$map
;
}
$sql
=
array
();
foreach
(
$need
as
$key
)
{
$sql
[]
=
qsprintf
(
$conn
,
'(%s)'
,
$key
);
}
$unguarded
=
AphrontWriteGuard
::
beginScopedUnguardedWrites
();
foreach
(
PhabricatorLiskDAO
::
chunkSQL
(
$sql
)
as
$chunk
)
{
queryfx
(
$conn
,
'INSERT IGNORE INTO %T (%C) VALUES %LQ'
,
$this
->
getTableName
(),
$column
,
$chunk
);
}
unset
(
$unguarded
);
$rows
=
queryfx_all
(
$conn
,
'SELECT id, %C FROM %T WHERE %C IN (%Ls)'
,
$column
,
$this
->
getTableName
(),
$column
,
$need
);
$rows
=
ipull
(
$rows
,
'id'
,
$column
);
foreach
(
$need
as
$key
)
{
if
(
isset
(
$rows
[
$key
]))
{
$map
[
$key
]
=
(
int
)
$rows
[
$key
];
}
else
{
throw
new
Exception
(
pht
(
'Failed to load or generate dimension ID ("%s") for dimension '
.
'key "%s".'
,
get_class
(
$this
),
$key
));
}
}
return
$map
;
}
}
Event Timeline
Log In to Comment