PageRenderTime 32ms CodeModel.GetById 7ms RepoModel.GetById 0ms app.codeStats 0ms

/core/CronArchive/FixedSiteIds.php

https://github.com/CodeYellowBV/piwik
PHP | 68 lines | 38 code | 13 blank | 17 comment | 3 complexity | dbbb847c1dff811c833b3d1836e4f475 MD5 | raw file
Possible License(s): LGPL-3.0, JSON, MIT, GPL-3.0, LGPL-2.1, GPL-2.0, AGPL-1.0, BSD-2-Clause, BSD-3-Clause
  1. <?php
  2. /**
  3. * Piwik - free/libre analytics platform
  4. *
  5. * @link http://piwik.org
  6. * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
  7. *
  8. */
  9. namespace Piwik\CronArchive;
  10. use Piwik\CronArchive;
  11. class FixedSiteIds
  12. {
  13. private $siteIds = array();
  14. private $index = -1;
  15. public function __construct($websiteIds)
  16. {
  17. if (!empty($websiteIds)) {
  18. $this->siteIds = $websiteIds;
  19. }
  20. }
  21. public function getInitialSiteIds()
  22. {
  23. return $this->siteIds;
  24. }
  25. /**
  26. * Get the number of total websites that needs to be processed.
  27. *
  28. * @return int
  29. */
  30. public function getNumSites()
  31. {
  32. return count($this->siteIds);
  33. }
  34. /**
  35. * Get the number of already processed websites. All websites were processed by the current archiver.
  36. *
  37. * @return int
  38. */
  39. public function getNumProcessedWebsites()
  40. {
  41. $numProcessed = $this->index + 1;
  42. if ($numProcessed > $this->getNumSites()) {
  43. return $this->getNumSites();
  44. }
  45. return $numProcessed;
  46. }
  47. public function getNextSiteId()
  48. {
  49. $this->index++;
  50. if (!empty($this->siteIds[$this->index])) {
  51. return $this->siteIds[$this->index];
  52. }
  53. return null;
  54. }
  55. }