Search code examples
phptypo3typo3-6.2.xtypo3-7.6.x

typo3 createAction of a backend extension does not persist data


I'm in a migration process from typo3 6.2.31 to 7.6.23

I have the following function:

public function createAction(\TYPO3\Institutsvideoverwaltung\Domain\Model\Category $newCategory) {
    $contentCat = $this->request->getArgument('newCategory');
    if ($contentCat['isRoot'] == '1') {
        $this->categoryRepository->add($newCategory);
        $this->addFlashMessage($newCategory->getName(), 'Kategorie erfolgreich angelegt!', \TYPO3\CMS\Core\Messaging\AbstractMessage::OK);
    } else {
        if (!empty($_POST['tx_institutsvideoverwaltung_auditgarant_institutsvideoverwaltungvideoverwaltungbackend']['catAllocationUIDs'])) {
            $catAllocationUIDs = $this->request->getArgument('catAllocationUIDs');
            foreach ($catAllocationUIDs as $catAllocationUID) {
                $category = $this->categoryRepository->findByUid($catAllocationUID);
                $category->addChildCategory($newCategory);
                $this->categoryRepository->update($category);
            }
            $this->addFlashMessage($newCategory->getName(), 'Kategorie erfolgreich angelegt!', \TYPO3\CMS\Core\Messaging\AbstractMessage::OK);
        } else {
            $this->addFlashMessage('Das Objekt wurde nicht angelegt, da keine Zuordnung erfolgt ist. Wenn es sich um kein Wurzelelement handelt, nehmen Sie zumindest eine Zuordnung vor.', '', \TYPO3\CMS\Core\Messaging\AbstractMessage::ERROR);
        }
    }
    /*  }*/
    $this->redirect('list');
}

It says all works fine, but it does not persist data. What could be the problem?

When I add manually a record to databse it is not shown as well :(

Update Out Var_dump enter image description here


Solution

  • After some TeamViewer investigations we found the problem located in the the Model and in the TCA.

    The Model had the attribute protected $uid = '' . Of course the UID cannot be a string and should not be declared as this. However, the debug in the createAction said the object is a "persisted entity" and so the Persistence Manager thought there is nothing to do. After removing the $uid from the model and updating to TCA to become 7 LTS compatible, the problem was solved.

    I guess its not a problem to declare the $uid as an integer in the model but as a string it was just too much for the system. Amazing that this worked in TYPO3 6 LTS...