Ergebnis 1 bis 14 von 14

Thema: Notification über Crons - Contao 4.13, NC 1.7 [GELÖST]

  1. #1
    Contao-Fan
    Registriert seit
    28.06.2009.
    Ort
    Steffisburg
    Beiträge
    480

    Daumen hoch Notification über Crons - Contao 4.13, NC 1.7 [GELÖST]

    Hallo zusammen

    Möchte über einen Cron ein MetaModels durchlaufen und dann pro Item eine Mail über $objNotification->send versenden!

    Der Cron läuft und die MM daten kommen auch, nur das versenden geht nicht und ich erhalte die Meldung

    Code:
    Failed to send notification: Failed to start the session because headers have already been sent by "/home/public_html/contao/vendor/symfony/http-foundation/Response.php" at line 381.
    PHP-Code:
    $objNotification Notification::findByPk(6);
    if (
    $objNotification === null) {
         
    System::log('The notification was not found ID 6'__METHOD__TL_ERROR);
         return;
    }

    foreach(
    $arrEmploymentData as $arrItem) {

         
    $arrTokens $this->sendEmploymentNotification($arrItem);
        
         
    // Sende die Benachrichtigung
         
    try {
              
    $objNotification->send($arrTokens$GLOBALS['TL_LANGUAGE']);
         } catch (\
    Exception $e) {
              
    System::log("Failed to send notification: " $e->getMessage(), __METHOD__TL_ERROR);
         }

    Was mache ich falsch
    Geändert von tognit (19.10.2024 um 13:21 Uhr)

  2. #2
    Contao-Urgestein
    Registriert seit
    24.02.2021.
    Beiträge
    1.539
    Partner-ID
    11715
    Contao-Projekt unterstützen

    Support Contao

    Standard

    Nur mal so als Frage, was für Abhängigkeiten hast du noch installiert und ist das ein PCT-Theme? Eventuell ist es unabhängig vom NC und irgendwas setzt hier HTTP Header

  3. #3
    Contao-Fan
    Registriert seit
    28.06.2009.
    Ort
    Steffisburg
    Beiträge
    480

    Standard

    Von PCT habe ich nur den pct_autogrid installiert

  4. #4
    Contao-Urgestein
    Registriert seit
    24.02.2021.
    Beiträge
    1.539
    Partner-ID
    11715
    Contao-Projekt unterstützen

    Support Contao

    Standard

    Du hast die Fragen nicht beantwortet https://community.contao.org/de/show...l=1#post589380

  5. #5
    Contao-Fan
    Registriert seit
    28.06.2009.
    Ort
    Steffisburg
    Beiträge
    480

    Standard

    Ein PCT-Thema ist es nicht

    und hier noch die composer.json

    Code:
    {
        "name": "contao/contao-demo",
        "type": "contao-theme",
        "description": "This is an example website for Contao, a powerful open source CMS that allows you to create professional websites and scalable web applications.",
        "version": "4.13",
        "require": {
            "contao-community-alliance/contao-multicolumnwizard-frontend-bundle": "^2.3",
            "contao-community-alliance/contao-textfield-multiple-bundle": "^2.3",
            "contao-community-alliance/dc-general-contao-frontend": "^2.3",
            "contao-themes-net/bootstrap-icons-inserttag": "^1.0",
            "contao/calendar-bundle": "4.13.*",
            "contao/comments-bundle": "4.13.*",
            "contao/conflicts": "*@dev",
            "contao/faq-bundle": "4.13.*",
            "contao/listing-bundle": "4.13.*",
            "contao/manager-bundle": "4.13.*",
            "contao/news-bundle": "4.13.*",
            "contao/newsletter-bundle": "4.13.*",
            "e-spin/form-scr-default-bundle": "1.0.4",
            "friends-of-contao/contao-memberlist": "^2.0",
            "heimrichhannot/contao-notification_center_plus": "^1.6",
            "heimrichhannot/contao-tab-control-bundle": "^1.2",
            "heimseiten/contao-sticky-footer-backend-bundle": "^1.1",
            "hofff/contao-calendarfield": "^4.0",
            "madeyourday/contao-rocksolid-custom-elements": "^2.4",
            "markocupic/export_table": "^5.6",
            "markocupic/import-from-csv-bundle": "^5.3",
            "markocupic/preloader-overlay": "^1.0",
            "metamodels/attribute_alias": "^2.3@dev",
            "metamodels/attribute_checkbox": "^2.3@dev",
            "metamodels/attribute_combinedvalues": "^2.3@dev",
            "metamodels/attribute_decimal": "^2.3@dev",
            "metamodels/attribute_file": "^2.3@dev",
            "metamodels/attribute_longtext": "^2.3@dev",
            "metamodels/attribute_numeric": "^2.3@dev",
            "metamodels/attribute_select": "^2.3@dev",
            "metamodels/attribute_tablemulti": "^2.3@dev",
            "metamodels/attribute_tabletext": "^2.3@dev",
            "metamodels/attribute_tags": "^2.3@dev",
            "metamodels/attribute_text": "^2.3@dev",
            "metamodels/attribute_timestamp": "^2.3@dev",
            "metamodels/attribute_url": "^2.3@dev",
            "metamodels/contao-frontend-editing": "^2.3@dev",
            "metamodels/core": "dev-release/2.3.0 as 2.3@dev",
            "metamodels/dropzone_file_upload": "^2.3@dev",
            "metamodels/filter_checkbox": "^2.3@dev",
            "metamodels/filter_fromto": "^2.3@dev",
            "metamodels/filter_register": "^2.3@dev",
            "metamodels/filter_select": "^2.3@dev",
            "metamodels/filter_tags": "^2.3@dev",
            "metamodels/filter_text": "^2.3@dev",
            "nesbot/carbon": "^3.8",
            "nutshell-framework/card-element": "^1.0",
            "oveleon/contao-member-extension-bundle": "^1.5",
            "pbd-kn/contao-inputvar-bundle": "^1.0",
            "richardhj/contao-ajax_reload_element": "^2.1",
            "ruegen-web-design/contao-dateselect": "^1.0",
            "terminal42/contao-ajaxform": "^1.3",
            "terminal42/contao-autoregistration": "^3.1",
            "terminal42/contao-folderpage": "^3.2",
            "terminal42/contao-inserttags": "^2.4",
            "terminal42/contao-mailusername": "^2.1",
            "terminal42/contao-shortlink": "^1.5",
            "terminal42/notification_center": "^1.7",
            "thescrat/contao-loginlink": "^1.0"
        },
        "extra": {
            "public-dir": "public",
            "contao-component-dir": "assets"
        },
        "scripts": {
            "post-install-cmd": [
                "@php vendor/bin/contao-setup"
            ],
            "post-update-cmd": [
                "@php vendor/bin/contao-setup"
            ]
        },
        "config": {
            "allow-plugins": {
                "contao-components/installer": true,
                "php-http/discovery": true,
                "contao-community-alliance/composer-plugin": true,
                "dealerdirect/phpcodesniffer-composer-installer": true,
                "contao/manager-plugin": true
            }
        }
    }

  6. #6
    Community-Moderatorin & Contao-Urgestein Avatar von mlweb
    Registriert seit
    10.07.2011.
    Beiträge
    7.453
    Contao-Projekt unterstützen

    Support Contao

    Standard

    Wenn ich es richtig sehe nutzt Du nicht das originale NC, sondern die Erweiterung heimrichhannot/contao-notification_center_plus . Das solltest Du unbedingt im Thread mitteilen. Eigentlich hatte ich angenommen es geht Dir um das NC von terminal 42.

    Nachtrag: Ich sehe gerade NC von Terminal 42 ist ja auch installiert.
    Geändert von mlweb (16.10.2024 um 07:10 Uhr)
    Ich habe Dir mit meinen Hinweisen geholfen und Du möchtest Dich bedanken?
    Unterstütze bitte das Contao-Projekt (Button Links)
    Weitere Spendenmöglichkeiten
    ------------------------------------------------------------------------------------------------------
    Contao-Dokumentation: Contao-Handbuch und Contao-Entwickler-Doku
    Contao-Online-Video-Kurse: Contao Academy
    Funktionalität erweitern: Contao-Erweiterungen

    Für Dinge die man mit html5 und css3 lösen kann, braucht man kein javascript.




  7. #7
    Contao-Fan
    Registriert seit
    28.06.2009.
    Ort
    Steffisburg
    Beiträge
    480

    Standard

    Ist contao-notification_center_plus nicht "nur" eine Erweiterung bzw. Ergänzung von nc?

    Die Benachrichtigung über Formulare, bzw. EventListener funktioniert, nur über den Cron klappt es nicht.

  8. #8
    Community-Moderatorin & Contao-Urgestein Avatar von mlweb
    Registriert seit
    10.07.2011.
    Beiträge
    7.453
    Contao-Projekt unterstützen

    Support Contao

    Standard

    Ich kenne die Erweiterung nicht. Bin nur drüber gestolpert und habe erst später gesehen, dass auch das NC von Terminal 42 installiert ist.
    Ich habe Dir mit meinen Hinweisen geholfen und Du möchtest Dich bedanken?
    Unterstütze bitte das Contao-Projekt (Button Links)
    Weitere Spendenmöglichkeiten
    ------------------------------------------------------------------------------------------------------
    Contao-Dokumentation: Contao-Handbuch und Contao-Entwickler-Doku
    Contao-Online-Video-Kurse: Contao Academy
    Funktionalität erweitern: Contao-Erweiterungen

    Für Dinge die man mit html5 und css3 lösen kann, braucht man kein javascript.




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

    Standard

    Poste deinen gesamten Code und was genau du versuchst auszuführen.
    » sponsor me via GitHub or Revolut

  10. #10
    Contao-Fan
    Registriert seit
    28.06.2009.
    Ort
    Steffisburg
    Beiträge
    480

    Standard

    Hier mein Code

    PHP-Code:
    <?php

    namespace App\Job;

    use 
    App\Helper\MetaModelsTemplateHelper;
    use 
    Codefog\HasteBundle\StringParser;
    use 
    Contao\System;
    use 
    Doctrine\DBAL\Connection
    use 
    NotificationCenter\Model\Notification;

    class 
    PrepareNotifyPublicJob
    {    
        private 
    Connection $connection;

        public function 
    __construct(
            
    Connection $connection,
        ) {
            
    $this->connection $connection;
        }

        public function 
    __invoke()
        {
            
    $objNotification Notification::findByPk(6);
            if (
    $objNotification === null) {
                
    System::log('The notification was not found ID 6'__METHOD__TL_ERROR);
                return;
            }

            
    $templateHelper System::getContainer()->get(MetaModelsTemplateHelper::class);

            
    $parentModelName 'mm_organization';
            
    $parentFilterId  33;
            
    $parentRenderId  27;

            
    $arrOrganizationData $templateHelper->getIitemDetailsWithFilterData($parentModelName$parentRenderId$parentFilterId);

            foreach(
    $arrOrganizationData as $arrOrganization) {

                
    $communicationData $this->connection->fetchAssociative("SELECT * FROM mm_helpercommunication WHERE organization_id = ?", [$arrOrganization['raw']['id']]);

                if (!
    $communicationData) {
                    
    $communicationData['daysBeforeEventReminder'] = 5;
                }

                
    $modelName 'mm_employment';
                
    $filterId 48;
                
    $renderId 11;
                
    $arrFilterAlias = ['organization_id_filter' => $arrOrganization['raw']['id'], 'day_filter' => $communicationData['daysBeforeEventReminder']];
        
                
    $arrEmploymentData $templateHelper->getIitemDetailsWithFilterData($modelName$renderId$filterId$arrFilterAlias);

                foreach(
    $arrEmploymentData as $arrItem) {

                    
    $arrTokens $this->sendEmploymentNotification($arrItem);
        
                    
    $employment_id $arrItem['raw']['id'];
                    
    $helperEmail $arrItem['raw']['helper']['email'];

                    try {
                        
    $objNotification->send($arrTokens$GLOBALS['TL_LANGUAGE']);
                        
    System::log("Helper Reminder Mailer: An email would be sent to email:$helperEmail to employment:$employment_id"__METHOD__TL_GENERAL);
                    } catch (\
    Exception $e) {
                        
    System::log("Failed to send to email:$helperEmail to employment:$employment_id e notification:" $e->getMessage(), __METHOD__TL_ERROR);
                    }
                }
            }
        }
    }
    Habe es mal über einen Cron der vom Server gestartet wird und erhalte die Meldung

    Code:
    12:55:02 ERROR     [app] Error: Class "NcNotificationModel" not found in /home/public_html/contao/vendor/contao/core-bundle/src/Resources/contao/library/Contao/Model/Registry.php:112
    Stack trace:
    #0 /home/public_html/contao/vendor/contao/core-bundle/src/Resources/contao/library/Contao/Model.php(766): Contao\Model\Registry->fetch('tl_nc_notificat...', 6)
    #1 /home/public_html/contao/src/Job/PrepareNotifyPublicJob.php(31): Contao\Model::findByPk(6)
    #2 /home/public_html/contao/vendor/contao/core-bundle/src/Cron/CronJob.php(42): App\Job\PrepareNotifyPublicJob->__invoke('cli')
    #3 /home/public_html/contao/vendor/contao/core-bundle/src/Cron/Cron.php(131): Contao\CoreBundle\Cron\CronJob->__invoke('cli')
    #4 /home/public_html/contao/vendor/contao/core-bundle/src/Command/CronCommand.php(36): Contao\CoreBundle\Cron\Cron->run('cli')
    #5 /home/public_html/contao/vendor/symfony/console/Command/Command.php(298): Contao\CoreBundle\Command\CronCommand->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
    #6 /home/public_html/contao/vendor/symfony/console/Application.php(1058): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
    #7 /home/public_html/contao/vendor/symfony/framework-bundle/Console/Application.php(96): Symfony\Component\Console\Application->doRunCommand(Object(Contao\CoreBundle\Command\CronCommand), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
    #8 /home/public_html/contao/vendor/symfony/console/Application.php(301): Symfony\Bundle\FrameworkBundle\Console\Application->doRunCommand(Object(Contao\CoreBundle\Command\CronCommand), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
    #9 /home/public_html/contao/vendor/symfony/framework-bundle/Console/Application.php(82): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
    #10 /home/public_html/contao/vendor/symfony/console/Application.php(171): Symfony\Bundle\FrameworkBundle\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
    #11 /home/public_html/contao/vendor/contao/manager-bundle/bin/contao-console(38): Symfony\Component\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput))
    #12 /home/public_html/contao/vendor/bin/contao-console(119): include('/home/...')
    #13 {main}
    12:55:02 CRITICAL  [console] Error thrown while running command "contao:cron". Message: "Class "NcNotificationModel" not found" ["exception" => Error { …},"command" => "contao:cron","message" => "Class "NcNotificationModel" not found"]
    Code:
    Error thrown while running command "contao:cron". Message: "Class "NcNotificationModel" not found"

  11. #11
    Contao-Urgestein
    Registriert seit
    24.02.2021.
    Beiträge
    1.539
    Partner-ID
    11715
    Contao-Projekt unterstützen

    Support Contao

    Standard

    Du musst deinen Code durchsuchen, wo der Alias NcNotificationModel verwendet wird.
    Vermutlich Notification as NcNotificationModel irgendwo vergessen, wo NcNotificationModel genutzt wird.

  12. #12
    Contao-Fan
    Registriert seit
    28.06.2009.
    Ort
    Steffisburg
    Beiträge
    480

    Standard

    NcNotificationModel gibt es nicht!? und wenn ich das ausklammere und die System::log prüfen möchte, kommt die Meldung

    Code:
    13:23:01 ERROR     [app] Error: Undefined constant "App\Job\TL_ERROR" in /home/public_html/contao/src/Job/PrepareNotifyPublicJob.php:25

  13. #13
    Contao-Urgestein
    Registriert seit
    24.02.2021.
    Beiträge
    1.539
    Partner-ID
    11715
    Contao-Projekt unterstützen

    Support Contao

    Standard

    Dann wird die Konstante TL_ERROR nicht erkannt (Diese solltest du auch nicht mehr verwenden für Contao 5), du solltest auf das LoggerInterface wechseln und es dir via DI inkludieren.

    Irgendeine Abhängigkeit oder dein eigener Code sorgen für den Fehler beim NC, da musst du jetzt mal durch die Liste der etlichen Erweiterungen schauen.
    Such doch mal im vendor nach NCNotificationModel

  14. #14
    Contao-Fan
    Registriert seit
    28.06.2009.
    Ort
    Steffisburg
    Beiträge
    480

    HTML

    Momentan brauche ich noch 4.13, aber danke für die Info

    Ich habe vergessen das Framework einzubinden!

    PHP-Code:
    private ContaoFramework $framework 
    So geht es!

Aktive Benutzer

Aktive Benutzer

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

Berechtigungen

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