Made Offers a bit more robust and operation atomic
This commit is contained in:
parent
af506435ac
commit
2da8da6b37
@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
use Joomla\CMS\Factory;
|
||||
|
||||
// No direct access.
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
@ -162,22 +164,35 @@ class CommonClubsModelClub extends AbstractCommonClubsModel
|
||||
$offerAssocFactory = new CommonClubsModelFactoryOfferassoc();
|
||||
$offerFactory = new CommonClubsModelFactoryOffer();
|
||||
|
||||
foreach($delIds as $id)
|
||||
$db = Factory::getDbo();
|
||||
$db->transactionStart(true);
|
||||
|
||||
try
|
||||
{
|
||||
$delId = (int) $id;
|
||||
$delObjs = $offerAssocFactory->loadElements("clubid = {$this->getId()} AND offerid = $delId");
|
||||
foreach($delObjs as $o)
|
||||
$o->delete();
|
||||
foreach($delIds as $id)
|
||||
{
|
||||
$delId = (int) $id;
|
||||
$delObjs = $offerAssocFactory->loadElements("clubid = {$this->getId()} AND offerid = $delId");
|
||||
foreach($delObjs as $o)
|
||||
$o->delete();
|
||||
}
|
||||
|
||||
foreach($newIds as $id)
|
||||
{
|
||||
$newId = (int) $id;
|
||||
$o = $offerAssocFactory->createNew();
|
||||
$o->setOffer($offerFactory->loadById($newId));
|
||||
$o->setClub($this);
|
||||
$o->save();
|
||||
}
|
||||
}
|
||||
catch (Exception $ex)
|
||||
{
|
||||
$db->transactionRollback(true);
|
||||
throw $ex;
|
||||
}
|
||||
|
||||
foreach($newIds as $id)
|
||||
{
|
||||
$newId = (int) $id;
|
||||
$o = $offerAssocFactory->createNew();
|
||||
$o->setOffer($offerFactory->loadById($newId));
|
||||
$o->setClub($this);
|
||||
$o->save();
|
||||
}
|
||||
$db->transactionCommit(true);
|
||||
}
|
||||
|
||||
public function getUsers()
|
||||
|
@ -349,8 +349,14 @@ class ClubsHelperControllerClub extends AbstractClubsHelperController
|
||||
|
||||
// TODO ACL needed
|
||||
|
||||
$this->club->setOfferIds($ids);
|
||||
$this->club->save();
|
||||
try
|
||||
{
|
||||
$this->club->setOfferIds($ids);
|
||||
}
|
||||
catch(ElementNotFoundException $ex)
|
||||
{
|
||||
throw new InvalidUserDataException('Es gab ein Problem mit der Eingabe. Bitte Seite neu laden und Daten erneut eintragen.');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user