Commit ca43ebdb authored by voleger's avatar voleger Committed by pifagor

Issue #3134540 by voleger, alex_optim, pifagor: Add exception handling in the...

Issue #3134540 by voleger, alex_optim, pifagor: Add exception handling in the xmlsitemap_sitemap_get_max_filesize function
parent a922fea2
...@@ -21,6 +21,7 @@ use Drupal\Core\Entity\ContentEntityInterface; ...@@ -21,6 +21,7 @@ use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\Core\Entity\ContentEntityTypeInterface; use Drupal\Core\Entity\ContentEntityTypeInterface;
use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\Query\QueryInterface; use Drupal\Core\Entity\Query\QueryInterface;
use Drupal\Core\File\Exception\FileException;
use Drupal\Core\File\FileSystemInterface; use Drupal\Core\File\FileSystemInterface;
use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Language\LanguageInterface; use Drupal\Core\Language\LanguageInterface;
...@@ -418,13 +419,23 @@ function xmlsitemap_sitemap_get_file(XmlSitemapInterface $sitemap, $chunk = 'ind ...@@ -418,13 +419,23 @@ function xmlsitemap_sitemap_get_file(XmlSitemapInterface $sitemap, $chunk = 'ind
* *
* @param \Drupal\xmlsitemap\XmlSitemapInterface $sitemap * @param \Drupal\xmlsitemap\XmlSitemapInterface $sitemap
* The XML sitemap object. * The XML sitemap object.
*
* @return int
* Maximum file size in the directory.
*/ */
function xmlsitemap_sitemap_get_max_filesize(XmlSitemapInterface $sitemap) { function xmlsitemap_sitemap_get_max_filesize(XmlSitemapInterface $sitemap) {
$dir = xmlsitemap_get_directory($sitemap); $dir = xmlsitemap_get_directory($sitemap);
$sitemap->setMaxFileSize(0); $sitemap->setMaxFileSize(0);
/** @var \Drupal\Core\File\FileSystemInterface $file_system */ /** @var \Drupal\Core\File\FileSystemInterface $file_system */
$file_system = \Drupal::service('file_system'); $file_system = \Drupal::service('file_system');
foreach ($file_system->scanDirectory($dir, '/\.xml$/') as $file) { try {
$files = $file_system->scanDirectory($dir, '/\.xml$/');
}
catch (FileException $e) {
// Ignore and return empty array for BC.
$files = [];
}
foreach ($files as $file) {
$sitemap->setMaxFileSize(max($sitemap->getMaxFileSize(), filesize($file->uri))); $sitemap->setMaxFileSize(max($sitemap->getMaxFileSize(), filesize($file->uri)));
} }
return $sitemap->getMaxFileSize(); return $sitemap->getMaxFileSize();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment