1
votes

I want to develop an extension for TYPO3 6.2.

In the controller class I created a action called "fetchFeUsersAction". This action loads a set of data from the table fe_users in the table which was created from the extensionbuilder from the model.

The function to the get the users in the Repository looks like this:

    public function getFeUsers()
{
    /** @var Query $q */
    $q = $this->createQuery();
    $q->statement('SELECT * from fe_users');
    $data = $q->execute(true);

    return $data;
}

This works very fine.

But now I want to store the results from the table fe_users in my model with this action:

public function fetchFeUsersAction()
{
    $data = $this->adressRepo->getFeUsers();
    foreach ($data as $feuser) {
        /** @var Adresse $address */
        $address = $this->objectManager->get(Adresse::class);

        $q= $this->adressRepo->createQuery();
        $q->matching(contains('email', $feuser['email']));
        $contain= $q->execute();

        if($contain==NULL){
        $address->setEmail($feuser['email']);
        $this->adressRepo->add($address);
    }

    }
    $this->redirect('list');
}

Here I want to check if the email adress is already stored in my table. If the email adress is not stored it should be added to the model. But it doesnt work. Even with an empty table. Without the condition it works very fine.

1

1 Answers

3
votes

Extbase persists the complete data into the DB later. You need to persist manually i think, like this:

/** @var \TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager */
$persistenceManager = GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager::class);
$persistenceManager->persistAll();

Not currently tested, just copied it from my of my extensions. but in there i had the same problem to check if it exists.

Hope this helps a little bit.