Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
feeds
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
drupal.org
feeds
Commits
68de746c
Commit
68de746c
authored
14 years ago
by
Alex Barth
Browse files
Options
Downloads
Patches
Plain Diff
#753426 Monkey Master, andrewlevine, alex_b: Partial update of nodes.
parent
ebaf53fc
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
CHANGELOG.txt
+1
-0
1 addition, 0 deletions
CHANGELOG.txt
plugins/FeedsNodeProcessor.inc
+39
-17
39 additions, 17 deletions
plugins/FeedsNodeProcessor.inc
tests/feeds.test
+13
-4
13 additions, 4 deletions
tests/feeds.test
with
53 additions
and
21 deletions
CHANGELOG.txt
+
1
−
0
View file @
68de746c
...
...
@@ -3,6 +3,7 @@
Feeds 6.x 1.X XXXX
------------------
- #753426 Monkey Master, andrewlevine, alex_b: Partial update of nodes.
- #840626 alevine, alex_b: Support using same mapping target multiple times.
- #624464 lyricnz, alex_b: Fix to "support tabs as delimiters".
- #840350 lyricnz: (Optionally) Transliterate enclosure filenames to provide
...
...
This diff is collapsed.
Click to expand it.
plugins/FeedsNodeProcessor.inc
+
39
−
17
View file @
68de746c
...
...
@@ -9,6 +9,11 @@
// Create or delete FEEDS_NODE_BATCH_SIZE at a time.
define
(
'FEEDS_NODE_BATCH_SIZE'
,
50
);
// Updating mode for existing nodes.
define
(
'FEEDS_NODE_SKIP_EXISTING'
,
0
);
define
(
'FEEDS_NODE_REPLACE_EXISTING'
,
1
);
define
(
'FEEDS_NODE_UPDATE_EXISTING'
,
2
);
/**
* Creates nodes from feed items.
*/
...
...
@@ -25,7 +30,7 @@ class FeedsNodeProcessor extends FeedsProcessor {
while
(
$item
=
$batch
->
shiftItem
())
{
// Create/update if item does not exist or update existing is enabled.
if
(
!
(
$nid
=
$this
->
existingItemId
(
$item
,
$source
))
||
$this
->
config
[
'update_existing'
])
{
if
(
!
(
$nid
=
$this
->
existingItemId
(
$item
,
$source
))
||
(
$this
->
config
[
'update_existing'
]
!=
FEEDS_NODE_SKIP_EXISTING
)
)
{
$node
=
$this
->
buildNode
(
$nid
,
$source
->
feed_nid
);
// Only proceed if item has actually changed.
...
...
@@ -142,7 +147,7 @@ class FeedsNodeProcessor extends FeedsProcessor {
$type
=
isset
(
$types
[
'story'
])
?
'story'
:
key
(
$types
);
return
array
(
'content_type'
=>
$type
,
'update_existing'
=>
0
,
'update_existing'
=>
FEEDS_NODE_SKIP_EXISTING
,
'expire'
=>
FEEDS_EXPIRE_NEVER
,
'mappings'
=>
array
(),
'author'
=>
0
,
...
...
@@ -179,9 +184,14 @@ class FeedsNodeProcessor extends FeedsProcessor {
'#default_value'
=>
$this
->
config
[
'expire'
],
);
$form
[
'update_existing'
]
=
array
(
'#type'
=>
'
checkbox
'
,
'#type'
=>
'
radios
'
,
'#title'
=>
t
(
'Update existing items'
),
'#description'
=>
t
(
'Check if existing items should be updated from the feed.'
),
'#description'
=>
t
(
'Choose how existing items should be updated from the feed.'
),
'#options'
=>
array
(
FEEDS_NODE_SKIP_EXISTING
=>
'Do not update existing item nodes'
,
FEEDS_NODE_REPLACE_EXISTING
=>
'Replace existing item nodes'
,
FEEDS_NODE_UPDATE_EXISTING
=>
'Update existing item nodes (slower than replacing them)'
,
),
'#default_value'
=>
$this
->
config
[
'update_existing'
],
);
return
$form
;
...
...
@@ -291,21 +301,31 @@ class FeedsNodeProcessor extends FeedsProcessor {
*/
protected
function
buildNode
(
$nid
,
$feed_nid
)
{
$node
=
new
stdClass
();
if
(
!
empty
(
$nid
))
{
$node
->
nid
=
$nid
;
$
node
->
vid
=
db_result
(
db_query
(
"SELECT vid FROM
{
node
}
WHERE nid = %d"
,
$nid
))
;
if
(
empty
(
$nid
))
{
$node
->
created
=
FEEDS_REQUEST_TIME
;
$
populate
=
TRUE
;
}
else
{
$node
->
created
=
FEEDS_REQUEST_TIME
;
if
(
$this
->
config
[
'update_existing'
]
==
FEEDS_NODE_UPDATE_EXISTING
)
{
$node
=
node_load
(
$nid
,
NULL
,
TRUE
);
}
else
{
$node
->
nid
=
$nid
;
$node
->
vid
=
db_result
(
db_query
(
"SELECT vid FROM
{
node
}
WHERE nid = %d"
,
$nid
));
$populate
=
TRUE
;
}
}
if
(
$populate
)
{
$node
->
type
=
$this
->
config
[
'content_type'
];
$node
->
changed
=
FEEDS_REQUEST_TIME
;
$node
->
feeds_node_item
=
new
stdClass
();
$node
->
feeds_node_item
->
id
=
$this
->
id
;
$node
->
feeds_node_item
->
imported
=
FEEDS_REQUEST_TIME
;
$node
->
feeds_node_item
->
feed_nid
=
$feed_nid
;
$node
->
feeds_node_item
->
url
=
''
;
$node
->
feeds_node_item
->
guid
=
''
;
}
$node
->
type
=
$this
->
config
[
'content_type'
];
$node
->
changed
=
FEEDS_REQUEST_TIME
;
$node
->
feeds_node_item
=
new
stdClass
();
$node
->
feeds_node_item
->
id
=
$this
->
id
;
$node
->
feeds_node_item
->
imported
=
FEEDS_REQUEST_TIME
;
$node
->
feeds_node_item
->
feed_nid
=
$feed_nid
;
$node
->
feeds_node_item
->
url
=
''
;
$node
->
feeds_node_item
->
guid
=
''
;
static
$included
;
if
(
!
$included
)
{
module_load_include
(
'inc'
,
'node'
,
'node.pages'
);
...
...
@@ -315,7 +335,9 @@ class FeedsNodeProcessor extends FeedsProcessor {
// Populate properties that are set by node_object_prepare().
$node
->
log
=
'Created/updated by FeedsNodeProcessor'
;
$node
->
uid
=
$this
->
config
[
'author'
];
if
(
$populate
)
{
$node
->
uid
=
$this
->
config
[
'author'
];
}
return
$node
;
}
...
...
This diff is collapsed.
Click to expand it.
tests/feeds.test
+
13
−
4
View file @
68de746c
...
...
@@ -144,8 +144,8 @@ class FeedsRSStoNodesTest extends FeedsWebTestCase {
$count
=
db_result
(
db_query
(
"SELECT COUNT(*) FROM
{
feeds_node_item
}
"
));
$this
->
assertEqual
(
$count
,
10
,
'Accurate number of items in database.'
);
// Enable
updat
e existing and import updated feed file.
$this
->
setSettings
(
'syndication'
,
'FeedsNodeProcessor'
,
array
(
'update_existing'
=>
TRUE
));
// Enable
replac
e existing and import updated feed file.
$this
->
setSettings
(
'syndication'
,
'FeedsNodeProcessor'
,
array
(
'update_existing'
=>
1
));
$feed_url
=
$GLOBALS
[
'base_url'
]
.
'/'
.
drupal_get_path
(
'module'
,
'feeds'
)
.
'/tests/feeds/developmentseed_changes.rss2'
;
$this
->
editFeedNode
(
$nid
,
$feed_url
);
$this
->
drupalPost
(
'node/'
.
$nid
.
'/import'
,
array
(),
'Import'
);
...
...
@@ -185,6 +185,15 @@ class FeedsRSStoNodesTest extends FeedsWebTestCase {
$count
=
db_result
(
db_query
(
"SELECT COUNT(*) FROM
{
feeds_node_item
}
fi JOIN
{
node
}
n ON fi.nid = n.nid WHERE n.uid = %d"
,
$author
->
uid
));
$this
->
assertEqual
(
$count
,
10
,
'Accurate number of items in database.'
);
// Set to update existing, remove authorship of above nodes and import again.
$this
->
setSettings
(
'syndication'
,
'FeedsNodeProcessor'
,
array
(
'update_existing'
=>
2
));
db_query
(
"UPDATE
{
node
}
n JOIN
{
feeds_node_item
}
fi ON n.nid = fi.nid SET n.uid = 0, fi.hash=''"
);
$this
->
drupalPost
(
'node/'
.
$nid
.
'/import'
,
array
(),
'Import'
);
$this
->
drupalGet
(
'node'
);
$this
->
assertNoPattern
(
'/<span class="submitted">(.*?)'
.
check_plain
(
$author
->
name
)
.
'<\/span>/'
);
$count
=
db_result
(
db_query
(
"SELECT COUNT(*) FROM
{
feeds_node_item
}
fi JOIN
{
node
}
n ON fi.nid = n.nid WHERE n.uid = %d"
,
$author
->
uid
));
$this
->
assertEqual
(
$count
,
0
,
'Accurate number of items in database.'
);
// Login with new user with only access content permissions.
$this
->
drupalLogin
(
$this
->
drupalCreateUser
()
...
...
@@ -289,8 +298,8 @@ class FeedsRSStoNodesTest extends FeedsWebTestCase {
$count
=
db_result
(
db_query
(
"SELECT COUNT(*) FROM
{
feeds_node_item
}
"
));
$this
->
assertEqual
(
$count
,
10
,
'Accurate number of items in database.'
);
// Enable
updat
e existing and import updated feed file.
$this
->
setSettings
(
'syndication_standalone'
,
'FeedsNodeProcessor'
,
array
(
'update_existing'
=>
TRUE
));
// Enable
replac
e existing and import updated feed file.
$this
->
setSettings
(
'syndication_standalone'
,
'FeedsNodeProcessor'
,
array
(
'update_existing'
=>
1
));
$feed_url
=
$GLOBALS
[
'base_url'
]
.
'/'
.
drupal_get_path
(
'module'
,
'feeds'
)
.
'/tests/feeds/developmentseed_changes.rss2'
;
$this
->
importURL
(
'syndication_standalone'
,
$feed_url
);
$this
->
assertText
(
'Updated 2 Story nodes.'
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment