<?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>Matt [Danger] &#187; Drupal</title>
	<atom:link href="http://mattdanger.net/tag/drupal/feed/" rel="self" type="application/rss+xml" />
	<link>http://mattdanger.net</link>
	<description>One step closer to world domination</description>
	<lastBuildDate>Thu, 06 May 2010 21:31:19 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Making database changes to Drupal multi-sites</title>
		<link>http://mattdanger.net/2009/12/making-database-changes-to-drupal-multi-sites/</link>
		<comments>http://mattdanger.net/2009/12/making-database-changes-to-drupal-multi-sites/#comments</comments>
		<pubDate>Tue, 22 Dec 2009 03:29:22 +0000</pubDate>
		<dc:creator>Matt Danger</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Drupal]]></category>
		<category><![CDATA[multi-site]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[shell]]></category>
		<category><![CDATA[terminal]]></category>

		<guid isPermaLink="false">http://mattdanger.net/?p=258</guid>
		<description><![CDATA[The company I work for hosts over 150 Drupal sites in a multi-site configuration and every so often I need to publish a change to the code that requires a database change. The large number of sites we host means that performing manual changes would require too much time and carries a chance of error. [...]]]></description>
			<content:encoded><![CDATA[<p>The company I work for hosts over 150 Drupal sites in a multi-site configuration and every so often I need to publish a change to the code that requires a database change. The large number of sites we host means that performing manual changes would require too much time and carries a chance of error. I&#8217;ve come up with a simple solution.</p>
<p>I first create a PHP script that bootstraps Drupal. Here is an example of a script that will rebuild the menu router tables.</p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// Bootstrap</span>
<span style="color: #b1b100;">require_once</span><span style="color: #009900;">&#40;</span><span style="">'includes/bootstrap.inc'</span><span style="color: #009900;">&#41;</span>;
<span style="color: #b1b100;">require_once</span><span style="color: #009900;">&#40;</span><span style="">'includes/common.inc'</span><span style="color: #009900;">&#41;</span>;
drupal_bootstrap<span style="color: #009900;">&#40;</span>DRUPAL_BOOTSTRAP_FULL<span style="color: #009900;">&#41;</span>;
&nbsp;
<span style="color: #666666; font-style: italic;">// Rebuild menus</span>
menu_rebuild<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
<span style="color: #990000;">print</span> <span style="">'Menu rebuild complete\n'</span>;</pre></div></div>

<p>I name this script <code>rebuild_menus.php</code> and upload it to my Drupal directory. Then, I create a text file on my desktop that contains a list of all the Drupal websites. This is an abbreviated example:</p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;">http<span style="color: #339933;">:</span><span style="color: #666666; font-style: italic;">//example1.com</span>
http<span style="color: #339933;">:</span><span style="color: #666666; font-style: italic;">//example2.com</span>
http<span style="color: #339933;">:</span><span style="color: #666666; font-style: italic;">//example3.com</span>
http<span style="color: #339933;">:</span><span style="color: #666666; font-style: italic;">//example4.com</span></pre></div></div>

<p>Finally, I execute the script on all the sites by running the following command:</p>
<p><code>for url in `cat list.txt`; do echo "Running script on $url"; curl $url/rebuild_menus.php; echo; done</code></p>
]]></content:encoded>
			<wfw:commentRss>http://mattdanger.net/2009/12/making-database-changes-to-drupal-multi-sites/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Programmatically create users in Drupal 6.x</title>
		<link>http://mattdanger.net/2009/12/programmatically-create-users-in-drupal-6-x/</link>
		<comments>http://mattdanger.net/2009/12/programmatically-create-users-in-drupal-6-x/#comments</comments>
		<pubDate>Thu, 17 Dec 2009 02:30:49 +0000</pubDate>
		<dc:creator>Matt Danger</dc:creator>
				<category><![CDATA[Drupal]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://mattdanger.net/?p=252</guid>
		<description><![CDATA[You can create a Drupal user by sending user_save() a null parameter and an array of user information. You can also assign a role by setting an array that is keyed with the role ID (rid). This can be obtained by calling user_roles() as shown in the example below.

// Get an array of roles
$roles = [...]]]></description>
			<content:encoded><![CDATA[<p>You can create a Drupal user by sending <code>user_save()</code> a null parameter and an array of user information. You can also assign a role by setting an array that is keyed with the role ID (rid). This can be obtained by calling <code>user_roles()</code> as shown in the example below.</p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// Get an array of roles</span>
<span style="color: #000088;">$roles</span> <span style="color: #339933;">=</span> user_roles<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
&nbsp;
<span style="color: #666666; font-style: italic;">// Basic account information</span>
<span style="color: #000088;">$user</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
  <span style="">'name'</span> <span style="color: #339933;">=&gt;</span> <span style="">'Some User'</span><span style="color: #339933;">,</span>
  <span style="">'pass'</span> <span style="color: #339933;">=&gt;</span> <span style="">'some_password'</span><span style="color: #339933;">,</span>
  <span style="">'mail'</span> <span style="color: #339933;">=&gt;</span> <span style="">'user@example.com'</span><span style="color: #339933;">,</span>
  <span style="">'status'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span>
  <span style="">'init'</span> <span style="color: #339933;">=&gt;</span> <span style="">'user@example.com'</span><span style="color: #339933;">,</span>
  <span style="">'roles'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array_search</span><span style="color: #009900;">&#40;</span><span style="">'some_role'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$roles</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
<span style="color: #009900;">&#41;</span>;
&nbsp;
<span style="color: #666666; font-style: italic;">// See if the user exists by calling Drupal's user_load()</span>
<span style="color: #000088;">$existing_user</span> <span style="color: #339933;">=</span> user_load<span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="">'name'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$user</span><span style="color: #009900;">&#91;</span><span style="">'name'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>;
&nbsp;
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$existing_user</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">uid</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// Save the user</span>
  <span style="color: #000088;">$user</span> <span style="color: #339933;">=</span> user_save<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">NULL</span><span style="color: #339933;">,</span> <span style="color: #000088;">$user</span><span style="color: #009900;">&#41;</span>;
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://mattdanger.net/2009/12/programmatically-create-users-in-drupal-6-x/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
