Merge remote-tracking branch 'upstream/master' into 20150306-elastic-indexer

Conflicts:
	bin/console
	bower.json
	composer.json
	composer.lock
	lib/Alchemy/Phrasea/Application.php
	lib/Alchemy/Phrasea/Border/Manager.php
	lib/Alchemy/Phrasea/Controller/Api/V1.php
	lib/Alchemy/Phrasea/Core/PhraseaEvents.php
	lib/Alchemy/Phrasea/SearchEngine/SearchEngineOptions.php
	lib/classes/caption/field.php
	lib/classes/record/Interface.php
	templates/web/prod/index.html.twig
	www/skins/prod/000000/prodcolor.css
This commit is contained in:
Nicolas Le Goff
2015-03-06 14:35:29 +01:00
committed by Mathieu Darse
1078 changed files with 7964 additions and 16363 deletions

View File

@@ -3,7 +3,7 @@
/*
* This file is part of Phraseanet
*
* (c) 2005-2014 Alchemy
* (c) 2005-2015 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
@@ -315,6 +315,32 @@ class record_adapter implements RecordInterface, cache_cacheableInterface
return $this;
}
public function set_mime($mime)
{
$old_mime = $this->get_mime();
// see http://lists.w3.org/Archives/Public/xml-dist-app/2003Jul/0064.html
if (!preg_match("/^[a-zA-Z0-9!#$%^&\*_\-\+{}\|'.`~]+\/[a-zA-Z0-9!#$%^&\*_\-\+{}\|'.`~]+$/", $mime)) {
throw new \Exception(sprintf('Unrecognized mime type %s', $mime));
}
$connection = connection::getPDOConnection($this->app, $this->get_sbas_id());
$sql = 'UPDATE record SET mime = :mime WHERE record_id = :record_id';
$stmt = $connection->prepare($sql);
$stmt->execute(array(':mime' => $mime, ':record_id' => $this->get_record_id()));
$stmt->closeCursor();
if ($mime !== $old_mime) {
$this->rebuild_subdefs();
}
$this->mime = $mime;
$this->delete_data_from_cache();
return $this;
}
/**
* Return true if the record is a grouping
*
@@ -619,10 +645,6 @@ class record_adapter implements RecordInterface, cache_cacheableInterface
continue;
}
if ($subdef->is_substituted()) {
continue;
}
$subdefs[$subdef->get_name()] = $subdef;
}
@@ -911,6 +933,79 @@ class record_adapter implements RecordInterface, cache_cacheableInterface
return $this->get_databox()->get_sbas_id();
}
public function substitute_subdef($name, MediaInterface $media, Application $app, $adapt=true)
{
$newfilename = $this->record_id . '_0_' . $name . '.' . $media->getFile()->getExtension();
if ($name == 'document') {
$baseprefs = $this->get_databox()->get_sxml_structure();
$pathhd = p4string::addEndSlash((string) ($baseprefs->path));
$filehd = $this->get_record_id() . "_document." . strtolower($media->getFile()->getExtension());
$pathhd = databox::dispatch($app['filesystem'], $pathhd);
$app['filesystem']->copy($media->getFile()->getRealPath(), $pathhd . $filehd, true);
$subdefFile = $pathhd . $filehd;
$meta_writable = true;
} else {
$type = $this->is_grouping() ? 'image' : $this->get_type();
$subdef_def = $this->get_databox()->get_subdef_structure()->get_subdef($type, $name);
if ($this->has_subdef($name) && $this->get_subdef($name)->is_physically_present()) {
$path_file_dest = $this->get_subdef($name)->get_pathfile();
$this->get_subdef($name)->remove_file();
$this->clearSubdefCache($name);
} else {
$path = databox::dispatch($app['filesystem'], $subdef_def->get_path());
$app['filesystem']->mkdir($path, 0750);
$path_file_dest = $path . $newfilename;
}
if($adapt) {
try {
$app['media-alchemyst']->turnInto(
$media->getFile()->getRealPath(),
$path_file_dest,
$subdef_def->getSpecs()
);
} catch (\MediaAlchemyst\Exception\ExceptionInterface $e) {
return $this;
}
$subdefFile = $path_file_dest;
}
else{
$app['filesystem']->copy($media->getFile()->getRealPath(), $path_file_dest);
$subdefFile = $path_file_dest;
}
$meta_writable = $subdef_def->meta_writeable();
}
$app['filesystem']->chmod($subdefFile, 0760);
$media = $app['mediavorus']->guess($subdefFile);
$subdef = media_subdef::create($app, $this, $name, $media);
$subdef->set_substituted(true);
$this->delete_data_from_cache(self::CACHE_SUBDEFS);
if ($meta_writable) {
$this->write_metas();
}
if ($name == 'document' && $adapt) {
$this->rebuild_subdefs();
}
return $this;
}
/**
*
* @param DOMDocument $dom_doc
@@ -1045,6 +1140,38 @@ class record_adapter implements RecordInterface, cache_cacheableInterface
return $this;
}
public function get_missing_subdefs()
{
$databox = $this->get_databox();
try {
$this->get_hd_file();
} catch (\Exception $e) {
return array();
}
$subDefDefinitions = $databox->get_subdef_structure()->getSubdefGroup($this->get_type());
if (!$subDefDefinitions) {
return array();
}
$record = $this;
$wanted_subdefs = array_map(function($subDef) {
return $subDef->get_name();
}, array_filter($subDefDefinitions, function($subDef) use ($record) {
return !$record->has_subdef($subDef->get_name());
}));
$missing_subdefs = array_map(function($subDef) {
return $subDef->get_name();
}, array_filter($this->get_subdefs(), function($subdef) {
return !$subdef->is_physically_present();
}));
return array_values(array_merge($wanted_subdefs, $missing_subdefs));
}
/**
*
* @return record_adapter
@@ -1227,7 +1354,6 @@ class record_adapter implements RecordInterface, cache_cacheableInterface
$record->delete_data_from_cache(\record_adapter::CACHE_SUBDEFS);
$record->insertTechnicalDatas($app['mediavorus']);
$record->rebuild_subdefs();
self::dispatchCreatedEvent($app, $record);
@@ -1390,7 +1516,7 @@ class record_adapter implements RecordInterface, cache_cacheableInterface
if (!$subdef->is_physically_present())
continue;
if ($subdef->get_name() === 'thumbnail' && $this->app['phraseanet.static-file-factory']->isStaticFileModeEnabled()) {
if ($subdef->get_name() === 'thumbnail') {
$this->app['filesystem']->remove($this->app['phraseanet.thumb-symlinker']->getSymlinkPath($subdef->get_pathfile()));
}
@@ -1467,7 +1593,7 @@ class record_adapter implements RecordInterface, cache_cacheableInterface
/* @var $repository Alchemy\Phrasea\Model\Repositories\OrderElementRepository */
foreach ($orderElementRepository->findBy(['recordId' => $this->get_record_id()]) as $order_element) {
if ($order_element->getSbasId($this->app) == $this->get_sbas_id()) {
$this->app['EM']->remove($order_element);
$this->app['orm.em']->remove($order_element);
}
}
@@ -1475,10 +1601,10 @@ class record_adapter implements RecordInterface, cache_cacheableInterface
/* @var $repository Alchemy\Phrasea\Model\Repositories\BasketElementRepository */
foreach ($basketElementRepository->findElementsByRecord($this) as $basket_element) {
$this->app['EM']->remove($basket_element);
$this->app['orm.em']->remove($basket_element);
}
$this->app['EM']->flush();
$this->app['orm.em']->flush();
$this->app['filesystem']->remove($ftodel);