php-sitemap
php-sitemap copied to clipboard
ImageSitemap accommulatedFileSize not recalculated
accommulatedFileSize need to be recalculated after opening new file inside createAdditionalSitemapFile. Overriding method createAdditionalSitemapFile inside ImageSitemap.php currently does not recalculate accommulatedFileSize, this cause new file produced on every call to writeXmlBody after first maxFileSize exceeded.
Are you sure? There's a test for this already and it's passing:
https://github.com/nilportugues/php-sitemap/blob/master/tests/SitemapTest.php#L101
Yes on my code, i'm creating ImageSitemap with 50000 url with maxFileSize 10Mb, when maxFileSize not used it create one 14Mb file, but when max size applied it's producing one 10Mb file and large number of small file. My current work arround solve my problem by adding recalculation inside ImageSitemap class on method createAdditionalSitemapFile https://github.com/nilportugues/php-sitemap/blob/master/src/ImageSitemap.php#L120 function `protected function createAdditionalSitemapFile($item, $url = '') { $this->appendToFile("\n"); parent::build(); $this->totalFiles++;
$this->createNewFilePointer();
$xmlData = $this->getHeader()
. "<url>\n<loc>{$url}</loc>\n"
. $item;
$this->appendToFile($xmlData);
$this->totalItems = 1;
$this->imageCount = 0;
$this->accommulatedFileSize = $this->getStringSize($xmlData);
}`
This will produce one 10Mb file and one 4mb file on my use case.
@njentit mind creating a pull request and running this case as a tests? If all tests still pass I'm certain it's a bug and you just solved it.