UrlRewriteBunchReplacer.php 852 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\CatalogUrlRewrite\Model;
  7. use Magento\UrlRewrite\Model\UrlPersistInterface;
  8. class UrlRewriteBunchReplacer
  9. {
  10. /**
  11. * @var UrlPersistInterface
  12. */
  13. private $urlPersist;
  14. /**
  15. * @param UrlPersistInterface $urlPersist
  16. */
  17. public function __construct(UrlPersistInterface $urlPersist)
  18. {
  19. $this->urlPersist = $urlPersist;
  20. }
  21. /**
  22. * Do Bunch Replace, with default bunch value = 10000
  23. *
  24. * @param array $urls
  25. * @param int $bunchSize
  26. * @return void
  27. */
  28. public function doBunchReplace(array $urls, $bunchSize = 10000)
  29. {
  30. foreach (array_chunk($urls, $bunchSize) as $urlsBunch) {
  31. $this->urlPersist->replace($urlsBunch);
  32. }
  33. }
  34. }