Posted by entrigan on September 11, 2010 at 6:38pm
So I have been importing some sites into aegir, following http://groups.drupal.org/node/24992, and a small issue came up: all of the filepath entries in the files table are "sites/default/files/*". So after the step mv sites/default sites/mysite.com, the filepaths are now wrong.
I solved this by running a query UPDATE files SET filepath = REPLACE(filepath, 'sites/default', 'sites/mysite.com');, But I am curious how other people have dealt with this issue. Am I doing something wrong?

Comments
That is what I have had to
That is what I have had to do. From now on it would be "best-practice" to make sites assuming a multi-site setup, to ease future transitions into systems like Aegir.
Sounds good, I made a note of
Sounds good, I made a note of it in the documentation http://groups.drupal.org/node/24992
Please correct as necessary.
I forgot to mention that
I forgot to mention that there is this module too: http://drupal.org/project/sitedir_migrate
In scenarios like this, I
In scenarios like this, I often do a little SQL to fix the files table:
UPDATE files SET filepath = REPLACE(filepath, 'sites/default/files', 'sites/example.com/files');Command Line PHP Filepath Conversion Script
I use this script and run it as aegir from the shell. Modify the variables at the top for your specific site.
$ php convert_filepaths.php
<?
/* multisite filepath conversion helper | Jerod Fritz (www.centogram.com) */
$hoststname='localhost';
$username='USERNAME';
$database='DATABASE';
$password='PASSWORD';
$oldsite = 'dev.oldsite.com';
$site = 'newsite.com';
$replacements = array(
array(
'this' => 'sites/default/files',
'with_this' => 'sites/' . $site . '/files',
),
array(
'this' => 'sites/all/themes',
'with_this' => 'sites/' . $site . '/themes',
),
array(
'this' => $oldsite,
'with_this' => $site,
),
);
$tables = array(
'boxes',
'files',
'node_revisions',
);
$columns = array();
mysql_connect($hostname, $username, $password);
if (mysql_select_db($database)) {
echo "\n[";
echo $database;
echo "]\n";
$tbl_status = 'SHOW TABLE STATUS FROM ' . $database . "\n";
$tbl_result = mysql_query($tbl_status);
if (mysql_num_rows($tbl_result)) {
$total_changed = 0;
while ($tbl_row = MYSQL_FETCH_ARRAY($tbl_result)) {
if(in_array($tbl_row[0],$tables)){
echo '[';
echo $tbl_row[0];
echo "]\n";
$columns = 'SHOW COLUMNS FROM ' . $tbl_row[0];
$columns_result = mysql_query($columns);
while ($tbl_columns_row = MYSQL_FETCH_ARRAY($columns_result)) {
echo "\t" . $tbl_columns_row[0];
echo "\n";
foreach($replacements as $replacement){
$replace_this = $replacement['this'];
$with_this = $replacement['with_this'];
$query = 'update ' . $tbl_row[0] . ' set ' . $tbl_columns_row[0] . ' = replace(' . $tbl_columns_row[0] . ', \'' . $replace_this . '\', \'' . $with_this . '\');';
$result = mysql_query($query);
if(mysql_affected_rows()){
printf("\t\t Updated %s -> %s : %d\n", $replace_this, $with_this, mysql_affected_rows());
$total += mysql_affected_rows();
}
}
}
}
}
printf("\n\n\nTOTAL CHANGED: %d\n", $total);
} else {
echo "[No Tables Found in Database]\n";
}
}
?>