コード例 #1
0
<?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
0
 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;
 }