diff --git a/changelog.json b/changelog.json index 7f4280e0..4ee1a4ab 100644 --- a/changelog.json +++ b/changelog.json @@ -1,4 +1,13 @@ [ + { + "version": "1.4.7", + "downloadUrl": "https://github.com/engram-design/FeedMe/archive/1.4.7.zip", + "date": "2016-02-29 01:00:00", + "notes": [ + "[Added] Added support for locales - set which locale you want your feed to go to.", + "[Added] Added support for non-http protocols for feeds (ftp://, file://, etc) [#29](https://github.com/engram-design/FeedMe/issues/29)" + ] + }, { "version": "1.4.6", "downloadUrl": "https://github.com/engram-design/FeedMe/archive/1.4.6.zip", diff --git a/feedme/FeedMePlugin.php b/feedme/FeedMePlugin.php index 2b8a3ccb..2a8877ac 100644 --- a/feedme/FeedMePlugin.php +++ b/feedme/FeedMePlugin.php @@ -24,12 +24,12 @@ public function getName() public function getVersion() { - return '1.4.6'; + return '1.4.7'; } public function getSchemaVersion() { - return '1.0.0'; + return '1.1.0'; } public function getDeveloper() diff --git a/feedme/controllers/FeedMe_FeedsController.php b/feedme/controllers/FeedMe_FeedsController.php index c7a2e8b4..f03bea69 100644 --- a/feedme/controllers/FeedMe_FeedsController.php +++ b/feedme/controllers/FeedMe_FeedsController.php @@ -46,6 +46,7 @@ public function getModelFromPost() { $feed->primaryElement = craft()->request->getPost('primaryElement'); $feed->section = craft()->request->getPost('section'); $feed->entrytype = craft()->request->getPost('entrytype'); + $feed->locale = craft()->request->getPost('locale'); $feed->duplicateHandle = craft()->request->getPost('duplicateHandle'); $feed->passkey = craft()->request->getPost('passkey'); $feed->backup = craft()->request->getPost('backup'); diff --git a/feedme/enums/FeedMe_Element.php b/feedme/enums/FeedMe_Element.php index 654a42fb..1e9ec6a1 100644 --- a/feedme/enums/FeedMe_Element.php +++ b/feedme/enums/FeedMe_Element.php @@ -19,4 +19,4 @@ class FeedMe_Element extends BaseEnum const Status = 'status'; const Locale = 'preferredLocale'; const Password = 'newPassword'; -} +} \ No newline at end of file diff --git a/feedme/migrations/m160222_000000_feedMe_addLocale.php b/feedme/migrations/m160222_000000_feedMe_addLocale.php new file mode 100644 index 00000000..176745f7 --- /dev/null +++ b/feedme/migrations/m160222_000000_feedMe_addLocale.php @@ -0,0 +1,12 @@ +db->createCommand()->addColumnAfter('feedme_feeds', 'locale', ColumnType::Varchar, 'entrytype'); + + return true; + } +} diff --git a/feedme/models/FeedMe_FeedModel.php b/feedme/models/FeedMe_FeedModel.php index 38bf9c13..10c84b3a 100644 --- a/feedme/models/FeedMe_FeedModel.php +++ b/feedme/models/FeedMe_FeedModel.php @@ -13,7 +13,7 @@ protected function defineAttributes() return array( 'id' => AttributeType::Number, 'name' => AttributeType::String, - 'feedUrl' => AttributeType::Url, + 'feedUrl' => AttributeType::Uri, 'feedType' => array(AttributeType::Enum, 'values' => array( FeedMe_FeedType::XML, FeedMe_FeedType::RSS, @@ -23,6 +23,7 @@ protected function defineAttributes() 'primaryElement' => AttributeType::String, 'section' => AttributeType::String, 'entrytype' => AttributeType::String, + 'locale' => AttributeType::String, 'duplicateHandle' => array(AttributeType::Enum, 'values' => array( FeedMe_Duplicate::Add, FeedMe_Duplicate::Update, diff --git a/feedme/records/FeedMe_FeedRecord.php b/feedme/records/FeedMe_FeedRecord.php index 5a4e44fb..59abd3ce 100644 --- a/feedme/records/FeedMe_FeedRecord.php +++ b/feedme/records/FeedMe_FeedRecord.php @@ -12,7 +12,7 @@ protected function defineAttributes() { return array( 'name' => array(AttributeType::String, 'required' => true), - 'feedUrl' => array(AttributeType::Url, 'required' => true), + 'feedUrl' => array(AttributeType::Uri, 'required' => true), 'feedType' => array(AttributeType::Enum, 'required' => true, 'values' => array( FeedMe_FeedType::XML, FeedMe_FeedType::RSS, @@ -22,6 +22,7 @@ protected function defineAttributes() 'primaryElement' => array(AttributeType::String), 'section' => array(AttributeType::String, 'required' => true), 'entrytype' => array(AttributeType::String, 'required' => true), + 'locale' => array(AttributeType::String), 'duplicateHandle' => array(AttributeType::Enum, 'required' => true, 'values' => array( FeedMe_Duplicate::Add, FeedMe_Duplicate::Update, diff --git a/feedme/services/FeedMeService.php b/feedme/services/FeedMeService.php index 4a980351..3023b99a 100644 --- a/feedme/services/FeedMeService.php +++ b/feedme/services/FeedMeService.php @@ -166,7 +166,9 @@ public function importSingleNode($node, $feed, $settings) $entry = craft()->feedMe_entry->prepForElementModel($fieldData, $entry); // Set our data for this EntryModel (our mapped data) - $entry->setContentFromPost($fieldData); + if (!$feed['locale']) { + $entry->setContentFromPost($fieldData); + } //echo '
'; //print_r($fieldData); @@ -180,14 +182,40 @@ public function importSingleNode($node, $feed, $settings) return false; } else { - // Successfully saved/added entry - if ($feed['duplicateHandle'] == FeedMe_Duplicate::Update) { - FeedMePlugin::log($feed->name . ': Entry successfully updated: ' . $entry->id, LogLevel::Info, true); + // If we're importing into a specific locale, we need to create this entry if it doesn't already exist + // completely blank of custom field content. After thats saved, we then re-fetch the entry for the specific + // locale and then add our field data. Doing this ensures its not copied across all locales. + if ($feed['locale']) { + $entryLocale = craft()->entries->getEntryById($entry->id, $feed['locale']); + + $entryLocale->setContentFromPost($fieldData); + + if (!craft()->entries->saveEntry($entryLocale)) { + FeedMePlugin::log($feed->name . ': ' . json_encode($entryLocale->getErrors()), LogLevel::Error, true); + + return false; + } else { + + // Successfully saved/added entry + if ($feed['duplicateHandle'] == FeedMe_Duplicate::Update) { + FeedMePlugin::log($feed->name . ': Entry successfully updated: ' . $entryLocale->id, LogLevel::Info, true); + } else { + FeedMePlugin::log($feed->name . ': Entry successfully added: ' . $entryLocale->id, LogLevel::Info, true); + } + + return true; + } } else { - FeedMePlugin::log($feed->name . ': Entry successfully added: ' . $entry->id, LogLevel::Info, true); - } - return true; + // Successfully saved/added entry + if ($feed['duplicateHandle'] == FeedMe_Duplicate::Update) { + FeedMePlugin::log($feed->name . ': Entry successfully updated: ' . $entry->id, LogLevel::Info, true); + } else { + FeedMePlugin::log($feed->name . ': Entry successfully added: ' . $entry->id, LogLevel::Info, true); + } + + return true; + } } } catch (\Exception $e) { FeedMePlugin::log($feed->name . ': Entry FeedMeError: ' . $e->getMessage() . '.', LogLevel::Error, true); diff --git a/feedme/services/FeedMe_EntryService.php b/feedme/services/FeedMe_EntryService.php index b99807f4..31fcc68c 100644 --- a/feedme/services/FeedMe_EntryService.php +++ b/feedme/services/FeedMe_EntryService.php @@ -29,6 +29,10 @@ public function setModel($settings) $element->sectionId = $settings['section']; $element->typeId = $settings['entrytype']; + if ($settings['locale']) { + $element->locale = $settings['locale']; + } + return $element; } @@ -43,6 +47,10 @@ public function setCriteria($settings) // Look in same section when replacing $criteria->sectionId = $settings['section']; $criteria->type = $settings['entrytype']; + + if ($settings['locale']) { + $criteria->locale = $settings['locale']; + } return $criteria; } diff --git a/feedme/services/FeedMe_FeedsService.php b/feedme/services/FeedMe_FeedsService.php index b19a4b45..fdc0093d 100644 --- a/feedme/services/FeedMe_FeedsService.php +++ b/feedme/services/FeedMe_FeedsService.php @@ -83,6 +83,7 @@ public function saveFeed(FeedMe_FeedModel $feed) $feedRecord->primaryElement = $feed->primaryElement; $feedRecord->section = $feed->section; $feedRecord->entrytype = $feed->entrytype; + $feedRecord->locale = $feed->locale; $feedRecord->duplicateHandle = $feed->duplicateHandle; $feedRecord->passkey = $feed->passkey; $feedRecord->backup = $feed->backup; diff --git a/feedme/templates/feeds/_edit.html b/feedme/templates/feeds/_edit.html index a57b2138..86be2abf 100644 --- a/feedme/templates/feeds/_edit.html +++ b/feedme/templates/feeds/_edit.html @@ -97,6 +97,23 @@ required: true, }) }} + {% if craft.isLocalized() %} + {% set locales = [] %} + + {% for locale in craft.i18n.getSiteLocales() %} + {% set locales = locales | merge([{ label: locale.name ~ ' (' ~ locale.id ~ ')', value: locale.id }]) %} + {% endfor %} + + {{ forms.selectField({ + label: "Locale" | t, + instructions: 'Choose which locale you want to save your feed data to.' | t, + id: 'locale', + name: 'locale', + options: locales, + value: feed.locale, + }) }} + {% endif %} +
{{ forms.selectField({