Importing Sites

Events happening in the community are now at Drupal community events on www.drupal.org.
entrigan's picture

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

zkrebs's picture

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

entrigan's picture

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

zkrebs's picture

I forgot to mention that there is this module too: http://drupal.org/project/sitedir_migrate

In scenarios like this, I

Josh Benner's picture

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

jerodfritz's picture

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";
  }
}

?>

Aegir hosting system

Group organizers

Group categories

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: