mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-17 15:03:25 +00:00
Extract whether subdef metadata updates are required
This commit is contained in:
@@ -79,7 +79,7 @@ class SubdefSubstituer
|
||||
|
||||
$subdefFile = $path_file_dest;
|
||||
|
||||
$meta_writable = $subdef_def->meta_writeable();
|
||||
$meta_writable = $subdef_def->isMetadataUpdateRequired();
|
||||
}
|
||||
|
||||
$this->fs->chmod($subdefFile, 0760);
|
||||
|
@@ -62,31 +62,17 @@ class WriteMetadataJob extends AbstractJob
|
||||
*/
|
||||
protected function doJob(JobData $data)
|
||||
{
|
||||
$app = $data->getApplication();
|
||||
$settings = simplexml_load_string($data->getTask()->getSettings());
|
||||
$clearDoc = (Boolean) (string) $settings->cleardoc;
|
||||
$MWG = (Boolean) (string) $settings->mwg;
|
||||
|
||||
foreach ($app->getDataboxes() as $databox) {
|
||||
foreach ($data->getApplication()->getDataboxes() as $databox) {
|
||||
$connection = $databox->get_connection();
|
||||
|
||||
$conn = $databox->get_connection();
|
||||
$metaSubdefs = [];
|
||||
|
||||
foreach ($databox->get_subdef_structure() as $type => $definitions) {
|
||||
foreach ($definitions as $sub) {
|
||||
$name = $sub->get_name();
|
||||
if ($sub->meta_writeable()) {
|
||||
$metaSubdefs[$name . '_' . $type] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$sql = 'SELECT record_id, coll_id, jeton FROM record WHERE (jeton & ' . PhraseaTokens::WRITE_META . ' > 0)';
|
||||
|
||||
$stmt = $conn->prepare($sql);
|
||||
$stmt->execute();
|
||||
$rs = $stmt->fetchAll(\PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
$statement = $connection->prepare('SELECT record_id, coll_id, jeton FROM record WHERE (jeton & :token > 0)');
|
||||
$statement->execute(['token' => PhraseaTokens::WRITE_META]);
|
||||
$rs = $statement->fetchAll(\PDO::FETCH_ASSOC);
|
||||
$statement->closeCursor();
|
||||
|
||||
foreach ($rs as $row) {
|
||||
$record_id = $row['record_id'];
|
||||
@@ -98,7 +84,7 @@ class WriteMetadataJob extends AbstractJob
|
||||
$subdefs = [];
|
||||
foreach ($record->get_subdefs() as $name => $subdef) {
|
||||
$write_document = (($token & PhraseaTokens::WRITE_META_DOC) && $name == 'document');
|
||||
$write_subdef = (($token & PhraseaTokens::WRITE_META_SUBDEF) && isset($metaSubdefs[$name . '_' . $type]));
|
||||
$write_subdef = (($token & PhraseaTokens::WRITE_META_SUBDEF) && $this->isSubdefMetadataUpdateRequired($databox, $type, $name));
|
||||
|
||||
if (($write_document || $write_subdef) && $subdef->is_physically_present()) {
|
||||
$subdefs[$name] = $subdef->get_pathfile();
|
||||
@@ -178,7 +164,7 @@ class WriteMetadataJob extends AbstractJob
|
||||
);
|
||||
}
|
||||
|
||||
$writer = $this->getMetadataWriter($app);
|
||||
$writer = $this->getMetadataWriter($data->getApplication());
|
||||
$writer->reset();
|
||||
|
||||
if($MWG) {
|
||||
@@ -196,10 +182,12 @@ class WriteMetadataJob extends AbstractJob
|
||||
}
|
||||
}
|
||||
|
||||
$sql = 'UPDATE record SET jeton=jeton & ~' . PhraseaTokens::WRITE_META . ' WHERE record_id = :record_id';
|
||||
$stmt = $conn->prepare($sql);
|
||||
$stmt->execute([':record_id' => $record_id]);
|
||||
$stmt->closeCursor();
|
||||
$statement = $connection->prepare('UPDATE record SET jeton=jeton & ~:token WHERE record_id = :record_id');
|
||||
$statement->execute([
|
||||
'record_id' => $record_id,
|
||||
'token' => PhraseaTokens::WRITE_META,
|
||||
]);
|
||||
$statement->closeCursor();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -212,4 +200,15 @@ class WriteMetadataJob extends AbstractJob
|
||||
{
|
||||
return $app['exiftool.writer'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \databox $databox
|
||||
* @param string $subdefType
|
||||
* @param string $subdefName
|
||||
* @return bool
|
||||
*/
|
||||
private function isSubdefMetadataUpdateRequired(\databox $databox, $subdefType, $subdefName)
|
||||
{
|
||||
return $databox->get_subdef_structure()->get_subdef($subdefType, $subdefName)->isMetadataUpdateRequired();
|
||||
}
|
||||
}
|
||||
|
@@ -32,7 +32,11 @@ class databox_subdef
|
||||
protected $path;
|
||||
protected $subdef_group;
|
||||
protected $labels = [];
|
||||
protected $write_meta;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
private $requiresMetadataUpdate;
|
||||
protected $downloadable;
|
||||
protected $translator;
|
||||
protected static $mediaTypeToSubdefTypes = [
|
||||
@@ -74,7 +78,7 @@ class databox_subdef
|
||||
$this->downloadable = p4field::isyes($sd->attributes()->downloadable);
|
||||
$this->path = trim($sd->path) !== '' ? p4string::addEndSlash(trim($sd->path)) : '';
|
||||
|
||||
$this->write_meta = p4field::isyes((string) $sd->meta);
|
||||
$this->requiresMetadataUpdate = p4field::isyes((string) $sd->meta);
|
||||
|
||||
foreach ($sd->label as $label) {
|
||||
$lang = trim((string) $label->attributes()->lang);
|
||||
@@ -242,13 +246,13 @@ class databox_subdef
|
||||
}
|
||||
|
||||
/**
|
||||
* Tells us if we have to write meta datas in the subdef
|
||||
* Tells us if we have to write meta data in the subdef
|
||||
*
|
||||
* @return boolean
|
||||
* @return bool
|
||||
*/
|
||||
public function meta_writeable()
|
||||
public function isMetadataUpdateRequired()
|
||||
{
|
||||
return $this->write_meta;
|
||||
return $this->requiresMetadataUpdate;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -14,8 +14,7 @@ use Symfony\Component\Translation\TranslatorInterface;
|
||||
class databox_subdefsStructure implements IteratorAggregate, Countable
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @var Array
|
||||
* @var array|databox_subdef[][]
|
||||
*/
|
||||
protected $AvSubdefs = [];
|
||||
|
||||
@@ -24,6 +23,11 @@ class databox_subdefsStructure implements IteratorAggregate, Countable
|
||||
*/
|
||||
private $translator;
|
||||
|
||||
/**
|
||||
* @var databox
|
||||
*/
|
||||
private $databox;
|
||||
|
||||
/**
|
||||
*
|
||||
* @return ArrayIterator
|
||||
@@ -133,10 +137,10 @@ class databox_subdefsStructure implements IteratorAggregate, Countable
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $subdef_type
|
||||
* @param $subdef_name
|
||||
* @param string $subdef_type
|
||||
* @param string $subdef_name
|
||||
*
|
||||
* @return mixed
|
||||
* @return databox_subdef
|
||||
* @throws Exception_Databox_SubdefNotFound
|
||||
*/
|
||||
public function get_subdef($subdef_type, $subdef_name)
|
||||
@@ -220,13 +224,14 @@ class databox_subdefsStructure implements IteratorAggregate, Countable
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $group
|
||||
* @param string $name
|
||||
* @param string $class
|
||||
* @param boolean $downloadable
|
||||
* @param Array $options
|
||||
* @param array $options
|
||||
* @param array $labels
|
||||
* @return databox_subdefsStructure
|
||||
* @throws Exception
|
||||
*/
|
||||
public function set_subdef($group, $name, $class, $downloadable, $options, $labels)
|
||||
{
|
||||
|
@@ -48,6 +48,9 @@ class patch_370alpha6a extends patchAbstract
|
||||
*/
|
||||
public function apply(base $databox, Application $app)
|
||||
{
|
||||
/**
|
||||
* @var databox $databox
|
||||
*/
|
||||
$structure = $databox->get_structure();
|
||||
|
||||
$DOM = new DOMDocument();
|
||||
@@ -90,7 +93,7 @@ class patch_370alpha6a extends patchAbstract
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function addScreenDeviceOption($root, $subdef, $groupname)
|
||||
protected function addScreenDeviceOption($root, databox_subdef $subdef, $groupname)
|
||||
{
|
||||
$optionsSubdef = $subdef->getOptions();
|
||||
|
||||
@@ -102,7 +105,7 @@ class patch_370alpha6a extends patchAbstract
|
||||
|
||||
$options['path'] = $subdef->get_path();
|
||||
$options['mediatype'] = $subdef->getSubdefType()->getType();
|
||||
$options['meta'] = $subdef->meta_writeable() ? 'yes' : 'no';
|
||||
$options['meta'] = $subdef->isMetadataUpdateRequired() ? 'yes' : 'no';
|
||||
$options['devices'] = [databox_subdef::DEVICE_SCREEN];
|
||||
|
||||
$root->set_subdef($groupname, $subdef->get_name(), $subdef->get_class(), $subdef->is_downloadable(), $options, []);
|
||||
|
@@ -949,7 +949,7 @@ class record_adapter implements RecordInterface, cache_cacheableInterface
|
||||
$subdefFile = $path_file_dest;
|
||||
}
|
||||
|
||||
$meta_writable = $subdef_def->meta_writeable();
|
||||
$meta_writable = $subdef_def->isMetadataUpdateRequired();
|
||||
}
|
||||
|
||||
$filesystem->chmod($subdefFile, 0760);
|
||||
|
@@ -258,7 +258,7 @@
|
||||
{{ 'Write Metas' | trans }}
|
||||
</td>
|
||||
<td>
|
||||
<input type="checkbox" value="yes" {% if subdef.meta_writeable() %}checked="checked"{% endif %} name="{{subdefgroup}}_{{subdefname}}_meta"/>
|
||||
<input type="checkbox" value="yes" {% if subdef.isMetadataUpdateRequired() %}checked="checked"{% endif %} name="{{subdefgroup}}_{{subdefname}}_meta"/>
|
||||
</td>
|
||||
<td></td>
|
||||
</tr>
|
||||
|
@@ -11,7 +11,7 @@ class databox_subdefTest extends \PhraseanetTestCase
|
||||
* @covers databox_subdef::__construct
|
||||
* @covers databox_subdef::get_class
|
||||
* @covers databox_subdef::get_name
|
||||
* @covers databox_subdef::meta_writeable
|
||||
* @covers databox_subdef::isMetadataUpdateRequired
|
||||
* @covers databox_subdef::getAvailableSubdefTypes
|
||||
* @covers databox_subdef::is_downloadable
|
||||
* @covers databox_subdef::get_labels
|
||||
@@ -60,7 +60,7 @@ class databox_subdefTest extends \PhraseanetTestCase
|
||||
$this->assertInstanceOf('\\Alchemy\\Phrasea\\Media\\Subdef\\Image', $type);
|
||||
}
|
||||
|
||||
$this->assertTrue($object->meta_writeable());
|
||||
$this->assertTrue($object->isMetadataUpdateRequired());
|
||||
|
||||
$this->assertEquals('preview_api', $object->get_name());
|
||||
$this->assertInstanceOf('\\MediaAlchemyst\\Specification\\Image', $object->getSpecs());
|
||||
@@ -77,7 +77,7 @@ class databox_subdefTest extends \PhraseanetTestCase
|
||||
* @covers databox_subdef::__construct
|
||||
* @covers databox_subdef::get_class
|
||||
* @covers databox_subdef::get_name
|
||||
* @covers databox_subdef::meta_writeable
|
||||
* @covers databox_subdef::isMetadataUpdateRequired
|
||||
* @covers databox_subdef::getAvailableSubdefTypes
|
||||
* @covers databox_subdef::is_downloadable
|
||||
* @covers databox_subdef::get_labels
|
||||
@@ -126,7 +126,7 @@ class databox_subdefTest extends \PhraseanetTestCase
|
||||
$this->assertInstanceOf('\\Alchemy\\Phrasea\\Media\\Subdef\\Subdef', $type);
|
||||
}
|
||||
|
||||
$this->assertFalse($object->meta_writeable());
|
||||
$this->assertFalse($object->isMetadataUpdateRequired());
|
||||
|
||||
$this->assertEquals('video_api', $object->get_name());
|
||||
$this->assertInstanceOf('\\MediaAlchemyst\\Specification\\Video', $object->getSpecs());
|
||||
|
Reference in New Issue
Block a user