public function markNotDuplicateWithMetaData(EventModel $notDuplicateEvent, EventEditMetaDataModel $eventEditMetaDataModel) { global $DB; $notDuplicateEvent->setIsDuplicateOfId(null); $this->eventDBAccess->update($notDuplicateEvent, array('is_duplicate_of_id'), $eventEditMetaDataModel); }
public function markDuplicateWithMetaData(AreaModel $duplicateArea, AreaModel $originalArea, AreaEditMetaDataModel $areaEditMetaDataModel) { global $DB; if ($duplicateArea->getId() == $originalArea->getId()) { return; } try { $DB->beginTransaction(); $duplicateArea->setIsDuplicateOfId($originalArea->getId()); $duplicateArea->setIsDeleted(true); $this->areaDBAccess->update($duplicateArea, array('is_duplicate_of_id', 'is_deleted'), $areaEditMetaDataModel); // Move Venues $venueDBAccess = new VenueDBAccess($DB, new \TimeSource()); $vrb = new VenueRepositoryBuilder(); $vrb->setArea($duplicateArea); $venueEditMetaData = new VenueEditMetaDataModel(); $venueEditMetaData->setUserAccount($areaEditMetaDataModel->getUserAccount()); foreach ($vrb->fetchAll() as $venue) { $venue->setAreaId($originalArea->getId()); $venueDBAccess->update($venue, array('area_id'), $venueEditMetaData); } // Move Events $eventRepoBuilder = new EventRepositoryBuilder(); $eventRepoBuilder->setArea($duplicateArea); $eventDBAccess = new EventDBAccess($DB, new \TimeSource()); $eventEditMetaData = new EventEditMetaDataModel(); $eventEditMetaData->setUserAccount($areaEditMetaDataModel->getUserAccount()); foreach ($eventRepoBuilder->fetchAll() as $event) { // Check Area actually matches here because we may get events at a venue. // Based on the order we do things in (ie Move Venue, Move Event) we shouldn't but let's be safe. if ($event->getAreaId() == $duplicateArea->getId() && $event->getVenueId() == null) { $event->setAreaId($originalArea->getId()); $eventDBAccess->update($event, array('area_id'), $eventEditMetaData); } } // Move Child Areas $areaRepoBuilder = new AreaRepositoryBuilder(); $areaRepoBuilder->setParentArea($duplicateArea); $areaRepoBuilder->setIncludeParentLevels(0); $flag = false; foreach ($areaRepoBuilder->fetchAll() as $area) { // lets just double check we haven't got any child areas. if ($area->getParentAreaId() == $duplicateArea->getId()) { $area->setParentAreaId($originalArea->getId()); $this->areaDBAccess->update($area, array('parent_area_id'), $areaEditMetaDataModel); $flag = true; } } if ($flag) { // now must clear caches $this->deleteParentCacheForArea($originalArea); $this->deleteParentCacheForArea($duplicateArea); } $DB->commit(); } catch (Exception $e) { $DB->rollBack(); } }
public function markDuplicateWithMetaData(VenueModel $duplicateVenue, VenueModel $originalVenue, VenueEditMetaDataModel $venueEditMetaDataModel) { global $DB; if ($duplicateVenue->getId() == $originalVenue->getId()) { return; } try { $DB->beginTransaction(); $duplicateVenue->setIsDeleted(true); $duplicateVenue->setIsDuplicateOfId($originalVenue->getId()); $this->venueDBAccess->update($duplicateVenue, array('is_deleted', 'is_duplicate_of_id'), $venueEditMetaDataModel); // Move any Events $eventEditMetaData = new EventEditMetaDataModel(); $eventEditMetaData->setUserAccount($venueEditMetaDataModel->getUserAccount()); $eventRepoBuilder = new EventRepositoryBuilder(); $eventRepoBuilder->setVenue($duplicateVenue); $eventDBAccess = new EventDBAccess($DB, new \TimeSource()); foreach ($eventRepoBuilder->fetchAll() as $event) { $event->setVenueId($originalVenue->getId()); $eventDBAccess->update($event, array('venue_id'), $eventEditMetaData); } $DB->commit(); } catch (Exception $e) { $DB->rollBack(); } }