Skip to content

Commit

Permalink
Merge pull request #45 from paavo/bugfix/fix-respect-site-and-dimensions
Browse files Browse the repository at this point in the history
BUGFIX: Respect site and dimensions in filter queries
  • Loading branch information
daniellienert authored May 11, 2022
2 parents 03bfb83 + 189bb34 commit 2f0d1a3
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 9 deletions.
10 changes: 6 additions & 4 deletions Classes/Controller/Backend/FormDataController.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,16 @@ public function indexAction(): void
/**
* @param string $formIdentifier
* @param string $hash
* @param string $siteName
* @param string $dimensionsHash
* @param string $exportDefinitionIdentifier
* @throws InvalidConfigurationTypeException
* @throws CannotBuildObjectException
* @throws UnknownObjectException
* @throws ConfigurationException
* @throws InvalidQueryException
*/
public function downloadAction(string $formIdentifier, string $hash, string $exportDefinitionIdentifier): void
public function downloadAction(string $formIdentifier, string $hash, string $siteName, string $dimensionsHash, string $exportDefinitionIdentifier): void
{
/** @var FormData[] $formDataItems */

Expand All @@ -97,7 +99,7 @@ public function downloadAction(string $formIdentifier, string $hash, string $exp

$formDataItems = array_map(static function (FormData $formData) use ($exportDefinition) {
return $formData->getProcessedFormData($exportDefinition);
}, $this->formDataRepository->findByFormIdentifierAndHash($formIdentifier, $hash)->toArray());
}, $this->formDataRepository->findByFormProperties($formIdentifier, $hash, $siteName, $dimensionsHash)->toArray());

$exporter->setFileName($fileName)->compileAndSend($formDataItems);
die();
Expand All @@ -110,7 +112,7 @@ public function downloadAction(string $formIdentifier, string $hash, string $exp
*/
public function previewAction(FormData $formDataEntry): void
{
$formDataEntries = $this->formDataRepository->findByFormIdentifierAndHash($formDataEntry->getFormIdentifier(), $formDataEntry->getHash());
$formDataEntries = $this->formDataRepository->findByFormProperties($formDataEntry->getFormIdentifier(), $formDataEntry->getHash(), $formDataEntry->getSiteName(), $formDataEntry->getDimensionsHash());
$scheduledExport = $this->scheduledExportRepository->findOneByFormIdentifier($formDataEntry->getFormIdentifier());

if ($formDataEntries->count() === 0) {
Expand All @@ -134,7 +136,7 @@ public function previewAction(FormData $formDataEntry): void
*/
public function deleteAction(FormData $formDataEntry): void
{
$this->formDataRepository->removeByFormIdentifierAndHash($formDataEntry->getFormIdentifier(), $formDataEntry->getHash());
$this->formDataRepository->removeByFormProperties($formDataEntry->getFormIdentifier(), $formDataEntry->getHash(), $formDataEntry->getSitename(), $formDataEntry->getDimensionsHash());
$this->redirect('index');
}

Expand Down
14 changes: 10 additions & 4 deletions Classes/Domain/Repository/FormDataRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,10 @@ public function findAllUniqueForms(): iterable
{
$queryBuilder = $this->createQueryBuilder('form');
return $queryBuilder
->groupBy('form.formIdentifier')
->groupBy('form.siteName')
->addgroupBy('form.formIdentifier')
->addGroupBy('form.hash')
->addGroupBy('form.dimensionsHash')
->addSelect('count(form) AS entryCount')
->addSelect('MAX(form.date) as latestDate')
->orderBy('latestDate', QueryInterface::ORDER_DESCENDING)
Expand All @@ -76,17 +78,21 @@ public function findAllUniqueForms(): iterable
/**
* @param string $formIdentifier
* @param string $hash
* @param string $siteName
* @param string $dimensionsHash
* @return QueryResultInterface
* @throws InvalidQueryException
*/
public function findByFormIdentifierAndHash(string $formIdentifier, string $hash): QueryResultInterface
public function findByFormProperties(string $formIdentifier, string $hash, string $siteName, string $dimensionsHash): QueryResultInterface
{
$query = $this->createQuery();

return $query->matching(
$query->logicalAnd(
$query->equals('formIdentifier', $formIdentifier),
$query->equals('hash', $hash),
$query->equals('siteName', $siteName),
$query->equals('dimensionsHash', $dimensionsHash),
$query->in('siteName', $this->accessibleSites)
)
)->execute();
Expand All @@ -101,9 +107,9 @@ public function findLatestVersionOfForm(string $formIdentifier): ?FormData
->execute()->getFirst();
}

public function removeByFormIdentifierAndHash(string $formIdentifier, string $hash): void
public function removeByFormProperties(string $formIdentifier, string $hash, string $siteName, string $dimensionsHash): void
{
foreach ($this->findByFormIdentifierAndHash($formIdentifier, $hash) as $formData) {
foreach ($this->findByFormProperties($formIdentifier, $hash, $siteName, $dimensionsHash) as $formData) {
$this->remove($formData);
}
}
Expand Down
2 changes: 1 addition & 1 deletion Classes/Domain/ScheduledExport/ScheduledExportSender.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ protected function prepareExportDefinitionNotSuitableMail(Message $mail, FormDat
*/
protected function prepareExportMail(FormData $formDataRepresentative, ExportDefinitionInterface $exportDefinition, string $exportFilePath, string $fileName, Message $mail): void
{
$formDataCollection = $this->formDataRepository->findByFormIdentifierAndHash($formDataRepresentative->getFormIdentifier(), $formDataRepresentative->getHash());
$formDataCollection = $this->formDataRepository->findByFormProperties($formDataRepresentative->getFormIdentifier(), $formDataRepresentative->getHash(), $formDataRepresentative->getSiteName(), $formDataRepresentative->getDimensionsHash());

$formDataItems = array_map(static function (FormData $formData) use ($exportDefinition) {
return $formData->getProcessedFormData($exportDefinition);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ prototype(PunktDe.Form.Persistence:Backend.FormData.Index) < prototype(Neos.Fusi
<Neos.Fusion.Form:Select field.name="exportDefinitionIdentifier">{props.options}</Neos.Fusion.Form:Select>
<Neos.Fusion.Form:Hidden field.name="formIdentifier" attributes.value={formData.formIdentifier}/>
<Neos.Fusion.Form:Hidden field.name="hash" attributes.value={formData.hash}/>
<Neos.Fusion.Form:Hidden field.name="siteName" attributes.value={formData.siteName}/>
<Neos.Fusion.Form:Hidden field.name="dimensionsHash" attributes.value={formData.dimensionsHash}/>
<Neos.Fusion.Form:Hidden field.name="hash" attributes.value={formData.hash}/>
<Neos.Fusion.Form:Button attributes.class="neos-button neos-button-primary">Download</Neos.Fusion.Form:Button>
</Neos.Fusion.Form:Form>
</td>
Expand Down

0 comments on commit 2f0d1a3

Please sign in to comment.