示例#1
0
 /**
  * Like Backdrop conf_path(), but searching from beneath.
  * Allows proper site uri detection in site sub-directories.
  *
  * Essentially looks for a settings.php file. Drush uses this
  * function to find a usable site based on the user's current
  * working directory.
  *
  * @param string
  *   Search starting path. Defaults to current working directory.
  *
  * @return
  *   Current site path (folder containing settings.php) or FALSE if not found.
  */
 protected function site_path($path = NULL)
 {
     $site_path = FALSE;
     $path = empty($path) ? drush_cwd() : $path;
     // Check the current path.
     if (file_exists($path . '/settings.php')) {
         $site_path = $path;
     } else {
         // Move up dir by dir and check each. Stop if we get to a Backdrop root.
         // We don't care if it is DRUSH_SELECTED_BACKDROP_ROOT or some other root.
         while (($path = _drush_shift_path_up($path)) && !drush_valid_root($path)) {
             if (file_exists($path . '/settings.php')) {
                 $site_path = $path;
                 break;
             }
         }
     }
     $site_root = drush_get_context('DRUSH_SELECTED_BACKDROP_ROOT');
     if (file_exists($site_root . '/sites/sites.php')) {
         $sites = array();
         // This will overwrite $sites with the desired mappings.
         include $site_root . '/sites/sites.php';
         // We do a reverse lookup here to determine the URL given the site key.
         if ($match = array_search($site_path, $sites)) {
             $site_path = $match;
         }
     }
     // Last resort: try from site root
     if (!$site_path) {
         if ($site_root) {
             if (file_exists($site_root . '/settings.php')) {
                 $site_path = $site_root;
             }
         }
     }
     return $site_path;
 }
示例#2
0
 /**
  * Validate the DRUSH_BOOTSTRAP_DRUPAL_ROOT phase.
  *
  * In this function, we will check if a valid Drupal directory is available.
  * We also determine the value that will be stored in the DRUSH_DRUPAL_ROOT
  * context and DRUPAL_ROOT constant if it is considered a valid option.
  */
 function bootstrap_drupal_root_validate()
 {
     $drupal_root = drush_get_context('DRUSH_SELECTED_DRUPAL_ROOT');
     if (empty($drupal_root)) {
         return drush_bootstrap_error('DRUSH_NO_DRUPAL_ROOT', dt("A Drupal installation directory could not be found"));
     }
     if (!($signature = drush_valid_root($drupal_root))) {
         return drush_bootstrap_error('DRUSH_INVALID_DRUPAL_ROOT', dt("The directory !drupal_root does not contain a valid Drupal installation", array('!drupal_root' => $drupal_root)));
     }
     $version = drush_drupal_version($drupal_root);
     $major_version = drush_drupal_major_version($drupal_root);
     if ($major_version <= 5) {
         return drush_set_error('DRUSH_DRUPAL_VERSION_UNSUPPORTED', dt('Drush !drush_version does not support Drupal !major_version.', array('!drush_version' => DRUSH_VERSION, '!major_version' => $major_version)));
     }
     drush_bootstrap_value('drupal_root', realpath($drupal_root));
     define('DRUSH_DRUPAL_SIGNATURE', $signature);
     return TRUE;
 }