abf281772ae7c21a6f16c38947de18da08f8defe
[yaffs-website] / vendor / drush / drush / includes / sitealias.inc
1 <?php
2
3 /**
4  * @file
5  * The site alias API.
6  *
7  * Run commands on remote server(s).
8  * @see example.aliases.yml
9  * @see http://drupal.org/node/670460
10  */
11
12 use Drush\Commands\core\StatusCommands;
13 use Drush\Drush;
14 use Drush\Log\LogLevel;
15 use Consolidation\SiteAlias\AliasRecord;
16 use Webmozart\PathUtil\Path;
17
18 /**
19  * Option keys used for site selection.
20  */
21 function drush_sitealias_site_selection_keys() {
22   return ['remote-host', 'remote-user', 'ssh-options', '#name', 'os'];
23 }
24
25 /**
26  * Get a site alias record given an alias name or site specification.
27  *
28  * If it is the name of a site alias, return the alias record from
29  * the site aliases array.
30  *
31  * If it is the name of a folder in the 'sites' folder, construct
32  * an alias record from values stored in settings.php.
33  *
34  * If it is a site specification, construct an alias record from the
35  * values in the specification.
36  *
37  * Site specifications come in several forms:
38  * - /path/to/drupal#sitename
39  * - user@server/path/to/drupal#sitename
40  * - user@server/path/to/drupal            (sitename == server)
41  * - user@server#sitename                  (only if $option['r'] set in some drushrc file on server)
42  * - #sitename                             (only if $option['r'] already set, and 'sitename' is a folder in $option['r']/sites)
43  * - sitename                              (only if $option['r'] already set, and 'sitename' is a folder in $option['r']/sites)
44  *
45  * Note that in the case of the first four forms, it is also possible
46  * to add additional site variable to the specification using uri query
47  * syntax.  For example:
48  *
49  *      user@server/path/to/drupal?db-url=...#sitename
50  *
51  * @param alias
52  *   An alias name or site specification
53  * @return array
54  *   An alias record, or empty if none found.
55  */
56 function drush_sitealias_get_record($alias, $alias_context = NULL) {
57   // If legacy code is still looking for an alias record this way, redirect the
58   // request to the alias manager.
59   $alias_record = Drush::aliasManager()->get($alias);
60   if (empty($alias_record)) {
61     return [];
62   }
63   $config_record = $alias_record->exportConfig();
64   $exported_config = $config_record->export();
65   return isset($exported_config['options']) ? $exported_config['options'] : [];
66 }
67
68 /**
69  * Determines whether a given site alias is for a remote site.
70  *
71  * @param string $alias
72  *   An alias name or site specification.
73  *
74  * @return bool
75  *   Returns TRUE if the alias refers to a remote site, FALSE if it does not, or NULL is unsure.
76  */
77 function drush_sitealias_is_remote_site($alias) {
78   if (is_array($alias) && !empty($alias['remote-host'])) {
79     return TRUE;
80   }
81   if (!is_string($alias) || !strlen($alias)) {
82     return NULL;
83   }
84
85   $site_record = drush_sitealias_get_record($alias);
86   if ($site_record) {
87     if (!empty($site_record['remote-host'])) {
88       return TRUE;
89     }
90     else {
91       return FALSE;
92     }
93   }
94   else {
95     drush_set_error('Unrecognized site alias.');
96   }
97 }
98