예제 #1
0
 function add($commandfile)
 {
     $load_command = FALSE;
     $module = basename($commandfile);
     $module = preg_replace('/\\.*drush[0-9]*\\.inc/', '', $module);
     $module_versionless = preg_replace('/\\.d([0-9]+)$/', '', $module);
     if (!isset($this->cache[$module_versionless])) {
         $drupal_version = '';
         if (preg_match('/\\.d([0-9]+)$/', $module, $matches)) {
             $drupal_version = $matches[1];
         }
         if (empty($drupal_version)) {
             $load_command = TRUE;
         } else {
             if (function_exists('drush_drupal_major_version') && $drupal_version == drush_drupal_major_version()) {
                 $load_command = TRUE;
             } else {
                 // Signal that we should try again on
                 // the next bootstrap phase.
                 $this->deferred[$module] = $commandfile;
             }
         }
         if ($load_command) {
             $this->cache[$module_versionless] = $commandfile;
             require_once $commandfile;
             unset($this->deferred[$module]);
         }
     }
     return $load_command;
 }
예제 #2
0
 public function install($profile)
 {
     $options['account-name'] = drush_prompt(dt('Enter the administrator (uid=1) account name'));
     $options['account-pass'] = drush_prompt(dt('Enter the administrator (uid=1) password'));
     $options['account-mail'] = drush_prompt(dt('Enter the administrator (uid=1) e-mail address'));
     $options['locale'] = drush_prompt(dt('Enter your desired locale'));
     $options['site-name'] = drush_prompt(dt('Enter the name of your site'));
     $options['site-mail'] = drush_prompt(dt('Enter the global mail address of your site'));
     // Setting the options as a drush command specific context so the site install
     // routine picks it up.
     drush_set_context('specific', $options);
     // Determin the major version and launch version specific installation.
     drush_include_engine('drupal', 'site_install', drush_drupal_major_version());
     drush_core_site_install_version($profile, $options);
     drush_log(dt('Installation finished.'), 'success');
 }
예제 #3
0
/**
 * Initialize auto-inc values on dev site.  Run this function only once, at setup.
 */
function __init()
{
    // Bring config vars into function namespace
    extract(__config());
    // Enable profile module
    drush_print("Installing profile module.");
    if (drush_drupal_major_version() < 7) {
        include_once 'includes/install.inc';
        drupal_install_modules(array('profile'));
    } else {
        module_enable(array('profile'));
    }
    // Set auto-increment values
    $tables = array('authmap', 'comments', 'files', 'node', 'node_revisions', 'profile_fields', 'role', 'term_data', 'url_alias', 'users', 'vocabulary');
    foreach ($tables as $table) {
        $value = ${$table};
        db_query("ALTER TABLE `{$table}` AUTO_INCREMENT = %d", $value);
        drush_print("Set auto-increment value for {$table} to {$value}");
    }
    unset($value);
    drush_print("Initialization done!");
}
예제 #4
0
 public function query_prefix($query)
 {
     // Inject table prefixes as needed.
     if (drush_has_boostrapped(DRUSH_BOOTSTRAP_DRUPAL_DATABASE)) {
         // Enable prefix processing which can be dangerous so off by default. See http://drupal.org/node/1219850.
         if (drush_get_option('db-prefix')) {
             if (drush_drupal_major_version() >= 7) {
                 $query = Database::getConnection()->prefixTables($query);
             } else {
                 $query = db_prefix_tables($query);
             }
         }
     }
     return $query;
 }
예제 #5
0
 /**
  * Bootstrap Drush with a valid Drupal Directory.
  *
  * In this function, the pwd will be moved to the root
  * of the Drupal installation.
  *
  * The DRUSH_DRUPAL_ROOT context, DRUSH_DRUPAL_CORE context, DRUPAL_ROOT, and the
  * DRUSH_DRUPAL_CORE constants are populated from the value that we determined during
  * the validation phase.
  *
  * We also now load the drushrc.php for this specific Drupal site.
  * We can now include files from the Drupal Tree, and figure
  * out more context about the platform, such as the version of Drupal.
  */
 function bootstrap_drupal_root()
 {
     // Load the config options from Drupal's /drush and sites/all/drush directories.
     drush_load_config('drupal');
     $drupal_root = drush_set_context('DRUSH_DRUPAL_ROOT', drush_bootstrap_value('drupal_root'));
     chdir($drupal_root);
     $version = drush_drupal_version();
     $major_version = drush_drupal_major_version();
     $core = $this->bootstrap_drupal_core($drupal_root);
     // DRUSH_DRUPAL_CORE should point to the /core folder in Drupal 8+ or to DRUPAL_ROOT
     // in prior versions.
     drush_set_context('DRUSH_DRUPAL_CORE', $core);
     define('DRUSH_DRUPAL_CORE', $core);
     _drush_preflight_global_options();
     drush_log(dt("Initialized Drupal !version root directory at !drupal_root", array("!version" => $version, '!drupal_root' => $drupal_root)));
 }
예제 #6
0
/**
 * Log the given user in to a bootstrapped Drupal site.
 *
 * @param mixed
 *   Numeric user id or user name.
 *
 * @return boolean
 *   TRUE if user was logged in, otherwise FALSE.
 */
function drush_drupal_login($drush_user)
{
    global $user;
    if (drush_drupal_major_version() >= 7) {
        $user = is_numeric($drush_user) ? user_load($drush_user) : user_load_by_name($drush_user);
    } else {
        $user = user_load(is_numeric($drush_user) ? array('uid' => $drush_user) : array('name' => $drush_user));
    }
    if (empty($user)) {
        if (is_numeric($drush_user)) {
            $message = dt('Could not login with user ID #!user.', array('!user' => $drush_user));
            if ($drush_user === 0) {
                $message .= ' ' . dt('This is typically caused by importing a MySQL database dump from a faulty tool which re-numbered the anonymous user ID in the users table. See !link for help recovering from this situation.', array('!link' => 'http://drupal.org/node/1029506'));
            }
        } else {
            $message = dt('Could not login with user account `!user\'.', array('!user' => $drush_user));
        }
        return drush_set_error('DRUPAL_USER_LOGIN_FAILED', $message);
    } else {
        $name = $user->name ? $user->name : variable_get('anonymous', t('Anonymous'));
        drush_log(dt('Successfully logged into Drupal as !name', array('!name' => $name . " (uid={$user->uid})")), 'bootstrap');
    }
    return TRUE;
}
예제 #7
0
/**
 * Log the given user in to a bootstrapped Drupal site.
 *
 * @param mixed
 *   Numeric user id or user name.
 *
 * @return boolean
 *   TRUE if user was logged in, otherwise FALSE.
 */
function drush_drupal_login($drush_user)
{
    global $user;
    if (drush_drupal_major_version() >= 7) {
        $user = is_numeric($drush_user) ? user_load($drush_user) : user_load_by_name($drush_user);
    } else {
        $user = user_load(is_numeric($drush_user) ? array('uid' => $drush_user) : array('name' => $drush_user));
    }
    if (empty($user)) {
        if (is_numeric($drush_user)) {
            $message = dt('Could not login with user ID #!user.', array('!user' => $drush_user));
        } else {
            $message = dt('Could not login with user account `!user\'.', array('!user' => $drush_user));
        }
        return drush_set_error('DRUPAL_USER_LOGIN_FAILED', $message);
    } else {
        $name = $user->name ? $user->name : variable_get('anonymous', t('Anonymous'));
        drush_log(dt('Successfully logged into Drupal as !name', array('!name' => $name . " (uid={$user->uid})")), 'bootstrap');
    }
    return TRUE;
}
예제 #8
0
파일: Rum.php 프로젝트: netsensei/Rum
 public function getCoreVersion()
 {
     if (is_null($this->core_version)) {
         if ($version = drush_drupal_major_version()) {
             return $version;
         }
         throw new RumNoValidCoreVersionException();
     }
     return $this->core_version;
 }
예제 #9
0
/**
 * Log the given user in to a bootstrapped Drupal site.
 *
 * @param mixed
 *   Numeric user id or user name.
 *
 * @return boolean
 *   TRUE if user was logged in, otherwise FALSE.
 */
function drush_drupal_login($drush_user)
{
    global $user;
    if (drush_drupal_major_version() >= 7) {
        $user = is_numeric($drush_user) ? user_load($drush_user) : user_load_by_name($drush_user);
    } else {
        $user = user_load(is_numeric($drush_user) ? array('uid' => $drush_user) : array('name' => $drush_user));
    }
    if (empty($user)) {
        if (is_numeric($drush_user)) {
            $message = dt('Could not login with user ID #%user.', array('%user' => $drush_user));
        } else {
            $message = dt('Could not login with user account `%user\'.', array('%user' => $drush_user));
        }
        return drush_set_error('DRUPAL_USER_LOGIN_FAILED', $message);
    }
    return TRUE;
}