function testSetChangedFlagsFromLast1()
 {
     $lastHistory = new VenueHistoryModel();
     $lastHistory->setFromDataBaseRow(array('venue_id' => 1, 'title' => 'New Venue', 'description' => '', 'lat' => 3.5, 'lng' => 3.5, 'country_id' => 88, 'area_id' => 4, 'user_account_id' => 1, 'created_at' => '2014-02-01 10:00:00', 'is_deleted' => 0, 'is_duplicate_of_id' => null, 'address' => '', 'address_code' => '', 'title_changed' => 0, 'description_changed' => 0, 'country_id_changed' => 0, 'area_id_changed' => 0, 'lng_changed' => 0, 'lat_changed' => 0, 'area_id_changed' => 0, 'is_deleted_changed' => 0, 'address_changed' => 0, 'address_code_changed' => 0));
     $venueHistory = new VenueHistoryModel();
     $venueHistory->setFromDataBaseRow(array('venue_id' => 1, 'title' => 'New Venue', 'description' => 'cat dog', 'lat' => 4.5, 'lng' => 3.5, 'country_id' => 88, 'area_id' => 4, 'user_account_id' => 1, 'created_at' => '2014-02-01 10:00:00', 'is_deleted' => 0, 'is_duplicate_of_id' => null, 'address' => '', 'address_code' => '', 'title_changed' => 0, 'description_changed' => 0, 'country_id_changed' => 0, 'area_id_changed' => 0, 'lng_changed' => 0, 'lat_changed' => 0, 'area_id_changed' => 0, 'is_deleted_changed' => 0, 'address_changed' => 0, 'address_code_changed' => 0));
     $venueHistory->setChangedFlagsFromLast($lastHistory);
     $this->assertEquals(false, $venueHistory->getTitleChanged());
     $this->assertEquals(true, $venueHistory->getDescriptionChanged());
     $this->assertEquals(false, $venueHistory->getCountryIdChanged());
     $this->assertEquals(false, $venueHistory->getIsDeletedChanged());
     $this->assertEquals(true, $venueHistory->getLatChanged());
     $this->assertEquals(false, $venueHistory->getLngChanged());
     $this->assertEquals(false, $venueHistory->getIsNew());
 }
 public function getSummary()
 {
     $txt = '';
     if ($this->venueHistoryModel->getIsNew()) {
         $txt .= 'New! ' . "\n";
     }
     if ($this->venueHistoryModel->isAnyChangeFlagsUnknown()) {
         $txt .= $this->venueHistoryModel->getDescription();
     } else {
         if ($this->venueHistoryModel->getTitleChanged()) {
             $txt .= 'Title Changed. ' . "\n";
         }
         if ($this->venueHistoryModel->getDescriptionChanged()) {
             $txt .= 'Description Changed. ' . "\n";
         }
         if ($this->venueHistoryModel->getAddressChanged()) {
             $txt .= 'Address Changed. ' . "\n";
         }
         if ($this->venueHistoryModel->getAddressCodeChanged()) {
             $txt .= 'Address Code Changed. ' . "\n";
         }
         if ($this->venueHistoryModel->getLatChanged() || $this->venueHistoryModel->getLngChanged()) {
             $txt .= 'Position on Map Changed. ' . "\n";
         }
         if ($this->venueHistoryModel->getAreaIdChanged()) {
             $txt .= 'Area Changed. ' . "\n";
         }
         if ($this->venueHistoryModel->getCountryIdChanged()) {
             $txt .= 'Country Changed. ' . "\n";
         }
         if ($this->venueHistoryModel->getIsDeletedChanged()) {
             $txt .= 'Deleted Changed: ' . ($this->venueHistoryModel->getIsDeleted() ? "Deleted" : "Restored") . "\n\n";
         }
     }
     return $txt;
 }
 function testIntegration2()
 {
     $this->addCountriesToTestDB();
     \TimeSource::mock(2014, 1, 1, 12, 0, 0);
     $user = new UserAccountModel();
     $user->setEmail("*****@*****.**");
     $user->setUsername("test");
     $user->setPassword("password");
     $userRepo = new UserAccountRepository();
     $userRepo->create($user);
     $site = new SiteModel();
     $site->setTitle("Test");
     $site->setSlug("test");
     $siteRepo = new SiteRepository();
     $siteRepo->create($site, $user, array(), $this->getSiteQuotaUsedForTesting());
     $countryRepo = new CountryRepository();
     $gb = $countryRepo->loadByTwoCharCode('GB');
     ## Create venue
     \TimeSource::mock(2014, 1, 1, 13, 0, 0);
     $venue = new VenueModel();
     $venue->setTitle("test");
     $venue->setDescription("test test");
     $venue->setCountryId($gb->getId());
     $venueRepo = new VenueRepository();
     $venueRepo->create($venue, $site, $user);
     ## Edit venue
     \TimeSource::mock(2014, 1, 1, 14, 0, 0);
     $venue = $venueRepo->loadById($venue->getId());
     $venue->setDescription("testy");
     $venue->setLat(3.6);
     $venue->setLng(3.7);
     $venueRepo->edit($venue, $user);
     ## Delete venue
     \TimeSource::mock(2014, 1, 1, 15, 0, 0);
     $venueRepo->delete($venue, $user);
     ## Now save changed flags on these .....
     $venueHistoryRepo = new VenueHistoryRepository();
     $stat = $this->app['db']->prepare("SELECT * FROM venue_history");
     $stat->execute();
     while ($data = $stat->fetch()) {
         $venueHistory = new VenueHistoryModel();
         $venueHistory->setFromDataBaseRow($data);
         $venueHistoryRepo->ensureChangedFlagsAreSet($venueHistory);
     }
     ## Now load and check
     $historyRepo = new HistoryRepositoryBuilder();
     $historyRepo->setVenue($venue);
     $historyRepo->setIncludeEventHistory(false);
     $historyRepo->setIncludeGroupHistory(false);
     $historyRepo->setIncludeVenueHistory(true);
     $histories = $historyRepo->fetchAll();
     $this->assertEquals(3, count($histories));
     #the delete
     $this->assertEquals(FALSE, $histories[0]->getTitleChanged());
     $this->assertEquals(false, $histories[0]->getDescriptionChanged());
     $this->assertEquals(false, $histories[0]->getCountryIdChanged());
     $this->assertEquals(true, $histories[0]->getIsDeletedChanged());
     $this->assertEquals(false, $histories[0]->getLatChanged());
     $this->assertEquals(false, $histories[0]->getLngChanged());
     #the edit
     $this->assertEquals(FALSE, $histories[1]->getTitleChanged());
     $this->assertEquals(true, $histories[1]->getDescriptionChanged());
     $this->assertEquals(false, $histories[1]->getCountryIdChanged());
     $this->assertEquals(false, $histories[1]->getIsDeletedChanged());
     $this->assertEquals(true, $histories[1]->getLatChanged());
     $this->assertEquals(true, $histories[1]->getLngChanged());
     #the create
     $this->assertEquals(true, $histories[2]->getTitleChanged());
     $this->assertEquals(true, $histories[2]->getDescriptionChanged());
     $this->assertEquals(true, $histories[2]->getCountryIdChanged());
     $this->assertEquals(false, $histories[2]->getIsDeletedChanged());
     $this->assertEquals(false, $histories[2]->getLatChanged());
     $this->assertEquals(false, $histories[2]->getLngChanged());
 }
 public function fetchAll()
 {
     global $DB, $app;
     $results = array();
     /////////////////////////// Events History
     if ($this->historyRepositoryBuilderConfig->getIncludeEventHistory()) {
         $where = array();
         $joins = array();
         $params = array();
         if ($this->historyRepositoryBuilderConfig->getEvent()) {
             $where[] = 'event_information.id=:event';
             $params['event'] = $this->historyRepositoryBuilderConfig->getEvent()->getId();
         }
         if ($this->historyRepositoryBuilderConfig->getGroup()) {
             // We use a seperate table here so if event is in 2 groups and we select events in 1 group that isn't the main group only,
             // the normal event_in_group table still shows the main group.
             $joins[] = " JOIN event_in_group AS event_in_group_select ON event_in_group_select.event_id = event_information.id " . "AND event_in_group_select.removed_at IS NULL AND event_in_group_select.group_id = :group_id ";
             $params['group_id'] = $this->historyRepositoryBuilderConfig->getGroup()->getId();
         }
         if ($this->historyRepositoryBuilderConfig->getSite()) {
             $where[] = 'event_information.site_id =:site';
             $params['site'] = $this->historyRepositoryBuilderConfig->getSite()->getId();
         }
         if ($this->historyRepositoryBuilderConfig->getVenue()) {
             $where[] = 'event_information.venue_id = :venue';
             $params['venue'] = $this->historyRepositoryBuilderConfig->getVenue()->getId();
         }
         if ($this->historyRepositoryBuilderConfig->getSince()) {
             $where[] = ' event_history.created_at >= :since ';
             $params['since'] = $this->historyRepositoryBuilderConfig->getSince()->format("Y-m-d H:i:s");
         }
         if ($this->historyRepositoryBuilderConfig->getNotUser()) {
             $where[] = 'event_history.user_account_id != :userid ';
             $params['userid'] = $this->historyRepositoryBuilderConfig->getNotUser()->getId();
         }
         if ($this->historyRepositoryBuilderConfig->getApi2app()) {
             $where[] = 'event_history.api2_application_id  = :api2app';
             $params['api2app'] = $this->historyRepositoryBuilderConfig->getApi2app()->getId();
         }
         if ($this->historyRepositoryBuilderConfig->getArea()) {
             $areaids = array($this->historyRepositoryBuilderConfig->getArea()->getId());
             $this->statAreas = $DB->prepare("SELECT area_id FROM cached_area_has_parent WHERE has_parent_area_id=:id");
             $this->statAreas->execute(array('id' => $this->historyRepositoryBuilderConfig->getArea()->getId()));
             while ($d = $this->statAreas->fetch()) {
                 $areaids[] = $d['area_id'];
             }
             $joins[] = " LEFT JOIN venue_information ON  event_information.venue_id = venue_information.id ";
             $where[] = ' (event_information.area_id IN (' . implode(",", $areaids) . ')  OR venue_information.area_id IN (' . implode(",", $areaids) . ') ) ';
         }
         if ($this->historyRepositoryBuilderConfig->getVenueVirtualOnly()) {
             // we check both on an OR, that way we get both
             // a) events that were not virtual and became virtual, we get their full history
             // b) events that were virtual and now aren't, we get some of their history
             $where[] = " ( event_information.is_virtual = '1' OR event_history.is_virtual = '1' )";
         }
         $sql = "SELECT event_history.*, group_information.title AS group_title,  group_information.id AS group_id,  event_information.slug AS event_slug, user_account_information.username AS user_account_username FROM event_history " . " LEFT JOIN user_account_information ON user_account_information.id = event_history.user_account_id " . " LEFT JOIN event_information ON event_information.id = event_history.event_id " . " LEFT JOIN event_in_group ON event_in_group.event_id = event_information.id AND event_in_group.removed_at IS NULL AND event_in_group.is_main_group = '1' " . " LEFT JOIN group_information ON group_information.id = event_in_group.group_id " . implode(" ", $joins) . ($where ? " WHERE " . implode(" AND ", $where) : "") . " ORDER BY event_history.created_at DESC LIMIT " . $this->historyRepositoryBuilderConfig->getLimit();
         //var_dump($sql); var_dump($params);
         $stat = $DB->prepare($sql);
         $stat->execute($params);
         while ($data = $stat->fetch()) {
             $eventHistory = new EventHistoryModel();
             $eventHistory->setFromDataBaseRow($data);
             $results[] = $eventHistory;
         }
     }
     /////////////////////////// Group History
     if ($this->historyRepositoryBuilderConfig->getIncludeGroupHistory()) {
         $where = array();
         $params = array();
         if ($this->historyRepositoryBuilderConfig->getEvent() && $this->historyRepositoryBuilderConfig->getEvent()->getGroupId()) {
             $where[] = 'group_information.id=:group';
             $params['group'] = $this->historyRepositoryBuilderConfig->getEvent()->getGroupId();
         } else {
             if ($this->historyRepositoryBuilderConfig->getGroup()) {
                 $where[] = 'group_information.id =:group';
                 $params['group'] = $this->historyRepositoryBuilderConfig->getGroup()->getId();
             }
         }
         if ($this->historyRepositoryBuilderConfig->getSite()) {
             $where[] = 'group_information.site_id =:site';
             $params['site'] = $this->historyRepositoryBuilderConfig->getSite()->getId();
         }
         if ($this->historyRepositoryBuilderConfig->getSince()) {
             $where[] = ' group_history.created_at >= :since ';
             $params['since'] = $this->historyRepositoryBuilderConfig->getSince()->format("Y-m-d H:i:s");
         }
         if ($this->historyRepositoryBuilderConfig->getNotUser()) {
             $where[] = 'group_history.user_account_id != :userid ';
             $params['userid'] = $this->historyRepositoryBuilderConfig->getNotUser()->getId();
         }
         if ($this->historyRepositoryBuilderConfig->getApi2app()) {
             $where[] = 'group_history.api2_application_id  = :api2app';
             $params['api2app'] = $this->historyRepositoryBuilderConfig->getApi2app()->getId();
         }
         $sql = "SELECT group_history.*, group_information.slug AS group_slug, user_account_information.username AS user_account_username FROM group_history " . " LEFT JOIN user_account_information ON user_account_information.id = group_history.user_account_id " . " LEFT JOIN group_information ON group_information.id = group_history.group_id " . ($where ? " WHERE " . implode(" AND ", $where) : "") . " ORDER BY group_history.created_at DESC LIMIT " . $this->historyRepositoryBuilderConfig->getLimit();
         //var_dump($sql); var_dump($params);
         $stat = $DB->prepare($sql);
         $stat->execute($params);
         while ($data = $stat->fetch()) {
             $groupHistory = new GroupHistoryModel();
             $groupHistory->setFromDataBaseRow($data);
             $results[] = $groupHistory;
         }
     }
     /////////////////////////// Venue History
     if ($this->historyRepositoryBuilderConfig->getIncludeVenueHistory()) {
         $where = array();
         $params = array();
         if ($this->historyRepositoryBuilderConfig->getEvent() && $this->historyRepositoryBuilderConfig->getEvent()->getVenueId()) {
             $where[] = 'venue_information.id=:venue';
             $params['venue'] = $this->historyRepositoryBuilderConfig->getEvent()->getVenueId();
         } else {
             if ($this->historyRepositoryBuilderConfig->getVenue()) {
                 $where[] = 'venue_information.id=:venue';
                 $params['venue'] = $this->historyRepositoryBuilderConfig->getVenue()->getId();
             }
         }
         if ($this->historyRepositoryBuilderConfig->getSite()) {
             $where[] = 'venue_information.site_id =:site';
             $params['site'] = $this->historyRepositoryBuilderConfig->getSite()->getId();
         }
         if ($this->historyRepositoryBuilderConfig->getSince()) {
             $where[] = ' venue_history.created_at >= :since ';
             $params['since'] = $this->historyRepositoryBuilderConfig->getSince()->format("Y-m-d H:i:s");
         }
         if ($this->historyRepositoryBuilderConfig->getNotUser()) {
             $where[] = 'venue_history.user_account_id != :userid ';
             $params['userid'] = $this->historyRepositoryBuilderConfig->getNotUser()->getId();
         }
         if ($this->historyRepositoryBuilderConfig->getApi2app()) {
             $where[] = 'venue_history.api2_application_id  = :api2app';
             $params['api2app'] = $this->historyRepositoryBuilderConfig->getApi2app()->getId();
         }
         $sql = "SELECT venue_history.*, venue_information.slug AS venue_slug, user_account_information.username AS user_account_username FROM venue_history " . " LEFT JOIN user_account_information ON user_account_information.id = venue_history.user_account_id " . " LEFT JOIN venue_information ON venue_information.id = venue_history.venue_id " . ($where ? " WHERE " . implode(" AND ", $where) : "") . " ORDER BY venue_history.created_at DESC LIMIT " . $this->historyRepositoryBuilderConfig->getLimit();
         //var_dump($sql); var_dump($params);
         $stat = $DB->prepare($sql);
         $stat->execute($params);
         while ($data = $stat->fetch()) {
             $venueHistory = new VenueHistoryModel();
             $venueHistory->setFromDataBaseRow($data);
             $results[] = $venueHistory;
         }
     }
     /////////////////////////// Area History
     if ($this->historyRepositoryBuilderConfig->getIncludeAreaHistory()) {
         $where = array();
         $params = array();
         $joins = array();
         if ($this->historyRepositoryBuilderConfig->getArea()) {
             // Will this produce dupes? No evidence so far but there was a note in EventRepositoryBuilder that said so.
             $joins[] = " LEFT JOIN cached_area_has_parent ON cached_area_has_parent.area_id = area_information.id ";
             $where[] = ' (area_information.id =:area OR cached_area_has_parent.has_parent_area_id =:area )';
             $params['area'] = $this->historyRepositoryBuilderConfig->getArea()->getId();
         }
         if ($this->historyRepositoryBuilderConfig->getSite()) {
             $where[] = 'area_information.site_id =:site';
             $params['site'] = $this->historyRepositoryBuilderConfig->getSite()->getId();
         }
         if ($this->historyRepositoryBuilderConfig->getSince()) {
             $where[] = ' area_history.created_at >= :since ';
             $params['since'] = $this->historyRepositoryBuilderConfig->getSince()->format("Y-m-d H:i:s");
         }
         if ($this->historyRepositoryBuilderConfig->getNotUser()) {
             $where[] = 'area_history.user_account_id != :userid ';
             $params['userid'] = $this->historyRepositoryBuilderConfig->getNotUser()->getId();
         }
         if ($this->historyRepositoryBuilderConfig->getApi2app()) {
             $where[] = 'area_history.api2_application_id  = :api2app';
             $params['api2app'] = $this->historyRepositoryBuilderConfig->getApi2app()->getId();
         }
         $sql = "SELECT area_history.*, area_information.slug AS area_slug, user_account_information.username AS user_account_username FROM area_history " . " LEFT JOIN user_account_information ON user_account_information.id = area_history.user_account_id " . " LEFT JOIN area_information ON area_information.id = area_history.area_id " . implode(" ", $joins) . ($where ? " WHERE " . implode(" AND ", $where) : "") . " ORDER BY area_history.created_at DESC LIMIT " . $this->historyRepositoryBuilderConfig->getLimit();
         //var_dump($sql); var_dump($params);
         $stat = $DB->prepare($sql);
         $stat->execute($params);
         while ($data = $stat->fetch()) {
             $areaHistory = new AreaHistoryModel();
             $areaHistory->setFromDataBaseRow($data);
             $results[] = $areaHistory;
         }
     }
     /////////////////////////// Tags History
     if ($this->historyRepositoryBuilderConfig->getIncludeTagHistory()) {
         $where = array();
         $params = array();
         if ($this->historyRepositoryBuilderConfig->getSite()) {
             $where[] = 'tag_information.site_id =:site';
             $params['site'] = $this->historyRepositoryBuilderConfig->getSite()->getId();
         }
         if ($this->historyRepositoryBuilderConfig->getSince()) {
             $where[] = ' tag_history.created_at >= :since ';
             $params['since'] = $this->historyRepositoryBuilderConfig->getSince()->format("Y-m-d H:i:s");
         }
         if ($this->historyRepositoryBuilderConfig->getNotUser()) {
             $where[] = 'tag_history.user_account_id != :userid ';
             $params['userid'] = $this->historyRepositoryBuilderConfig->getNotUser()->getId();
         }
         if ($this->historyRepositoryBuilderConfig->getApi2app()) {
             $where[] = 'tag_history.api2_application_id  = :api2app';
             $params['api2app'] = $this->historyRepositoryBuilderConfig->getApi2app()->getId();
         }
         $sql = "SELECT tag_history.*, tag_information.slug AS tag_slug, user_account_information.username AS user_account_username FROM tag_history " . " LEFT JOIN user_account_information ON user_account_information.id = tag_history.user_account_id " . " LEFT JOIN tag_information ON tag_information.id = tag_history.tag_id " . ($where ? " WHERE " . implode(" AND ", $where) : "") . " ORDER BY tag_history.created_at DESC LIMIT " . $this->historyRepositoryBuilderConfig->getLimit();
         //var_dump($sql); var_dump($params);
         $stat = $DB->prepare($sql);
         $stat->execute($params);
         while ($data = $stat->fetch()) {
             $tagHistory = new TagHistoryModel();
             $tagHistory->setFromDataBaseRow($data);
             $results[] = $tagHistory;
         }
     }
     /////////////////////////// Import URL History
     if ($this->historyRepositoryBuilderConfig->getIncludeImportURLHistory()) {
         $where = array();
         $params = array();
         if ($this->historyRepositoryBuilderConfig->getSite()) {
             $where[] = 'import_url_information.site_id =:site';
             $params['site'] = $this->historyRepositoryBuilderConfig->getSite()->getId();
         }
         if ($this->historyRepositoryBuilderConfig->getGroup()) {
             $where[] = 'import_url_information.group_id =:group';
             $params['group'] = $this->historyRepositoryBuilderConfig->getGroup()->getId();
         }
         if ($this->historyRepositoryBuilderConfig->getSince()) {
             $where[] = ' import_url_history.created_at >= :since ';
             $params['since'] = $this->historyRepositoryBuilderConfig->getSince()->format("Y-m-d H:i:s");
         }
         if ($this->historyRepositoryBuilderConfig->getNotUser()) {
             $where[] = 'import_url_history.user_account_id != :userid ';
             $params['userid'] = $this->historyRepositoryBuilderConfig->getNotUser()->getId();
         }
         if ($this->historyRepositoryBuilderConfig->getApi2app()) {
             $where[] = 'import_url_history.api2_application_id  = :api2app';
             $params['api2app'] = $this->historyRepositoryBuilderConfig->getApi2app()->getId();
         }
         $sql = "SELECT import_url_history.*, import_url_information.slug AS import_url_slug, " . "user_account_information.username AS user_account_username " . " FROM import_url_history " . " LEFT JOIN user_account_information ON user_account_information.id = import_url_history.user_account_id " . " LEFT JOIN import_url_information ON import_url_information.id = import_url_history.import_url_id " . ($where ? " WHERE " . implode(" AND ", $where) : "") . " ORDER BY import_url_history.created_at DESC LIMIT " . $this->historyRepositoryBuilderConfig->getLimit();
         //var_dump($sql); var_dump($params);
         $stat = $DB->prepare($sql);
         $stat->execute($params);
         while ($data = $stat->fetch()) {
             $tagHistory = new ImportURLHistoryModel();
             $tagHistory->setFromDataBaseRow($data);
             $results[] = $tagHistory;
         }
     }
     ////////////////////// Others!
     foreach ($app['extensions']->getExtensions() as $ext) {
         $results = array_merge($results, $ext->getHistoryRepositoryBuilderData($this->historyRepositoryBuilderConfig));
     }
     ////////////////////// Finally sort & truncate
     $usort = function ($a, $b) {
         if ($a->getCreatedAtTimeStamp() == $b->getCreatedAtTimeStamp()) {
             return 0;
         } else {
             if ($a->getCreatedAtTimeStamp() > $b->getCreatedAtTimeStamp()) {
                 return -1;
             } else {
                 return 1;
             }
         }
     };
     usort($results, $usort);
     array_slice($results, 0, $this->historyRepositoryBuilderConfig->getLimit());
     return $results;
 }
 public function ensureChangedFlagsAreSet(VenueHistoryModel $venuehistory)
 {
     global $DB;
     // do we already have them?
     if (!$venuehistory->isAnyChangeFlagsUnknown()) {
         return;
     }
     // load last.
     $stat = $DB->prepare("SELECT * FROM venue_history WHERE venue_id = :id AND created_at < :at " . "ORDER BY created_at DESC");
     $stat->execute(array('id' => $venuehistory->getId(), 'at' => $venuehistory->getCreatedAt()->format("Y-m-d H:i:s")));
     // Apply what we know!
     if ($stat->rowCount() == 0) {
         $venuehistory->setChangedFlagsFromNothing();
     } else {
         while ($venuehistory->isAnyChangeFlagsUnknown() && ($lastHistoryData = $stat->fetch())) {
             $lastHistory = new VenueHistoryModel();
             $lastHistory->setFromDataBaseRow($lastHistoryData);
             $venuehistory->setChangedFlagsFromLast($lastHistory);
         }
     }
     // Save back to DB
     $sqlFields = array();
     $sqlParams = array('id' => $venuehistory->getId(), 'created_at' => $venuehistory->getCreatedAt()->format("Y-m-d H:i:s"), 'is_new' => $venuehistory->getIsNew() ? 1 : 0);
     if ($venuehistory->getTitleChangedKnown()) {
         $sqlFields[] = " title_changed = :title_changed ";
         $sqlParams['title_changed'] = $venuehistory->getTitleChanged() ? 1 : -1;
     }
     if ($venuehistory->getDescriptionChangedKnown()) {
         $sqlFields[] = " description_changed = :description_changed ";
         $sqlParams['description_changed'] = $venuehistory->getDescriptionChanged() ? 1 : -1;
     }
     if ($venuehistory->getLatChangedKnown()) {
         $sqlFields[] = " lat_changed = :lat_changed ";
         $sqlParams['lat_changed'] = $venuehistory->getLatChanged() ? 1 : -1;
     }
     if ($venuehistory->getLngChangedKnown()) {
         $sqlFields[] = " lng_changed = :lng_changed ";
         $sqlParams['lng_changed'] = $venuehistory->getLngChanged() ? 1 : -1;
     }
     if ($venuehistory->getCountryIdChangedKnown()) {
         $sqlFields[] = " country_id_changed = :country_id_changed ";
         $sqlParams['country_id_changed'] = $venuehistory->getCountryIdChanged() ? 1 : -1;
     }
     if ($venuehistory->getAreaIdChangedKnown()) {
         $sqlFields[] = " area_id_changed = :area_id_changed ";
         $sqlParams['area_id_changed'] = $venuehistory->getAreaIdChanged() ? 1 : -1;
     }
     if ($venuehistory->getAddressChangedKnown()) {
         $sqlFields[] = " address_changed = :address_changed ";
         $sqlParams['address_changed'] = $venuehistory->getAddressChanged() ? 1 : -1;
     }
     if ($venuehistory->getAddressCodeChangedKnown()) {
         $sqlFields[] = " address_code_changed = :address_code_changed ";
         $sqlParams['address_code_changed'] = $venuehistory->getAddressCodeChanged() ? 1 : -1;
     }
     if ($venuehistory->getIsDuplicateOfIdChangedKnown()) {
         $sqlFields[] = " is_duplicate_of_id_changed  = :is_duplicate_of_id_changed ";
         $sqlParams['is_duplicate_of_id_changed'] = $venuehistory->getIsDuplicateOfIdChangedKnown() ? 1 : -1;
     }
     if ($venuehistory->getIsDeletedChangedKnown()) {
         $sqlFields[] = " is_deleted_changed = :is_deleted_changed ";
         $sqlParams['is_deleted_changed'] = $venuehistory->getIsDeletedChanged() ? 1 : -1;
     }
     $statUpdate = $DB->prepare("UPDATE venue_history SET " . " is_new = :is_new, " . implode(" , ", $sqlFields) . " WHERE venue_id = :id AND created_at = :created_at");
     $statUpdate->execute($sqlParams);
 }