public function actionSaveIdentity()
{
$this->requirePostRequest();
$locale = craft()->request->getPost('locale');
if (!$locale) {
$locale = craft()->language;
}
$record = Seomatic_SettingsRecord::model()->findByAttributes(array('locale' => $locale));
if (!$record) {
throw new Exception(Craft::t('No SEOmatic Settings record exists'));
}
/* -- Set the Identity attributes, defaulting to the existing values for whatever is missing from the post data */
$record->googleSiteVerification = craft()->request->getPost('googleSiteVerification', $record->googleSiteVerification);
$record->bingSiteVerification = craft()->request->getPost('bingSiteVerification', $record->bingSiteVerification);
$record->googleAnalyticsUID = craft()->request->getPost('googleAnalyticsUID', $record->googleAnalyticsUID);
$record->googleTagManagerID = craft()->request->getPost('googleTagManagerID', $record->googleTagManagerID);
$record->googleAnalyticsSendPageview = craft()->request->getPost('googleAnalyticsSendPageview', $record->googleAnalyticsSendPageview);
$record->googleAnalyticsAdvertising = craft()->request->getPost('googleAnalyticsAdvertising', $record->googleAnalyticsAdvertising);
$record->googleAnalyticsEcommerce = craft()->request->getPost('googleAnalyticsEcommerce', $record->googleAnalyticsEcommerce);
$record->googleAnalyticsEEcommerce = craft()->request->getPost('googleAnalyticsEEcommerce', $record->googleAnalyticsEEcommerce);
$record->googleAnalyticsLinkAttribution = craft()->request->getPost('googleAnalyticsLinkAttribution', $record->googleAnalyticsLinkAttribution);
$record->googleAnalyticsLinker = craft()->request->getPost('googleAnalyticsLinker', $record->googleAnalyticsLinker);
$record->siteOwnerType = craft()->request->getPost('siteOwnerType', $record->siteOwnerType);
$record->siteOwnerSubType = craft()->request->getPost('siteOwnerSubType', $record->siteOwnerSubType);
$record->siteOwnerSpecificType = craft()->request->getPost('siteOwnerSpecificType', $record->siteOwnerSpecificType);
/* -- Generic owner fields */
$record->genericOwnerName = craft()->request->getPost('genericOwnerName', $record->genericOwnerName);
$record->genericOwnerAlternateName = craft()->request->getPost('genericOwnerAlternateName', $record->genericOwnerAlternateName);
$record->genericOwnerDescription = craft()->seomatic->truncateStringOnWord(craft()->request->getPost('genericOwnerDescription', $record->genericOwnerDescription), 1024);
$record->genericOwnerUrl = craft()->request->getPost('genericOwnerUrl', $record->genericOwnerUrl);
$record->genericOwnerTelephone = craft()->request->getPost('genericOwnerTelephone', $record->genericOwnerTelephone);
$record->genericOwnerEmail = craft()->request->getPost('genericOwnerEmail', $record->genericOwnerEmail);
$record->genericOwnerStreetAddress = craft()->request->getPost('genericOwnerStreetAddress', $record->genericOwnerStreetAddress);
$record->genericOwnerAddressLocality = craft()->request->getPost('genericOwnerAddressLocality', $record->genericOwnerAddressLocality);
$record->genericOwnerAddressRegion = craft()->request->getPost('genericOwnerAddressRegion', $record->genericOwnerAddressRegion);
$record->genericOwnerPostalCode = craft()->request->getPost('genericOwnerPostalCode', $record->genericOwnerPostalCode);
$record->genericOwnerAddressCountry = craft()->request->getPost('genericOwnerAddressCountry', $record->genericOwnerAddressCountry);
$record->genericOwnerGeoLatitude = craft()->request->getPost('genericOwnerGeoLatitude', $record->genericOwnerGeoLatitude);
$record->genericOwnerGeoLongitude = craft()->request->getPost('genericOwnerGeoLongitude', $record->genericOwnerGeoLongitude);
/* -- Corporation owner fields http://schema.org/Organization */
$record->organizationOwnerDuns = craft()->request->getPost('organizationOwnerDuns', $record->organizationOwnerDuns);
$record->organizationOwnerFounder = craft()->request->getPost('organizationOwnerFounder', $record->organizationOwnerFounder);
$record->organizationOwnerFoundingDate = craft()->request->getPost('organizationOwnerFoundingDate', $record->organizationOwnerFoundingDate);
$record->organizationOwnerFoundingLocation = craft()->request->getPost('organizationOwnerFoundingLocation', $record->organizationOwnerFoundingLocation);
$record->organizationOwnerContactPoints = craft()->request->getPost('organizationOwnerContactPoints', array());
/* -- Person owner fields https://schema.org/Person */
$record->personOwnerGender = craft()->request->getPost('personOwnerGender', $record->personOwnerGender);
$record->personOwnerBirthPlace = craft()->request->getPost('personOwnerBirthPlace', $record->personOwnerBirthPlace);
/* -- LocalBusiness owner fields https://schema.org/LocalBusiness */
$hours = craft()->request->getPost('localBusinessOwnerOpeningHours', array());
craft()->seomatic->convertTimes($hours, craft()->getTimeZone());
$record->localBusinessOwnerOpeningHours = $hours;
/* -- Corporation owner fields http://schema.org/Corporation */
$record->corporationOwnerTickerSymbol = craft()->request->getPost('corporationOwnerTickerSymbol', $record->corporationOwnerTickerSymbol);
/* -- Restaurant owner fields https://schema.org/Restaurant */
$record->restaurantOwnerServesCuisine = craft()->request->getPost('restaurantOwnerServesCuisine', $record->restaurantOwnerServesCuisine);
$record->restaurantOwnerMenuUrl = craft()->request->getPost('restaurantOwnerMenuUrl', $record->restaurantOwnerMenuUrl);
$record->restaurantOwnerReservationsUrl = craft()->request->getPost('restaurantOwnerReservationsUrl', $record->restaurantOwnerReservationsUrl);
$record->genericOwnerImageId = craft()->request->getPost('genericOwnerImageId', $record->genericOwnerImageId);
$assetId = !empty($record->genericOwnerImageId) ? $record->genericOwnerImageId[0] : null;
$record->genericOwnerImageId = $assetId;
if ($record->save()) {
craft()->userSession->setNotice(Craft::t('SEOmatic Site Identity saved.'));
$this->redirectToPostedUrl($record);
} else {
craft()->userSession->setError(Craft::t('Couldn’t save SEOmatic Site Identity.'));
$this->redirectToPostedUrl($record);
}
}