[TYPO3-english] Typo3 6.2 extbase repository object cloning not saving records properly

Arun Chandran arunchandran2010 at gmail.com
Mon Oct 12 15:30:24 CEST 2015


Hi Guys,

I've an event creating extension which contains an option to create events
for the users. This is implemented using extbase repository method. In the
event creation form I've a start date, end date and weekdays which the
events should be repeated.

For example if I set start date as 13-10-2015 and end date as 30-10-2015.
And selected the weekday as "Wednesday".So the event will repeated in all
"Wednesdays" between 13 and 30.

When I create a non-repeated event, it will work properly. But for the
recurring event, I've implemented the cloning method of extbase repository.

*if (!empty($endDateRecurring) && !empty($recurringWeekDays)) {
            $endDate = new \DateTime($endDateRecurring);
            $startDate = $newEvent->getDate();
            $startDate->setTime(0, 0);
            $datetimeDiff = $startDate->diff($endDate);

            for ( $event=1; $event <= $datetimeDiff->days; $event++ ) {
                $checkDate = $newEvent->getDate()->add(new
\DateInterval('P'.$event.'D'));
                $dayOfWeekNo = date('w',$checkDate->getTimestamp());

                if ( in_array( $dayOfWeekNo, $recurringWeekDays ) ) {

                    $eventProperties =
\TYPO3\CMS\Extbase\Reflection\ObjectAccess::getGettableProperties(
$newEvent );

\TYPO3\CMS\Extbase\Reflection\ObjectAccess::setProperty( $eventProperties,
'date', $eventProperties['date']->add(new \DateInterval('P1D') ) );

                    $eventCopy =
$this->objectManager->create('\TYPO3\EventCreate\Domain\Model\Event');

                    foreach ( $eventProperties as $propertyName =>
$propertyValue ) {
                        if
(\TYPO3\CMS\Extbase\Reflection\ObjectAccess::isPropertySettable($eventCopy,
                            $propertyName) && !in_array($propertyName,
array('uid','pid'))) {
                                $propertyValue =
\TYPO3\CMS\Extbase\Reflection\ObjectAccess::getProperty( $newEvent,
$propertyName );

\TYPO3\CMS\Extbase\Reflection\ObjectAccess::setProperty( $eventCopy,
$propertyName, $propertyValue );
                            }
                    }
                    //TODO: cloning doesn't work because the id is already
set and it thus doesn't add a new object to the repository.
                    //either create a new object and copy all content
properties, or find another way to add more events to the db for recurring
days.
                    $this->eventRepository->add($eventCopy);

$this->objectManger->get('Tx_Extbase_Persistence_Manager')->persistAll();
                }
            }
        }*

Here $recurringWeekDays is an array which contains selected repeated
weekday id ( For Monday-1, Tuesday-2 like this ).

Issue is when there is any number of days to be inserted, then only one
record inserted to the database. In the above example 3 Wednesdays between
13th and 30th October. But only one record inserted.

If anybody knows the solution, please help.

Thanks,
Arun Chandran


More information about the TYPO3-english mailing list