mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-10 11:33:17 +00:00
Change Elastic Field structure to cope with Collection base_ids
This commit is contained in:
@@ -20,6 +20,7 @@ class Field
|
||||
private $is_private;
|
||||
private $is_facet;
|
||||
private $thesaurus_roots;
|
||||
private $used_by_collections;
|
||||
|
||||
public static function createFromLegacyField(databox_field $field)
|
||||
{
|
||||
@@ -54,9 +55,9 @@ class Field
|
||||
case databox_field::TYPE_STRING:
|
||||
case databox_field::TYPE_TEXT:
|
||||
return Mapping::TYPE_STRING;
|
||||
default:
|
||||
throw new Exception(sprintf('Invalid field type "%s", expected "date", "number" or "string".', $type));
|
||||
}
|
||||
|
||||
throw new \InvalidArgumentException(sprintf('Invalid field type "%s", expected "date", "number" or "string".', $type));
|
||||
}
|
||||
|
||||
public function __construct($name, $type, array $options = [])
|
||||
@@ -97,6 +98,11 @@ class Field
|
||||
return $this->type;
|
||||
}
|
||||
|
||||
public function getCollections()
|
||||
{
|
||||
return $this->collections;
|
||||
}
|
||||
|
||||
public function isSearchable()
|
||||
{
|
||||
return $this->is_searchable;
|
||||
|
@@ -208,6 +208,9 @@ class databox extends base
|
||||
return $this->ord;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return appbox
|
||||
*/
|
||||
public function get_appbox()
|
||||
{
|
||||
return $this->app['phraseanet.appbox'];
|
||||
@@ -235,10 +238,8 @@ class databox extends base
|
||||
return $base_ids;
|
||||
}
|
||||
|
||||
$conn = $this->app['phraseanet.appbox']->get_connection();
|
||||
$sql = "SELECT b.base_id FROM bas b
|
||||
WHERE b.sbas_id = :sbas_id AND b.active = '1'
|
||||
ORDER BY b.ord ASC";
|
||||
$conn = $this->get_appbox()->get_connection();
|
||||
$sql = "SELECT b.base_id FROM bas b WHERE b.sbas_id = :sbas_id AND b.active = '1' ORDER BY b.ord ASC";
|
||||
$stmt = $conn->prepare($sql);
|
||||
$stmt->execute([':sbas_id' => $this->id]);
|
||||
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
@@ -14,8 +14,8 @@ class FieldTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testBasicMerge()
|
||||
{
|
||||
$field = new Field('foo', Mapping::TYPE_STRING);
|
||||
$other = new Field('foo', Mapping::TYPE_STRING);
|
||||
$field = new Field('foo', Mapping::TYPE_STRING, ['used_by_collections' => ['1', '2']]);
|
||||
$other = new Field('foo', Mapping::TYPE_STRING, ['used_by_collections' => ['3', '4']]);
|
||||
$merged = $field->mergeWith($other);
|
||||
$this->assertInstanceOf(Field::class, $merged);
|
||||
$this->assertNotSame($field, $merged);
|
||||
@@ -26,6 +26,7 @@ class FieldTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertFalse($merged->isPrivate());
|
||||
$this->assertFalse($merged->isFacet());
|
||||
$this->assertNull($merged->getThesaurusRoots());
|
||||
$this->assertEquals(['1', '2', '3', '4'], $merged->getCollections());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -34,22 +34,21 @@ class StructureTest extends \PHPUnit_Framework_TestCase
|
||||
$field->isPrivate()->willReturn(false);
|
||||
$field->isFacet()->willReturn(false);
|
||||
$field->hasConceptInference()->willReturn(false);
|
||||
$field->getCollections()->willReturn(['1']);
|
||||
|
||||
$structure->add($field->reveal());
|
||||
$this->assertCount(1, $structure->getAllFields());
|
||||
|
||||
$conflicting_field = $this->prophesize(Field::class);
|
||||
$conflicting_field->getName()->willReturn('foo');
|
||||
$conflicting_field->getType()->willReturn(Mapping::TYPE_STRING);
|
||||
$conflicting_field->isPrivate()->willReturn(false);
|
||||
$conflicting_field->isFacet()->willReturn(false);
|
||||
$conflicting_field->hasConceptInference()->willReturn(false);
|
||||
$dummy = $conflicting_field->reveal();
|
||||
$conflicting_field = new Field('foo', Mapping::TYPE_STRING, ['2']);
|
||||
|
||||
$field->mergeWith($dummy)->willReturn($dummy);
|
||||
$merged = new Field('foo', Mapping::TYPE_STRING, ['1', '2']);
|
||||
|
||||
$field->mergeWith($conflicting_field)->willReturn($merged);
|
||||
// Should still have only one (both have the same name)
|
||||
$structure->add($dummy);
|
||||
$this->assertCount(1, $structure->getAllFields());
|
||||
$structure->add($conflicting_field);
|
||||
$this->assertCount(1, $fields = $structure->getAllFields());
|
||||
$this->assertInternalType('array', $fields);
|
||||
$this->assertSame($merged, reset($fields));
|
||||
}
|
||||
|
||||
public function testFieldMerge()
|
||||
@@ -166,7 +165,7 @@ class StructureTest extends \PHPUnit_Framework_TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException DomainException
|
||||
* @expectedException \DomainException
|
||||
* @expectedExceptionMessageRegExp #field#u
|
||||
*/
|
||||
public function testPrivateCheckWithInvalidField()
|
||||
|
Reference in New Issue
Block a user