Extract whether subdef metadata updates are required

This commit is contained in:
Benoît Burnichon
2016-01-22 17:15:51 +01:00
parent 401ed4f431
commit f501cba16b
8 changed files with 63 additions and 52 deletions

View File

@@ -79,7 +79,7 @@ class SubdefSubstituer
$subdefFile = $path_file_dest; $subdefFile = $path_file_dest;
$meta_writable = $subdef_def->meta_writeable(); $meta_writable = $subdef_def->isMetadataUpdateRequired();
} }
$this->fs->chmod($subdefFile, 0760); $this->fs->chmod($subdefFile, 0760);

View File

@@ -62,31 +62,17 @@ class WriteMetadataJob extends AbstractJob
*/ */
protected function doJob(JobData $data) protected function doJob(JobData $data)
{ {
$app = $data->getApplication();
$settings = simplexml_load_string($data->getTask()->getSettings()); $settings = simplexml_load_string($data->getTask()->getSettings());
$clearDoc = (Boolean) (string) $settings->cleardoc; $clearDoc = (Boolean) (string) $settings->cleardoc;
$MWG = (Boolean) (string) $settings->mwg; $MWG = (Boolean) (string) $settings->mwg;
foreach ($app->getDataboxes() as $databox) { foreach ($data->getApplication()->getDataboxes() as $databox) {
$connection = $databox->get_connection();
$conn = $databox->get_connection(); $statement = $connection->prepare('SELECT record_id, coll_id, jeton FROM record WHERE (jeton & :token > 0)');
$metaSubdefs = []; $statement->execute(['token' => PhraseaTokens::WRITE_META]);
$rs = $statement->fetchAll(\PDO::FETCH_ASSOC);
foreach ($databox->get_subdef_structure() as $type => $definitions) { $statement->closeCursor();
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();
foreach ($rs as $row) { foreach ($rs as $row) {
$record_id = $row['record_id']; $record_id = $row['record_id'];
@@ -98,7 +84,7 @@ class WriteMetadataJob extends AbstractJob
$subdefs = []; $subdefs = [];
foreach ($record->get_subdefs() as $name => $subdef) { foreach ($record->get_subdefs() as $name => $subdef) {
$write_document = (($token & PhraseaTokens::WRITE_META_DOC) && $name == 'document'); $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()) { if (($write_document || $write_subdef) && $subdef->is_physically_present()) {
$subdefs[$name] = $subdef->get_pathfile(); $subdefs[$name] = $subdef->get_pathfile();
@@ -178,7 +164,7 @@ class WriteMetadataJob extends AbstractJob
); );
} }
$writer = $this->getMetadataWriter($app); $writer = $this->getMetadataWriter($data->getApplication());
$writer->reset(); $writer->reset();
if($MWG) { if($MWG) {
@@ -196,10 +182,12 @@ class WriteMetadataJob extends AbstractJob
} }
} }
$sql = 'UPDATE record SET jeton=jeton & ~' . PhraseaTokens::WRITE_META . ' WHERE record_id = :record_id'; $statement = $connection->prepare('UPDATE record SET jeton=jeton & ~:token WHERE record_id = :record_id');
$stmt = $conn->prepare($sql); $statement->execute([
$stmt->execute([':record_id' => $record_id]); 'record_id' => $record_id,
$stmt->closeCursor(); 'token' => PhraseaTokens::WRITE_META,
]);
$statement->closeCursor();
} }
} }
} }
@@ -212,4 +200,15 @@ class WriteMetadataJob extends AbstractJob
{ {
return $app['exiftool.writer']; 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();
}
} }

View File

@@ -32,7 +32,11 @@ class databox_subdef
protected $path; protected $path;
protected $subdef_group; protected $subdef_group;
protected $labels = []; protected $labels = [];
protected $write_meta;
/**
* @var bool
*/
private $requiresMetadataUpdate;
protected $downloadable; protected $downloadable;
protected $translator; protected $translator;
protected static $mediaTypeToSubdefTypes = [ protected static $mediaTypeToSubdefTypes = [
@@ -74,7 +78,7 @@ class databox_subdef
$this->downloadable = p4field::isyes($sd->attributes()->downloadable); $this->downloadable = p4field::isyes($sd->attributes()->downloadable);
$this->path = trim($sd->path) !== '' ? p4string::addEndSlash(trim($sd->path)) : ''; $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) { foreach ($sd->label as $label) {
$lang = trim((string) $label->attributes()->lang); $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;
} }
/** /**

View File

@@ -14,8 +14,7 @@ use Symfony\Component\Translation\TranslatorInterface;
class databox_subdefsStructure implements IteratorAggregate, Countable class databox_subdefsStructure implements IteratorAggregate, Countable
{ {
/** /**
* * @var array|databox_subdef[][]
* @var Array
*/ */
protected $AvSubdefs = []; protected $AvSubdefs = [];
@@ -24,6 +23,11 @@ class databox_subdefsStructure implements IteratorAggregate, Countable
*/ */
private $translator; private $translator;
/**
* @var databox
*/
private $databox;
/** /**
* *
* @return ArrayIterator * @return ArrayIterator
@@ -133,10 +137,10 @@ class databox_subdefsStructure implements IteratorAggregate, Countable
} }
/** /**
* @param $subdef_type * @param string $subdef_type
* @param $subdef_name * @param string $subdef_name
* *
* @return mixed * @return databox_subdef
* @throws Exception_Databox_SubdefNotFound * @throws Exception_Databox_SubdefNotFound
*/ */
public function get_subdef($subdef_type, $subdef_name) public function get_subdef($subdef_type, $subdef_name)
@@ -220,13 +224,14 @@ class databox_subdefsStructure implements IteratorAggregate, Countable
} }
/** /**
* * @param string $group
* @param string $group * @param string $name
* @param string $name * @param string $class
* @param string $class * @param boolean $downloadable
* @param boolean $downloadable * @param array $options
* @param Array $options * @param array $labels
* @return databox_subdefsStructure * @return databox_subdefsStructure
* @throws Exception
*/ */
public function set_subdef($group, $name, $class, $downloadable, $options, $labels) public function set_subdef($group, $name, $class, $downloadable, $options, $labels)
{ {

View File

@@ -48,6 +48,9 @@ class patch_370alpha6a extends patchAbstract
*/ */
public function apply(base $databox, Application $app) public function apply(base $databox, Application $app)
{ {
/**
* @var databox $databox
*/
$structure = $databox->get_structure(); $structure = $databox->get_structure();
$DOM = new DOMDocument(); $DOM = new DOMDocument();
@@ -90,7 +93,7 @@ class patch_370alpha6a extends patchAbstract
return true; return true;
} }
protected function addScreenDeviceOption($root, $subdef, $groupname) protected function addScreenDeviceOption($root, databox_subdef $subdef, $groupname)
{ {
$optionsSubdef = $subdef->getOptions(); $optionsSubdef = $subdef->getOptions();
@@ -102,7 +105,7 @@ class patch_370alpha6a extends patchAbstract
$options['path'] = $subdef->get_path(); $options['path'] = $subdef->get_path();
$options['mediatype'] = $subdef->getSubdefType()->getType(); $options['mediatype'] = $subdef->getSubdefType()->getType();
$options['meta'] = $subdef->meta_writeable() ? 'yes' : 'no'; $options['meta'] = $subdef->isMetadataUpdateRequired() ? 'yes' : 'no';
$options['devices'] = [databox_subdef::DEVICE_SCREEN]; $options['devices'] = [databox_subdef::DEVICE_SCREEN];
$root->set_subdef($groupname, $subdef->get_name(), $subdef->get_class(), $subdef->is_downloadable(), $options, []); $root->set_subdef($groupname, $subdef->get_name(), $subdef->get_class(), $subdef->is_downloadable(), $options, []);

View File

@@ -949,7 +949,7 @@ class record_adapter implements RecordInterface, cache_cacheableInterface
$subdefFile = $path_file_dest; $subdefFile = $path_file_dest;
} }
$meta_writable = $subdef_def->meta_writeable(); $meta_writable = $subdef_def->isMetadataUpdateRequired();
} }
$filesystem->chmod($subdefFile, 0760); $filesystem->chmod($subdefFile, 0760);

View File

@@ -258,7 +258,7 @@
{{ 'Write Metas' | trans }} {{ 'Write Metas' | trans }}
</td> </td>
<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></td> <td></td>
</tr> </tr>

View File

@@ -11,7 +11,7 @@ class databox_subdefTest extends \PhraseanetTestCase
* @covers databox_subdef::__construct * @covers databox_subdef::__construct
* @covers databox_subdef::get_class * @covers databox_subdef::get_class
* @covers databox_subdef::get_name * @covers databox_subdef::get_name
* @covers databox_subdef::meta_writeable * @covers databox_subdef::isMetadataUpdateRequired
* @covers databox_subdef::getAvailableSubdefTypes * @covers databox_subdef::getAvailableSubdefTypes
* @covers databox_subdef::is_downloadable * @covers databox_subdef::is_downloadable
* @covers databox_subdef::get_labels * @covers databox_subdef::get_labels
@@ -60,7 +60,7 @@ class databox_subdefTest extends \PhraseanetTestCase
$this->assertInstanceOf('\\Alchemy\\Phrasea\\Media\\Subdef\\Image', $type); $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->assertEquals('preview_api', $object->get_name());
$this->assertInstanceOf('\\MediaAlchemyst\\Specification\\Image', $object->getSpecs()); $this->assertInstanceOf('\\MediaAlchemyst\\Specification\\Image', $object->getSpecs());
@@ -77,7 +77,7 @@ class databox_subdefTest extends \PhraseanetTestCase
* @covers databox_subdef::__construct * @covers databox_subdef::__construct
* @covers databox_subdef::get_class * @covers databox_subdef::get_class
* @covers databox_subdef::get_name * @covers databox_subdef::get_name
* @covers databox_subdef::meta_writeable * @covers databox_subdef::isMetadataUpdateRequired
* @covers databox_subdef::getAvailableSubdefTypes * @covers databox_subdef::getAvailableSubdefTypes
* @covers databox_subdef::is_downloadable * @covers databox_subdef::is_downloadable
* @covers databox_subdef::get_labels * @covers databox_subdef::get_labels
@@ -126,7 +126,7 @@ class databox_subdefTest extends \PhraseanetTestCase
$this->assertInstanceOf('\\Alchemy\\Phrasea\\Media\\Subdef\\Subdef', $type); $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->assertEquals('video_api', $object->get_name());
$this->assertInstanceOf('\\MediaAlchemyst\\Specification\\Video', $object->getSpecs()); $this->assertInstanceOf('\\MediaAlchemyst\\Specification\\Video', $object->getSpecs());