mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-24 02:13:15 +00:00
@@ -11,6 +11,10 @@
|
||||
|
||||
namespace Alchemy\Phrasea\TaskManager\Editor;
|
||||
|
||||
use Alchemy\Phrasea\Application;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
|
||||
use Alchemy\Phrasea\Core\Configuration\PropertyAccess;
|
||||
|
||||
class SubdefsEditor extends AbstractEditor
|
||||
@@ -40,7 +44,7 @@ class SubdefsEditor extends AbstractEditor
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<tasksettings>
|
||||
<embedded>1</embedded>
|
||||
<sbas>0</sbas>
|
||||
<sbas/>
|
||||
<type_image>1</type_image>
|
||||
<type_video>1</type_video>
|
||||
<type_audio>1</type_audio>
|
||||
@@ -60,7 +64,7 @@ EOF;
|
||||
protected function getFormProperties()
|
||||
{
|
||||
return [
|
||||
'sbas' => static::FORM_TYPE_INTEGER,
|
||||
'sbas[]' => static::FORM_TYPE_INTEGER,
|
||||
'type_image' => static::FORM_TYPE_BOOLEAN,
|
||||
'type_video' => static::FORM_TYPE_BOOLEAN,
|
||||
'type_audio' => static::FORM_TYPE_BOOLEAN,
|
||||
@@ -70,7 +74,115 @@ EOF;
|
||||
'flush' => static::FORM_TYPE_INTEGER,
|
||||
'maxrecs' => static::FORM_TYPE_INTEGER,
|
||||
'maxmegs' => static::FORM_TYPE_INTEGER,
|
||||
'embedded' => static::FORM_TYPE_BOOLEAN
|
||||
'embedded' => static::FORM_TYPE_BOOLEAN,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function updateXMLWithRequest(Request $request)
|
||||
{
|
||||
$dom = $this->createBlankDom();
|
||||
$dom->formatOutput = true;
|
||||
$dom->preserveWhiteSpace = false;
|
||||
|
||||
if (false === @$dom->loadXML($request->request->get('xml'))) {
|
||||
throw new BadRequestHttpException('Invalid XML data.');
|
||||
}
|
||||
|
||||
// delete empty /text-nodes so the output can be better formatted
|
||||
$nodesToDel = array();
|
||||
for($node = $dom->documentElement->firstChild; $node; $node=$node->nextSibling) {
|
||||
if($node->nodeType == XML_TEXT_NODE && trim($node->data)=="") {
|
||||
$nodesToDel[] = $node;
|
||||
}
|
||||
}
|
||||
foreach($nodesToDel as $node) {
|
||||
$dom->documentElement->removeChild($node);
|
||||
}
|
||||
|
||||
$dom->normalizeDocument();
|
||||
foreach ($this->getFormProperties() as $name => $type) {
|
||||
|
||||
$multi = false;
|
||||
if(substr($name, -2)== "[]") {
|
||||
$multi = true;
|
||||
$name = substr($name, 0, strlen($name)-2);
|
||||
}
|
||||
|
||||
$values = $request->request->get($name);
|
||||
if($values === null && !$multi) {
|
||||
switch($type) {
|
||||
case static::FORM_TYPE_INTEGER:
|
||||
case static::FORM_TYPE_BOOLEAN:
|
||||
$values = "0";
|
||||
break;
|
||||
case static::FORM_TYPE_STRING:
|
||||
$values = "";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// erase the former setting but keep the node in place.
|
||||
// in case on multi-valued, keep only the first node (except if no value at all: erase all)
|
||||
$nodesToDel = array();
|
||||
foreach($dom->getElementsByTagName($name) as $i=>$node) {
|
||||
// empty
|
||||
while ($child = $node->firstChild) {
|
||||
$node->removeChild($child);
|
||||
}
|
||||
// keep the first for multi, only if there is something to write
|
||||
if($i > 0 || ($multi && $values===null) ) {
|
||||
$nodesToDel[] = $node;
|
||||
}
|
||||
}
|
||||
foreach($nodesToDel as $node) {
|
||||
$dom->documentElement->removeChild($node);
|
||||
}
|
||||
|
||||
// if no multiple-setting to write, no reason to create an empty node
|
||||
if($values === null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if(!is_array($values)) {
|
||||
$values = array($values);
|
||||
}
|
||||
|
||||
// in case the node did not exist at all, create one
|
||||
if ( ($node = $dom->getElementsByTagName($name)->item(0)) === null) {
|
||||
$node = $dom->documentElement->appendChild($dom->createElement($name));
|
||||
}
|
||||
|
||||
// because dom::insertBefore is used, reverse allows to respect order while serializing.
|
||||
$values = array_reverse($values);
|
||||
|
||||
// write
|
||||
foreach($values as $i=>$value) {
|
||||
if($i>0) {
|
||||
// multi-valued ? add an entry
|
||||
$node = $dom->documentElement->insertBefore($dom->createElement($name), $node);
|
||||
}
|
||||
$node->appendChild($dom->createTextNode($this->toXMLValue($type, $value)));
|
||||
}
|
||||
}
|
||||
$dom->normalizeDocument();
|
||||
|
||||
return new Response($dom->saveXML(), 200, ['Content-type' => 'text/xml']);
|
||||
}
|
||||
|
||||
private function toXMLValue($type, $value)
|
||||
{
|
||||
switch ($type) {
|
||||
case static::FORM_TYPE_BOOLEAN:
|
||||
$value = (!$value ? '0' : '1');
|
||||
break;
|
||||
case static::FORM_TYPE_INTEGER:
|
||||
$value = ($value !== null ? (string)((int) $value) : '');
|
||||
break;
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -60,18 +60,40 @@ class SubdefsJob extends AbstractJob
|
||||
|
||||
Image2Image::$lookForEmbeddedPreview = $thumbnailExtraction;
|
||||
|
||||
$sqlqmark = array();
|
||||
$sqlparms = array();
|
||||
foreach(array('image',
|
||||
'video',
|
||||
'audio',
|
||||
'document',
|
||||
'flash',
|
||||
'unknown') as $type) {
|
||||
if (!isset($settings->{"type_" . $type}) || !\p4field::isno($settings->{"type_" . $type})) {
|
||||
$sqlqmark[] = '?';
|
||||
$sqlparms[] = $type;
|
||||
}
|
||||
}
|
||||
if(count($sqlqmark) == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($app['phraseanet.appbox']->get_databoxes() as $databox) {
|
||||
if (!$this->isStarted()) {
|
||||
break;
|
||||
}
|
||||
|
||||
if(count($settings->xpath("sbas[text()=".$databox->get_sbas_id() ."]")) == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$conn = $databox->get_connection();
|
||||
|
||||
$sql = 'SELECT coll_id, record_id
|
||||
FROM record
|
||||
WHERE jeton & ' . PhraseaTokens::MAKE_SUBDEF . ' > 0
|
||||
ORDER BY record_id DESC LIMIT 0, 30';
|
||||
$sql = 'SELECT coll_id, record_id FROM record'
|
||||
. ' WHERE jeton & ' . PhraseaTokens::MAKE_SUBDEF . ' > 0'
|
||||
. ' AND type IN(' . implode(',', $sqlqmark) . ')'
|
||||
. ' ORDER BY record_id DESC LIMIT 0, 30';
|
||||
$stmt = $conn->prepare($sql);
|
||||
$stmt->execute();
|
||||
$stmt->execute($sqlparms);
|
||||
$rs = $stmt->fetchAll(\PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
|
||||
@@ -89,19 +111,19 @@ class SubdefsJob extends AbstractJob
|
||||
$this->log('warning', sprintf("Generate subdefs failed for : sbasid=%s / databox=%s / recordid=%s : %s", $databox->get_sbas_id(), $databox->get_dbname() , $row['record_id'], $e->getMessage()));
|
||||
}
|
||||
|
||||
$sql = 'UPDATE record
|
||||
SET jeton=(jeton & ~' . PhraseaTokens::MAKE_SUBDEF . '), moddate=NOW()
|
||||
WHERE record_id=:record_id';
|
||||
$sql = 'UPDATE record'
|
||||
. ' SET jeton=(jeton & ~' . PhraseaTokens::MAKE_SUBDEF . '), moddate=NOW()'
|
||||
. ' WHERE record_id=:record_id';
|
||||
|
||||
$stmt = $conn->prepare($sql);
|
||||
$stmt->execute([':record_id' => $row['record_id']]);
|
||||
$stmt->closeCursor();
|
||||
|
||||
// rewrite metadata
|
||||
$sql = 'UPDATE record
|
||||
SET status=(status & ~0x03),
|
||||
jeton=(jeton | ' . PhraseaTokens::WRITE_META_SUBDEF . ')
|
||||
WHERE record_id=:record_id';
|
||||
$sql = 'UPDATE record'
|
||||
. ' SET status=(status & ~0x03),'
|
||||
. ' jeton=(jeton | ' . PhraseaTokens::WRITE_META_SUBDEF . ')'
|
||||
. ' WHERE record_id=:record_id';
|
||||
$stmt = $conn->prepare($sql);
|
||||
$stmt->execute([':record_id' => $row['record_id']]);
|
||||
$stmt->closeCursor();
|
||||
@@ -117,4 +139,5 @@ class SubdefsJob extends AbstractJob
|
||||
|
||||
$app['elasticsearch.indexer']->flushQueue();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -4,15 +4,12 @@
|
||||
<div class="control-group">
|
||||
<label class="control-label"> {{ 'Databox' | trans }}</label>
|
||||
<div class="controls">
|
||||
<select name="sbas">
|
||||
<option value="">{{ 'All' | trans }}</option>
|
||||
{% for databox in app['phraseanet.appbox'].get_databoxes() %}
|
||||
<option value="{{ databox.get_sbas_id() }}">
|
||||
{{ databox.get_viewname() }}
|
||||
({{ databox.get_sbas_id() }})
|
||||
</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
{% for databox in app['phraseanet.appbox'].get_databoxes() %}
|
||||
<label class="checkbox inline">
|
||||
<input type="checkbox" name="sbas[]" value="{{ databox.get_sbas_id() }}"> {{ databox.get_viewname() }}
|
||||
({{ databox.get_sbas_id() }})
|
||||
</label>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
<div class="control-group">
|
||||
@@ -71,7 +68,7 @@
|
||||
{% block javascript %}
|
||||
function minmax(v, _min, _max)
|
||||
{
|
||||
if(v == NaN || v < _min)
|
||||
if(isNaN(v) || v < _min)
|
||||
{
|
||||
v = _min;
|
||||
}
|
||||
@@ -87,29 +84,31 @@
|
||||
xml = $.parseXML(xml);
|
||||
xml = $(xml);
|
||||
|
||||
with(document.forms['graphicForm'])
|
||||
var gform = document.forms['graphicForm'];
|
||||
|
||||
gform.embedded.checked = !!parseInt(xml.find("embedded").text());
|
||||
gform.type_image.checked = !!parseInt(xml.find("type_image").text());
|
||||
gform.type_video.checked = !!parseInt(xml.find("type_video").text());
|
||||
gform.type_audio.checked = !!parseInt(xml.find("type_audio").text());
|
||||
gform.type_document.checked = !!parseInt(xml.find("type_document").text());
|
||||
gform.type_flash.checked = !!parseInt(xml.find("type_flash").text());
|
||||
gform.type_unknown.checked = !!parseInt(xml.find("type_unknown").text());
|
||||
gform.flush.value = minmax(parseInt(xml.find("flush").text()), 1, 100);
|
||||
gform.maxrecs.value = minmax(parseInt(xml.find("maxrecs").text()), 10, 100);
|
||||
gform.maxmegs.value = minmax(parseInt(xml.find("maxmegs").text()), 64, 512);
|
||||
for(i=0; i < gform['sbas[]'].length; i++)
|
||||
{
|
||||
embedded.checked = !!parseInt(xml.find("embedded").text());
|
||||
type_image.checked = !!parseInt(xml.find("type_image").text());
|
||||
type_video.checked = !!parseInt(xml.find("type_video").text());
|
||||
type_audio.checked = !!parseInt(xml.find("type_audio").text());
|
||||
type_document.checked = !!parseInt(xml.find("type_document").text());
|
||||
type_flash.checked = !!parseInt(xml.find("type_flash").text());
|
||||
type_unknown.checked = !!parseInt(xml.find("type_unknown").text());
|
||||
flush.value = minmax(parseInt(xml.find("flush").text()), 1, 100);
|
||||
maxrecs.value = minmax(parseInt(xml.find("maxrecs").text()), 10, 100);
|
||||
maxmegs.value = minmax(parseInt(xml.find("maxmegs").text()), 64, 512);
|
||||
for(i in sbas.options)
|
||||
var sbid = gform['sbas[]'][i].value;
|
||||
|
||||
if(xml.find("sbas").filter(function(){return $(this).text()==sbid}).length > 0)
|
||||
{
|
||||
if(sbas.options[i].value == parseInt(xml.find("sbas").text()) )
|
||||
{
|
||||
sbas.options[i].selected = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
sbas.options[i].selected = false;
|
||||
}
|
||||
gform['sbas[]'][i].checked = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
gform['sbas[]'][i].checked = false;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,16 +55,6 @@
|
||||
</script>
|
||||
</div>
|
||||
<script type="text/javascript">
|
||||
(function( $ ){
|
||||
$.fn.serializeJSON=function() {
|
||||
var json = {};
|
||||
jQuery.map($(this).serializeArray(), function(n, i){
|
||||
json[n['name']] = n['value'];
|
||||
});
|
||||
|
||||
return json;
|
||||
};
|
||||
})( jQuery );
|
||||
|
||||
$(document).ready(function(){
|
||||
$("#taskTabs").tabs({
|
||||
@@ -126,10 +116,10 @@
|
||||
});
|
||||
|
||||
function xmlFromForm(callback) {
|
||||
var data = $("#graphicForm").serializeJSON();
|
||||
data["xml"] = $("#txtareaxml").val();
|
||||
var formData = $("#graphicForm").serializeArray();
|
||||
formData.push({"name":"xml", "value":$("#txtareaxml").val()});
|
||||
$.ajax({ url: "{{ path('admin_tasks_xml_from_form', {'task' : task.getId()}) }}"
|
||||
, data: data
|
||||
, data: formData
|
||||
, dataType:'text'
|
||||
, type:"POST"
|
||||
, success:function(data) {
|
||||
|
||||
@@ -12,7 +12,17 @@ class SubdefsEditorTest extends EditorTestCase
|
||||
[
|
||||
'<?xml version="1.0" encoding="UTF-8"?>
|
||||
<tasksettings>
|
||||
<sbas></sbas><type_image>0</type_image><type_video>0</type_video><type_audio>0</type_audio><type_document>0</type_document><type_flash>0</type_flash><type_unknown>0</type_unknown><flush></flush><maxrecs></maxrecs><maxmegs></maxmegs><embedded>0</embedded></tasksettings>
|
||||
<type_image>0</type_image>
|
||||
<type_video>0</type_video>
|
||||
<type_audio>0</type_audio>
|
||||
<type_document>0</type_document>
|
||||
<type_flash>0</type_flash>
|
||||
<type_unknown>0</type_unknown>
|
||||
<flush>0</flush>
|
||||
<maxrecs>0</maxrecs>
|
||||
<maxmegs>0</maxmegs>
|
||||
<embedded>0</embedded>
|
||||
</tasksettings>
|
||||
',
|
||||
'<?xml version="1.0" encoding="UTF-8"?>
|
||||
<tasksettings>
|
||||
@@ -67,16 +77,15 @@ class SubdefsEditorTest extends EditorTestCase
|
||||
'<?xml version="1.0" encoding="UTF-8"?>
|
||||
<tasksettings>
|
||||
<customtag>value</customtag>
|
||||
<sbas></sbas>
|
||||
<type_image>0</type_image>
|
||||
<type_video>0</type_video>
|
||||
<type_audio>0</type_audio>
|
||||
<type_document>0</type_document>
|
||||
<type_flash>0</type_flash>
|
||||
<type_unknown>0</type_unknown>
|
||||
<flush></flush>
|
||||
<maxrecs></maxrecs>
|
||||
<maxmegs></maxmegs>
|
||||
<flush>0</flush>
|
||||
<maxrecs>0</maxrecs>
|
||||
<maxmegs>0</maxmegs>
|
||||
<embedded>0</embedded>
|
||||
</tasksettings>
|
||||
',
|
||||
|
||||
Reference in New Issue
Block a user