Skip to content

Commit

Permalink
refs #3786 make sure a website is set in case only one website is req…
Browse files Browse the repository at this point in the history
…uested
  • Loading branch information
tsteur committed Oct 29, 2013
1 parent 021ef62 commit a841abc
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions plugins/MultiSites/API.php
Expand Up @@ -159,9 +159,9 @@ public function getOne($idSite, $period, $date, $segment = false, $_restrictSite
);
}

private function buildDataTable($sites, $period, $date, $segment, $_restrictSitesToLogin, $enhanced, $multipleWebsitesRequested)
private function buildDataTable($idSitesOrIdSite, $period, $date, $segment, $_restrictSitesToLogin, $enhanced, $multipleWebsitesRequested)
{
$allWebsitesRequested = ($sites == 'all');
$allWebsitesRequested = ($idSitesOrIdSite == 'all');
if ($allWebsitesRequested) {
if (Piwik::isUserIsSuperUser()
// Hack: when this API function is called as a Scheduled Task, Super User status is enforced.
Expand All @@ -179,9 +179,15 @@ private function buildDataTable($sites, $period, $date, $segment, $_restrictSite
}
}

if ($allWebsitesRequested) {
$sitesToProblablyAdd = Site::$infoSites;
} else {
$sitesToProblablyAdd = array(APISitesManager::getInstance()->getSiteFromId($idSitesOrIdSite));
}

// build the archive type used to query archive data
$archive = Archive::build(
$sites,
$idSitesOrIdSite,
$period,
$date,
$segment,
Expand Down Expand Up @@ -215,7 +221,7 @@ private function buildDataTable($sites, $period, $date, $segment, $_restrictSite
if (!($dataTable instanceof DataTable\Map)
&& $dataTable->getRowsCount() > 0
) {
$firstSite = is_array($sites) ? reset($sites) : $sites;
$firstSite = is_array($idSitesOrIdSite) ? reset($idSitesOrIdSite) : $idSitesOrIdSite;

$firstDataTableRow = $dataTable->getFirstRow();
$firstDataTableRow->setColumn('label', $firstSite);
Expand All @@ -224,10 +230,10 @@ private function buildDataTable($sites, $period, $date, $segment, $_restrictSite

if ($dataTable instanceof DataTable\Map) {
foreach ($dataTable->getDataTables() as $table) {
$this->addMissingWebsites($table, $fieldsToGet);
$this->addMissingWebsites($table, $fieldsToGet, $sitesToProblablyAdd);
}
} else {
$this->addMissingWebsites($dataTable, $fieldsToGet);
$this->addMissingWebsites($dataTable, $fieldsToGet, $sitesToProblablyAdd);
}

// calculate total visits/actions/revenue
Expand All @@ -243,7 +249,7 @@ private function buildDataTable($sites, $period, $date, $segment, $_restrictSite
// put there is put directly in DataTable::metadata.
$dataTable->setMetadata(self::getLastPeriodMetadataName('date'), $lastPeriod);
}
$pastArchive = Archive::build($sites, $period, $strLastDate, $segment, $_restrictSitesToLogin);
$pastArchive = Archive::build($idSitesOrIdSite, $period, $strLastDate, $segment, $_restrictSitesToLogin);
$pastData = $pastArchive->getDataTableFromNumeric($fieldsToGet);

if ($pastData instanceof DataTable\Map
Expand Down Expand Up @@ -480,16 +486,17 @@ private static function getLastPeriodMetadataName($name)
/**
* @param $dataTable
* @param $fieldsToGet
* @param $sitesToProblablyAdd
*/
private function addMissingWebsites($dataTable, $fieldsToGet)
private function addMissingWebsites($dataTable, $fieldsToGet, $sitesToProblablyAdd)
{
$siteIdsInDataTable = array();
foreach ($dataTable->getRows() as $row) {
/** @var DataTable\Row $row */
$siteIdsInDataTable[] = $row->getColumn('label');
}

foreach (Site::$infoSites as $site) {
foreach ($sitesToProblablyAdd as $site) {
if (!in_array($site['idsite'], $siteIdsInDataTable)) {
$siteRow = array_combine($fieldsToGet, array_pad(array(), count($fieldsToGet), 0));
$siteRow['label'] = (int)$site['idsite'];
Expand Down

0 comments on commit a841abc

Please sign in to comment.