mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-24 02:13:15 +00:00
task subdef
- better format of xml settings - fix filter on document type - fix filter on multiple databoxes - fix unit tests
This commit is contained in:
@@ -64,7 +64,7 @@ EOF;
|
|||||||
protected function getFormProperties()
|
protected function getFormProperties()
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'sbas' => static::FORM_TYPE_INTEGER,
|
'sbas[]' => static::FORM_TYPE_INTEGER,
|
||||||
'type_image' => static::FORM_TYPE_BOOLEAN,
|
'type_image' => static::FORM_TYPE_BOOLEAN,
|
||||||
'type_video' => static::FORM_TYPE_BOOLEAN,
|
'type_video' => static::FORM_TYPE_BOOLEAN,
|
||||||
'type_audio' => static::FORM_TYPE_BOOLEAN,
|
'type_audio' => static::FORM_TYPE_BOOLEAN,
|
||||||
@@ -84,35 +84,72 @@ EOF;
|
|||||||
public function updateXMLWithRequest(Request $request)
|
public function updateXMLWithRequest(Request $request)
|
||||||
{
|
{
|
||||||
$dom = $this->createBlankDom();
|
$dom = $this->createBlankDom();
|
||||||
|
$dom->formatOutput = true;
|
||||||
|
$dom->preserveWhiteSpace = false;
|
||||||
|
|
||||||
if (false === @$dom->loadXML($request->request->get('xml'))) {
|
if (false === @$dom->loadXML($request->request->get('xml'))) {
|
||||||
throw new BadRequestHttpException('Invalid XML data.');
|
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) {
|
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);
|
$values = $request->request->get($name);
|
||||||
if($values === null) {
|
if($values === null && !$multi) {
|
||||||
$values = array();
|
switch($type) {
|
||||||
} elseif(!is_array($values)) {
|
case static::FORM_TYPE_INTEGER:
|
||||||
$values = array($values);
|
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.
|
// 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)
|
// 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) {
|
foreach($dom->getElementsByTagName($name) as $i=>$node) {
|
||||||
if($i > 0 || count($values)==0) {
|
// empty
|
||||||
$node->parentNode->removeChild($node);
|
while ($child = $node->firstChild) {
|
||||||
} else {
|
$node->removeChild($child);
|
||||||
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// if no setting to write, no reason to create a node
|
foreach($nodesToDel as $node) {
|
||||||
if(count($values) == 0) {
|
$dom->documentElement->removeChild($node);
|
||||||
|
}
|
||||||
|
|
||||||
|
// if no multiple-setting to write, no reason to create an empty node
|
||||||
|
if($values === null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(!is_array($values)) {
|
||||||
|
$values = array($values);
|
||||||
|
}
|
||||||
|
|
||||||
// in case the node did not exist at all, create one
|
// in case the node did not exist at all, create one
|
||||||
if ( ($node = $dom->getElementsByTagName($name)->item(0)) === null) {
|
if ( ($node = $dom->getElementsByTagName($name)->item(0)) === null) {
|
||||||
$node = $dom->documentElement->appendChild($dom->createElement($name));
|
$node = $dom->documentElement->appendChild($dom->createElement($name));
|
||||||
@@ -130,6 +167,7 @@ EOF;
|
|||||||
$node->appendChild($dom->createTextNode($this->toXMLValue($type, $value)));
|
$node->appendChild($dom->createTextNode($this->toXMLValue($type, $value)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
$dom->normalizeDocument();
|
||||||
|
|
||||||
return new Response($dom->saveXML(), 200, ['Content-type' => 'text/xml']);
|
return new Response($dom->saveXML(), 200, ['Content-type' => 'text/xml']);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -73,6 +73,9 @@ class SubdefsJob extends AbstractJob
|
|||||||
$sqlparms[] = $type;
|
$sqlparms[] = $type;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if(count($sqlqmark) == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
foreach ($app['phraseanet.appbox']->get_databoxes() as $databox) {
|
foreach ($app['phraseanet.appbox']->get_databoxes() as $databox) {
|
||||||
if (!$this->isStarted()) {
|
if (!$this->isStarted()) {
|
||||||
@@ -86,11 +89,9 @@ class SubdefsJob extends AbstractJob
|
|||||||
$conn = $databox->get_connection();
|
$conn = $databox->get_connection();
|
||||||
|
|
||||||
$sql = 'SELECT coll_id, record_id FROM record'
|
$sql = 'SELECT coll_id, record_id FROM record'
|
||||||
. ' WHERE jeton & ' . PhraseaTokens::MAKE_SUBDEF . ' > 0';
|
. ' WHERE jeton & ' . PhraseaTokens::MAKE_SUBDEF . ' > 0'
|
||||||
if(count($sqlqmark) > 0) {
|
. ' AND type IN(' . implode(',', $sqlqmark) . ')'
|
||||||
$sql .= ' AND type IN(' . implode(',', $sqlqmark) . ')';
|
. ' ORDER BY record_id DESC LIMIT 0, 30';
|
||||||
}
|
|
||||||
$sql .= ' ORDER BY record_id DESC LIMIT 0, 30';
|
|
||||||
$stmt = $conn->prepare($sql);
|
$stmt = $conn->prepare($sql);
|
||||||
$stmt->execute($sqlparms);
|
$stmt->execute($sqlparms);
|
||||||
$rs = $stmt->fetchAll(\PDO::FETCH_ASSOC);
|
$rs = $stmt->fetchAll(\PDO::FETCH_ASSOC);
|
||||||
|
|||||||
@@ -67,7 +67,7 @@
|
|||||||
{% block javascript %}
|
{% block javascript %}
|
||||||
function minmax(v, _min, _max)
|
function minmax(v, _min, _max)
|
||||||
{
|
{
|
||||||
if(v == NaN || v < _min)
|
if(isNaN(v) || v < _min)
|
||||||
{
|
{
|
||||||
v = _min;
|
v = _min;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,17 @@ class SubdefsEditorTest extends EditorTestCase
|
|||||||
[
|
[
|
||||||
'<?xml version="1.0" encoding="UTF-8"?>
|
'<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<tasksettings>
|
<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"?>
|
'<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<tasksettings>
|
<tasksettings>
|
||||||
@@ -29,7 +39,7 @@ class SubdefsEditorTest extends EditorTestCase
|
|||||||
<type_document>0</type_document>
|
<type_document>0</type_document>
|
||||||
<type_flash>0</type_flash>
|
<type_flash>0</type_flash>
|
||||||
<type_unknown>0</type_unknown>
|
<type_unknown>0</type_unknown>
|
||||||
<flush>0</flush>
|
<flush>1</flush>
|
||||||
<maxrecs>12</maxrecs>
|
<maxrecs>12</maxrecs>
|
||||||
<maxmegs>1</maxmegs>
|
<maxmegs>1</maxmegs>
|
||||||
<embedded>1</embedded>
|
<embedded>1</embedded>
|
||||||
@@ -67,16 +77,15 @@ class SubdefsEditorTest extends EditorTestCase
|
|||||||
'<?xml version="1.0" encoding="UTF-8"?>
|
'<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<tasksettings>
|
<tasksettings>
|
||||||
<customtag>value</customtag>
|
<customtag>value</customtag>
|
||||||
<sbas></sbas>
|
|
||||||
<type_image>0</type_image>
|
<type_image>0</type_image>
|
||||||
<type_video>0</type_video>
|
<type_video>0</type_video>
|
||||||
<type_audio>0</type_audio>
|
<type_audio>0</type_audio>
|
||||||
<type_document>0</type_document>
|
<type_document>0</type_document>
|
||||||
<type_flash>0</type_flash>
|
<type_flash>0</type_flash>
|
||||||
<type_unknown>0</type_unknown>
|
<type_unknown>0</type_unknown>
|
||||||
<flush></flush>
|
<flush>0</flush>
|
||||||
<maxrecs></maxrecs>
|
<maxrecs>0</maxrecs>
|
||||||
<maxmegs></maxmegs>
|
<maxmegs>0</maxmegs>
|
||||||
<embedded>0</embedded>
|
<embedded>0</embedded>
|
||||||
</tasksettings>
|
</tasksettings>
|
||||||
',
|
',
|
||||||
|
|||||||
Reference in New Issue
Block a user