Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F990938
20210802.legalpad_document_signature.02.phid-populate.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
20210802.legalpad_document_signature.02.phid-populate.php
View Options
<?php
$phid_type
=
PhabricatorLegalpadDocumentSignaturePHIDType
::
TYPECONST
;
$docsig_table
=
new
LegalpadDocumentSignature
();
$conn
=
$docsig_table
->
establishConnection
(
'w'
);
$table_name
=
$docsig_table
->
getTableName
();
$chunk_size
=
4096
;
$temporary_table
=
'tmp_20210802_docsig_id_map'
;
try
{
queryfx
(
$conn
,
'CREATE TEMPORARY TABLE %T (
docsig_id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
docsig_phid VARBINARY(64) NOT NULL)'
,
$temporary_table
);
}
catch
(
AphrontAccessDeniedQueryException
$ex
)
{
throw
new
PhutilProxyException
(
pht
(
'Failed to "CREATE TEMPORARY TABLE". You may need to "GRANT" the '
.
'current MySQL user this permission.'
),
$ex
);
}
$table_iterator
=
id
(
new
LiskRawMigrationIterator
(
$conn
,
$table_name
))
->
setPageSize
(
$chunk_size
);
$chunk_iterator
=
new
PhutilChunkedIterator
(
$table_iterator
,
$chunk_size
);
foreach
(
$chunk_iterator
as
$chunk
)
{
$map
=
array
();
foreach
(
$chunk
as
$docsig_row
)
{
$phid
=
$docsig_row
[
'phid'
];
if
(
strlen
(
$phid
))
{
continue
;
}
$phid
=
PhabricatorPHID
::
generateNewPHID
(
$phid_type
);
$id
=
$docsig_row
[
'id'
];
$map
[(
int
)
$id
]
=
$phid
;
}
if
(!
$map
)
{
continue
;
}
$sql
=
array
();
foreach
(
$map
as
$docsig_id
=>
$docsig_phid
)
{
$sql
[]
=
qsprintf
(
$conn
,
'(%d, %s)'
,
$docsig_id
,
$docsig_phid
);
}
queryfx
(
$conn
,
'TRUNCATE TABLE %T'
,
$temporary_table
);
queryfx
(
$conn
,
'INSERT INTO %T (docsig_id, docsig_phid) VALUES %LQ'
,
$temporary_table
,
$sql
);
queryfx
(
$conn
,
'UPDATE %T c JOIN %T x ON c.id = x.docsig_id
SET c.phid = x.docsig_phid'
,
$table_name
,
$temporary_table
);
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Wed, Jun 18, 9:15 PM (1 d, 18 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
228617
Default Alt Text
20210802.legalpad_document_signature.02.phid-populate.php (1 KB)
Attached To
Mode
rP Phorge
Attached
Detach File
Event Timeline
Log In to Comment