heimrichhannot / contao-categories-bundle

This bundle allows to assign nestable categories to arbitrary entities in Contao-driven systems.
4 stars 2 forks source link

Missing requirements in composer.json #10

Closed arboc closed 3 years ago

arboc commented 3 years ago

Context
Contao version: 4.9
Bundle version: 1.1
PHP version: 7.3

Description
Missing dependency / requirements

in class CategoryChoiceTypeyou are using some methods from heimrichhannot/contao-filter-bundle

...
namespace HeimrichHannot\CategoriesBundle\Filter\Type;

use Contao\System;
use HeimrichHannot\FilterBundle\Config\FilterConfig;
use HeimrichHannot\FilterBundle\Filter\Type\ChoiceType;
use HeimrichHannot\FilterBundle\Model\FilterConfigElementModel;

these requirements are not mentioned in the composer.json.

Defcon0 commented 3 years ago

This is not a hard dependency. Does it throw exceptions in your case if you don't have filter bundle installed?

We try to keep the hard (and needed) dependencies as less as possible.

arboc commented 3 years ago

During installation (composer install / update) you get an error, that the class FilterConfig is not found.
Than the Installation is cancelled.

Defcon0 commented 3 years ago

@koertho Could you please dig into this? We need to keep it that way that it's not a hard dep.

@arboc Could you please provide the complete error stack? Thanks!

arboc commented 3 years ago
// Warming up the cache for the prod environment with debug
 // false

16:59:03 ERROR     [console] Error thrown while running command "--ansi cache:warmup --env=prod". Message: "Class 'HeimrichHannot\FilterBundle\Filter\Type\ChoiceType' not found" ["exception" => Error { …},"command" => "--ansi cache:warmup --env=prod","message" => "Class 'HeimrichHannot\FilterBundle\Filter\Type\ChoiceType' not found"]

In CategoryChoiceType.php line 16:

  Attempted to load class "ChoiceType" from namespace "HeimrichHannot\FilterB
  undle\Filter\Type".
  Did you forget a "use" statement for another namespace?

cache:warmup [--no-optional-warmers] [-h|--help] [-q|--quiet] [-v|vv|vvv|--verbose] [-V|--version] [--ansi] [--no-ansi] [-n|--no-interaction] [-e|--env ENV] [--] <command>

Script Contao\ManagerBundle\Composer\ScriptHandler::initializeApplication handling the post-update-cmd event terminated with an exception

  [RuntimeException]
  An error occurred while executing the "cache:warmup" command: 16:59:03 ERROR     [console] Error thrown while running c
  ommand "--ansi cache:warmup --env=prod". Message: "Class 'HeimrichHannot\FilterBundle\Filter\Type\ChoiceType' not found" [
  [0;38;5;208m"exception" => Error { …},"command" => "
  --ansi cache:warmup --env=prod","message" => "Class 'Heimric
  hHannot\FilterBundle\Filter\Type\ChoiceType' not found"]

  In CategoryChoiceType.php line 16:

    Attempted to load class "ChoiceType" from namespace "HeimrichHannot\FilterB
    undle\Filter\Type".
    Did you forget a "use" statement for another namespace?

  cache:warmup [--no-optional-warmers] [-h|--help] [-q|--quiet] [-v|vv|vvv|--verbose] [-V|--version] [--ansi] [--no-ansi] [-n|--no-inter
  action] [-e|--env ENV] [--] <command>

install [--prefer-source] [--prefer-dist] [--dry-run] [--dev] [--no-suggest] [--no-dev] [--no-autoloader] [--no-scripts] [--no-progress] [--no-install] [-v|vv|vvv|--verbose] [-o|--optimize-autoloader] [-a|--classmap-authoritative] [--apcu-autoloader] [--apcu-autoloader-prefix APCU-AUTOLOADER-PREFIX] [--ignore-platform-req IGNORE-PLATFORM-REQ] [--ignore-platform-reqs] [--] [<packages>]...
koertho commented 3 years ago

I could not reproduce this error. Clean contao 4.9 install. Tried with composer and contao manager, dev and prod environments. No errors. Maybe you have another bundle install that do some strange class checking on warmup?

arboc commented 3 years ago

after hours I found, how to reproduce:

We use a .env and .env.local where our database connection is defined.
With these files, we get the error. Without these files every thing works fine.

arboc commented 3 years ago

in addition: it doesn't matter, where you define your database connection. (parameters.yml, .env) In the moment it is defined, the error will occur.

koertho commented 3 years ago

Very strange, database has nothing to do with class loading. Can you run the cache warmup command with verbose flag? cache:warmup -v

arboc commented 3 years ago
 // Warming up the cache for the prod environment with debug false

12:48:25 ERROR     [console] Error thrown while running command "cache:warmup -v". Message: "Class 'HeimrichHannot\FilterBundle\Filter\Type\ChoiceType' not found" ["exception" => Error { …},"command" => "cache:warmup -v","message" => "Class 'HeimrichHannot\FilterBundle\Filter\Type\ChoiceType' not found"]

In CategoryChoiceType.php line 16:

  [Symfony\Component\ErrorHandler\Error\ClassNotFoundError]
  Attempted to load class "ChoiceType" from namespace "HeimrichHannot\FilterBundle\Filter\Type".
  Did you forget a "use" statement for another namespace?

Exception trace:
  at /srv/htdocs/arne/contao4/test/vendor/heimrichhannot/contao-categories-bundle/src/Filter/Type/CategoryChoiceType.php:16
 include() at /srv/htdocs/arne/contao4/test/vendor/composer/ClassLoader.php:444
 Composer\Autoload\includeFile() at /srv/htdocs/arne/contao4/test/vendor/composer/ClassLoader.php:322
 Composer\Autoload\ClassLoader->loadClass() at n/a:n/a
 spl_autoload_call() at /srv/htdocs/arne/contao4/test/vendor/heimrichhannot/contao-categories-bundle/src/Resources/contao/languages/en/tl_filter_config_element.php:13
 include() at /srv/htdocs/arne/contao4/test/vendor/contao/core-bundle/src/Resources/contao/library/Contao/System.php:501
 Contao\System::loadLanguageFile() at /srv/htdocs/arne/contao4/test/vendor/netzmacht/contao-toolkit/src/Dca/Manager.php:90
 Netzmacht\Contao\Toolkit\Dca\Manager->getDefinition() at /srv/htdocs/arne/contao4/test/vendor/contao-bootstrap/grid/src/Listener/Hook/RegisterFixContentParentRelationsFixerListener.php:67
 ContaoBootstrap\Grid\Listener\Hook\RegisterFixContentParentRelationsFixerListener->onLoadDataContainer() at /srv/htdocs/arne/contao4/test/vendor/contao/core-bundle/src/Resources/contao/library/Contao/DcaLoader.php:118
 Contao\DcaLoader->loadDcaFiles() at /srv/htdocs/arne/contao4/test/vendor/contao/core-bundle/src/Resources/contao/library/Contao/DcaLoader.php:70
 Contao\DcaLoader->load() at /srv/htdocs/arne/contao4/test/vendor/contao/core-bundle/src/Resources/contao/library/Contao/Controller.php:1360
 Contao\Controller::loadDataContainer() at /srv/htdocs/arne/contao4/test/vendor/contao/core-bundle/src/Framework/Adapter.php:44
 Contao\CoreBundle\Framework\Adapter->__call() at /srv/htdocs/arne/contao4/test/vendor/heimrichhannot/contao-utils-bundle/src/Dca/DcaUtil.php:977
 HeimrichHannot\UtilsBundle\Dca\DcaUtil->loadDc() at /srv/htdocs/arne/contao4/test/vendor/heimrichhannot/contao-utils-bundle/src/Cache/DatabaseTreeCache.php:255
 HeimrichHannot\UtilsBundle\Cache\DatabaseTreeCache->generateAllCacheTree() at /srv/htdocs/arne/contao4/test/vendor/heimrichhannot/contao-utils-bundle/src/Cache/UtilCacheWarmer.php:132
 HeimrichHannot\UtilsBundle\Cache\UtilCacheWarmer->generateDatabaseTreeCache() at /srv/htdocs/arne/contao4/test/vendor/heimrichhannot/contao-utils-bundle/src/Cache/UtilCacheWarmer.php:84
 HeimrichHannot\UtilsBundle\Cache\UtilCacheWarmer->warmUp() at /srv/htdocs/arne/contao4/test/vendor/symfony/http-kernel/CacheWarmer/CacheWarmerAggregate.php:97
 Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerAggregate->warmUp() at /srv/htdocs/arne/contao4/test/vendor/symfony/framework-bundle/Command/CacheWarmupCommand.php:80
 Symfony\Bundle\FrameworkBundle\Command\CacheWarmupCommand->execute() at /srv/htdocs/arne/contao4/test/vendor/symfony/console/Command/Command.php:255
 Symfony\Component\Console\Command\Command->run() at /srv/htdocs/arne/contao4/test/vendor/symfony/console/Application.php:1027
 Symfony\Component\Console\Application->doRunCommand() at /srv/htdocs/arne/contao4/test/vendor/symfony/framework-bundle/Console/Application.php:97
 Symfony\Bundle\FrameworkBundle\Console\Application->doRunCommand() at /srv/htdocs/arne/contao4/test/vendor/symfony/console/Application.php:273
 Symfony\Component\Console\Application->doRun() at /srv/htdocs/arne/contao4/test/vendor/symfony/framework-bundle/Console/Application.php:83
 Symfony\Bundle\FrameworkBundle\Console\Application->doRun() at /srv/htdocs/arne/contao4/test/vendor/symfony/console/Application.php:149
 Symfony\Component\Console\Application->run() at /srv/htdocs/arne/contao4/test/vendor/contao/manager-bundle/bin/contao-console:38
koertho commented 3 years ago

@arboc Thanks, that's helpful.

@Defcon0 Looks like this is the DatabaseTreeUtil in the cache warmer again. I think we should remove this from the utils bundle, as it just build a cache, that contao build by itself and is often the reason for error.

koertho commented 3 years ago

@arboc Can you try without cache warmup (cache:clear --no-warmup)?

Defcon0 commented 3 years ago

@arboc Thanks, that's helpful.

@Defcon0 Looks like this is the DatabaseTreeUtil in the cache warmer again. I think we should remove this from the utils bundle, as it just build a cache, that contao build by itself and is often the reason for error.

Is it used anywhere we know of? Maybe we should provide a config switch to turn it on again. Would that be possible?

arboc commented 3 years ago

the cache:clear --no-warmup works.

koertho commented 3 years ago

@arboc Did had the filter bundle installed before? Does the table tl_filter_configelement exist in your db? Cause the DatabaseTreeUtil loads all tl* tables from the database!

the cache:clear --no-warmup works.

Another sign that it's the DatabaseTreeUtil

@Defcon0 We just need to disable it in the cache warmer, not kill the util itself. But yes, we could provide a config.

arboc commented 3 years ago

@koertho yes, I had the filter bundle installed before. And the tables tl_filter* exist. They coudn't deleted because of that error.

After I deleted them manually from the database, I was able to uninstall the filter bundle without issues.

koertho commented 3 years ago

That was the problem in combination with the databasetree util cache warmer. We will deactivate it by default in the next utils bundle update as it has no impact on existing projects and lead to errors like this. Thanks for reporting and providing all necessary informations!

koertho commented 3 years ago

@arboc The problem was fixed in utils bundle. Thanks for reporting!