<?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>Fri, 02 Dec 2011 18:20:32 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Reduce Drupal system load caused by 404s</title>
		<link>http://mattdanger.net/2011/07/reduce-drupal-system-load-caused-by-404s/</link>
		<comments>http://mattdanger.net/2011/07/reduce-drupal-system-load-caused-by-404s/#comments</comments>
		<pubDate>Fri, 22 Jul 2011 04:30:27 +0000</pubDate>
		<dc:creator>Matt Danger</dc:creator>
				<category><![CDATA[Drupal]]></category>
		<category><![CDATA[Performance]]></category>
		<category><![CDATA[404]]></category>
		<category><![CDATA[Fast 404]]></category>
		<category><![CDATA[optimization]]></category>
		<category><![CDATA[Page Not Found]]></category>
		<category><![CDATA[performance]]></category>

		<guid isPermaLink="false">http://mattdanger.net/?p=324</guid>
		<description><![CDATA[Running multiple large Drupal sites on one machine has created some performance anxiety for us. Certain high traffic periods combined with aggressive web crawlers have ground our servers to a halt on a few occasions. My latest investigation went into cleaning up popular 404 requests on our larger sites. This noticeably reduced disk I/O. I&#8230;]]></description>
			<content:encoded><![CDATA[<p>Running multiple large Drupal sites on one machine has created some performance anxiety for us. Certain high traffic periods combined with aggressive web crawlers have ground our servers to a halt on a few occasions.</p>
<p>My latest investigation went into cleaning up popular 404 requests on our larger sites. This noticeably reduced disk I/O. I wanted to take 404 a step further and change the way Drupal 404s were handled on our machines. I turned to the <a href="http://drupal.org/project/fast_404">Fast 404</a> module.</p>
<p>Fast 404 works by intercepting the Drupal bootstrap process and performing its own path and file checking. Fast 404 configuration and execution is performed in the site&#8217;s settings.php file.</p>
<p>Version 6.x-1.1 did not work immediately out of the box and required a few changes and bug fixes. I have submitted them to the module author.</p>
<p>The whitelisting did not seem to work so I altered line 38 from:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">in_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'QUERY_STRING'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span><span style="color: #000088;">$allowed</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">TRUE</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// URL is whitelisted. Assumed good.</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>To:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$allowed</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$needle</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: #990000;">stristr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'QUERY_STRING'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span><span style="color: #000088;">$needle</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">TRUE</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// URL is whitelisted. Assumed good.</span>
  <span style="color: #009900;">&#125;</span> 
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Line 111:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$sql</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;SELECT path FROM menu_router WHERE '<span style="color: #009933; font-weight: bold;">%s</span>' LIKE CONCAT(path,'%')&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$sql2</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;SELECT pid FROM url_alias WHERE '<span style="color: #009933; font-weight: bold;">%s</span>' LIKE CONCAT(dst,'%')&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$sql3</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;SELECT rid FROM path_redirect WHERE '<span style="color: #009933; font-weight: bold;">%s</span>' LIKE source&quot;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Change to:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$sql</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;SELECT path FROM &quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$db_prefix</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'default'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;menu_router WHERE path LIKE '<span style="color: #009933; font-weight: bold;">%%</span>s%'&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$sql2</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;SELECT pid FROM &quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$db_prefix</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'default'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;url_alias WHERE dst LIKE '<span style="color: #009933; font-weight: bold;">%%</span>s%' &quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$sql3</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;SELECT rid FROM &quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$db_prefix</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'default'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;path_redirect WHERE '<span style="color: #009933; font-weight: bold;">%s</span>' LIKE source&quot;</span><span style="color: #339933;">;</span></pre></div></div>

<p>I also changed line 48 to remove duplicate code:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'HTTP/1.0 404 Not Found'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$fast_404_html</span> <span style="color: #339933;">=</span> variable_get<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'fast_404_html'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;&lt;head&gt;&lt;title&gt;404 Not Found&lt;/title&gt;&lt;/head&gt;&lt;body&gt;&lt;h1&gt;Not Found&lt;/h1&gt;&lt;p&gt;The requested URL &quot;@path&quot; was not found on this server.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">print</span> <span style="color: #990000;">strtr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fast_404_html</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'@path'</span> <span style="color: #339933;">=&gt;</span> check_plain<span style="color: #009900;">&#40;</span>request_uri<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">exit</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Change to the function that calls the same code:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">fast_404_error_return<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>One limitation of the Fast 404 module are that it will print a generic &#8220;Page Not Found&#8221; message on a white page. We would prefer to have a themed landing page similar to Drupal&#8217;s normal 404 page. My solution was to create a static 404.html file for the site and tell Fast 404 to print the contents of the file instead of its generic message.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$conf</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'fast_404_html'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">file_get_contents</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'./sites/pathtosite/404.html'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>I also wanted to keep track of the requests Fast 404 was catching. I added a direct <code>syslog()<code> call. If your Drupal site is not currently configured to use Syslog <a href="http://mattdanger.net/2011/02/setup-syslog-on-drupal-6-x-and-7-x/">see my post on setup and configuration</a>. The log format I chose fit our needs, you could format it however you like.</p>
<p>Around line 186, inside <code>fast_404_error_return()</code>:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">syslog</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'SERVER_NAME'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">' Fast_404 '</span><span style="color: #339933;">.</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'REMOTE_ADDR'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">' '</span><span style="color: #339933;">.</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'SCRIPT_URI'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">' '</span><span style="color: #339933;">.</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'HTTP_USER_AGENT'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">' '</span><span style="color: #339933;">.</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'HTTP_REFERER'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>I think monitored my Drupal log file for false positives and added them to the white list.</p>
<p>Take a look at your Drupal site and see if you have a lot of 404s being served. If so, try this module out and see if load is reduced.</p>
]]></content:encoded>
			<wfw:commentRss>http://mattdanger.net/2011/07/reduce-drupal-system-load-caused-by-404s/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Setup Syslog on Drupal 6.x and 7.x</title>
		<link>http://mattdanger.net/2011/02/setup-syslog-on-drupal-6-x-and-7-x/</link>
		<comments>http://mattdanger.net/2011/02/setup-syslog-on-drupal-6-x-and-7-x/#comments</comments>
		<pubDate>Thu, 24 Feb 2011 21:13:07 +0000</pubDate>
		<dc:creator>Matt Danger</dc:creator>
				<category><![CDATA[Drupal]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[multisite]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[syslog]]></category>

		<guid isPermaLink="false">http://mattdanger.net/?p=309</guid>
		<description><![CDATA[By design Drupal 6.x sites will log all activity to the database using a core feature called watchdog. Not having to require users to configure permissions for a log file on the server reduces install instructions (and possible errors) and creates a more seamless experience for Drupal users and administrators. Unfortunately, this makes monitoring a&#8230;]]></description>
			<content:encoded><![CDATA[<p>By design Drupal 6.x sites will log all activity to the database using a core feature called watchdog. Not having to require users to configure permissions for a log file on the server reduces install instructions (and possible errors) and creates a more seamless experience for Drupal users and administrators. Unfortunately, this makes monitoring a large multisite installs more laborious.</p>
<p>Enter Syslog.</p>
<p>Syslog is a local and network logging service that has been around since the 1980s. Most *nix systems come preloaded with Syslog and fortunately for us Drupal has a Syslog module included with the 6.x and 7.x cores. Here&#8217;s how to set it up:</p>
<p><strong>1) Install &amp; configure the Syslog module</strong></p>
<p>Go to your module install page, <code>/admin/build/modules</code> and install the Syslog module. Then go to the Syslog settings page, <code>/admin/settings/logging/syslog</code>, and select which Syslog level to attach to the log messages. Choose one that is not in use by Syslog</p>
<p><strong>2) Configure Syslog</strong></p>
<p>Edit <code>/etc/syslog.conf</code> and add:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">local0.<span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>log<span style="color: #000000; font-weight: bold;">/</span>drupal.log</pre></div></div>

<p>Then, restart Syslog</p>
<p><strong>3) Disable Watchdog database logging</strong></p>
<p>This will require us to edit the Drupal core (oh noes)<br />
Edit drupal/modules/dblog/dblog.module and comment out the contents of dblog_watchdog() (Around line 132)</p>
<p>Original:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> dblog_watchdog<span style="color: #009900;">&#40;</span><span style="color: #000088;">$log</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: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000088;">$current_db</span> <span style="color: #339933;">=</span> db_set_active<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  db_query<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;INSERT INTO {watchdog}
    (uid, type, message, variables, severity, link, location, referer, hostname, timestamp)
    VALUES
    (<span style="color: #009933; font-weight: bold;">%d</span>, '<span style="color: #009933; font-weight: bold;">%s</span>', '<span style="color: #009933; font-weight: bold;">%s</span>', '<span style="color: #009933; font-weight: bold;">%s</span>', <span style="color: #009933; font-weight: bold;">%d</span>, '<span style="color: #009933; font-weight: bold;">%s</span>', '<span style="color: #009933; font-weight: bold;">%s</span>', '<span style="color: #009933; font-weight: bold;">%s</span>', '<span style="color: #009933; font-weight: bold;">%s</span>', <span style="color: #009933; font-weight: bold;">%d</span>)&quot;</span><span style="color: #339933;">,</span>
    <span style="color: #000088;">$log</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'user'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">uid</span><span style="color: #339933;">,</span>
    <span style="color: #000088;">$log</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;">$log</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'message'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
    <span style="color: #990000;">serialize</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$log</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'variables'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
    <span style="color: #000088;">$log</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'severity'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
    <span style="color: #000088;">$log</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'link'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
    <span style="color: #000088;">$log</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'request_uri'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
    <span style="color: #000088;">$log</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'referer'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
    <span style="color: #000088;">$log</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'ip'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
    <span style="color: #000088;">$log</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'timestamp'</span><span style="color: #009900;">&#93;</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: #000088;">$current_db</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    db_set_active<span style="color: #009900;">&#40;</span><span style="color: #000088;">$current_db</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Change to:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> dblog_watchdog<span style="color: #009900;">&#40;</span><span style="color: #000088;">$log</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: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #666666; font-style: italic;">/*
  $current_db = db_set_active();
  db_query(&quot;INSERT INTO {watchdog}
    (uid, type, message, variables, severity, link, location, referer, hostname, timestamp)
    VALUES
    (%d, '%s', '%s', '%s', %d, '%s', '%s', '%s', '%s', %d)&quot;,
    $log['user']-&gt;uid,
    $log['type'],
    $log['message'],
    serialize($log['variables']),
    $log['severity'],
    $log['link'],
    $log['request_uri'],
    $log['referer'],
    $log['ip'],
    $log['timestamp']);
&nbsp;
  if ($current_db) {
    db_set_active($current_db);
  }
*/</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>And you&#8217;re done.</p>
]]></content:encoded>
			<wfw:commentRss>http://mattdanger.net/2011/02/setup-syslog-on-drupal-6-x-and-7-x/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Use Drush to update a module in a Drupal multisite environment</title>
		<link>http://mattdanger.net/2011/01/use-drush-to-update-a-module-in-a-drupal-multisite-environment/</link>
		<comments>http://mattdanger.net/2011/01/use-drush-to-update-a-module-in-a-drupal-multisite-environment/#comments</comments>
		<pubDate>Tue, 11 Jan 2011 03:34:59 +0000</pubDate>
		<dc:creator>Matt Danger</dc:creator>
				<category><![CDATA[Drupal]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[drush]]></category>

		<guid isPermaLink="false">http://mattdanger.net/?p=304</guid>
		<description><![CDATA[I love Drush. It makes managing my Drupal multisite installs much less complicated. I used to write custom scripts to loop through all the sites an perform actions but this little bit of code has made my maintenance tasks so much simpler. for SITE in `ls /path/to/drupal/sites &#124; grep "\."`; do /path/to/drush --uri=$SITE --root=/path/to/drupal --yes&#8230;]]></description>
			<content:encoded><![CDATA[<p>I love <a href="http://drupal.org/projects/drush">Drush</a>. It makes managing my Drupal multisite installs much less complicated. I used to write custom scripts to loop through all the sites an perform actions but this little bit of code has made my maintenance tasks so much simpler.</p>
<pre style="bash">

for SITE in `ls /path/to/drupal/sites | grep "\."`;
do
/path/to/drush --uri=$SITE --root=/path/to/drupal --yes updatedb
done
</pre>
]]></content:encoded>
			<wfw:commentRss>http://mattdanger.net/2011/01/use-drush-to-update-a-module-in-a-drupal-multisite-environment/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<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.&#8230;]]></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" 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="color: #0000ff;">'includes/bootstrap.inc'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">require_once</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'includes/common.inc'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
drupal_bootstrap<span style="color: #009900;">&#40;</span>DRUPAL_BOOTSTRAP_FULL<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</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: #339933;">;</span>
<span style="color: #b1b100;">print</span> <span style="color: #0000ff;">'Menu rebuild complete\n'</span><span style="color: #339933;">;</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" 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>0</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&#8230;]]></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" 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><span style="color: #339933;">;</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="color: #0000ff;">'name'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Some User'</span><span style="color: #339933;">,</span>
  <span style="color: #0000ff;">'pass'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'some_password'</span><span style="color: #339933;">,</span>
  <span style="color: #0000ff;">'mail'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'user@example.com'</span><span style="color: #339933;">,</span>
  <span style="color: #0000ff;">'status'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span>
  <span style="color: #0000ff;">'init'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'user@example.com'</span><span style="color: #339933;">,</span>
  <span style="color: #0000ff;">'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="color: #0000ff;">'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><span style="color: #339933;">;</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="color: #0000ff;">'name'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$user</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'name'</span><span style="color: #009900;">&#93;</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><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: #009900; font-weight: bold;">NULL</span><span style="color: #339933;">,</span> <span style="color: #000088;">$user</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</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>0</slash:comments>
		</item>
	</channel>
</rss>

