You are here

class Tasks in MongoDB 8

Hierarchy

  • class \Drupal\Core\Database\Install\Tasks
    • class \Drupal\Driver\Database\mongodb\Install\Tasks

Expanded class hierarchy of Tasks

File

drivers/lib/Drupal/Driver/Database/mongodb/Install/Tasks.php, line 10

Namespace

Drupal\Driver\Database\mongodb\Install
View source
class Tasks extends BaseTasks {

  /**
   * Structure that describes each task to run.
   *
   * @var array
   *
   * Each value of the tasks array is an associative array defining the function
   * to call (optional) and any arguments to be passed to the function.
   */
  protected $tasks = array(
    array(
      'function' => 'checkEngineVersion',
      'arguments' => array(),
    ),
    array(
      'function' => 'installSettings',
      'arguments' => array(),
    ),
  );

  /**
   * Return the human-readable name of the driver.
   */
  public function name() {
    return t('MongoDB');
  }
  public function runTasks() {
    if (!Settings::get('bootstrap_config_storage')) {
      \Drupal::service('class_loader')
        ->addPsr4('Drupal\\mongodb\\', 'modules/mongodb/src');
    }
    parent::runTasks();
  }
  protected function hasPdoDriver() {
    throw new \LogicException('I am not supposed to be called.');
  }
  public function installable() {
    return extension_loaded('mongo') && file_exists(DRUPAL_ROOT . '/modules/mongodb/src/MongoCollectionFactory.php');
  }
  public function getFormOptions(array $database) {
    $form = parent::getFormOptions($database);

    // Remove the options that only apply to client/server style databases.
    unset($form['username'], $form['password'], $form['advanced_options']['host'], $form['advanced_options']['port']);

    // Make the text more accurate for MongoDB.
    $form['database']['#title'] = t('Connection string');
    $form['database']['#description'] = t('The connection string to the MongoDB install/cluster where @drupal data will be stored.', array(
      '@drupal' => drupal_install_profile_distribution_name(),
    ));
    $default_database = 'mongodb://localhost:27017';
    $form['database']['#default_value'] = empty($database['database']) ? $default_database : $database['database'];
    return $form;
  }
  protected function installSettings() {
    if (Settings::get('bootstrap_config_storage')) {
      return;
    }
    $conf_path = conf_path(FALSE);
    copy(__DIR__ . '/settings.php', "{$conf_path}/settings.testing.php");
    $settingsfile = "{$conf_path}/settings.php";
    file_put_contents($settingsfile, "include __DIR__ . '/settings.testing.php';\n", FILE_APPEND);

    // Now re-read settings.php.

    /** @var \Drupal\Core\Installer\InstallerKernel $kernel */
    $kernel = \Drupal::service('kernel');
    $class_loader = \Drupal::service('class_loader');
    $site_path = $kernel
      ->getSitePath();
    for ($dir = __DIR__; $dir && !is_dir("{$dir}/core"); $dir = dirname($dir)) {
    }

    // Invalidate settings.php before loading it.
    OpCodeCache::invalidate($settingsfile);

    // Now reload settings.php.
    Settings::initialize($dir, $site_path, $class_loader);

    // And make the next rebuild utilize the new bootstrap config storage.
    $kernel
      ->resetConfigStorage();
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Tasks::$pdoDriver protected property The name of the PDO driver this database type requires. 3
Tasks::$results protected property Results from tasks.
Tasks::$tasks protected property Structure that describes each task to run. Overrides Tasks::$tasks
Tasks::checkEngineVersion protected function Check the engine version. 1
Tasks::connect protected function Check if we can connect to the database. 3
Tasks::engineVersionRequirementsCheck final public function Checks engine version requirements for the status report.
Tasks::fail protected function Assert test as failed.
Tasks::getFormOptions public function Return driver specific configuration options. Overrides Tasks::getFormOptions
Tasks::hasPdoDriver protected function Ensure the PDO driver is supported by the version of PHP in use. Overrides Tasks::hasPdoDriver
Tasks::installable public function Check whether Drupal is installable on the database. Overrides Tasks::installable
Tasks::installSettings protected function
Tasks::minimumVersion public function Return the minimum required version of the engine. 3
Tasks::name public function Return the human-readable name of the driver. Overrides Tasks::name
Tasks::pass protected function Assert test as a pass.
Tasks::runTasks public function Run database tasks and tests to see if Drupal can run on the database. Overrides Tasks::runTasks
Tasks::runTestQuery protected function Run SQL tests to ensure the database can execute commands with the current user.
Tasks::validateDatabaseSettings public function Validates driver specific configuration settings.