Performance
6 years ago
FixedSiteIds.php
6 years ago
SegmentArchivingRequestUrlProvider.php
6 years ago
SharedSiteIds.php
6 years ago
SitesToReprocessDistributedList.php
6 years ago
StopArchiverException.php
6 years ago
FixedSiteIds.php
66 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Piwik - free/libre analytics platform |
| 4 | * |
| 5 | * @link https://matomo.org |
| 6 | * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later |
| 7 | * |
| 8 | */ |
| 9 | namespace Piwik\CronArchive; |
| 10 | |
| 11 | |
| 12 | class FixedSiteIds |
| 13 | { |
| 14 | private $siteIds = array(); |
| 15 | private $index = -1; |
| 16 | |
| 17 | public function __construct($websiteIds) |
| 18 | { |
| 19 | if (!empty($websiteIds)) { |
| 20 | $this->siteIds = array_values($websiteIds); |
| 21 | } |
| 22 | } |
| 23 | |
| 24 | public function getInitialSiteIds() |
| 25 | { |
| 26 | return $this->siteIds; |
| 27 | } |
| 28 | |
| 29 | /** |
| 30 | * Get the number of total websites that needs to be processed. |
| 31 | * |
| 32 | * @return int |
| 33 | */ |
| 34 | public function getNumSites() |
| 35 | { |
| 36 | return count($this->siteIds); |
| 37 | } |
| 38 | |
| 39 | /** |
| 40 | * Get the number of already processed websites. All websites were processed by the current archiver. |
| 41 | * |
| 42 | * @return int |
| 43 | */ |
| 44 | public function getNumProcessedWebsites() |
| 45 | { |
| 46 | $numProcessed = $this->index + 1; |
| 47 | |
| 48 | if ($numProcessed > $this->getNumSites()) { |
| 49 | return $this->getNumSites(); |
| 50 | } |
| 51 | |
| 52 | return $numProcessed; |
| 53 | } |
| 54 | |
| 55 | public function getNextSiteId() |
| 56 | { |
| 57 | $this->index++; |
| 58 | |
| 59 | if (!empty($this->siteIds[$this->index])) { |
| 60 | return $this->siteIds[$this->index]; |
| 61 | } |
| 62 | |
| 63 | return null; |
| 64 | } |
| 65 | } |
| 66 |