You are here

function _google_tag_directory_prepare in GoogleTagManager 7

Prepares directory for base or realm specific snippet files.

Return value

bool Whether the directory was prepared.

1 call to _google_tag_directory_prepare()
_google_tag_assets_create in includes/admin.inc
Saves snippet files and data layer classes based on current settings.

File

includes/admin.inc, line 282
Contains the administrative page and form callbacks.

Code

function _google_tag_directory_prepare($realm_name = '') {

  // From google_tag_requirements(); this should be a helper function (in core).
  $directory = 'public://google_tag';
  $directory .= $realm_name ? "/{$realm_name}" : '';
  if (is_dir($directory) && _google_tag_is_writable($directory) && _google_tag_is_executable($directory)) {
    return TRUE;
  }
  if (_file_prepare_directory($directory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS)) {
    return TRUE;
  }

  // The snippet directory does not exist or is not writable or searchable.
  // If applicable, get the directory path of stream wrapper.
  $wrapper = file_stream_wrapper_get_instance_by_uri($directory);
  if (method_exists($wrapper, 'getDirectoryPath') && ($path = $wrapper
    ->getDirectoryPath())) {

    // getDirectoryPath() is not defined in StreamWrapperInterface; it
    // exists in LocalStream and the local storage replacement classes in
    // google_appengine; s3fs returns an empty string.
    $path .= str_replace('public://', '/', $directory);
  }
  elseif (!($path = $wrapper
    ->getExternalUrl())) {
    $path = $directory;
  }
  $args = array(
    '%directory' => $path,
  );
  $message = 'The directory %directory could not be prepared for use, possibly due to file system permissions. The directory either does not exist, or is not writable or searchable.';
  _google_tag_message_display($message, $args, 'error');
  watchdog('google_tag', $message, $args, WATCHDOG_ERROR);
  return FALSE;
}