You are here

function xmlsitemap_check_all_directories in XML sitemap 2.x

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

Check all directories.

1 call to xmlsitemap_check_all_directories()
xmlsitemap_requirements in ./xmlsitemap.install
Implements hook_requirements().

File

./xmlsitemap.module, line 506
xmlsitemap XML sitemap

Code

function xmlsitemap_check_all_directories() {
  $directories = [];
  $sitemaps = xmlsitemap_sitemap_load_multiple(FALSE);
  foreach ($sitemaps as $sitemap) {
    $directory = xmlsitemap_get_directory($sitemap);
    $directories[$directory] = $directory;
  }

  /** @var \Drupal\Core\File\FileSystemInterface $filesystem */
  $filesystem = \Drupal::service('file_system');
  foreach ($directories as $directory) {
    $result = $filesystem
      ->prepareDirectory($directory, $filesystem::CREATE_DIRECTORY | $filesystem::MODIFY_PERMISSIONS);
    if ($result) {
      $directories[$directory] = TRUE;
    }
    else {
      $directories[$directory] = FALSE;
    }
  }
  return $directories;
}