public function markDuplicateWithMetaData(GroupModel $duplicateGroup, GroupModel $originalGroup, GroupEditMetaDataModel $groupEditMetaDataModel) { global $DB; if ($duplicateGroup->getId() == $originalGroup->getId()) { return; } try { $DB->beginTransaction(); $duplicateGroup->setIsDeleted(true); $duplicateGroup->setIsDuplicateOfId($originalGroup->getId()); $this->groupDBAccess->update($duplicateGroup, array('is_deleted', 'is_duplicate_of_id'), $groupEditMetaDataModel); // Users Watching Group $ufgr = new UserWatchesGroupRepository(); $usersRepo = new UserAccountRepositoryBuilder(); $usersRepo->setWatchesGroup($duplicateGroup); foreach ($usersRepo->fetchAll() as $user) { $ufgr->startUserWatchingGroupIfNotWatchedBefore($user, $originalGroup); } // Events in Group $statCheck = $DB->prepare("SELECT * FROM event_in_group WHERE group_id=:group_id AND " . " event_id=:event_id AND removed_at IS NULL "); $statAdd = $DB->prepare("INSERT INTO event_in_group (group_id,event_id,added_by_user_account_id,added_at,addition_approved_at,is_main_group) " . "VALUES (:group_id,:event_id,:added_by_user_account_id,:added_at,:addition_approved_at,:is_main_group)"); $erb = new EventRepositoryBuilder(); $erb->setGroup($duplicateGroup); foreach ($erb->fetchAll() as $event) { // check event not already in list $statCheck->execute(array('group_id' => $originalGroup->getId(), 'event_id' => $event->getId())); if ($statCheck->rowCount() == 0) { // TODO is_main_group ?????????????????? $statAdd->execute(array('group_id' => $originalGroup->getId(), 'event_id' => $event->getId(), 'is_main_group' => 0, 'added_by_user_account_id' => $user ? $user->getId() : null, 'added_at' => \TimeSource::getFormattedForDataBase(), 'addition_approved_at' => \TimeSource::getFormattedForDataBase())); } } $DB->commit(); } catch (Exception $e) { $DB->rollBack(); } }