Logo Search packages:      
Sourcecode: aegir-provision version File versions  Download package

_provision_mysql_suggest_db_name ( url  ) 

Find a viable database name, based on available information.

This function exists solely to work past mysql's database name restrictions. As mysql also does not have the ability to rename databases, it is completely possible that sites will be running with derivative names on the same server, until the upgrade / restore process is completed.

Definition at line 217 of file provision_mysql.drush.inc.

                                                {
  if ($sid = drush_get_option('site_id')) {
    $suggest_base = 'site_'. $sid;
  }
  elseif ($name = drush_get_option('db_name')) {
    // consider the verified database name if no site id was provided
    //
    // we strip out eventual _N suffixes before finding a new db name
    // this is necessary because we may already have gone through this
    // process (in a migration) and had a _N suffix added
    $suggest_base = preg_replace('/_\d+$/', '', $name);
  }
  else {
    // This is a last option, and not ideal: base the db name on the
    // site name
    //
    // Provision only users will trigger this mostly.
    $suggest_base = substr(str_replace(array(".", "-"), '' , ereg_replace("^www\.", "", $url)), 0, 14);
  }
  $suggest[] = $suggest_base;
  for ($i = 0; $i < 100; $i++) {
    $suggest[] = $suggest_base .'_'. $i;
  }

  foreach ($suggest as $option) {
    if (!_provision_mysql_database_exists($option)) {
      return $option;
    }
  }

  drush_set_error('PROVISION_CREATE_DB_FAILED', dt("Could not find a free database names after 100 attempts"));
  return false;

}


Generated by  Doxygen 1.6.0   Back to index