2

我编写了必须引导的 PHP 脚本ex1.mydrupalsite.pl

这些网站使用 Aegir 平台托管。

结构如下所示:

/var/aegir/platforms/drupal-7.31/sites/ex1.mydrupalsite.pl
/var/aegir/platforms/drupal-7.31/sites/ex2.mydrupalsite.pl
# etc...

我一直在尝试:

define('DRUPAL_ROOT', '/var/aegir/platforms/drupal-7.31');
require_once DRUPAL_ROOT . '/includes/bootstrap.inc';
$_SERVER['HTTP_HOST'] = 'ex1.mydrupalsite.pl';
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
$_SERVER['REQUEST_METHOD'] = 'GET';
$_SERVER['SCRIPT_NAME'] = '/' . basename(__FILE__);
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);

但没有运气。

4

2 回答 2

2

我在任何地方都没有找到答案,所以经过一番努力,这里是如何做到这一点:

<?php
  # Set username and password
  $username = 'NAME';
  $password = 'PASSWORD';

  # Drupal Bootstrap code
  define('DRUPAL_ROOT', '/var/aegir/platforms/drupal_7');
  require_once DRUPAL_ROOT . '/includes/bootstrap.inc';

  # My attempt at injecting variables for multisite stuff to fit aegir
  $variables['url'] = 'http://example.com/';

  $databases['default']['default'] = array(
    'driver' => 'mysql',
    'database' => 'mydb',
    'username' => 'myuser',
    'password' => 'mypass',
    'host' => 'localhost',
    'port' => '3306',
  );

  $db_url['default'] = 'mysql://sqluser:sqlpass@localhost:3306/sqldb';

  drupal_override_server_variables($variables);

  # Try to bootstrap
  drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);

  # Try to login
  $uid = FALSE;
  $account = user_load_by_name($username);
  if ($account) {
    // Allow alternate password hashing schemes.
    require_once DRUPAL_ROOT . '/' . variable_get('password_inc', 'includes/password.inc');
    if (user_check_password($password, $account)) {
      // Successful authentication.
      $uid = $account->uid;

     // Update user to new password scheme if needed.
      if (user_needs_new_hash($account)) {
        user_save($account, array('pass' => $password));
      }
    }
  }
  debug($uid);
于 2016-05-12T16:33:56.607 回答
-1

问题是在 Aegir 安装中,数据库访问信息不是存储在 settings.php 中,而是作为 $_SERVER 环境变量存储在 /var/aegir/config/server_master/apache/vhost.d/[sitename] 中。您需要在脚本中专门声明它们。

或者更好的是,使用“Drush scr”来运行脚本。它将为您完成引导工作!有关更详细的说明,请参见http://www.oliverdavies.uk/blog/dont-bootstrap-drupal-use-drush/ 。

于 2015-07-31T03:20:05.383 回答