Skip to content

Changed repository_reference to simple objects #121

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion App/AppRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public function checkIndex(IndexUUID $indexUUID): bool;
*
* @param IndexUUID $indexUUID
* @param Config $config
* @param bool $forceReindex
* @param bool $forceReindex
*
* @throws ResourceNotAvailableException
*/
Expand Down
2 changes: 1 addition & 1 deletion App/DiskAppRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public function checkIndex(IndexUUID $indexUUID): bool
*
* @param IndexUUID $indexUUID
* @param Config $config
* @param bool $forceReindex
* @param bool $forceReindex
*
* @throws ResourceNotAvailableException
*/
Expand Down
4 changes: 2 additions & 2 deletions App/HttpAppRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ public function checkIndex(IndexUUID $indexUUID): bool
*
* @param IndexUUID $indexUUID
* @param Config $config
* @param bool $forceReindex
* @param bool $forceReindex
*
* @throws ResourceNotAvailableException
*/
Expand All @@ -287,7 +287,7 @@ public function configureIndex(
),
'post',
[
'force_reindex' => $forceReindex
'force_reindex' => $forceReindex,
],
$config->toArray(),
Http::getApisearchHeaders($this)
Expand Down
2 changes: 1 addition & 1 deletion App/InMemoryAppRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public function checkIndex(IndexUUID $indexUUID): bool
*
* @param IndexUUID $indexUUID
* @param Config $config
* @param bool $forceReindex
* @param bool $forceReindex
*
* @throws ResourceNotAvailableException
*/
Expand Down
2 changes: 1 addition & 1 deletion App/MockAppRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public function checkIndex(IndexUUID $indexUUID): bool
*
* @param IndexUUID $indexUUID
* @param Config $config
* @param bool $forceReindex
* @param bool $forceReindex
*
* @throws ResourceNotAvailableException
*/
Expand Down
45 changes: 33 additions & 12 deletions Model/Item.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,14 @@ class Item implements HttpTransportable, UUIDReference
private $score;

/**
* @var RepositoryReference
* @var AppUUID|null
*/
private $repositoryReference;
private $appUUID;

/**
* @var IndexUUID|null
*/
private $indexUUID;

/**
* Item constructor.
Expand Down Expand Up @@ -496,19 +501,28 @@ public function setScore(float $score)
}

/**
* @return RepositoryReference|null
* @param RepositoryReference $repositoryReference
*/
public function getRepositoryReference():? RepositoryReference
public function setRepositoryReference(RepositoryReference $repositoryReference)
{
return $this->repositoryReference;
$this->appUUID = $repositoryReference->getAppUUID();
$this->indexUUID = $repositoryReference->getIndexUUID();
}

/**
* @param RepositoryReference $repositoryReference
* @return AppUUID|null
*/
public function setRepositoryReference(RepositoryReference $repositoryReference)
public function getAppUUID(): ?AppUUID
{
$this->repositoryReference = $repositoryReference;
return $this->appUUID;
}

/**
* @return IndexUUID|null
*/
public function getIndexUUID(): ?IndexUUID
{
return $this->indexUUID;
}

/**
Expand All @@ -532,8 +546,11 @@ public function toArray(): array
'highlights' => $this->highlights,
'is_promoted' => !$this->promoted ? null : true,
'score' => $this->score,
'repository_reference' => $this->repositoryReference instanceof RepositoryReference
? $this->repositoryReference->compose()
'app_uuid' => $this->appUUID instanceof AppUUID
? $this->appUUID->toArray()
: null,
'index_uuid' => $this->indexUUID instanceof IndexUUID
? $this->indexUUID->toArray()
: null,
], function ($element) {
return
Expand Down Expand Up @@ -602,8 +619,12 @@ public static function createFromArray(array $array): self
$item->setScore((float) $array['score']);
}

if (isset($array['repository_reference']) && !is_null($array['repository_reference'])) {
$item->setRepositoryReference(RepositoryReference::createFromComposed($array['repository_reference']));
if (isset($array['app_uuid']) && !is_null($array['app_uuid'])) {
$item->appUUID = AppUUID::createFromArray($array['app_uuid']);
}

if (isset($array['index_uuid']) && !is_null($array['index_uuid'])) {
$item->indexUUID = IndexUUID::createFromArray($array['index_uuid']);
}

return $item;
Expand Down
2 changes: 1 addition & 1 deletion Repository/HttpRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public function updateItems(
}

/**
* Delete items by query
* Delete items by query.
*
* @param Query $query
*/
Expand Down
2 changes: 1 addition & 1 deletion Repository/InMemoryRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public function updateItems(
}

/**
* Delete items by query
* Delete items by query.
*
* @param Query $query
*/
Expand Down
2 changes: 1 addition & 1 deletion Repository/MockRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public function updateItems(
}

/**
* Delete items by query
* Delete items by query.
*
* @param Query $query
*/
Expand Down
2 changes: 1 addition & 1 deletion Repository/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ abstract public function updateItems(
);

/**
* Delete items by query
* Delete items by query.
*
* @param Query $query
*/
Expand Down
2 changes: 1 addition & 1 deletion Repository/TransformableRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ public function updateItems(
}

/**
* Delete items by query
* Delete items by query.
*
* @param Query $query
*/
Expand Down
26 changes: 17 additions & 9 deletions Tests/Model/ItemTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ public function testScore()
}

/**
* Test index and app UUID
* Test index and app UUID.
*/
public function testIndexAndAppUUID()
{
Expand All @@ -440,22 +440,30 @@ public function testIndexAndAppUUID()
$repositoryReference = RepositoryReference::create($appUUID, $indexUUID);

$item = Item::create(ItemUUID::createByComposedUUID('1~item'));
$this->assertNull($item->getRepositoryReference());
$this->assertNull($item->getAppUUID());
$this->assertNull($item->getIndexUUID());
$item = Item::createFromArray($item->toArray());
$this->assertNull($item->getRepositoryReference());


$this->assertNull($item->getAppUUID());
$this->assertNull($item->getIndexUUID());

$item = Item::create(ItemUUID::createByComposedUUID('1~item'));
$item->setRepositoryReference($repositoryReference);
$this->assertEquals(
$repositoryReference,
$item->getRepositoryReference()
$repositoryReference->getIndexUUID(),
$item->getIndexUUID()
);
$this->assertEquals(
$repositoryReference->getAppUUID(),
$item->getAppUUID()
);
$item = Item::createFromArray($item->toArray());
$this->assertEquals(
$repositoryReference,
$item->getRepositoryReference()
$repositoryReference->getAppUUID(),
$item->getAppUUID()
);
$this->assertEquals(
$repositoryReference->getAppUUID(),
$item->getAppUUID()
);
}
}