本文整理汇总了PHP中PhabricatorFile::establishConnection方法的典型用法代码示例。如果您正苦于以下问题:PHP PhabricatorFile::establishConnection方法的具体用法?PHP PhabricatorFile::establishConnection怎么用?PHP PhabricatorFile::establishConnection使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PhabricatorFile
的用法示例。
在下文中一共展示了PhabricatorFile::establishConnection方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: pht
<?php
echo pht('Populating Phabricator files with mail keys xactions...') . "\n";
$table = new PhabricatorFile();
$table_name = $table->getTableName();
$conn_w = $table->establishConnection('w');
$conn_w->openTransaction();
$sql = array();
foreach (new LiskRawMigrationIterator($conn_w, 'file') as $row) {
// NOTE: MySQL requires that the INSERT specify all columns which don't
// have default values when configured in strict mode. This query will
// never actually insert rows, but we need to hand it values anyway.
$sql[] = qsprintf($conn_w, '(%d, %s, 0, 0, 0, 0, 0, 0, 0, 0)', $row['id'], Filesystem::readRandomCharacters(20));
}
if ($sql) {
foreach (PhabricatorLiskDAO::chunkSQL($sql, ', ') as $chunk) {
queryfx($conn_w, 'INSERT INTO %T
(id, mailKey, phid, byteSize, storageEngine, storageFormat,
storageHandle, dateCreated, dateModified, metadata) VALUES %Q ' . 'ON DUPLICATE KEY UPDATE mailKey = VALUES(mailKey)', $table_name, $chunk);
}
}
$table->saveTransaction();
echo pht('Done.') . "\n";
示例2: loadPage
protected function loadPage()
{
$table = new PhabricatorFile();
$conn_r = $table->establishConnection('r');
$data = queryfx_all($conn_r, 'SELECT f.* FROM %T f %Q %Q %Q %Q', $table->getTableName(), $this->buildJoinClause($conn_r), $this->buildWhereClause($conn_r), $this->buildOrderClause($conn_r), $this->buildLimitClause($conn_r));
$files = $table->loadAllFromArray($data);
if (!$files) {
return $files;
}
// We need to load attached objects to perform policy checks for files.
// First, load the edges.
$edge_type = PhabricatorEdgeConfig::TYPE_FILE_HAS_OBJECT;
$file_phids = mpull($files, 'getPHID');
$edges = id(new PhabricatorEdgeQuery())->withSourcePHIDs($file_phids)->withEdgeTypes(array($edge_type))->execute();
$object_phids = array();
foreach ($files as $file) {
$phids = array_keys($edges[$file->getPHID()][$edge_type]);
$file->attachObjectPHIDs($phids);
foreach ($phids as $phid) {
$object_phids[$phid] = true;
}
}
// If this file is a transform of another file, load that file too. If you
// can see the original file, you can see the thumbnail.
// TODO: It might be nice to put this directly on PhabricatorFile and remove
// the PhabricatorTransformedFile table, which would be a little simpler.
$xforms = id(new PhabricatorTransformedFile())->loadAllWhere('transformedPHID IN (%Ls)', $file_phids);
$xform_phids = mpull($xforms, 'getOriginalPHID', 'getTransformedPHID');
foreach ($xform_phids as $derived_phid => $original_phid) {
$object_phids[$original_phid] = true;
}
$object_phids = array_keys($object_phids);
// Now, load the objects.
$objects = array();
if ($object_phids) {
// NOTE: We're explicitly turning policy exceptions off, since the rule
// here is "you can see the file if you can see ANY associated object".
// Without this explicit flag, we'll incorrectly throw unless you can
// see ALL associated objects.
$objects = id(new PhabricatorObjectQuery())->setParentQuery($this)->setViewer($this->getViewer())->withPHIDs($object_phids)->setRaisePolicyExceptions(false)->execute();
$objects = mpull($objects, null, 'getPHID');
}
foreach ($files as $file) {
$file_objects = array_select_keys($objects, $file->getObjectPHIDs());
$file->attachObjects($file_objects);
}
foreach ($files as $key => $file) {
$original_phid = idx($xform_phids, $file->getPHID());
if ($original_phid == PhabricatorPHIDConstants::PHID_VOID) {
// This is a special case for builtin files, which are handled
// oddly.
$original = null;
} else {
if ($original_phid) {
$original = idx($objects, $original_phid);
if (!$original) {
// If the viewer can't see the original file, also prevent them from
// seeing the transformed file.
$this->didRejectResult($file);
unset($files[$key]);
continue;
}
} else {
$original = null;
}
}
$file->attachOriginalFile($original);
}
return $files;
}