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

Fix loadDataContainer for load Class #50

Merged
merged 2 commits into from Jan 19, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .composer-require-checker.json
Expand Up @@ -9,6 +9,7 @@
"Contao\\ManagerPlugin\\Config\\ContainerBuilder",
"Contao\\ManagerPlugin\\Config\\ExtensionPluginInterface",
"Contao\\ManagerPlugin\\Dependency\\DependentPluginInterface",
"ContaoCommunityAlliance\\DcGeneral\\DC\\General",
"ContaoCommunityAlliance\\DcGeneral\\Contao\\Compatibility\\DcCompat",
"ContaoCommunityAlliance\\DcGeneral\\Contao\\Dca\\Palette\\LegacyPalettesParser",
"ContaoCommunityAlliance\\DcGeneral\\DataDefinition\\Definition\\DefaultPalettesDefinition",
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/diagnostics.yml
Expand Up @@ -25,7 +25,7 @@ jobs:
phpcq_flags: ''
- php: 8.2
phpcq_install: 'update'
phpcq_flags: '--exit-0'
phpcq_flags: ''

steps:
- name: Pull source
Expand Down
10 changes: 8 additions & 2 deletions src/Listener/BuildPalettesListener.php
Expand Up @@ -8,15 +8,17 @@
* @author David Molineus <david.molineus@netzmacht.de>
* @author Christopher Bölter <christopher@boelter.eu>
* @author Sven Baumann <baumann.sv@gmail.com>
* @author Ingolf Steinhardt <info@e-spin.de>
* @copyright 2013-2014 bit3 UG
* @copyright 2015-2018 Contao Community Alliance.
* @copyright 2015-2023 Contao Community Alliance.
* @license LGPL-3.0+ https://github.com/contao-community-alliance/meta-palettes/license
* @link https://github.com/bit3/contao-meta-palettes
*/

namespace ContaoCommunityAlliance\MetaPalettes\Listener;

use Contao\System;
use ContaoCommunityAlliance\DcGeneral\DC\General;
use ContaoCommunityAlliance\MetaPalettes\Parser\Interpreter;
use ContaoCommunityAlliance\MetaPalettes\Parser\Parser;

Expand Down Expand Up @@ -69,7 +71,11 @@ public function onLoadDataContainer($strTable)

// The MetaPalettesBuilder is used for DC_General
if (isset($GLOBALS['TL_DCA'][$strTable]['config']['dataContainer'])
&& $GLOBALS['TL_DCA'][$strTable]['config']['dataContainer'] == 'General'
&& in_array(
$GLOBALS['TL_DCA'][$strTable]['config']['dataContainer'],
['General', General::class],
true
)
) {
return;
}
Expand Down
16 changes: 10 additions & 6 deletions src/Listener/SubSelectPalettesListener.php
Expand Up @@ -3,7 +3,7 @@
/**
* This file is part of contao-community-alliance/meta-palettes.
*
* (c) 2015-2022 Contao Community Alliance.
* (c) 2015-2023 Contao Community Alliance.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
Expand All @@ -17,7 +17,7 @@
* @author Sven Baumann <baumann.sv@gmail.com>
* @author Ingolf Steinhardt <info@e-spin.de>
* @copyright 2013-2014 bit3 UG
* @copyright 2015-2022 Contao Community Alliance.
* @copyright 2015-2023 Contao Community Alliance.
* @license https://github.com/contao-community-alliance/meta-palettes/license LGPL-3.0-or-later
* @filesource
*/
Expand All @@ -34,6 +34,8 @@
use ContaoCommunityAlliance\DcGeneral\Data\ModelInterface;
use ContaoCommunityAlliance\MetaPalettes\MetaPalettes;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Exception;

use const E_USER_DEPRECATED;
use const E_USER_ERROR;

Expand Down Expand Up @@ -163,6 +165,8 @@ protected function triggerSubselectPaletteError($strTable, $strSelector, $arrPal
* @return mixed|null
*
* @SuppressWarnings(PHPMD.Superglobals)
*
* @throws Exception When error at schema manager.
*/
private function getValue($dataContainer, $strTable, $strSelector)
{
Expand Down Expand Up @@ -190,7 +194,7 @@ private function getValue($dataContainer, $strTable, $strSelector)

// or break, when unable to handle data container
if ($dataContainer instanceof DC_Table
&& $this->connection->getSchemaManager()->tablesExist([$dataContainer->table])
&& $this->connection->createSchemaManager()->tablesExist([$dataContainer->table])
) {
return $this->fetchValueFromDatabase($dataContainer, $strSelector);
}
Expand Down Expand Up @@ -322,6 +326,8 @@ private function applyPalette($strTable, $strSelector, $strPalette)
* @param string $strSelector Selector field name.
*
* @return mixed
*
* @throws Exception When query failed.
*/
private function fetchValueFromDatabase($dataContainer, $strSelector)
{
Expand All @@ -331,9 +337,7 @@ private function fetchValueFromDatabase($dataContainer, $strSelector)
->where('id=:value')
->setParameter('value', $dataContainer->id)
->setMaxResults(1)
->execute();

assert(! is_int($statement));
->executeQuery();

if ($statement->rowCount() === 0) {
return null;
Expand Down