Ergebnis 1 bis 3 von 3

Thema: Cron-Job wirft einen Fehler wegen Model-Import

  1. #1
    Contao-Nutzer Avatar von dako314
    Registriert seit
    04.05.2013.
    Ort
    Mannheim
    Beiträge
    120

    Beitrag Cron-Job wirft einen Fehler wegen Model-Import

    Hallo,

    ich habe einen Cron-Job mit Annotations nach der offiziellen Doku aufgesetzt. Das sieht ungefähr so aus:

    PHP-Code:

    <?php

    declare(strict_types=1);

    namespace 
    App\Cron;

    use 
    Contao\CoreBundle\ServiceAnnotation\CronJob;

    use 
    App\Model\VideoModel;

    /**
     * @CronJob("minutely")
     */
    class VimeoCron
    {
      public function 
    __invoke(): void
      
    {
         
    //der code
         
    $videos VideoModel::findBy([], []); //nur ein Beispiel, hier tritt der Fehler auf
      
    }
    Leider erhalte ich in der Zeile, die ich im Code markiert habe, immer einen Fehler:

    In System.php line 176:
    [RuntimeException]
    The Symfony container is not available, did you initialize the Contao framework?

    Exception trace:
    at /vendor/contao/core-bundle/src/Resources/contao/library/Contao/System.php:176
    Contao\System->import() at /vendor/contao/core-bundle/src/Resources/contao/library/Contao/System.php:121
    Contao\System->__construct() at /vendor/contao/core-bundle/src/Resources/contao/library/Contao/DcaExtractor.php:107
    Contao\DcaExtractor->__construct() at /vendor/contao/core-bundle/src/Resources/contao/library/Contao/DcaExtractor.php:142
    Contao\DcaExtractor::getInstance() at /vendor/contao/core-bundle/src/Resources/contao/library/Contao/Model/QueryBuilder.php:33
    Contao\Model\QueryBuilder::find() at /vendor/contao/core-bundle/src/Resources/contao/library/Contao/Model.php:1213
    Contao\Model::buildFindQuery() at /vendor/contao/core-bundle/src/Resources/contao/library/Contao/Model.php:1053
    Contao\Model::find() at /vendor/contao/core-bundle/src/Resources/contao/library/Contao/Model.php:946
    Contao\Model::findBy() at /src/Cron/VimeoCron.php:38
    App\Cron\VimeoCron->__invoke() at /vendor/contao/core-bundle/src/Cron/CronJob.php:58
    Contao\CoreBundle\Cron\CronJob->__invoke() at /vendor/contao/core-bundle/src/Cron/Cron.php:119
    Contao\CoreBundle\Cron\Cron->run() at /vendor/contao/core-bundle/src/Command/CronCommand.php:45
    Contao\CoreBundle\Command\CronCommand->execute() at /vendor/symfony/console/Command/Command.php:255
    Symfony\Component\Console\Command\Command->run() at /vendor/symfony/console/Application.php:1027
    Symfony\Component\Console\Application->doRunCommand() at /vendor/symfony/framework-bundle/Console/Application.php:97
    Symfony\Bundle\FrameworkBundle\Console\Application->doRunCommand() at /vendor/symfony/console/Application.php:273
    Symfony\Component\Console\Application->doRun() at /vendor/symfony/framework-bundle/Console/Application.php:83
    Symfony\Bundle\FrameworkBundle\Console\Application->doRun() at /vendor/symfony/console/Application.php:149
    Symfony\Component\Console\Application->run() at /vendor/contao/manager-bundle/bin/contao-console:38

    Woran kann das liegen? Cache / Autoloader ist alles schon geleert, der restliche Code bzw. die Models funktionieren auch innerhalb von Contao, nur in den CronJobs nicht. Es hat auch zuletzt noch funktioniert.

    Das ist übrigens meine service.yml:

    PHP-Code:
    services:
      
    _defaults:
        
    autowiretrue
        autoconfigure
    true
        
    public: false
      _instanceof
    :
        
    Contao\CoreBundle\Framework\FrameworkAwareInterface:
          
    calls:
            - [
    "setFramework", ["@contao.framework"]]
      
    App\:
        
    resource: ../src
        exclude
    : ../src/{Entity,Migrations,Model,Resources,Tests,Widget}
      
    App\Controller\:
        
    resource: ../src/Controller
        
    public: true
        arguments
    :
          - 
    '@contao.security.frontend_user_provider'
          
    '@security.token_storage'
          
    '@contao.routing.url_generator'
          
    '@event_dispatcher'
          
    '@session'
          
    '%kernel.environment%'
          
    '@contao.security.user_checker'
      
    App\Controller\FrontendModule\:
        
    resource: ../src/Controller/FrontendModule
        
    public: true 
    Und das meine routing.yml:

    PHP-Code:
    app.controller:
      
    resource: ../src/Controller
      type
    annotation 
    Danke,

    Viele Grüße
    Daniel Koch

  2. #2
    Community-Moderator
    Wandelndes Contao-Lexikon
    Avatar von Spooky
    Registriert seit
    12.04.2012.
    Ort
    Scotland
    Beiträge
    34.063
    Partner-ID
    10107

    Standard

    Um Dinge aus dem Contao Legacy Framework nutzen zu können, darunter fallen auch Models, musst du das Contao Framework initialisieren. Dazu injectest du dir den ContaoFramework service.

  3. #3
    Contao-Nutzer Avatar von dako314
    Registriert seit
    04.05.2013.
    Ort
    Mannheim
    Beiträge
    120

    Standard

    Danke Spooky. Wieder was gelernt!

Aktive Benutzer

Aktive Benutzer

Aktive Benutzer in diesem Thema: 1 (Registrierte Benutzer: 0, Gäste: 1)

Lesezeichen

Lesezeichen

Berechtigungen

  • Neue Themen erstellen: Nein
  • Themen beantworten: Nein
  • Anhänge hochladen: Nein
  • Beiträge bearbeiten: Nein
  •