0

I have a problem with accessing the crdate of a fe_user in a croniob task. I have an extended Frontend user model where I added this adjustments: https://stackoverflow.com/a/50663006/1684975

Additionaly I've added a mapping via ts

config.tx_extbase {
  persistence {
    classes {

      TYPO3\CMS\Extbase\Domain\Model\FrontendUser {
        subclasses {
          Tx_MyExt_User = ACV\MyExt\Domain\Model\User

        }
      }
      Paul\MyExt\Domain\Model\User {
        mapping {
          tableName = fe_users
          recordType = Tx_MyExt_User
          columns {
            crdate.mapOnProperty = crdate
          }
        }
      }

    }
  }
}

When I fire up the Scheduler task manual via the Scheduler BE module it's ok. But when the real cronjob kicks in I get the error

Uncaught TYPO3 Exception Call to a member function getTimestamp() on null

In the Scheduler task, I get the crDate via the getter and try to get the timestamp…

$users = $frontendRepository->findByOptIn(false);
foreach ($users as $user) {
  if ($user->getCrdate()->getTimestamp() < strtotime('-5 days')) {
    $frontendRepository->remove($user);
  }
}

The mode of the user is correct. I can access other custom properties I've added to the model.

It's TYPO3 v9.5.26.

The odd thing is that it runs locally in my dev environment.

Did someone have an idea what could cause the problem?

biesior
  • 55,576
  • 10
  • 125
  • 182
Paul
  • 289
  • 2
  • 14
  • "*when the real cronjob kicks in...*" what do you mean exactly? cron just runs your Scheduler's tasks, so in general *it should work*. is your task valid class? how Do you run Scheduler from cron? Please add some details cause for now it's not quite sure. And basic question: did you clear all possible caches? ;) when manipulating mappings sometimes you need to do it several times. ;) – biesior Jun 01 '21 at 14:42
  • What do your model looks like ? Extends, properties, .... ? – Stefan Bürk Jun 01 '21 at 15:47
  • What I mean with "kicks in" is that the scheduler is called by the server cronjob runner. Its running on a mittwald server which have a redefined preset for typo3 cronjobs and never had any problems. I don't think that this could be the problem, like you said it "should work" and I wouldn't ask here. Additional info, it's a non composer T3 installation. @StefanBürk It extends from the FrontendUser and have nothing fancy in it. I mean it works when I run it manually in the t3 Backend so the code should be ok. – Paul Jun 01 '21 at 20:22
  • Will make a test the next days on one of our MW instances. FE user with override in scheduler. (We normaly do no stuff in scheduler .. we run commands directly ). Is it possible you can provide your extended user class ? At least your property definition with the getter/setter fr the crdate stuff with docblocks ? – Stefan Bürk Jun 01 '21 at 20:40
  • Its exactly like in the SO link I've linked in my question. – Paul Jun 01 '21 at 20:42
  • Ok I gave up. I've changed the code that I doesn't use the repository anymore and go directly down to the DB via ConnectionPool and do a select and update/delete on the entries in the DB. :/ – Paul Jun 07 '21 at 11:50

1 Answers1

0

Add a file <extensionfolder>/ext_typoscript_setup.typoscript and add your TypoScript in there:

config.tx_extbase {
  persistence {
    classes {

      TYPO3\CMS\Extbase\Domain\Model\FrontendUser {
        subclasses {
          Tx_MyExt_User = ACV\MyExt\Domain\Model\User

        }
      }
      Paul\MyExt\Domain\Model\User {
        mapping {
          tableName = fe_users
          recordType = Tx_MyExt_User
          columns {
            crdate.mapOnProperty = crdate
          }
        }
      }

    }
  }
}

Alternativly you can add an include there to your TypoScript file in your extension Configuration/TypoScript folder.

If you are in CLI Context, it can be that the TypoScript is not loaded fully for the mapping/extbase configuration, which would match your description that in the BE Context it works, but not in Cronjob/CLI Context.

Stefan Bürk
  • 524
  • 4
  • 8
  • I have this configuration in the ext_typoscript_setup.typoscript. I try it with the include... – Paul Jun 01 '21 at 20:25