Changeset View
Changeset View
Standalone View
Standalone View
src/applications/files/storage/PhabricatorFile.php
Show First 20 Lines • Show All 320 Lines • ▼ Show 20 Lines | private static function buildFromFileData($data, array $params = array()) { | ||||
assert_instances_of($engines, 'PhabricatorFileStorageEngine'); | assert_instances_of($engines, 'PhabricatorFileStorageEngine'); | ||||
if (!$engines) { | if (!$engines) { | ||||
throw new Exception(pht('No valid storage engines are available!')); | throw new Exception(pht('No valid storage engines are available!')); | ||||
} | } | ||||
$file = self::initializeNewFile(); | $file = self::initializeNewFile(); | ||||
$aes_type = PhabricatorFileAES256StorageFormat::FORMATKEY; | |||||
$has_aes = PhabricatorKeyring::getDefaultKeyName($aes_type); | |||||
if ($has_aes !== null) { | |||||
$default_key = PhabricatorFileAES256StorageFormat::FORMATKEY; | |||||
} else { | |||||
$default_key = PhabricatorFileRawStorageFormat::FORMATKEY; | $default_key = PhabricatorFileRawStorageFormat::FORMATKEY; | ||||
} | |||||
$key = idx($params, 'format', $default_key); | $key = idx($params, 'format', $default_key); | ||||
// Callers can pass in an object explicitly instead of a key. This is | // Callers can pass in an object explicitly instead of a key. This is | ||||
// primarily useful for unit tests. | // primarily useful for unit tests. | ||||
if ($key instanceof PhabricatorFileStorageFormat) { | if ($key instanceof PhabricatorFileStorageFormat) { | ||||
$format = clone $key; | $format = clone $key; | ||||
} else { | } else { | ||||
$format = clone PhabricatorFileStorageFormat::requireFormat($key); | $format = clone PhabricatorFileStorageFormat::requireFormat($key); | ||||
▲ Show 20 Lines • Show All 101 Lines • ▼ Show 20 Lines | public function migrateToEngine(PhabricatorFileStorageEngine $engine) { | ||||
$this->deleteFileDataIfUnused( | $this->deleteFileDataIfUnused( | ||||
$old_engine, | $old_engine, | ||||
$old_identifier, | $old_identifier, | ||||
$old_handle); | $old_handle); | ||||
return $this; | return $this; | ||||
} | } | ||||
public function migrateToStorageFormat(PhabricatorFileStorageFormat $format) { | |||||
if (!$this->getID() || !$this->getStorageHandle()) { | |||||
throw new Exception( | |||||
pht("You can not migrate a file which hasn't yet been saved.")); | |||||
} | |||||
$data = $this->loadFileData(); | |||||
$params = array( | |||||
'name' => $this->getName(), | |||||
); | |||||
$engine = $this->instantiateStorageEngine(); | |||||
$old_handle = $this->getStorageHandle(); | |||||
$properties = $format->newStorageProperties(); | |||||
$this->setStorageFormat($format->getStorageFormatKey()); | |||||
$this->setStorageProperties($properties); | |||||
list($identifier, $new_handle) = $this->writeToEngine( | |||||
$engine, | |||||
$data, | |||||
$params); | |||||
$this->setStorageHandle($new_handle); | |||||
$this->save(); | |||||
$this->deleteFileDataIfUnused( | |||||
$engine, | |||||
$identifier, | |||||
$old_handle); | |||||
return $this; | |||||
} | |||||
public function cycleMasterStorageKey(PhabricatorFileStorageFormat $format) { | |||||
if (!$this->getID() || !$this->getStorageHandle()) { | |||||
throw new Exception( | |||||
pht("You can not cycle keys for a file which hasn't yet been saved.")); | |||||
} | |||||
$properties = $format->cycleStorageProperties(); | |||||
$this->setStorageProperties($properties); | |||||
$this->save(); | |||||
return $this; | |||||
} | |||||
private function writeToEngine( | private function writeToEngine( | ||||
PhabricatorFileStorageEngine $engine, | PhabricatorFileStorageEngine $engine, | ||||
$data, | $data, | ||||
array $params) { | array $params) { | ||||
$engine_class = get_class($engine); | $engine_class = get_class($engine); | ||||
$key = $this->getStorageFormat(); | $key = $this->getStorageFormat(); | ||||
▲ Show 20 Lines • Show All 950 Lines • Show Last 20 Lines |