Merge pull request #1091 from nlegoff/yeah-yeah-yeah

[3.8.6][PHRAS-136] Add static file mode to serve thumbnails
This commit is contained in:
Nicolas Le Goff
2014-09-24 14:07:06 +02:00
24 changed files with 828 additions and 11 deletions

View File

@@ -445,6 +445,21 @@ class databox extends base
public function unmount_databox()
{
if ($this->app['phraseanet.static-file-factory']->isStaticFileModeEnabled()) {
$sql = "SELECT path, file FROM subdef WHERE `name`='thumbnail'";
$stmt = $this->get_connection()->prepare($sql);
$stmt->execute();
$rows = $stmt->fetchAll(\PDO::FETCH_ASSOC);
$stmt->closeCursor();
foreach ($rows as $row) {
$pathfile = $this->app['phraseanet.thumb-symlinker']->getSymlinkPath(sprintf(
'%s/%s',
rtrim($row['path'], '/'),
$row['file']
));
$this->app['filesystem']->remove($pathfile);
}
}
foreach ($this->get_collections() as $collection) {
$collection->unmount_collection($this->app);
}

View File

@@ -730,6 +730,10 @@ class media_subdef extends media_abstract implements cache_cacheableInterface
$subdef->get_permalink()->delete_data_from_cache();
}
if ($name === 'thumbnail' && $app['phraseanet.static-file-factory']->isStaticFileModeEnabled()) {
$app['phraseanet.thumb-symlinker']->symlink($subdef->get_pathfile());
}
unset($media);
return $subdef;
@@ -742,10 +746,18 @@ class media_subdef extends media_abstract implements cache_cacheableInterface
*/
protected function generate_url()
{
if ( ! $this->is_physically_present()) {
if (!$this->is_physically_present()) {
return;
}
if ($this->get_name() === 'thumbnail') {
if ($this->app['phraseanet.static-file-factory']->isStaticFileModeEnabled() && null !== $url = $this->app['phraseanet.static-file']->getUrl($this->get_pathfile())) {
$this->url = $url;
return;
}
}
if ($this->app['phraseanet.h264-factory']->isH264Enabled() && in_array($this->mime, array('video/mp4'))) {
if (null !== $url = $this->app['phraseanet.h264']->getUrl($this->get_pathfile())) {
$this->url = $url;
@@ -758,6 +770,7 @@ class media_subdef extends media_abstract implements cache_cacheableInterface
. "/" . $this->record->get_record_id() . "/"
. $this->get_name() . "/");
return;
}

View File

@@ -0,0 +1,65 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2014 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
use Alchemy\Phrasea\Application;
use Symfony\Component\Finder\Finder;
use Symfony\Component\Filesystem\Filesystem;
class patch_386alpha3a implements patchInterface
{
/** @var string */
private $release = '3.8.5-alpha.1';
/** @var array */
private $concern = array(base::APPLICATION_BOX);
/**
* {@inheritdoc}
*/
public function get_release()
{
return $this->release;
}
/**
* {@inheritdoc}
*/
public function require_all_upgrades()
{
return false;
}
/**
* {@inheritdoc}
*/
public function concern()
{
return $this->concern;
}
/**
* {@inheritdoc}
*/
public function apply(base $appbox, Application $app)
{
$config = $app['phraseanet.configuration']->getConfig();
$config['static-file'] = array(
'enabled' => false,
'type' => '',
'symlink-directory' => '',
);
$app['phraseanet.configuration']->setConfig($config);
return true;
}
}

View File

@@ -1514,6 +1514,10 @@ class record_adapter implements record_Interface, cache_cacheableInterface
if (!$subdef->is_physically_present())
continue;
if ($subdef->get_name() === 'thumbnail' && $this->app['phraseanet.static-file-factory']->isStaticFileModeEnabled()) {
$this->app['filesystem']->remove($this->app['phraseanet.thumb-symlinker']->getSymlinkPath($subdef->get_pathfile()));
}
$ftodel[] = $subdef->get_pathfile();
$watermark = $subdef->get_path() . 'watermark_' . $subdef->get_file();
if (file_exists($watermark))