<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Delaware Web Designers - Inclind, Inc Internet Professionals &#187; drupal xmlrpc</title>
	<atom:link href="http://www.delawarewebdesigner.com/tag/drupal-xmlrpc/feed" rel="self" type="application/rss+xml" />
	<link>http://www.delawarewebdesigner.com</link>
	<description>Inclind, Inc - Delaware Web Designers - Professional Delaware Web Design Since 1999</description>
	<lastBuildDate>Wed, 12 May 2010 16:21:54 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Sync Drupal Content Using Services and xmlrpc()</title>
		<link>http://www.delawarewebdesigner.com/tech-stuff/sync-drupal-content-using-services-and-xmlrpc.htm</link>
		<comments>http://www.delawarewebdesigner.com/tech-stuff/sync-drupal-content-using-services-and-xmlrpc.htm#comments</comments>
		<pubDate>Sat, 19 Dec 2009 01:52:37 +0000</pubDate>
		<dc:creator>Kevin Quillen</dc:creator>
				<category><![CDATA[Drupal Development]]></category>
		<category><![CDATA[How To's]]></category>
		<category><![CDATA[Tech Stuff]]></category>
		<category><![CDATA[Web 2.0]]></category>
		<category><![CDATA[Web Applications]]></category>
		<category><![CDATA[drupal modules]]></category>
		<category><![CDATA[drupal node service]]></category>
		<category><![CDATA[drupal Services API]]></category>
		<category><![CDATA[drupal services module]]></category>
		<category><![CDATA[drupal xmlrpc]]></category>
		<category><![CDATA[push content with drupal services]]></category>

		<guid isPermaLink="false">http://www.delawarewebdesigner.com/?p=427</guid>
		<description><![CDATA[Have you ever wondered how to push custom content from one Drupal site to another Drupal site?
There are a handful of ways to do this. One way would be to create an external database connection, talk to it, and update the data in our database through raw PHP. But that&#8217;s not really good, not to [...]]]></description>
			<content:encoded><![CDATA[<p>Have you ever wondered how to push custom content from one Drupal site to another Drupal site?</p>
<p>There are a handful of ways to do this. One way would be to create an external database connection, talk to it, and update the data in our database through raw PHP. But that&#8217;s not really good, not to mention slow, and also very <em>un</em> Drupal.</p>
<p>Another way would be to utilize Domain Access, and publish content to affiliated sites. That works in some cases, but what if these sites are independent from each other with different companies managing them? You would then have the nightmare of dealing with prefixed tables, back-end training issues, and the occasional node overlap from misconfiguring Domain Access.</p>
<p>A third way would be to utilize FeedAPI (or its successor, Feeds), to read from an RSS feed. Then you could parse and import that content at regular intervals. Sounds great, but if you plan on importing custom node types that have extensive CCK fields, files and images, prepare to sit down and code plugins and parsers galore to support CCK as data sources to target.</p>
<p>The third way is the one I thought I could get working. It seems so simple in theory that you can create an RSS/XML/JSON data structure with Views, and then tell Feeds to take that feed and parse it. True, it works if you are using a basic content type like Story or Page, but all bets are off once CCK comes into play- and who doesn&#8217;t use CCK these days? Hats off to Alex Barth / Development Seed though on Feeds, its a great start and sure to grow into a monster data consuming module. I do want to use for future projects, just not for this function.</p>
<p>One way that most people are not aware of is to take advantage of Drupal&#8217;s XML-RPC functions through the <a href="http://drupal.org/project/Services" target="_blank">Services</a> module. In short, the <a href="http://drupal.org/project/Services" target="_blank">Services</a> module provides:</p>
<blockquote><p><strong>A standardized solution of integrating external applications with Drupal. Service callbacks may be used with multiple interfaces like XMLRPC, JSON, REST, SOAP, AMF, etc. This allows a Drupal site to provide web services via multiple interfaces while using the same callback code.</strong></p></blockquote>
<p>So, then we got the idea to have the &#8216;master&#8217; Drupal site act as a SOAP server with the <a href="http://drupal.org/project/Services" target="_blank">Services</a> module, and provide our own custom services in order to get the job done. This runs once an hour, requires no user interaction, fails silently, and only requires two modules. Effectively, it also allows us to not have to use:</p>
<ul>
<li>Domain Access</li>
<li>FeedAPI/Feeds</li>
<li>Multi-site Setup</li>
</ul>
<p>The benefit of this is every site can run independently from one another and be customized various ways, while still receiving key content from the parent website. Thus is the beauty of XMLRPC/SOAP.</p>
<p>The next part was to create my own custom method so I can request a list of node ID&#8217;s from the parent server. There is no method of getting all node ID&#8217;s out of the box, but you can easily create them. Here is what I came up with:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// CODE ON PARENT SERVER</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> homes_service_service<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
		<span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
			<span style="color: #0000ff;">'#method'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'node.getAllHomes'</span><span style="color: #339933;">,</span>
			<span style="color: #0000ff;">'#callback'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'homes_service_node_get_all_homes'</span><span style="color: #339933;">,</span>
			<span style="color: #0000ff;">'#return'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'array'</span><span style="color: #339933;">,</span>
			<span style="color: #0000ff;">'#help'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Return a list of node id\'s that are of the Home content type.'</span><span style="color: #339933;">,</span>
		<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
	<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> homes_service_node_get_all_homes<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> db_query<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'SELECT nid FROM {node} WHERE type = &quot;%s&quot;'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'homes'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$home</span> <span style="color: #339933;">=</span> db_fetch_array<span style="color: #009900;">&#40;</span><span style="color: #000088;">$result</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$home</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'nid'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$homes</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$home</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'nid'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>	
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #b1b100;">return</span> <span style="color: #000088;">$homes</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// CODE ON REMOTE SERVERS</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> homes_sync_get_node_list<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// user authentication code here</span>
	<span style="color: #666666; font-style: italic;">// connect as 'services' user with 'services' role</span>
	<span style="color: #666666; font-style: italic;">// that way, drupal permissions are respected</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// user.login method used</span>
	<span style="color: #666666; font-style: italic;">// we get a successful login if the return is an array and the array values match our login information</span>
        <span style="color: #666666; font-style: italic;">// this needs a little more work so the parent server knows exactly who is requesting information       </span>
&nbsp;
	<span style="color: #000088;">$user</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'user'</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$password</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'password'</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000088;">$authenticate</span> <span style="color: #339933;">=</span> xmlrpc<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'http://upgrade.beracahhomes.com/services/xmlrpc'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'user.login'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$user</span><span style="color: #339933;">,</span> <span style="color: #000088;">$password</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">is_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$authenticate</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$authenticate</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'user'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'name'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">===</span> <span style="color: #000088;">$user</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$authenticate</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'user'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'status'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
		<span style="color: #000088;">$node_ids</span> <span style="color: #339933;">=</span> xmlrpc<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'http://www.parentsite.com/services/xmlrpc'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'node.getAllHomes'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>xmlrpc_error<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$error</span> <span style="color: #339933;">=</span> xmlrpc_error<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			watchdog<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'homes_sync'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Error getting node list from parent server. Error: @error.'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'@error'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$error</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> WATCHDOG_CRITICAL<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$node_ids</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$nid</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #000088;">$nodes</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$nid</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
			variable_set<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'parent_home_nodes'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$nodes</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			watchdog<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'homes_sync'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Successfully retrieved node list from parent server.'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> WATCHDOG_NOTICE<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	homes_sync_perform_update<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> homes_sync_perform_update<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #000088;">$node_ids</span> <span style="color: #339933;">=</span> variable_get<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'parent_home_nodes'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$node_ids</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$nid</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$data</span> <span style="color: #339933;">=</span> xmlrpc<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'http://www.parentsite.com/services/xmlrpc'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'node.get'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$nid</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> db_fetch_array<span style="color: #009900;">&#40;</span>db_query<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'SELECT n.nid, n.title, n.type FROM {node} n WHERE n.title = &quot;%s&quot; AND n.type = &quot;%s&quot;'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'title'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'homes'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>xmlrpc_error<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$error</span> <span style="color: #339933;">=</span> xmlrpc_error<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			watchdog<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'homes_sync'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Could not perform XMLRPC request. Error: @error.'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'@error'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$error</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> WATCHDOG_CRITICAL<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">is_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #000088;">$node</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span>
&nbsp;
				<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$result</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$result</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'nid'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
					<span style="color: #000088;">$node</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">nid</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$result</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'nid'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span>
&nbsp;
				<span style="color: #000088;">$node</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">type</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'type'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
				<span style="color: #000088;">$node</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">uid</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
				<span style="color: #000088;">$node</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">status</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'status'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
				<span style="color: #000088;">$node</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">created</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'created'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
				<span style="color: #000088;">$node</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">changed</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'changed'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
				<span style="color: #000088;">$node</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">comment</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'comment'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
				<span style="color: #000088;">$node</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">promote</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'promote'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
				<span style="color: #000088;">$node</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">moderate</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'moderate'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
				<span style="color: #000088;">$node</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">sticky</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'sticky'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
				<span style="color: #000088;">$node</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">tnid</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'tnid'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
				<span style="color: #000088;">$node</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">translate</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'translate'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
				<span style="color: #000088;">$node</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">title</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'title'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
				<span style="color: #000088;">$node</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">body</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'body'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
				<span style="color: #000088;">$node</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">teaser</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'teaser'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
				<span style="color: #000088;">$node</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">format</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'format'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
				<span style="color: #000088;">$node</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">name</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'name'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
				<span style="color: #000088;">$node</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">data</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'data'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
				<span style="color: #000088;">$node</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">path</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'path'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
				<span style="color: #000088;">$node</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">field_type</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'value'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'field_type'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'value'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
				<span style="color: #000088;">$node</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">field_number_of_bathrooms</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'value'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'field_number_of_bathrooms'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'value'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
				<span style="color: #000088;">$node</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">field_number_of_bedrooms</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'value'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'field_number_of_bedrooms'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'value'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
				<span style="color: #000088;">$node</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">field_number_of_floors</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'value'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'field_number_of_floors'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'value'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
				<span style="color: #000088;">$node</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">field_square_footage</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'value'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'field_square_footage'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'value'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
				node_save<span style="color: #009900;">&#40;</span><span style="color: #000088;">$node</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
				<span style="color: #990000;">unset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$node</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span>	
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> homes_sync_cron<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	homes_sync_get_node_list<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p><strong>For some reason, I can&#8217;t have two instances of wp-syntax in a single post, so bear with me. The above code is part of two seperate modules, one on the parent server, and one on the remote server (as notated with the PHP comment).</strong></p>
<p>The module code (after CODE ON PARENT SERVER)  resides on the parent server. This uses hook_service to talk to Services, and says expose node.getAllHomes as a request. That request method then calls the homes_service_node_get_all_homes function, which does a SQL query returns an array of node id&#8217;s that I am looking for.</p>
<p>I could easily return all nodes as their full node objects, but for performance reasons, I&#8217;d rather get a short list and save them on the receiving end. That way, I can create/update a handful at a time instead of all at once, which lightens the load on the database and application server.</p>
<p>On the receiving end, we need some code that creates the request that is sent to the parent server. Using hook_cron, I can send this request on an automated basis. The module code (after CODE ON REMOTE SERVERS) looks for the node list locally, and constructs single requests to retrieve node data one at a time. From there, it constructs a node object and saves it all with node_save. If the node already exists, based on type and title (our node ID&#8217;s will not match, but our title certainly will, since child sites cannot create or edit these nodes) it grabs the node ID from the local database and puts that in with the node object. node_save is a great function that can handle creating or updating data with the same structure. So, if the update runs again and passes us the same data, it will recognize it already has it, and update the record instead of create duplicates. Slick.</p>
<p>So what do we have? If we deploy the remote code on multiple remote sites, they can all sync up specific content with the parent website without anyone having to do anything special. So long as the parent site admin provides content, everyone will get it.</p>
<p>This is a quick implementation of course. I am fleshing out the authentication further as well as staggering the amount of data updated every cron run. With the core functionality in place, I can focus on security and speed. The next step is retrieving files and images using the same methods, and I will go over that in another post when I get a chance.</p>
<p>I hope fellow Drupalers found this useful, because I found that documentation on this is touch and go (and probably a reason not many utilize XMLRPC/Services). It&#8217;s a very powerful feature.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.delawarewebdesigner.com/tech-stuff/sync-drupal-content-using-services-and-xmlrpc.htm/feed</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
	</channel>
</rss>
