php-sitemap icon indicating copy to clipboard operation
php-sitemap copied to clipboard

ImageSitemap accommulatedFileSize not recalculated

Open njentit opened this issue 8 years ago • 3 comments

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.

njentit avatar Jul 03 '16 11:07 njentit

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

nilportugues avatar Jul 03 '16 11:07 nilportugues

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 avatar Jul 03 '16 11:07 njentit

@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.

nilportugues avatar Jul 03 '16 11:07 nilportugues