Skip to content

Commit

Permalink
version 1.4.7
Browse files Browse the repository at this point in the history
  • Loading branch information
engram-design committed Feb 28, 2016
1 parent 0341fbe commit 472dc48
Show file tree
Hide file tree
Showing 11 changed files with 90 additions and 12 deletions.
9 changes: 9 additions & 0 deletions changelog.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
4 changes: 2 additions & 2 deletions feedme/FeedMePlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
1 change: 1 addition & 0 deletions feedme/controllers/FeedMe_FeedsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
2 changes: 1 addition & 1 deletion feedme/enums/FeedMe_Element.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ class FeedMe_Element extends BaseEnum
const Status = 'status';
const Locale = 'preferredLocale';
const Password = 'newPassword';
}
}
12 changes: 12 additions & 0 deletions feedme/migrations/m160222_000000_feedMe_addLocale.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php
namespace Craft;

class m160222_000000_feedMe_addLocale extends BaseMigration
{
public function safeUp()
{
craft()->db->createCommand()->addColumnAfter('feedme_feeds', 'locale', ColumnType::Varchar, 'entrytype');

return true;
}
}
3 changes: 2 additions & 1 deletion feedme/models/FeedMe_FeedModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion feedme/records/FeedMe_FeedRecord.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
42 changes: 35 additions & 7 deletions feedme/services/FeedMeService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 '<pre>';
//print_r($fieldData);
Expand All @@ -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);
Expand Down
8 changes: 8 additions & 0 deletions feedme/services/FeedMe_EntryService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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;
}
Expand Down
1 change: 1 addition & 0 deletions feedme/services/FeedMe_FeedsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
17 changes: 17 additions & 0 deletions feedme/templates/feeds/_edit.html
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}

<hr>

{{ forms.selectField({
Expand Down

0 comments on commit 472dc48

Please sign in to comment.