mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-17 15:03:25 +00:00
Remove binary Adapters
This commit is contained in:
@@ -12,261 +12,248 @@
|
||||
class lazaretFile
|
||||
{
|
||||
|
||||
protected $storage = array();
|
||||
protected $storage = array();
|
||||
|
||||
/**
|
||||
*
|
||||
* @param int $lazaret_id
|
||||
* @return lazaretFile
|
||||
*/
|
||||
function __construct($lazaret_id)
|
||||
{
|
||||
$conn = connection::getPDOConnection();
|
||||
/**
|
||||
*
|
||||
* @param int $lazaret_id
|
||||
* @return lazaretFile
|
||||
*/
|
||||
function __construct($lazaret_id)
|
||||
{
|
||||
$conn = connection::getPDOConnection();
|
||||
|
||||
$sql = 'SELECT filename, filepath, base_id,
|
||||
$sql = 'SELECT filename, filepath, base_id,
|
||||
uuid, status, created_on, usr_id
|
||||
FROM lazaret WHERE id = :lazaret_id';
|
||||
|
||||
$stmt = $conn->prepare($sql);
|
||||
$stmt->execute(array(':lazaret_id' => $lazaret_id));
|
||||
$row = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
$stmt = $conn->prepare($sql);
|
||||
$stmt->execute(array(':lazaret_id' => $lazaret_id));
|
||||
$row = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
|
||||
if (!$row)
|
||||
throw new Exception(_('L\'element n\'existe pas ou plus'));
|
||||
if ( ! $row)
|
||||
throw new Exception(_('L\'element n\'existe pas ou plus'));
|
||||
|
||||
$this->id = $lazaret_id;
|
||||
$this->filename = $row['filename'];
|
||||
$this->filepath = $row['filepath'];
|
||||
$this->status = $row['status'];
|
||||
$this->base_id = $row['base_id'];
|
||||
$this->uuid = $row['uuid'];
|
||||
$this->created_on = new DateTime($row['created_on']);
|
||||
$this->usr_id = $row['usr_id'];
|
||||
$this->id = $lazaret_id;
|
||||
$this->filename = $row['filename'];
|
||||
$this->filepath = $row['filepath'];
|
||||
$this->status = $row['status'];
|
||||
$this->base_id = $row['base_id'];
|
||||
$this->uuid = $row['uuid'];
|
||||
$this->created_on = new DateTime($row['created_on']);
|
||||
$this->usr_id = $row['usr_id'];
|
||||
|
||||
return $this;
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return lazaretFile
|
||||
*/
|
||||
public function add_to_base()
|
||||
{
|
||||
$registry = registry::get_instance();
|
||||
/**
|
||||
*
|
||||
* @return lazaretFile
|
||||
*/
|
||||
public function add_to_base()
|
||||
{
|
||||
$registry = registry::get_instance();
|
||||
|
||||
$file = new system_file($registry->get('GV_RootPath') . 'tmp/lazaret/' . $this->filepath);
|
||||
$file = new system_file($registry->get('GV_RootPath') . 'tmp/lazaret/' . $this->filepath);
|
||||
|
||||
if (($record_id = p4file::archiveFile(
|
||||
$file, $this->base_id, false, $this->filename)) === false)
|
||||
throw new Exception(_('Impossible dajouter le fichier a la base'));
|
||||
if (($record_id = p4file::archiveFile(
|
||||
$file, $this->base_id, false, $this->filename)) === false)
|
||||
throw new Exception(_('Impossible dajouter le fichier a la base'));
|
||||
|
||||
$sbas_id = phrasea::sbasFromBas($this->base_id);
|
||||
$connbas = connection::getPDOConnection($sbas_id);
|
||||
$sbas_id = phrasea::sbasFromBas($this->base_id);
|
||||
$connbas = connection::getPDOConnection($sbas_id);
|
||||
|
||||
$sql = 'UPDATE record
|
||||
$sql = 'UPDATE record
|
||||
SET status = (status | ' . $this->status . ')
|
||||
WHERE record_id = :record_id';
|
||||
|
||||
$stmt = $connbas->prepare($sql);
|
||||
$stmt->execute(array(':record_id' => $record_id));
|
||||
$stmt->closeCursor();
|
||||
$stmt = $connbas->prepare($sql);
|
||||
$stmt->execute(array(':record_id' => $record_id));
|
||||
$stmt->closeCursor();
|
||||
|
||||
$this->delete();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return lazaretFile
|
||||
*/
|
||||
public function delete()
|
||||
{
|
||||
$conn = connection::getPDOConnection();
|
||||
$registry = registry::get_instance();
|
||||
|
||||
try
|
||||
{
|
||||
$sql = 'DELETE FROM lazaret WHERE id = :lazaret_id';
|
||||
$stmt = $conn->prepare($sql);
|
||||
$stmt->execute(array(':lazaret_id' => $this->id));
|
||||
$stmt->closeCursor();
|
||||
|
||||
$file = $registry->get('GV_RootPath') . 'tmp/lazaret/' . $this->filepath;
|
||||
$thumbnail = $file . '_thumbnail.jpg';
|
||||
|
||||
@unlink($thumbnail);
|
||||
@unlink($file);
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
$this->delete();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param Int $lazaret_id
|
||||
* @param Int $record_id
|
||||
* @return lazaretFile
|
||||
*/
|
||||
public function substitute($lazaret_id, $record_id)
|
||||
{
|
||||
$registry = registry::get_instance();
|
||||
|
||||
$sbas_id = phrasea::sbasFromBas($this->base_id);
|
||||
$connbas = connection::getPDOConnection($sbas_id);
|
||||
|
||||
$base_id = false;
|
||||
|
||||
$sql = 'SELECT coll_id FROM record WHERE record_id = :record_id';
|
||||
|
||||
$stmt = $connbas->prepare($sql);
|
||||
$stmt->execute(array(':record_id' => $record_id));
|
||||
$row = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
|
||||
if (!$row)
|
||||
throw new Exception(_('Impossible de trouver la base'));
|
||||
|
||||
$base_id = phrasea::baseFromColl($sbas_id, $row['coll_id']);
|
||||
|
||||
$pathfile = $registry->get('GV_RootPath') . 'tmp/lazaret/' . $this->filepath;
|
||||
|
||||
$record = new record_adapter($sbas_id, $record_id);
|
||||
$record->substitute_subdef('document', new system_file($pathfile));
|
||||
|
||||
$this->delete();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public static function move_uploaded_to_lazaret(
|
||||
system_file $system_file, $base_id, $filename, $errors='', $status=false)
|
||||
{
|
||||
$appbox = appbox::get_instance(\bootstrap::getCore());
|
||||
$session = $appbox->get_session();
|
||||
$registry = $appbox->get_registry();
|
||||
$conn = $appbox->get_connection();
|
||||
$system = system_server::get_platform();
|
||||
|
||||
if (!$status)
|
||||
$status = '0';
|
||||
|
||||
$usr_id = $session->is_authenticated() ? $session->get_usr_id() : false;
|
||||
|
||||
$lazaret_root = $registry->get('GV_RootPath') . 'tmp/lazaret/';
|
||||
$pathinfo = pathinfo($filename);
|
||||
|
||||
$tmp_filename = $filename;
|
||||
|
||||
$n = 1;
|
||||
while (file_exists($lazaret_root . $tmp_filename))
|
||||
/**
|
||||
*
|
||||
* @return lazaretFile
|
||||
*/
|
||||
public function delete()
|
||||
{
|
||||
$tmp_filename = $pathinfo['filename']
|
||||
$conn = connection::getPDOConnection();
|
||||
$registry = registry::get_instance();
|
||||
|
||||
try
|
||||
{
|
||||
$sql = 'DELETE FROM lazaret WHERE id = :lazaret_id';
|
||||
$stmt = $conn->prepare($sql);
|
||||
$stmt->execute(array(':lazaret_id' => $this->id));
|
||||
$stmt->closeCursor();
|
||||
|
||||
$file = $registry->get('GV_RootPath') . 'tmp/lazaret/' . $this->filepath;
|
||||
$thumbnail = $file . '_thumbnail.jpg';
|
||||
|
||||
@unlink($thumbnail);
|
||||
@unlink($file);
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param Int $lazaret_id
|
||||
* @param Int $record_id
|
||||
* @return lazaretFile
|
||||
*/
|
||||
public function substitute($lazaret_id, $record_id)
|
||||
{
|
||||
$registry = registry::get_instance();
|
||||
|
||||
$sbas_id = phrasea::sbasFromBas($this->base_id);
|
||||
$connbas = connection::getPDOConnection($sbas_id);
|
||||
|
||||
$base_id = false;
|
||||
|
||||
$sql = 'SELECT coll_id FROM record WHERE record_id = :record_id';
|
||||
|
||||
$stmt = $connbas->prepare($sql);
|
||||
$stmt->execute(array(':record_id' => $record_id));
|
||||
$row = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
|
||||
if ( ! $row)
|
||||
throw new Exception(_('Impossible de trouver la base'));
|
||||
|
||||
$base_id = phrasea::baseFromColl($sbas_id, $row['coll_id']);
|
||||
|
||||
$pathfile = $registry->get('GV_RootPath') . 'tmp/lazaret/' . $this->filepath;
|
||||
|
||||
$record = new record_adapter($sbas_id, $record_id);
|
||||
$record->substitute_subdef('document', new system_file($pathfile));
|
||||
|
||||
$this->delete();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public static function move_uploaded_to_lazaret(system_file $system_file, $base_id, $filename, $errors = '', $status = false)
|
||||
{
|
||||
$Core = \bootstrap::getCore();
|
||||
$appbox = appbox::get_instance($Core);
|
||||
$session = $appbox->get_session();
|
||||
$registry = $appbox->get_registry();
|
||||
$conn = $appbox->get_connection();
|
||||
|
||||
if ( ! $status)
|
||||
{
|
||||
$status = '0';
|
||||
}
|
||||
|
||||
$usr_id = $session->is_authenticated() ? $session->get_usr_id() : false;
|
||||
|
||||
$lazaret_root = $registry->get('GV_RootPath') . 'tmp/lazaret/';
|
||||
$pathinfo = pathinfo($filename);
|
||||
|
||||
$tmp_filename = $filename;
|
||||
|
||||
$n = 1;
|
||||
while (file_exists($lazaret_root . $tmp_filename))
|
||||
{
|
||||
$tmp_filename = $pathinfo['filename']
|
||||
. '-' . $n . '.' . $pathinfo['extension'];
|
||||
$n++;
|
||||
}
|
||||
$n ++;
|
||||
}
|
||||
|
||||
$pathfile = $lazaret_root . $tmp_filename;
|
||||
$uuid = $system_file->read_uuid();
|
||||
$sha256 = $system_file->get_sha256();
|
||||
rename($system_file->getPathname(), $pathfile);
|
||||
$pathfile = $lazaret_root . $tmp_filename;
|
||||
$uuid = $system_file->read_uuid();
|
||||
$sha256 = $system_file->get_sha256();
|
||||
rename($system_file->getPathname(), $pathfile);
|
||||
|
||||
unset($system_file);
|
||||
unset($system_file);
|
||||
|
||||
$system_file = new system_file($pathfile);
|
||||
$system_file->chmod();
|
||||
$system_file = new system_file($pathfile);
|
||||
$system_file->chmod();
|
||||
|
||||
try
|
||||
{
|
||||
$system_file = new system_file($pathfile);
|
||||
switch ($system_file->get_phrasea_type())
|
||||
{
|
||||
case 'image':
|
||||
default:
|
||||
$adapter = new binaryAdapter_image_resize($registry);
|
||||
break;
|
||||
case 'video':
|
||||
$adapter = new binaryAdapter_video_toimage($registry);
|
||||
break;
|
||||
case 'flash':
|
||||
$adapter = new binaryAdapter_flash_toimage($registry);
|
||||
break;
|
||||
case 'audio':
|
||||
$adapter = new binaryAdapter_audio_previewExtract($registry);
|
||||
break;
|
||||
}
|
||||
$adapter->execute($system_file, $pathfile . "_thumbnail.jpg", array('size' => 300));
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
try
|
||||
{
|
||||
$spec = new MediaAlchemyst\Specification\Image();
|
||||
$spec->setDimensions(200, 200);
|
||||
|
||||
}
|
||||
$Core['media-alchemyst']
|
||||
->open($pathfile)
|
||||
->turnInto($spec, $pathfile . "_thumbnail.jpg")
|
||||
->close();
|
||||
}
|
||||
catch (\MediaAlchemyst\Exception\RuntimeException $e)
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
}
|
||||
|
||||
$sql = 'INSERT INTO lazaret
|
||||
try
|
||||
{
|
||||
|
||||
$sql = 'INSERT INTO lazaret
|
||||
(id, filename, filepath, base_id, uuid, sha256,
|
||||
errors, status, created_on, usr_id)
|
||||
VALUES (null, :filename, :filepath, :base_id,
|
||||
:uuid, :sha256, :errors, 0b' . $status . ', NOW(), :usr_id )';
|
||||
|
||||
$params = array(
|
||||
':filename' => $filename
|
||||
, ':filepath' => $tmp_filename
|
||||
, ':base_id' => $base_id
|
||||
, ':uuid' => $uuid
|
||||
, ':sha256' => $sha256
|
||||
, ':errors' => $errors
|
||||
, ':usr_id' => ($usr_id ? $usr_id : null
|
||||
)
|
||||
);
|
||||
$params = array(
|
||||
':filename' => $filename
|
||||
, ':filepath' => $tmp_filename
|
||||
, ':base_id' => $base_id
|
||||
, ':uuid' => $uuid
|
||||
, ':sha256' => $sha256
|
||||
, ':errors' => $errors
|
||||
, ':usr_id' => ($usr_id ? $usr_id : null
|
||||
)
|
||||
);
|
||||
|
||||
$stmt = $conn->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
$stmt->closeCursor();
|
||||
$stmt = $conn->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
$stmt->closeCursor();
|
||||
|
||||
return true;
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function stream_thumbnail($id)
|
||||
{
|
||||
$conn = connection::getPDOConnection();
|
||||
$registry = registry::get_instance();
|
||||
$sql = "SELECT filepath FROM lazaret WHERE id = :lazaret_id";
|
||||
|
||||
$stmt = $conn->prepare($sql);
|
||||
$stmt->execute(array(':lazaret_id' => $id));
|
||||
$row = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
|
||||
if ($row)
|
||||
public static function stream_thumbnail($id)
|
||||
{
|
||||
$pathfile = $registry->get('GV_RootPath') . 'tmp/lazaret/'
|
||||
$conn = connection::getPDOConnection();
|
||||
$registry = registry::get_instance();
|
||||
$sql = "SELECT filepath FROM lazaret WHERE id = :lazaret_id";
|
||||
|
||||
$stmt = $conn->prepare($sql);
|
||||
$stmt->execute(array(':lazaret_id' => $id));
|
||||
$row = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
|
||||
if ($row)
|
||||
{
|
||||
$pathfile = $registry->get('GV_RootPath') . 'tmp/lazaret/'
|
||||
. $row['filepath'] . '_thumbnail.jpg';
|
||||
|
||||
$response = set_export::stream_file(
|
||||
$pathfile,
|
||||
basename($pathfile),
|
||||
'image/jpeg',
|
||||
'inline'
|
||||
);
|
||||
$response->send();
|
||||
$response = set_export::stream_file(
|
||||
$pathfile, basename($pathfile), 'image/jpeg', 'inline'
|
||||
);
|
||||
$response->send();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user