Changeset View
Changeset View
Standalone View
Standalone View
src/applications/files/storage/PhabricatorFile.php
Show First 20 Lines • Show All 416 Lines • ▼ Show 20 Lines | public static function newFromFileData($data, array $params = array()) { | ||||
if ($file) { | if ($file) { | ||||
return $file; | return $file; | ||||
} | } | ||||
return self::buildFromFileData($data, $params); | return self::buildFromFileData($data, $params); | ||||
} | } | ||||
public function migrateToEngine(PhabricatorFileStorageEngine $engine) { | public function migrateToEngine( | ||||
PhabricatorFileStorageEngine $engine, | |||||
$make_copy) { | |||||
if (!$this->getID() || !$this->getStorageHandle()) { | if (!$this->getID() || !$this->getStorageHandle()) { | ||||
throw new Exception( | throw new Exception( | ||||
pht("You can not migrate a file which hasn't yet been saved.")); | pht("You can not migrate a file which hasn't yet been saved.")); | ||||
} | } | ||||
$data = $this->loadFileData(); | $data = $this->loadFileData(); | ||||
$params = array( | $params = array( | ||||
'name' => $this->getName(), | 'name' => $this->getName(), | ||||
); | ); | ||||
list($new_identifier, $new_handle) = $this->writeToEngine( | list($new_identifier, $new_handle) = $this->writeToEngine( | ||||
$engine, | $engine, | ||||
$data, | $data, | ||||
$params); | $params); | ||||
$old_engine = $this->instantiateStorageEngine(); | $old_engine = $this->instantiateStorageEngine(); | ||||
$old_identifier = $this->getStorageEngine(); | $old_identifier = $this->getStorageEngine(); | ||||
$old_handle = $this->getStorageHandle(); | $old_handle = $this->getStorageHandle(); | ||||
$this->setStorageEngine($new_identifier); | $this->setStorageEngine($new_identifier); | ||||
$this->setStorageHandle($new_handle); | $this->setStorageHandle($new_handle); | ||||
$this->save(); | $this->save(); | ||||
if (!$make_copy) { | |||||
$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) { | public function migrateToStorageFormat(PhabricatorFileStorageFormat $format) { | ||||
if (!$this->getID() || !$this->getStorageHandle()) { | if (!$this->getID() || !$this->getStorageHandle()) { | ||||
throw new Exception( | throw new Exception( | ||||
pht("You can not migrate a file which hasn't yet been saved.")); | pht("You can not migrate a file which hasn't yet been saved.")); | ||||
▲ Show 20 Lines • Show All 1,003 Lines • Show Last 20 Lines |