Failed custom job

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • shalmaxb
    Senior Member
    • Mar 2015
    • 1603

    Failed custom job

    Hello,
    I try to implement a custom Job for an entity to recalculate fomula by CRON. The Job is running but fails.

    Here is my php-script in folder Jobs:

    PHP Code:
    <?php
    
    namespace Espo\Custom\Jobs;
    
    use Espo\Core\Job\JobDataLess;
    
    class RecalculateKlassen implements JobDataLess
    {
    public function run(): void
    {
    $entityManager = $this->getEntityManager();
    $repository = $entityManager->getRepository('Klassen');
    
    $records = $repository->find();
    
    foreach ($records as $record) {
    $entityManager->getFormulaManager()->run($record);
    $entityManager->saveEntity($record);
    }
    }
    }
    and I get this error.

    Code:
    [2024-12-15 15:22:01] CRITICAL: (0) Failed job 675ef41971db1e741. Call to undefined method Espo\Custom\Jobs\RecalculateKLassen::getEntityMana ger() :: /var/www/vhosts/xxx/xxx/custom/Espo/Custom/Jobs/RecalculateKlassen.php(11)

    Could anyone tell me, which method would not be defiend and how to repair that?
    The entity is called "Klassen" (the app is workshop administration where the workshop has (school)-classes). I already thought it could be because of the word "Klassen"?
    Last edited by shalmaxb; 12-15-2024, 03:29 PM.
  • yuri
    Member
    • Mar 2014
    • 8443

    #2
    You need to pass the entityManager (and formulaManager) through the contsructor.

    PHP Code:
    
    use Espo\ORM\EntityManager;
    use Espo\Core\Formula\Manager;
    
    class RecalculateKlassen implements JobDataLess
    {
        public function __construct(
            private EntityManager $entityManager,
            private Manager $formulaManager,
        ) {}
    
        public function run(): void
        {
    
               $this->entityManager;
               $this->formulaManager;
        }
    } 
    
    Last edited by yuri; 12-15-2024, 05:55 PM.
    If you find EspoCRM good, we would greatly appreciate if you could give the project a star on GitHub. We believe our work truly deserves more recognition. Thanks.

    Comment


    • shalmaxb
      shalmaxb commented
      Editing a comment
      yuri, must it not be called "construct" instead of "constructor?

    • yuri
      yuri commented
      Editing a comment
      Right. I've mistaken.
  • shalmaxb
    Senior Member
    • Mar 2015
    • 1603

    #3
    discarded
    Last edited by shalmaxb; 12-15-2024, 04:09 PM.

    Comment

    Working...