You are here

function module_builder_update_documentation in Module Builder 5

Same name and namespace in other branches
  1. 6.2 includes/update.inc \module_builder_update_documentation()
  2. 6.2 includes/update_7.inc \module_builder_update_documentation()
  3. 7 includes/update.inc \module_builder_update_documentation()
  4. 7 includes/update_7.inc \module_builder_update_documentation()

Initiates documentation upate routine.

1 call to module_builder_update_documentation()
module_builder_update_button in ./module_builder.module
Form after_build handler. If update button was clicked, update hooks documentation. Rest of form is not submitted. Cribbed from node_form_add_preview()

File

./module_builder.module, line 1094
Builds scaffolding for custom modules.

Code

function module_builder_update_documentation() {

  // check we have a directory before we begin
  // sanity check. need to verify /files exists before we do anything. see http://drupal.org/node/367138
  $files = file_create_path();
  file_check_directory($files, FILE_CREATE_DIRECTORY);
  $directory = file_create_path(variable_get('module_builder_hooks_directory', 'hooks'));

  // Retrieve remote hook file listing from cvs.drupal.org
  $hook_listing = drupal_http_request(MODULE_BUILDER_HOOKS_URL);
  if (isset($hook_listing->error)) {
    drupal_set_message(t('Unable to obtain hook documentation from the <a href="@cvs-server">CVS server</a>.', array(
      '@cvs-server' => url(MODULE_BUILDER_HOOKS_URL),
    )), 'error');
    return FALSE;
  }
  $hook_files = array();

  // Parse out list of URLs
  preg_match_all(MODULE_BUILDER_URL_PATTERN, $hook_listing->data, $url_matches);
  foreach ($url_matches[1] as $url_match) {

    // Parse out file name
    preg_match(MODULE_BUILDER_FILE_PATTERN, $url_match, $file_matches);

    // Store value of URL to hook documentation file and its name
    $hook_file_url = MODULE_BUILDER_CVS_URL . $url_match;
    $hook_file_name = $file_matches[2];
    $hook_files[$hook_file_name] = $hook_file_url;
  }

  // Retrieve each file and store it in the hooks directory, overwriting what's currently there
  foreach ($hook_files as $file_name => $file_url) {
    $file_contents = drupal_http_request($file_url);
    file_save_data($file_contents->data, "{$directory}/{$file_name}", FILE_EXISTS_REPLACE);
  }

  // Finally, set the last updated variable
  variable_set('module_builder_last_update', format_date(time()));

  // inform that hook documentation has been downloaded.
  drupal_set_message(t("Module Builder has just downloaded hook documentation to your %dir directory from CVS. This documentation contains detailed descriptions and usage examples of each of Drupal's hooks. Please view the files for more information, or view them online at the <a href=\"!api\">Drupal API documentation</a> site.", array(
    '%dir' => 'files/' . variable_get('module_builder_hooks_directory', 'hooks'),
    '!api' => url('http://api.drupal.org/api/HEAD', NULL, NULL, TRUE),
  )));
}