why are two records getting added to the database when I only call my typo3 repository->add method once?

StackOverflow https://stackoverflow.com/questions/22360177

  •  13-06-2023
  •  | 
  •  

Question

here is the code that runs and that results in two sentmessage objects getting added to the table:

        $sentmessage = null;
    //add entry into sent message table          Tx_BpsMessagecentre_Domain_Model_Sentmessage
    $sentmessage = $this->objectManager->create('Tx_BpsMessagecentre_Domain_Model_Sentmessage');
        //now just fill in the object 
    $sentmessage->setBpsmessageid($bPSMessage->getUid());
    $sentmessage->setBody($bPSMessage->getBody());
    $sentmessage->setSubject($bPSMessage->getSubject());
    $sentmessage->setCouponlist($bPSMessage->getCouponlist());
    $sentmessage->setHallname($bPSMessage->getHall()->getHall());
    $sentmessage->setHalladdress($bPSMessage->getHall()->getAddress());
    $sentmessage->setHallurl($bPSMessage->getHall()->getUrl());
    $sentmessage->setBanner($bPSMessage->getBanner());

    $this->sentmessageRepository->add($sentmessage);
        $this->objectManager->get('Tx_Extbase_Persistence_Manager')->persistAll();
    die; //if I take out this die and the persist call above I still get two records added

I am using typo3 v 4.5.32 with extbase 1.3. The sentmessage object is one I had to create manually - ie without extension builder, so there might be some misconfiguration in the TCA somewhere but I have no idea what would cause this.

Thanks

PS: a piece of my ext_localconf.php showing some of my plugins

Tx_Extbase_Utility_Extension::configurePlugin(
    $_EXTKEY,
    'Bpsmonthly',
    array(
        'BPSMessage' => 'cronMonthlys'      
    ),
    // non-cacheable actions
    array(
        'BPSMessage' => 'create, update, delete',
    )

);

Tx_Extbase_Utility_Extension::configurePlugin(
    $_EXTKEY,
    'Bpsbirthdays',
    array(
        'BPSMessage' => 'cronBirthdays'         
    ),
    // non-cacheable actions
    array(
        'BPSMessage' => 'create, update, delete',
    )

);

Tx_Extbase_Utility_Extension::configurePlugin(
    $_EXTKEY,
    'BpsAnnuals',
    array(
        'BPSMessage' => 'cronAnnuals'       
    ),
    // non-cacheable actions
    array(
        'BPSMessage' => 'create, update, delete',
    )

);
Was it helpful?

Solution

Ok, found the bug, it was actually caused by my debug code that spit some url out to the page, the url got resolved by the browser to hit the action again (probably a url in an img tag) and boom. so the bug only exists while debugging. I love programming. Is there a way to delete my dumbest questions from stackoverflow?

OTHER TIPS

most probably you have the two plugins from the same extension in your website - therefore everything is processed twice.

Maybe persisting your changes takes a loooooong time (e.g., >30 sec). In such cases, I experienced that under some conditions the browser posts again (!) the query, resulting in what you describe.

As I experienced the same behaviour, but under other circumstances, I'm adding my case as an answer here, maybe it helps someone.

If you're working with multiple records in the same form (model having child records) and they all are not persisted, make sure to not set the parent record on the child records.

This will lead to the multiple-rows behaviour:

$foo = ObjectManager->get('Foo\\Bar\\Domain\\Model\\Foo');
$bar = ObjectManager->get('Foo\\Bar\\Domain\\Model\\Bar');
$bar->setFoo($foo); // <-- Should not be done
$foo->add($bar);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top