You are here

function xmlsitemap_check_directory in XML sitemap 2.x

Same name and namespace in other branches
  1. 8 xmlsitemap.module \xmlsitemap_check_directory()
  2. 6.2 xmlsitemap.module \xmlsitemap_check_directory()
  3. 7.2 xmlsitemap.module \xmlsitemap_check_directory()

Check that the sitemap files directory exists and is writable.

4 calls to xmlsitemap_check_directory()
XmlSitemapGenerator::regenerateBatchGenerate in src/XmlSitemapGenerator.php
Batch callback; generate all pages of a sitemap.
XmlSitemapSettingsForm::buildForm in src/Form/XmlSitemapSettingsForm.php
Form constructor.
xmlsitemap_install in ./xmlsitemap.install
Implements hook_install().
xmlsitemap_requirements in ./xmlsitemap.install
Implements hook_requirements().

File

./xmlsitemap.module, line 492
xmlsitemap XML sitemap

Code

function xmlsitemap_check_directory(XmlSitemapInterface $sitemap = NULL) {
  $directory = xmlsitemap_get_directory($sitemap);

  /** @var \Drupal\Core\File\FileSystemInterface $filesystem */
  $filesystem = \Drupal::service('file_system');
  $result = $filesystem
    ->prepareDirectory($directory, FileSystemInterface::CREATE_DIRECTORY | FileSystemInterface::MODIFY_PERMISSIONS);
  if (!$result) {
    \Drupal::logger('file system')
      ->error('The directory %directory does not exist or is not writable.', [
      '%directory' => $directory,
    ]);
  }
  return $result;
}