2011-01-22 18:33:00 -08:00
|
|
|
<?php
|
|
|
|
|
|
2011-07-19 22:48:38 -07:00
|
|
|
/**
|
|
|
|
|
* Simple blob store DAO for @{class:PhabricatorMySQLFileStorageEngine}.
|
|
|
|
|
*
|
|
|
|
|
* @group filestorage
|
|
|
|
|
*/
|
2012-03-13 11:18:11 -07:00
|
|
|
final class PhabricatorFileStorageBlob extends PhabricatorFileDAO {
|
2012-08-27 15:40:28 -07:00
|
|
|
// max_allowed_packet defaults to 1 MiB, escaping can make the data twice
|
|
|
|
|
// longer, query fits in the rest.
|
|
|
|
|
const CHUNK_SIZE = 5e5;
|
2011-01-22 18:33:00 -08:00
|
|
|
|
|
|
|
|
protected $data;
|
|
|
|
|
|
2012-08-27 15:40:28 -07:00
|
|
|
private $fullData;
|
|
|
|
|
|
|
|
|
|
protected function willWriteData(array &$data) {
|
|
|
|
|
parent::willWriteData($data);
|
|
|
|
|
|
|
|
|
|
$this->fullData = $data['data'];
|
|
|
|
|
if (strlen($data['data']) > self::CHUNK_SIZE) {
|
|
|
|
|
$data['data'] = substr($data['data'], 0, self::CHUNK_SIZE);
|
|
|
|
|
$this->openTransaction();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function didWriteData() {
|
|
|
|
|
$size = self::CHUNK_SIZE;
|
|
|
|
|
$length = strlen($this->fullData);
|
|
|
|
|
if ($length > $size) {
|
|
|
|
|
$conn = $this->establishConnection('w');
|
|
|
|
|
for ($offset = $size; $offset < $length; $offset += $size) {
|
|
|
|
|
queryfx(
|
|
|
|
|
$conn,
|
|
|
|
|
'UPDATE %T SET data = CONCAT(data, %s) WHERE %C = %d',
|
|
|
|
|
$this->getTableName(),
|
|
|
|
|
substr($this->fullData, $offset, $size),
|
|
|
|
|
$this->getIDKeyForUse(),
|
|
|
|
|
$this->getID());
|
|
|
|
|
}
|
|
|
|
|
$this->saveTransaction();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
parent::didWriteData();
|
|
|
|
|
}
|
|
|
|
|
|
2011-01-22 18:33:00 -08:00
|
|
|
}
|