mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-23 18:03:17 +00:00
@@ -26,7 +26,7 @@ class RecordEditSubscriber implements EventSubscriberInterface
|
|||||||
return array(
|
return array(
|
||||||
PhraseaEvents::RECORD_EDIT => 'onEdit',
|
PhraseaEvents::RECORD_EDIT => 'onEdit',
|
||||||
PhraseaEvents::RECORD_UPLOAD => 'onEdit',
|
PhraseaEvents::RECORD_UPLOAD => 'onEdit',
|
||||||
RecordEvents::ROTATE => 'onRotate',
|
RecordEvents::ROTATE => 'onRecordChange',
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -81,18 +81,26 @@ class MediaSubdefRepository
|
|||||||
*/
|
*/
|
||||||
public function save($subdefs)
|
public function save($subdefs)
|
||||||
{
|
{
|
||||||
if (!is_array($subdefs) || !$subdefs instanceof \Traversable) {
|
$data = array_map([$this->hydrator, 'extract'], $this->normalizeToArray($subdefs));
|
||||||
$subdefs = [$subdefs];
|
|
||||||
} elseif ($subdefs instanceof \Traversable) {
|
|
||||||
$subdefs = iterator_to_array($subdefs);
|
|
||||||
}
|
|
||||||
Assertion::allIsInstanceOf($subdefs, \media_subdef::class);
|
|
||||||
|
|
||||||
$data = array_map([$this->hydrator, 'extract'], $subdefs);
|
|
||||||
|
|
||||||
$this->repository->save($data);
|
$this->repository->save($data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param \media_subdef|\media_subdef[] $subdefs
|
||||||
|
*/
|
||||||
|
public function delete($subdefs)
|
||||||
|
{
|
||||||
|
$subdefIds = array_map(function (\media_subdef $subdef) {
|
||||||
|
return [
|
||||||
|
'record_id' => $subdef->get_record_id(),
|
||||||
|
'name' => $subdef->get_name(),
|
||||||
|
];
|
||||||
|
}, $this->normalizeToArray($subdefs));
|
||||||
|
|
||||||
|
$this->repository->delete($subdefIds);
|
||||||
|
}
|
||||||
|
|
||||||
public function clear()
|
public function clear()
|
||||||
{
|
{
|
||||||
$this->idMap = [];
|
$this->idMap = [];
|
||||||
@@ -135,4 +143,20 @@ class MediaSubdefRepository
|
|||||||
|
|
||||||
return $instances;
|
return $instances;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param \media_subdef|\media_subdef[] $subdefs
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
private function normalizeToArray($subdefs)
|
||||||
|
{
|
||||||
|
if (!is_array($subdefs) || !$subdefs instanceof \Traversable) {
|
||||||
|
$subdefs = [$subdefs];
|
||||||
|
} elseif ($subdefs instanceof \Traversable) {
|
||||||
|
$subdefs = iterator_to_array($subdefs);
|
||||||
|
}
|
||||||
|
Assertion::allIsInstanceOf($subdefs, \media_subdef::class);
|
||||||
|
|
||||||
|
return $subdefs;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -158,39 +158,16 @@ class media_subdef extends media_abstract implements cache_cacheableInterface
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$sql = <<<'SQL'
|
$data = self::getMediaSubdefRepository($this->app, $this->record->getDataboxId())
|
||||||
SELECT subdef_id, name, file, width, height, mime, path, size, substit, created_on, updated_on, etag
|
->findOneByRecordIdAndName($this->record->getRecordId(), $this->name);
|
||||||
FROM subdef
|
|
||||||
WHERE name = :name AND record_id = :record_id
|
|
||||||
SQL;
|
|
||||||
|
|
||||||
$row = $this->getDataboxConnection()->fetchAssoc($sql, [
|
if ($data) {
|
||||||
'record_id' => $this->record->getRecordId(),
|
$this->loadFromArray($data->toArray());
|
||||||
'name' => $this->name
|
|
||||||
]);
|
|
||||||
|
|
||||||
if ($row) {
|
|
||||||
$this->loadFromArray([
|
|
||||||
'width' => (int)$row['width'],
|
|
||||||
'size' => (int)$row['size'],
|
|
||||||
'height' => (int)$row['height'],
|
|
||||||
'mime' => $row['mime'],
|
|
||||||
'file' => $row['file'],
|
|
||||||
'path' => p4string::addEndSlash($row['path']),
|
|
||||||
'physically_present' => true,
|
|
||||||
'is_substituted' => (bool)$row['substit'],
|
|
||||||
'subdef_id' => (int)$row['subdef_id'],
|
|
||||||
'updated_on' => $row['updated_on'],
|
|
||||||
'created_on' => $row['created_on'],
|
|
||||||
'etag' => $row['etag'] ?: null,
|
|
||||||
]);
|
|
||||||
} elseif ($substitute === false) {
|
} elseif ($substitute === false) {
|
||||||
throw new Exception_Media_SubdefNotFound($this->name . ' not found');
|
throw new Exception_Media_SubdefNotFound($this->name . ' not found');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$row) {
|
$this->loadFromArray([]);
|
||||||
$this->markPhysicallyUnavailable();
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->set_data_to_cache($this->toArray());
|
$this->set_data_to_cache($this->toArray());
|
||||||
}
|
}
|
||||||
@@ -293,21 +270,16 @@ SQL;
|
|||||||
*/
|
*/
|
||||||
public function delete()
|
public function delete()
|
||||||
{
|
{
|
||||||
$subdef_id = $this->subdef_id;
|
|
||||||
$this->remove_file();
|
$this->remove_file();
|
||||||
|
|
||||||
$connection = $this->getDataboxConnection();
|
$connection = $this->getDataboxConnection();
|
||||||
|
|
||||||
$connection->executeUpdate(
|
|
||||||
'DELETE FROM subdef WHERE subdef_id = :subdef_id',
|
|
||||||
['subdef_id' => $subdef_id]
|
|
||||||
);
|
|
||||||
|
|
||||||
$connection->executeUpdate(
|
$connection->executeUpdate(
|
||||||
'DELETE FROM permalinks WHERE subdef_id = :subdef_id',
|
'DELETE FROM permalinks WHERE subdef_id = :subdef_id',
|
||||||
['subdef_id'=>$subdef_id]
|
['subdef_id' => $this->subdef_id]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
self::getMediaSubdefRepository($this->app, $this->record->getDataboxId())->delete($this);
|
||||||
$this->delete_data_from_cache();
|
$this->delete_data_from_cache();
|
||||||
$this->record->delete_data_from_cache(record_adapter::CACHE_SUBDEFS);
|
$this->record->delete_data_from_cache(record_adapter::CACHE_SUBDEFS);
|
||||||
}
|
}
|
||||||
@@ -336,6 +308,7 @@ SQL;
|
|||||||
$this->width = 256;
|
$this->width = 256;
|
||||||
$this->height = 256;
|
$this->height = 256;
|
||||||
$this->file = $this->getSubstituteFilename();
|
$this->file = $this->getSubstituteFilename();
|
||||||
|
$this->etag = null;
|
||||||
|
|
||||||
$this->path = $this->app['root.path'] . '/www/assets/common/images/icons/substitution/';
|
$this->path = $this->app['root.path'] . '/www/assets/common/images/icons/substitution/';
|
||||||
$this->url = Url::factory('/assets/common/images/icons/substitution/' . $this->file);
|
$this->url = Url::factory('/assets/common/images/icons/substitution/' . $this->file);
|
||||||
@@ -403,12 +376,7 @@ SQL;
|
|||||||
{
|
{
|
||||||
$this->etag = $etag;
|
$this->etag = $etag;
|
||||||
|
|
||||||
$this->getDataboxConnection()->executeUpdate(
|
return $this->save();
|
||||||
'UPDATE subdef SET etag = :etag WHERE subdef_id = :subdef_id',
|
|
||||||
[':subdef_id' => $this->subdef_id, ':etag' => $etag]
|
|
||||||
);
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -418,17 +386,7 @@ SQL;
|
|||||||
{
|
{
|
||||||
$this->is_substituted = !!$substit;
|
$this->is_substituted = !!$substit;
|
||||||
|
|
||||||
$this->getDataboxConnection()->executeUpdate(
|
return $this->save();
|
||||||
'UPDATE subdef SET substit = :substit, updated_on=NOW() WHERE subdef_id = :subdef_id',
|
|
||||||
[
|
|
||||||
':subdef_id' => $this->subdef_id,
|
|
||||||
':substit' => $this->is_substituted
|
|
||||||
]
|
|
||||||
);
|
|
||||||
|
|
||||||
$this->delete_data_from_cache();
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -607,27 +565,10 @@ SQL;
|
|||||||
|
|
||||||
$media = $mediavorus->guess($this->getRealPath());
|
$media = $mediavorus->guess($this->getRealPath());
|
||||||
|
|
||||||
$sql = <<<'SQL'
|
|
||||||
UPDATE subdef SET height = :height , width = :width, updated_on = NOW()
|
|
||||||
WHERE record_id = :record_id AND name = :name
|
|
||||||
SQL;
|
|
||||||
|
|
||||||
$this->getDataboxConnection()->executeUpdate(
|
|
||||||
$sql,
|
|
||||||
[
|
|
||||||
':width' => $media->getWidth(),
|
|
||||||
':height' => $media->getHeight(),
|
|
||||||
':record_id' => $this->get_record_id(),
|
|
||||||
':name' => $this->get_name(),
|
|
||||||
]
|
|
||||||
);
|
|
||||||
|
|
||||||
$this->width = $media->getWidth();
|
$this->width = $media->getWidth();
|
||||||
$this->height = $media->getHeight();
|
$this->height = $media->getHeight();
|
||||||
|
|
||||||
$this->delete_data_from_cache();
|
return $this->save();
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -796,7 +737,6 @@ SQL;
|
|||||||
|
|
||||||
public function delete_data_from_cache($option = null)
|
public function delete_data_from_cache($option = null)
|
||||||
{
|
{
|
||||||
$this->setEtag(null);
|
|
||||||
$databox = $this->get_record()->getDatabox();
|
$databox = $this->get_record()->getDatabox();
|
||||||
|
|
||||||
$databox->delete_data_from_cache($this->get_cache_key($option));
|
$databox->delete_data_from_cache($this->get_cache_key($option));
|
||||||
@@ -873,4 +813,14 @@ SQL;
|
|||||||
|
|
||||||
return $this->app['phraseanet.h264']->getUrl($this->getRealPath());
|
return $this->app['phraseanet.h264']->getUrl($this->getRealPath());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
private function save()
|
||||||
|
{
|
||||||
|
self::getMediaSubdefRepository($this->app, $this->record->getDataboxId())->save($this);
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user