Skip to content
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

Rework the model collector #540

Merged
merged 21 commits into from
Feb 28, 2022
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
95eca8f
Rework the model collector.
baumannsven Jul 18, 2020
7b18734
Add dynamically declared property $defaultProviderName
dmolineus Nov 15, 2021
ec2b010
Add unit tests for ModelCollector::searchParentOfIn and remove condition
dmolineus Nov 15, 2021
c1e3ca4
Check the model provider in all search methods
dmolineus Nov 17, 2021
ec1f567
Guard that root and parent provider are defined when searching a parent
dmolineus Nov 17, 2021
4b3ef32
Fix unit tests
dmolineus Nov 22, 2021
75d4faf
Rename searchParentFromHierarchical to searchParentOfRootModel and de…
dmolineus Nov 22, 2021
b32e452
Use the model collector instead of expecting that an inverse filter i…
dmolineus Nov 22, 2021
d50031e
Follow the interface ParentChildConditionInterface::getInverseFilterFor
dmolineus Nov 22, 2021
2ceecba
Improve test method names
dmolineus Nov 22, 2021
9049596
Add unit test for hierachical search by inverse filter
dmolineus Nov 22, 2021
508256b
Fix code style
dmolineus Nov 22, 2021
51517d7
Fix existing code style violations
dmolineus Jan 5, 2022
999caea
Switch to github actions
dmolineus Jan 5, 2022
459ee4f
Do not limit searchParentOf to model originating from current data co…
dmolineus Feb 21, 2022
5e99407
Drop searchParentOfRootModel()
dmolineus Feb 21, 2022
ba51701
Add allowed plugins
dmolineus Feb 21, 2022
f0c111f
Add missing authors
dmolineus Feb 24, 2022
f2a6b8f
Silence develop code warning
dmolineus Feb 24, 2022
8397202
Fix more issues detected by phpmd
dmolineus Feb 24, 2022
7826ab3
Fix some code review issues from discodier
baumannsven Feb 28, 2022
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
49 changes: 49 additions & 0 deletions .github/workflows/diagnostics.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: DC General

on:
push:
pull_request:

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
php: [7.3, 7.4]
contao: [~4.4.0, ~4.9.0]

steps:
- name: PHP ${{ matrix.php }} ${{ matrix.contao }} Pull source
uses: actions/checkout@v2
with:
fetch-depth: 0

# see https://github.com/shivammathur/setup-php
- name: PHP ${{ matrix.php }} ${{ matrix.contao }} Setup PHP.
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
coverage: none

- name: PHP ${{ matrix.php }} ${{ matrix.contao }} Cache composer cache directory
uses: actions/cache@v1
env:
cache-name: composer-cache-dir
with:
path: ~/.cache/composer
key: ${{ runner.os }}-build-${{ env.cache-name }}

- name: PHP ${{ matrix.php }} ${{ matrix.contao }} Cache vendor directory
uses: actions/cache@v1
env:
cache-name: composer-vendor
with:
path: vendor
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
- name: PHP ${{ matrix.php }} ${{ matrix.contao }} Install composer dependencies
run: composer update --prefer-dist --no-interaction --no-suggest

- name: PHP ${{ matrix.php }} ${{ matrix.contao }} Run tests
run: ant -keep-going
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,7 @@ composer.lock
.sass-cache
build/
.phpunit.result.cache

# PHPCQ and related tools
.php_cs.cache
build.properties
43 changes: 0 additions & 43 deletions .travis.yml

This file was deleted.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[![Build Status](https://travis-ci.org/contao-community-alliance/dc-general.png)](https://travis-ci.org/contao-community-alliance/dc-general)
[![Build Status](https://github.com/contao-community-alliance/dc-general/actions/workflows/diagnostics.yml/badge.svg)](https://github.com/contao-community-alliance/dc-general/actions)
[![Latest Version tagged](http://img.shields.io/github/tag/contao-community-alliance/dc-general.svg)](https://github.com/contao-community-alliance/dc-general/tags)
[![Latest Version on Packagist](http://img.shields.io/packagist/v/contao-community-alliance/dc-general.svg)](https://packagist.org/packages/contao-community-alliance/dc-general)
[![Installations via composer per month](http://img.shields.io/packagist/dm/contao-community-alliance/dc-general.svg)](https://packagist.org/packages/contao-community-alliance/dc-general)
Expand Down
6 changes: 6 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,5 +81,11 @@
},
"scripts": {
"php-cs-fixer": "php-cs-fixer fix --rules=@PSR2"
},
"config": {
"allow-plugins": {
"contao-components/installer": false,
"contao/manager-plugin": true
}
}
}
9 changes: 6 additions & 3 deletions src/Cache/Http/InvalidCacheTags.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/**
* This file is part of contao-community-alliance/dc-general.
*
* (c) 2013-2020 Contao Community Alliance.
* (c) 2013-2021 Contao Community Alliance.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
Expand All @@ -12,7 +12,8 @@
*
* @package contao-community-alliance/dc-general
* @author Sven Baumann <[email protected]>
* @copyright 2013-2020 Contao Community Alliance.
* @author David Molineus <[email protected]>
* @copyright 2013-2021 Contao Community Alliance.
* @license https://github.com/contao-community-alliance/dc-general/blob/master/LICENSE LGPL-3.0-or-later
* @filesource
*/
Expand Down Expand Up @@ -146,7 +147,9 @@ private function addRelatedModelsTag(ModelInterface $model): void

/** @var DefaultCollection $parentModels */
$parentModels = $dataProvider
->fetchAll($dataProvider->getEmptyConfig()->setFilter($parentCondition->getInverseFilterFor($model)));
->fetchAll(
$dataProvider->getEmptyConfig()->setFilter((array) $parentCondition->getInverseFilterFor($model))
);
foreach ($parentModels as $parentModel) {
$this->addModelTag($parentModel);
}
Expand Down
14 changes: 9 additions & 5 deletions src/Contao/Subscriber/FallbackResetSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/**
* This file is part of contao-community-alliance/dc-general.
*
* (c) 2013-2019 Contao Community Alliance.
* (c) 2013-2021 Contao Community Alliance.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
Expand All @@ -14,13 +14,15 @@
* @author Christian Schiffler <[email protected]>
* @author Sven Baumann <[email protected]>
* @author Ingolf Steinhardt <[email protected]>
* @copyright 2013-2019 Contao Community Alliance.
* @author David Molineus <[email protected]>
* @copyright 2013-2021 Contao Community Alliance.
* @license https://github.com/contao-community-alliance/dc-general/blob/master/LICENSE LGPL-3.0-or-later
* @filesource
*/

namespace ContaoCommunityAlliance\DcGeneral\Contao\Subscriber;

use ContaoCommunityAlliance\DcGeneral\Controller\ModelCollector;
use ContaoCommunityAlliance\DcGeneral\Data\ConfigInterface;
use ContaoCommunityAlliance\DcGeneral\Data\ModelManipulator;
use ContaoCommunityAlliance\DcGeneral\Event\AbstractModelAwareEvent;
Expand Down Expand Up @@ -160,9 +162,11 @@ private function determineFilterConfig(AbstractModelAwareEvent $event)
);

if (null !== $parentFilter) {
$parentConfig = $dataProvider->getEmptyConfig()->setFilter($parentFilter->getInverseFilterFor($model));
$parentProvider = $environment->getDataProvider($parentFilter->getSourceName());
$parent = $parentProvider->fetchAll($parentConfig)->get(0);
$parent = (new ModelCollector($environment))->searchParentOf($model);
if ($parent === null) {
return null;
}

return $dataProvider->getEmptyConfig()->setFilter($parentFilter->getFilter($parent));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,7 @@ private function getGrandParentId(
$grandParentProvider = $environment->getDataProvider($grandParentName);

$config = $grandParentProvider->getEmptyConfig();
$config->setFilter($relationship->getInverseFilterFor($parentModel));
$config->setFilter((array) $relationship->getInverseFilterFor($parentModel));

$parents = $grandParentProvider->fetchAll($config);

Expand Down
15 changes: 7 additions & 8 deletions src/Contao/View/Contao2BackendView/ButtonRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* This file is part of contao-community-alliance/dc-general.
*
* (c) 2013-2021 Contao Community Alliance.
* (c) 2013-2022 Contao Community Alliance.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
Expand All @@ -16,7 +17,8 @@
* @author Sven Baumann <[email protected]>
* @author Ingolf Steinhardt <[email protected]>
* @author Richard Henkenjohann <[email protected]>
* @copyright 2013-2021 Contao Community Alliance.
* @author David Molineus <[email protected]>
* @copyright 2013-2022 Contao Community Alliance.
* @license https://github.com/contao-community-alliance/dc-general/blob/master/LICENSE LGPL-3.0-or-later
* @filesource
*/
Expand Down Expand Up @@ -124,13 +126,10 @@ public function __construct(EnvironmentInterface $environment)
$this->circularModelIds = [];

// We must only check for CUT operation here as pasting copy'ed parents is allowed.
$cutItems = \array_filter(
$this->clipboardItems,
function ($item) {
/** @var ItemInterface $item */
return $item->getAction() === $item::CUT;
}
);
$cutItems = \array_filter($this->clipboardItems, function ($item) {
/** @var ItemInterface $item */
return $item->getAction() === $item::CUT;
});
$cutModels = $controller->getModelsFromClipboardItems($cutItems);
$collector = new ModelCollector($environment);
foreach ($cutModels as $model) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/**
* This file is part of contao-community-alliance/dc-general.
*
* (c) 2013-2021 Contao Community Alliance.
* (c) 2013-2022 Contao Community Alliance.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
Expand All @@ -16,7 +16,7 @@
* @author Stefan Heimes <[email protected]>
* @author Sven Baumann <[email protected]>
* @author Richard Henkenjohann <[email protected]>
* @copyright 2013-2021 Contao Community Alliance.
* @copyright 2013-2022 Contao Community Alliance.
* @license https://github.com/contao-community-alliance/dc-general/blob/master/LICENSE LGPL-3.0-or-later
* @filesource
*/
Expand Down Expand Up @@ -483,9 +483,6 @@ private function prepareWidgetAttributes(ModelInterface $model, PropertyInterfac
],
'options' => $this->getOptionsForWidget($property, $model),
'eval' => $propExtra,
// @codingStandardsIgnoreStart
// 'foreignKey' => null
// @codingStandardsIgnoreEnd
];

if (isset($propExtra['reference'])) {
Expand Down
6 changes: 4 additions & 2 deletions src/Contao/View/Contao2BackendView/TreePicker.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/**
* This file is part of contao-community-alliance/dc-general.
*
* (c) 2013-2021 Contao Community Alliance.
* (c) 2013-2022 Contao Community Alliance.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
Expand All @@ -16,7 +16,9 @@
* @author Tristan Lins <[email protected]>
* @author Sven Baumann <[email protected]>
* @author Richard Henkenjohann <[email protected]>
* @copyright 2013-2021 Contao Community Alliance.
* @author Ingolf Steinhardt <[email protected]>
* @author David Molineus <[email protected]>
* @copyright 2013-2022 Contao Community Alliance.
* @license https://github.com/contao-community-alliance/dc-general/blob/master/LICENSE LGPL-3.0-or-later
* @filesource
*/
Expand Down
11 changes: 6 additions & 5 deletions src/Contao/View/Contao2BackendView/Widget/FileTree.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/**
* This file is part of contao-community-alliance/dc-general.
*
* (c) 2013-2021 Contao Community Alliance.
* (c) 2013-2022 Contao Community Alliance.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
Expand All @@ -16,7 +16,7 @@
* @author Stefan Heimes <[email protected]>
* @author Ingolf Steinhardt <[email protected]>
* @author Sven Baumann <[email protected]>
* @copyright 2013-2021 Contao Community Alliance.
* @copyright 2013-2022 Contao Community Alliance.
* @license https://github.com/contao-community-alliance/dc-general/blob/master/LICENSE LGPL-3.0-or-later
* @filesource
*/
Expand Down Expand Up @@ -370,19 +370,20 @@ protected function renderIcon($model, $imagesOnly = false, $downloads = false)
return Image::getHtml($file->icon) . ' ' . $info;
}

return $this->generateGalleryImage($model, $file, $info);
return $this->generateGalleryImage($file, $info);
}

/**
* Generate an image for use as gallery listing.
*
* @param FilesModel $model The file model in use.
* @param File $file The image file being rendered.
* @param string $info The image information.
*
* @return string
*
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
private function generateGalleryImage($model, File $file, $info)
private function generateGalleryImage(File $file, $info)
{
if ($file->viewWidth && $file->viewHeight
&& ($file->isSvgImage
Expand Down
Loading