provision.api.php 11.3 KB
Newer Older
drumm's avatar
drumm committed
1 2
<?php
/**
3 4
 * @file
 * Provision API
drumm's avatar
drumm committed
5 6
 *
 * @see drush.api.php
7
 * @see drush_command_invoke_all()
drumm's avatar
drumm committed
8 9
 */

10 11 12 13 14 15
/**
 * Possible variables to set in local.drushrc.php or another drushrc location Drush supports.
 *
 * usage:
 *   $options['provision_backup_suffix'] = '.tar.bz2';
 *
helmo's avatar
helmo committed
16 17
 * provision_verify_platforms_before_migrate
 *   When migrating many sites turning this off can save time, default TRUE.
18
 *
helmo's avatar
helmo committed
19 20
 * provision_backup_suffix
 *   Method to set the compression used for backups... e.g. '.tar.bz2' or '.tar.', defaults to '.tar.gz'.
21
 *
22 23 24
 * provision_apache_conf_suffix
 *   Set to TRUE to generate apache vhost files with a .conf suffix, default FALSE.
 *   This takes advantage of the IncludeOptional statment introduced in Apache 2.3.6.
25
 *   WARNING: After turning this on you need to re-verify all your sites, then servers,
26
 *   and then cleanup the old configfiles (those without the .conf suffix).
27
 *   Or run: `rename s/$/.conf/ /var/aegir/config/server_master/apache/vhost.d/*` for each server.
28
 *
helmo's avatar
helmo committed
29 30
 * provision_create_local_settings_file
 *   Create a site 'local.settings.php' file if one isn't found, default TRUE.
31 32 33 34 35 36
 *
 * provision_mysqldump_suppress_gtid_restore
 *   Don't restore GTIDs from a database export.  Set to TRUE for MySQL versions 5.6 and above to
 *   avoid having restores error out during operations such as cloning, migrating, and restoring from
 *   backup.  Default is FALSE.
 *
helmo's avatar
helmo committed
37
 * provision_composer_install_platforms
38
 *   Set to FALSE to prevent provision from ever running `composer install`.
helmo's avatar
helmo committed
39 40 41
 *   Default is TRUE.
 *
 * provision_composer_install_platforms_verify_always
42 43 44 45 46 47
 *   By default, provision will run `composer install` every time a platform
 *   is verified.
 *
 *   Set to FALSE to only run `composer install` once. If composer.json
 *   changes, you will have to run `composer install` manually.
 *
helmo's avatar
helmo committed
48
 *   Default is TRUE.
49 50 51 52 53 54
 *
 * provision_composer_install_command
 *
 *   The full command to run during platform verify.
 *   Default is 'composer install --no-interaction --no-progress --no-dev'
 *
55
 */
drumm's avatar
drumm committed
56

57
/**
58
 * Implements hook_drush_load(). Deprecated. Removed in Drush 7.x.
59 60 61 62 63 64 65 66 67 68 69
 *
 * In a drush contrib check if the frontend part (hosting_hook variant) is enabled.
 */
function hook_drush_load() {
  $features = drush_get_option('hosting_features', array());
  $hook_feature_name = 'something';

  return array_key_exists($hook_feature_name, $features) // Front-end module is installed...
    && $features[$hook_feature_name];                    // ... and enabled.
}

drumm's avatar
drumm committed
70 71
/**
 * Advertise what service types are available and their default
72
 * implementations. Services are class Provision_Service_{type}_{service} in
drumm's avatar
drumm committed
73 74 75 76 77 78 79
 * {type}/{service}/{service}_service.inc files.
 *
 * @return
 *   An associative array of type => default. Default may be NULL.
 *
 * @see provision.service.inc
 */
ergonlogic's avatar
ergonlogic committed
80
function hook_provision_services() {
drumm's avatar
drumm committed
81 82 83 84 85
  return array('db' => NULL);
}

/**
 * Append PHP code to Drupal's settings.php file.
86
 *
drumm's avatar
drumm committed
87 88 89 90 91
 * To use templating, return an include statement for the template.
 *
 * @param $uri
 *   URI for the site.
 * @param $data
92
 *   Associative array of data from Provision_Config_Drupal_Settings::data.
drumm's avatar
drumm committed
93 94 95 96
 *
 * @return
 *   Lines to add to the site's settings.php file.
 *
97
 * @see Provision_Config_Drupal_Settings
drumm's avatar
drumm committed
98
 */
99
function hook_provision_drupal_config($uri, $data) {
drumm's avatar
drumm committed
100 101 102 103 104
  return '$conf[\'reverse_proxy\'] = TRUE;';
}

/**
 * Append Apache configuration to server configuration.
105
 *
drumm's avatar
drumm committed
106 107
 * To use templating, return an include statement for the template.
 *
108 109 110
 * The d() function is available to retrieve more information from the aegir
 * context.
 *
drumm's avatar
drumm committed
111
 * @param $data
112
 *   Associative array of data from Provision_Config_Apache_Server::data.
drumm's avatar
drumm committed
113 114 115 116
 *
 * @return
 *   Lines to add to the configuration file.
 *
117
 * @see Provision_Config_Apache_Server
drumm's avatar
drumm committed
118
 */
ergonlogic's avatar
ergonlogic committed
119
function hook_provision_apache_server_config($data) {
drumm's avatar
drumm committed
120 121 122 123
}

/**
 * Append Apache configuration to platform configuration.
124
 *
drumm's avatar
drumm committed
125 126
 * To use templating, return an include statement for the template.
 *
127 128 129
 * The d() function is available to retrieve more information from the aegir
 * context.
 *
drumm's avatar
drumm committed
130
 * @param $data
131
 *   Associative array of data from Provision_Config_Apache_Platform::data.
drumm's avatar
drumm committed
132 133 134 135
 *
 * @return
 *   Lines to add to the configuration file.
 *
136
 * @see Provision_Config_Apache_Platform
drumm's avatar
drumm committed
137 138 139 140 141 142
 */
function drush_hook_provision_apache_dir_config($data) {
}

/**
 * Append Apache configuration to site vhost configuration.
143
 *
drumm's avatar
drumm committed
144 145
 * To use templating, return an include statement for the template.
 *
146 147 148
 * The d() function is available to retrieve more information from the aegir
 * context.
 *
drumm's avatar
drumm committed
149 150 151
 * @param $uri
 *   URI for the site.
 * @param $data
152
 *   Associative array of data from Provision_Config_Apache_Site::data.
drumm's avatar
drumm committed
153 154 155 156
 *
 * @return
 *   Lines to add to the configuration file.
 *
157
 * @see Provision_Config_Apache_Site
drumm's avatar
drumm committed
158 159 160
 */
function drush_hook_provision_apache_vhost_config($uri, $data) {
}
161

162 163 164 165 166
/**
 * Append Nginx configuration to server configuration.
 *
 * To use templating, return an include statement for the template.
 *
167 168 169
 * The d() function is available to retrieve more information from the aegir
 * context.
 *
170 171 172 173 174 175 176 177
 * @param $data
 *   Associative array of data from Provision_Config_Nginx_Server::data.
 *
 * @return
 *   Lines to add to the configuration file.
 *
 * @see Provision_Config_Nginx_Server
 */
ergonlogic's avatar
ergonlogic committed
178
function hook_provision_nginx_server_config($data) {
179 180 181 182 183 184 185
}

/**
 * Append Nginx configuration to platform configuration.
 *
 * To use templating, return an include statement for the template.
 *
186 187 188
 * The d() function is available to retrieve more information from the aegir
 * context.
 *
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204
 * @param $data
 *   Associative array of data from Provision_Config_Nginx_Platform::data.
 *
 * @return
 *   Lines to add to the configuration file.
 *
 * @see Provision_Config_Nginx_Platform
 */
function drush_hook_provision_nginx_dir_config($data) {
}

/**
 * Append Nginx configuration to site vhost configuration.
 *
 * To use templating, return an include statement for the template.
 *
205 206 207
 * The d() function is available to retrieve more information from the aegir
 * context.
 *
208 209 210 211 212 213 214 215 216 217 218 219 220
 * @param $uri
 *   URI for the site.
 * @param $data
 *   Associative array of data from Provision_Config_Nginx_Site::data.
 *
 * @return
 *   Lines to add to the configuration file.
 *
 * @see Provision_Config_Nginx_Site
 */
function drush_hook_provision_nginx_vhost_config($uri, $data) {
}

221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252
/**
 * Specify a different template for rendering a config file.
 *
 * @param $config
 *   The Provision_config object trying to find its template.
 *
 * @return
 *   A filename of a template to use for rendering.
 *
 * @see hook_provision_config_load_templates_alter()
 */
function hook_provision_config_load_templates($config) {
  if (is_a($config, 'Provision_Config_Drupal_Settings')) {
    $file = dirname(__FILE__) . '/custom-php-settings.tpl.php';
    return $file;
  }
}

/**
 * Alter the templates suggested for rendering a config file.
 *
 * @param $templates
 *   The array of templates suggested by other Drush commands.
 * @param $config
 *   The Provision_config object trying to find its template.
 *
 * @see hook_provision_config_load_templates()
 */
function hook_provision_config_load_templates_alter(&$templates, $config) {
  // Don't let any custom templates be used.
  $templates = array();
}
253

254
/**
255
 * Alter the variables used for rendering a config file.
256 257 258 259 260 261
 *
 * When implementing this hook, the function name should start with your file's name, not "drush_".
 *
 * @param $variables
 *   The variables that are about to be injected into the template.
 * @param $template
262
 *   The template file chosen for use.
263 264 265 266 267 268
 * @param $config
 *   The Provision_config object trying to find its template.
 *
 * @see hook_provision_config_load_templates()
 * @see hook_provision_config_load_templates_alter()
 */
269
function hook_provision_config_variables_alter(&$variables, $template, $config) {
helmo's avatar
helmo committed
270

271 272
  // If this is the vhost template and the http service is Docker...
  if (is_a($config, 'Provision_Config_Apache_Site') && is_a(d()->platform->service('http'), 'Provision_Service_http_apache_docker')) {
helmo's avatar
helmo committed
273

274 275 276 277 278
    // Force the listen port to be 80.
    $variables['http_port'] = '80';
  }
}

279 280 281 282 283 284 285 286 287 288
/**
 * Alter the array of directories to create.
 *
 * @param $mkdir
 *    The array of directories to create.
 * @param string $url
 *    The url of the site being invoked.
 */
function hook_provision_drupal_create_directories_alter(&$mkdir, $url) {
  $mkdir["sites/$url/my_special_dir"] = 02770;
289
  $mkdir["sites/$url/my_other_dir"] = FALSE; // Skip the chmod on this directory.
290 291 292 293 294 295 296 297 298 299 300 301
}

/**
 * Alter the array of directories to change group ownership of.
 *
 * @param $chgrp
 *    The array of directories to change group ownership of.
 * @param string $url
 *    The url of the site being invoked.
 */
function hook_provision_drupal_chgrp_directories_alter(&$chgrp, $url) {
  $chgrp["sites/$url/my_special_dir"] = d('@server_master')->web_group;
302
  $chgrp["sites/$url/my_other_dir"] = FALSE; // Skip the chgrp on this directory.
303
}
304

ergonlogic's avatar
ergonlogic committed
305 306 307 308
/**
 * Alter the array of directories to not to recurse into in mkdir and chgrp
 * operations.
 *
309 310
 * @param $chgrp_not_recursive
 *    The array of directories not to recurse into.
ergonlogic's avatar
ergonlogic committed
311 312 313
 * @param string $url
 *    The url of the site being invoked.
 */
314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329
function hook_provision_drupal_chgrp_not_recursive_directories_alter($chgrp_not_recursive, $url) {
  $chgrp_not_recursive[] = "sites/$url/my_special_dir";
  unset($chgrp_not_recursive["sites/$url"]); // Allow recursion where we otherwise wouldn't.
}

/**
 * Alter the array of directories to not to recurse into in chmod operations.
 *
 * @param $chmod_not_recursive
 *    The array of directories not to recurse into.
 * @param string $url
 *    The url of the site being invoked.
 */
function hook_provision_drupal_chmod_not_recursive_directories_alter($chmod_not_recursive, $url) {
  $chmod_not_recursive[] = "sites/$url/my_special_dir";
  unset($chmod_not_recursive["sites/$url"]); // Allow recursion where we otherwise wouldn't.
ergonlogic's avatar
ergonlogic committed
330
}
331 332 333 334 335 336 337 338 339 340 341 342

/**
 * Alter the settings array just before starting the provision install.
 *
 * @param $settings
 *    The array with settings.
 * @param $url
 *    The site url.
 */
function hook_provision_drupal_install_settings_alter(&$settings, $url) {
  $settings['forms']['install_configure_form']['update_status_module'] = array();
}
343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360

/**
 * Alter the options passed to 'provision-deploy' when it is invoked in
 * restore, clone and migrate tasks.
 *
 * @param array $deploy_options
 *   Options passed to the invocation of provision-deploy.
 * @param string $context
 *   The type of task invoking the hook (e.g., 'clone').
 */
function hook_provision_deploy_options_alter(&$deploy_options, $context) {
  // From hosting_s3; see: https://www.drupal.org/node/2412563
  // Inject the backup bucket name during the 'clone' task, so that it is
  // available in deploy().
  if ($bucket = drush_get_option('s3_backup_name', FALSE)) {
    $deploy_options['s3_backup_name'] = $bucket;
  }
}
361 362 363 364 365 366 367

/**
 * Alter the array of regexes used to filter mysqldumps.
 *
 * @param $regexes
 *   An array of patterns to match (keys) and replacement patterns (values).
 *   Setting a value to FALSE will omit the line entirely from the database
368
 *   dump. Defaults are set in Provision_Service_db_mysql::get_regexes().
369
 */
370 371 372 373 374 375 376
function hook_provision_mysql_regex_alter(&$regexes) {
  $regexes = array(
    // remove these lines entirely.
    '#/\*!50013 DEFINER=.*/#' => FALSE,
    // just remove the matched content.
    '#/\*!50017 DEFINER=`[^`]*`@`[^`]*`\s*\*/#' => '',
    // replace matched content as needed
377
    '#/\*!50001 CREATE ALGORITHM=UNDEFINED \*/#' => "/*!50001 CREATE */",
378 379
  );
}