function connect() { chdir(DRUPAL_ROOT); require_once './includes/bootstrap.inc'; drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL); set_error_handler('drupal_error_handler'); }
/** * Bootstrap all of Drupal (DRUPAL_BOOTSTRAP_FULL phase) and set the * current working directory to the Drupal root path. */ function xcvs_bootstrap($xcvs) { chdir($xcvs['drupal_path']); // Bootstrap Drupal so we can use Drupal functions to access the databases, etc. if (!file_exists('./includes/bootstrap.inc')) { fwrite(STDERR, "Error: failed to load Drupal's bootstrap.inc file.\n"); exit(1); } // Set up a few variables, Drupal might not bootstrap without those. // Copied from scripts/drupal.sh. $_SERVER['HTTP_HOST'] = 'default'; $_SERVER['PHP_SELF'] = '/index.php'; $_SERVER['REMOTE_ADDR'] = '127.0.0.1'; $_SERVER['SERVER_SOFTWARE'] = 'PHP CLI'; $_SERVER['REQUEST_METHOD'] = 'GET'; $_SERVER['QUERY_STRING'] = ''; $_SERVER['PHP_SELF'] = $_SERVER['REQUEST_URI'] = '/'; // Set up the multisite directory if necessary. if ($xcvs['multisite_directory']) { $_SERVER['HTTP_HOST'] = $xcvs['multisite_directory']; // Set a dummy script name, so the multisite configuration // file search will always trigger. $_SERVER['SCRIPT_NAME'] = '/foo'; } require_once './includes/bootstrap.inc'; drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL); }
protected function setUp() { parent::setUp(); // Enfore the settings load in order to overrides the path.inc file drupal_bootstrap(DRUPAL_BOOTSTRAP_CONFIGURATION); $GLOBALS['conf']['path_inc'] = __DIR__ . '/../sf_dic.path.inc'; }
function insert_door_to_drupal($door_id) { // set HTTP_HOST or drupal will refuse to bootstrap $_SERVER['HTTP_HOST'] = 'zl-apps'; $_SERVER['REMOTE_ADDR'] = '127.0.0.1'; include_once DRUPAL_ROOT . '/includes/bootstrap.inc'; drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL); $door = new Door(); $door_detail = $door->read(null, $door_id); $door_nid = null; $query = new EntityFieldQuery(); $entities = $query->entityCondition('entity_type', 'node')->entityCondition('bundle', 'doors')->propertyCondition('status', 1)->fieldCondition('field_door_id', 'value', $door_detail['Door']['id'], '=')->execute(); foreach ($entities['node'] as $nid => $value) { $door_nid = $nid; break; // no need to loop more even if there is multiple (it is supposed to be unique } $node = null; if (is_null($door_nid)) { $node = new stdClass(); $node->language = LANGUAGE_NONE; } else { $node = node_load($door_nid); } $node->type = 'doors'; node_object_prepare($node); $node->title = $door_detail['Door']['door_style']; $node->field_door_id[$node->language][0]['value'] = $door_detail['Door']['id']; $node->sell_price = 0; $node->model = $door_detail['Door']['door_style']; $node->shippable = 1; $path = 'door/' . $node->title; $node->path = array('alias' => $path); node_save($node); }
/** * Bootstrap Drupal to the specified phase. * * @param string $current_phase * * @return mixed */ public function boot($current_phase) { if (!static::$isEnvironmentInitialized) { self::prepareEnvironment($this->root, $this->serverVars); } return drupal_bootstrap(constant($current_phase)); }
/** * Creates a collection object. Optionally can associate it with a single collection with parameter $pid. * * @param string $pid The pid of the collection to represent. * @return CollectionClass */ function CollectionClass($pid = null) { drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL); if (!empty($pid)) { module_load_include('$php', 'Fedora_Repository', 'ObjectHelper'); $this->collection_object = new ObjectHelper($pid); } }
function ObjectEpistemetecHelper() { drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL); module_load_include('php', 'Fedora_Repository', 'ConnectionHelper'); $connectionHelper = new ConnectionHelper(); //$this->fedoraUser = $connectionHelper->getUser(); //$this->fedoraPass = $connectionHelper->getPassword(); }
public function initialize(\Boris\Boris $boris, $dir) { parent::initialize($boris, $dir); chdir($dir); define('DRUPAL_ROOT', $dir); require_once "{$dir}/includes/bootstrap.inc"; drupal_override_server_variables(); drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL); }
function EpistemetecNode() { define('ITEM_DL', 'fedora_obj'); define('COLLECTION_DL', 'fedora_collectiondl'); define('IMAGE_DL', 'img_'); define('AUDIO_DL', 'aud_'); define('VIDEO_DL', 'vid_'); drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL); }
function Object_Pool($object_pool_id = null) { module_load_include('nc', 'Object_Pool', ''); drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL); if (!empty($object_pool_id)) { $this->object_pool_id = $object_pool_id; $this->loadDBObjectPool(); $this->loadFedoraObjectPool(); } }
function bootstrap_drupal_full() { if (!drush_get_context('DRUSH_QUIET', FALSE)) { ob_start(); } drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL); if (!drush_get_context('DRUSH_QUIET', FALSE)) { ob_end_clean(); } parent::bootstrap_drupal_full(); }
private function getCacheMode() { // Check for a cache mode force from settings.php. if (variable_get('page_cache_without_database')) { $cache_enabled = TRUE; } else { drupal_bootstrap(DRUPAL_BOOTSTRAP_VARIABLES, FALSE); $cache_enabled = variable_get('cache'); } return $cache_enabled; }
/** * { @inheritdoc } */ public function bootstrapDrupal() { $this->config['root'] = $this->getDrupalRoot(); $this->validateDrupalRoot($this->config['root']); // Do a Drush-style bootstrap. define('DRUPAL_ROOT', $this->config['root']); require_once DRUPAL_ROOT . '/includes/bootstrap.inc'; drupal_override_server_variables(); // Bootstrap Drupal. drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL); }
protected function execute(InputInterface $input, OutputInterface $output) { // Prevent PHP notice. $_SERVER['REMOTE_ADDR'] = '127.0.0.1'; define('DRUPAL_ROOT', __DIR__ . '/../../../../../..'); require_once DRUPAL_ROOT . '/includes/bootstrap.inc'; drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL); $this->getApplication()->setCatchExceptions(false); $boris = new Boris(); $boris->setPrompt('oxygen> '); $boris->start(); }
function drupalize() { while (!@stat('./includes/bootstrap.inc')) { chdir('..'); } #module_load_include('/includes/bootstrap.inc', 'image', 'includes/bootstrap'); require_once './includes/bootstrap.inc'; drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL); // See http://drupal.org/node/211378#comment-924059 #drupal_bootstrap(DRUPAL_BOOTSTRAP_DATABASE); #drupal_cron_run(); }
function CheckAuthentication($drupal_path) { static $authenticated; if (!isset($authenticated)) { if (!isset($bootstrap_file_found) || $bootstrap_file_found) { $current_cwd = getcwd(); if (!defined('DRUPAL_ROOT')) { define('DRUPAL_ROOT', $drupal_path); } // Simulate being in the drupal root folder so we can share the session chdir(DRUPAL_ROOT); global $base_url; $base_root = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' ? 'https' : 'http'; $base_url = $base_root .= '://' . preg_replace('/[^a-z0-9-:._]/i', '', $_SERVER['HTTP_HOST']); if ($dir = trim(dirname($_SERVER['SCRIPT_NAME']), '\\,/')) { $base_path = "/{$dir}"; $base_url .= $base_path; } // correct base_url so it points to Drupal root $pos = strpos($base_url, '/sites/'); $base_url = substr($base_url, 0, $pos); // drupal root absolute url // If we aren't in a Drupal installation, or if Drupal path hasn't been properly found, die if (!file_exists(DRUPAL_ROOT . '/includes/bootstrap.inc')) { die("The CMS integration service for -drupal- requires KCFinder to be properly placed inside your Drupal installation."); } // bootstrap require_once DRUPAL_ROOT . '/includes/bootstrap.inc'; drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL); // if user has access permission... if (user_access('access kcfinder')) { if (!isset($_SESSION['KCFINDER'])) { $_SESSION['KCFINDER'] = array(); $_SESSION['KCFINDER']['disabled'] = false; } // User has permission, so make sure KCFinder is not disabled! if (!isset($_SESSION['KCFINDER']['disabled'])) { $_SESSION['KCFINDER']['disabled'] = false; } global $user; $_SESSION['KCFINDER']['uploadURL'] = strtr(variable_get('kcfinder_upload_url', 'sites/default/files/kcfinder'), array('%u' => $user->uid, '%n' => $user->name)); $_SESSION['KCFINDER']['uploadDir'] = strtr(variable_get('kcfinder_upload_dir', ''), array('%u' => $user->uid, '%n' => $user->name)); $_SESSION['KCFINDER']['theme'] = variable_get('kcfinder_theme', 'oxygen'); //echo '<br />uploadURL: ' . $_SESSION['KCFINDER']['uploadURL']<br />; //echo '<br />uploadDir: ' . $_SESSION['KCFINDER']['uploadDir']<br />; chdir($current_cwd); return true; } chdir($current_cwd); return false; } } }
/** * Create an object to represent an item in the Fedora repository. * Throws a SOAPException if the PID is not in the repository. * * @param string $pid * @return Fedora_Item */ function Fedora_Item($pid) { drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL); module_load_include('php', 'Fedora_Repository', 'ConnectionHelper'); module_load_include('inc', 'Fedora_Repository', 'api/fedora_utils'); if (empty(self::$connection_helper)) { self::$connection_helper = new ConnectionHelper(); } $this->pid = $pid; $raw_objprofile = $this->soap_call('getObjectProfile', array('pid' => $this->pid, 'asOfDateTime' => "")); $this->object_profile = !empty($raw_objprofile) ? $raw_objprofile->objectProfile : ''; }
function bootstrap_drupal_full() { if (!drush_get_context('DRUSH_QUIET', FALSE)) { ob_start(); } drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL); if (!drush_get_context('DRUSH_QUIET', FALSE)) { ob_end_clean(); } // Unset drupal error handler and restore drush's one. restore_error_handler(); parent::bootstrap_drupal_full(); }
/** * {@inheritdoc} */ public function bootstrap() { // Validate, and prepare environment for Drupal bootstrap. if (!defined('DRUPAL_ROOT')) { define('DRUPAL_ROOT', $this->drupalRoot); require_once DRUPAL_ROOT . '/includes/bootstrap.inc'; $this->validateDrupalSite(); } // Bootstrap Drupal. chdir(DRUPAL_ROOT); drupal_bootstrap(DRUPAL_BOOTSTRAP_CONFIGURATION); if (empty($GLOBALS['databases'])) { throw new BootstrapException('Missing database setting, verify the database configuration in settings.php.'); } drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL); }
/** * {@inheritDoc} */ public function bootstrap() { // Validate, and prepare environment for Drupal bootstrap. if (!defined('DRUPAL_ROOT')) { define('DRUPAL_ROOT', $this->drupalRoot); } // Bootstrap Drupal. $current_path = getcwd(); chdir(DRUPAL_ROOT); require_once DRUPAL_ROOT . '/core/includes/bootstrap.inc'; $this->validateDrupalSite(); drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL); // Initialise an anonymous session. required for the bootstrap. \Drupal::service('session_manager')->startLazy(); chdir($current_path); }
function Workflow($workflow_id = null, $fill_fedora = false) { module_load_include('nc', 'Workflow', ''); drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL); if (!empty($fill_fedora)) { $this->fill_fedora = $fill_fedora; } if (!empty($workflow_id)) { $this->workflow_id = $workflow_id; $this->loadDBWorkflow(); $this->loadPermissions(); $this->loadUsers(); $this->loadWorkflowPools(); $this->prioritizeWorkflowPool(); } }
/** * Constructor. Receive and store module config. * * @param $config * * @throws Codeception\Exception\ModuleConfig * If drupal_root is not set/accessible. */ public function __construct($config) { $this->config = $config; if (!$this->config['enabled']) { return; } if (empty($this->config['drupal_root']) || !file_exists($this->config['drupal_root'])) { throw new Codeception\Exception\ModuleConfig("VariableStorageBootstrapped", "drupal_root not set."); } $thisdir = getcwd(); $_SERVER['REMOTE_ADDR'] = ""; chdir($this->config['drupal_root']); define('DRUPAL_ROOT', $this->config['drupal_root']); require_once $this->config['drupal_root'] . "/includes/bootstrap.inc"; drupal_bootstrap(DRUPAL_BOOTSTRAP_VARIABLES); chdir($thisdir); }
/** * Constructor * * @return void */ protected function __construct() { if (!defined('DRUPAL_ROOT') && \XLite\Core\Config::getInstance()->CDev->DrupalConnector->drupal_root_path && !isset($this->initialized)) { $this->initialized = false; if (file_exists(\XLite\Core\Config::getInstance()->CDev->DrupalConnector->drupal_root_path . '/includes/bootstrap.inc')) { define('DRUPAL_ROOT', \XLite\Core\Config::getInstance()->CDev->DrupalConnector->drupal_root_path); require_once DRUPAL_ROOT . '/includes/bootstrap.inc'; if ($this->initializeDrupalStart()) { drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL); $this->finalizeDrupalStart(); $this->initialized = true; } } } elseif (defined('DRUPAL_ROOT')) { $this->initialized = true; } }
function CheckAuthentication() { static $authenticated; if (!isset($authenticated)) { if (!empty($_SERVER['SCRIPT_FILENAME'])) { $drupal_path = dirname(dirname(dirname(dirname($_SERVER['SCRIPT_FILENAME'])))); if (!file_exists($drupal_path . '/includes/bootstrap.inc')) { $drupal_path = dirname(dirname(dirname($_SERVER['SCRIPT_FILENAME']))); $depth = 2; do { $drupal_path = dirname($drupal_path); $depth++; } while (!($bootstrap_file_found = file_exists($drupal_path . '/includes/bootstrap.inc')) && $depth < 10); } } if (!isset($bootstrap_file_found) || !$bootstrap_file_found) { $drupal_path = '../../../../..'; if (!file_exists($drupal_path . '/includes/bootstrap.inc')) { $drupal_path = '../..'; do { $drupal_path .= '/..'; $depth = substr_count($drupal_path, '..'); } while (!($bootstrap_file_found = file_exists($drupal_path . '/includes/bootstrap.inc')) && $depth < 10); } } if (!isset($bootstrap_file_found) || $bootstrap_file_found) { $current_cwd = getcwd(); chdir($drupal_path); if (!defined('DRUPAL_ROOT')) { define('DRUPAL_ROOT', $drupal_path); } require_once DRUPAL_ROOT . '/includes/bootstrap.inc'; drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL); $authenticated = user_access('allow CKFinder file uploads'); if (isset($_GET['id'], $_SESSION['ckeditor'][$_GET['id']]['UserFilesPath'], $_SESSION['ckeditor'][$_GET['id']]['UserFilesAbsolutePath'])) { $_SESSION['ckeditor']['UserFilesPath'] = $_SESSION['ckeditor'][$_GET['id']]['UserFilesPath']; $_SESSION['ckeditor']['UserFilesAbsolutePath'] = $_SESSION['ckeditor'][$_GET['id']]['UserFilesAbsolutePath']; } chdir($current_cwd); } } return $authenticated; }
/** * Registers services on the given app. * * This method should only be used to configure services and parameters. * It should not get services. * * @param Application $app An Application instance */ public function register(Application $app) { $app['drupal.bootstrap.class'] = 'Bangpound\\Bridge\\Drupal\\Bootstrap'; $app['drupal.class'] = 'Druplex'; $app['legacy.request_matcher'] = $app->share($app->extend('legacy.request_matcher', function (RequestMatcher $matcher, $c) { $matcher->matchAttribute('_legacy', 'drupal'); return $matcher; })); $app['drupal.listener.header'] = $app->share(function ($c) { return new HeaderListener($c['legacy.request_matcher']); }); $app['drupal.bootstrap'] = $app->share(function () use($app) { /** @var Bootstrap $bootstrap */ $bootstrap = new $app['drupal.bootstrap.class'](); $bootstrap->setEventDispatcher($app['dispatcher']); require_once $app['web_dir'] . '/includes/bootstrap.inc'; drupal_bootstrap(NULL, TRUE, $bootstrap); return $bootstrap; }); $app->before(function (Request $request) use($app) { $app['drupal.bootstrap']; define('DRUPAL_ROOT', getcwd()); drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL); $pathinfo = $request->getPathInfo(); // The 'q' variable is pervasive in Drupal, so it's best to just keep // it even though it's very un-Symfony. $path = drupal_get_normal_path(substr($pathinfo, 1)); if (variable_get('menu_rebuild_needed', FALSE) || !variable_get('menu_masks', array())) { menu_rebuild(); } $original_map = arg(NULL, $path); $parts = array_slice($original_map, 0, MENU_MAX_PARTS); $ancestors = menu_get_ancestors($parts); $router_item = db_query_range('SELECT * FROM {menu_router} WHERE path IN (:ancestors) ORDER BY fit DESC', 0, 1, array(':ancestors' => $ancestors))->fetchAssoc(); if ($router_item) { // Allow modules to alter the router item before it is translated and // checked for access. drupal_alter('menu_get_item', $router_item, $path, $original_map); // The requested path is an unalaised Drupal route. $request->attributes->add(array('_route' => $router_item['path'], '_legacy' => 'drupal')); } }, 33); }
function xgit_bootstrap() { global $xgit; // Add $drupal_path to current value of the PHP include_path. set_include_path(get_include_path() . PATH_SEPARATOR . $xgit['drupal_path']); if (empty($_ENV['GIT_DRUPAL_UID'])) { fwrite(STDERR, "Error: No environment variable 'GIT_DRUPAL_UID' set or it is empty.\n"); exit(VERSIONCONTROL_GIT_ERROR_NO_UID); } $xgit['uid'] = $_ENV['GIT_DRUPAL_UID']; chdir($xgit['drupal_path']); // Bootstrap Drupal so we can use drupal functions to access the databases, etc. if (!file_exists('./includes/bootstrap.inc')) { fwrite(STDERR, "Error: failed to load Drupal's bootstrap.inc file.\n"); exit(VERSIONCONTROL_GIT_ERROR_FAILED_BOOTSTRAP); } // Set up the multisite directory if necessary. if ($xgit['multisite_directory']) { $_SERVER['HTTP_HOST'] = $xgit['multisite_directory']; // Set a dummy script name, so the multisite configuration // file search will always trigger. $_SERVER['SCRIPT_NAME'] = '/foo'; } require_once './includes/bootstrap.inc'; drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL); // Overwrite db_prefix if this is a simpletest run. if (isset($GLOBALS['simpletest_db_prefix'])) { $GLOBALS['db_prefix'] = $GLOBALS['simpletest_db_prefix']; } require_once drupal_get_path('module', 'versioncontrol_git') . '/versioncontrol_git.module'; require_once drupal_get_path('module', 'versioncontrol_git') . '/versioncontrol_git.log.inc'; $xgit['repo'] = versioncontrol_get_repository($xgit['repo_id']); if (!isset($_ENV['GIT_DIR'])) { xgit_help($this_file, STDERR); exit(VERSIONCONTROL_GIT_ERROR_NO_GIT_DIR); } $xgit['git_dir'] = $_ENV['PWD']; if (empty($xgit['repo'])) { $message = "Error: git repository with id '%s' does not exist.\n"; fwrite(STDERR, sprintf($message, $xgit['repo_id'])); exit(VERSIONCONTROL_GIT_ERROR_NO_REPOSITORY); } }
function CheckAuthentication() { static $authenticated; if (!isset($authenticated)) { $result = false; if (!empty($_SERVER['SCRIPT_FILENAME'])) { $drupal_path = dirname(dirname(dirname(dirname($_SERVER['SCRIPT_FILENAME'])))); if (!file_exists($drupal_path . "/includes/bootstrap.inc")) { $drupal_path = dirname(dirname(dirname($_SERVER['SCRIPT_FILENAME']))); $depth = 2; do { $drupal_path = dirname($drupal_path); $depth++; } while (!($bootstrapFileFound = file_exists($drupal_path . "/includes/bootstrap.inc")) && $depth < 10); } } if (!isset($bootstrapFileFound) || !$bootstrapFileFound) { $drupal_path = "../../../"; if (!file_exists($drupal_path . "/includes/bootstrap.inc")) { $drupal_path = "../.."; do { $drupal_path .= "/.."; $depth = substr_count($drupal_path, ".."); } while (!($bootstrapFileFound = file_exists($drupal_path . "/includes/bootstrap.inc")) && $depth < 10); } } if (!isset($bootstrapFileFound) || $bootstrapFileFound) { $fck_cwd = getcwd(); chdir($drupal_path); require_once "./includes/bootstrap.inc"; drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL); $authenticated = user_access("allow fckeditor file uploads"); if (isset($_SESSION['FCKeditor']['UserFilesPath'], $_SESSION['FCKeditor']['UserFilesAbsolutePath'])) { $GLOBALS['fck_user_files_path'] = $_SESSION['FCKeditor']['UserFilesPath']; $GLOBALS['fck_user_files_absolute_path'] = $_SESSION['FCKeditor']['UserFilesAbsolutePath']; } chdir($fck_cwd); } } return $authenticated; }
/** * Initializes the container. * * This can be safely called from hook_boot() because the container will * only be build if we have reached the DRUPAL_BOOTSTRAP_FULL phase. * * @return bool * TRUE when the container was initialized, FALSE otherwise. */ public static function init() { // If this is set already, just return. if (isset(static::$container)) { return TRUE; } $container_builder = static::getContainerBuilder(); if ($container_builder->isCached()) { static::$container = $container_builder->compile(); static::dispatchStaticEvent('containerReady', array(static::$container)); return TRUE; } // If we have not yet fully bootstrapped, we can't build the container. if (drupal_bootstrap(NULL, FALSE) != DRUPAL_BOOTSTRAP_FULL) { return FALSE; } // Rebuild the container. static::$container = $container_builder->compile(); static::dispatchStaticEvent('containerReady', array(static::$container)); return (bool) static::$container; }
/** * Called first to validate credentials * @see IAuthorization::Validate() */ public function Validate($username, $password) { $isValid = false; // Authentication against Drupal // Make Drupal PHP' s current directory. chdir(DRUPAL_DIRECTORY); // Bootstrap Drupal up through the database phase so that we can query it include_once DRUPAL_DIRECTORY . '/includes/bootstrap.inc'; drupal_bootstrap(DRUPAL_BOOTSTRAP_DATABASE); //Query the database to see if this user is valid $result = db_result(db_query('SELECT uid FROM {users} WHERE uid = %d', $username)); if ($result) { //If that user exists, check to see if the password is correct $result = db_result(db_query('SELECT pass FROM {users} WHERE uid = %d', $username)); if (md5($password) == $result) { $isValid = true; } } //TODO: Optionally auth against Booked Scheduler. //MPinnegar - I don't think we should auth against phpSched. Shouldn't we be authorizing exclusively against the Drupal install? return $isValid; }
/** * Find if a Drupal instance is configured for testing and bootstrap it if * found. * * @return mixed The Drupal database connection object whose type depends * on version major */ public static function findDrupalDatabaseConnection() { if (self::$bootstrapped) { return self::$databaseConnection; } else { $variableName = 'DRUPAL_PATH'; // Try to find out the right site root. $path = getenv($variableName); if ($path && is_dir($path) && file_exists($path . '/index.php')) { $bootstrapInc = $path . '/includes/bootstrap.inc'; if (!is_file($bootstrapInc)) { // It's configured, but wrongly configured, alert user trigger_error(sprintf("Configured Drupal path is a not a Drupal installation" + " or version mismatch: '%s' (version major: %d)", $path, 7)); return null; } if (!($handle = fopen($bootstrapInc, 'r'))) { trigger_error(sprintf("Cannot open for reading: '%s'", $bootstrapInc)); return null; } $buffer = fread($handle, 512); fclose($handle); $matches = []; if (preg_match("/^\\s*define\\('VERSION', '([^']+)'/ims", $buffer, $matches)) { list($parsedMajor) = explode('.', $matches[1]); } if (!isset($parsedMajor) || empty($parsedMajor)) { trigger_error(sprintf("Could not parse core version in: '%s'", $bootstrapInc)); return null; } // We are OK to go define('DRUPAL_ROOT', $path); require_once $bootstrapInc; self::$bootstrapped = true; drupal_bootstrap(DRUPAL_BOOTSTRAP_DATABASE); return self::$databaseConnection = \Database::getConnection(); } } return null; }