[TYPO3-mvc] prevent extbase from updating my records
Stefan Frömken
firma at sfroemken.de
Wed Mar 14 16:43:12 CET 2012
Am 14.03.2012 16:01, schrieb Stefan Frömken:
> Am 14.03.2012 14:49, schrieb Stefan Frömken:
>> Am 14.03.2012 14:39, schrieb Stefan Frömken:
>>> Hello MVC-List,
>>>
>>> I have to group some objects and numeric properties have to be summed
>>> up. But when I execute a setter of my object, this record gets updated
>>> in my database! How to prevent extbase from updating my database? This
>>> new value is only for fluid and extbase internally calculations, but
>>> never for the DB!
>>>
>>> Stefan
>>
>> hmmm...maybe "clone" is my solution. Let's try it.
> clone don't works. max_execution_time of 120 seconds exceeded.
> Maybe creation of a new model of the same type works better.
OK...creation of a new model works, but there was also a problem in my
foreach-loop which results in max_execution_time exceeded.
I have created a little method to create a copy of my models:
THX Stefan
/**
* make a copy of a domain model object
*
* @param Tx_Extbase_DomainObject_DomainObjectInterface $object The
object to copy
* @return Tx_Extbase_DomainObject_DomainObjectInterface The copied object
*/
public function
makeCopyOfModelObject(Tx_Extbase_DomainObject_DomainObjectInterface
$object) {
// the object must be an instance of DomainModels
if(!$object instanceof Tx_Extbase_DomainObject_AbstractEntity) return
$object;
// get type of model
$type = get_class($object);
// create an empty model class
$model = $this->objectManager->get($type);
// get an array with all getable properties and their values
$properties =
Tx_Extbase_Reflection_ObjectAccess::getGettableProperties($object);
// set the retrieved values to our new model
// TODO: Maybe someone has a better possibility how to copy objects
into another object
foreach($properties as $property => $value) {
if(Tx_Extbase_Reflection_ObjectAccess::isPropertySettable($model,
$property)) {
Tx_Extbase_Reflection_ObjectAccess::setProperty($model, $property,
$value);
}
}
return $model;
}
More information about the TYPO3-project-typo3v4mvc
mailing list