diff options
-rw-r--r-- | core/API/DataTableManipulator.php | 3 | ||||
-rw-r--r-- | core/Archive.php | 2 | ||||
-rw-r--r-- | core/Archive/DataTableFactory.php | 7 | ||||
-rw-r--r-- | core/DataTable/Renderer/Rss.php | 5 | ||||
-rw-r--r-- | core/Site.php | 13 | ||||
-rw-r--r-- | plugins/API/ProcessedReport.php | 3 | ||||
-rw-r--r-- | plugins/Actions/API.php | 4 | ||||
-rw-r--r-- | plugins/CoreVisualizations/JqplotDataGenerator/Evolution.php | 7 | ||||
-rwxr-xr-x | plugins/DBStats/MySQLMetadataProvider.php | 3 | ||||
-rw-r--r-- | plugins/Goals/API.php | 4 | ||||
-rw-r--r-- | plugins/ImageGraph/API.php | 3 | ||||
-rw-r--r-- | tests/PHPUnit/Core/DataTableTest.php | 2 |
12 files changed, 38 insertions, 18 deletions
diff --git a/core/API/DataTableManipulator.php b/core/API/DataTableManipulator.php index b85a28a707..f85b653200 100644 --- a/core/API/DataTableManipulator.php +++ b/core/API/DataTableManipulator.php @@ -11,6 +11,7 @@ namespace Piwik\API; use Exception; +use Piwik\Archive\DataTableFactory; use Piwik\DataTable\Row; use Piwik\DataTable; use Piwik\Period\Range; @@ -119,7 +120,7 @@ abstract class DataTableManipulator $request['idSubtable'] = $idSubTable; if ($dataTable) { - $period = $dataTable->getMetadata('period'); + $period = $dataTable->getMetadata(DataTableFactory::TABLE_METADATA_PERIOD_INDEX); if ($period instanceof Range) { $request['date'] = $period->getDateStart() . ',' . $period->getDateEnd(); } else { diff --git a/core/Archive.php b/core/Archive.php index 1f9d571fb8..f1627a8eb1 100644 --- a/core/Archive.php +++ b/core/Archive.php @@ -712,7 +712,7 @@ class Archive * whether archiving should be launched based on whether $this->idarchives has a * an entry for a specific 'done' flag. * - * If this function is not called, then periods with no visits will not add + * If this function is not called, then periods with no visits will not add * entries to the cache. If the archive is used again, SQL will be executed to * try and find the archive IDs even though we know there are none. */ diff --git a/core/Archive/DataTableFactory.php b/core/Archive/DataTableFactory.php index ab6cd5e568..a053c6b09c 100644 --- a/core/Archive/DataTableFactory.php +++ b/core/Archive/DataTableFactory.php @@ -80,6 +80,9 @@ class DataTableFactory */ private $defaultRow; + const TABLE_METADATA_SITE_INDEX = 'site'; + const TABLE_METADATA_PERIOD_INDEX = 'period'; + /** * Constructor. */ @@ -383,8 +386,8 @@ class DataTableFactory { $periods = $this->periods; $table->filter(function ($table) use ($periods) { - $table->setMetadata('site', new Site($table->getMetadata('site'))); - $table->setMetadata('period', $periods[$table->getMetadata('period')]); + $table->setMetadata(self::TABLE_METADATA_SITE_INDEX, new Site($table->getMetadata(self::TABLE_METADATA_SITE_INDEX))); + $table->setMetadata(self::TABLE_METADATA_PERIOD_INDEX, $periods[$table->getMetadata(self::TABLE_METADATA_PERIOD_INDEX)]); }); } diff --git a/core/DataTable/Renderer/Rss.php b/core/DataTable/Renderer/Rss.php index dee117a90f..d9eadf9afd 100644 --- a/core/DataTable/Renderer/Rss.php +++ b/core/DataTable/Renderer/Rss.php @@ -11,6 +11,7 @@ namespace Piwik\DataTable\Renderer; use Exception; +use Piwik\Archive; use Piwik\Common; use Piwik\DataTable\Renderer; use Piwik\DataTable; @@ -75,8 +76,8 @@ class Rss extends Renderer $moreRecentFirst = array_reverse($table->getDataTables(), true); foreach ($moreRecentFirst as $date => $subtable) { /** @var DataTable $subtable */ - $timestamp = $subtable->getMetadata('period')->getDateStart()->getTimestamp(); - $site = $subtable->getMetadata('site'); + $timestamp = $subtable->getMetadata(Archive\DataTableFactory::TABLE_METADATA_PERIOD_INDEX)->getDateStart()->getTimestamp(); + $site = $subtable->getMetadata(Archive\DataTableFactory::TABLE_METADATA_SITE_INDEX); $pudDate = date('r', $timestamp); diff --git a/core/Site.php b/core/Site.php index 9d14ead63c..bcbf0572ff 100644 --- a/core/Site.php +++ b/core/Site.php @@ -72,6 +72,15 @@ class Site } /** + * @param $idsite + * @param $site + */ + protected static function setSite($idsite, $site) + { + self::$infoSites[$idsite] = $site; + } + + /** * Sets the cached Site data with a non-associated array of site data. * * @param array $sites The array of sites data. eg, @@ -91,6 +100,7 @@ class Site self::setSites($sitesById); } + /** * Returns a string representation of the site this instance references. * @@ -313,7 +323,8 @@ class Site $idsite = (int)$idsite; if (!isset(self::$infoSites[$idsite])) { - self::$infoSites[$idsite] = API::getInstance()->getSiteFromId($idsite); + $site = API::getInstance()->getSiteFromId($idsite); + self::setSite($idsite, $site); } return self::$infoSites[$idsite][$field]; diff --git a/plugins/API/ProcessedReport.php b/plugins/API/ProcessedReport.php index 1daa576323..d502c297ef 100644 --- a/plugins/API/ProcessedReport.php +++ b/plugins/API/ProcessedReport.php @@ -12,6 +12,7 @@ namespace Piwik\Plugins\API; use Exception; use Piwik\API\Request; +use Piwik\Archive\DataTableFactory; use Piwik\Common; use Piwik\DataTable\Row; use Piwik\DataTable\Simple; @@ -421,7 +422,7 @@ class ProcessedReport list($enhancedSimpleDataTable, $rowMetadata) = $this->handleSimpleDataTable($idSite, $simpleDataTable, $columns, $hasDimension, $showRawMetrics); $enhancedSimpleDataTable->setAllTableMetadata($simpleDataTable->getAllTableMetadata()); - $period = $simpleDataTable->getMetadata('period')->getLocalizedLongString(); + $period = $simpleDataTable->getMetadata(DataTableFactory::TABLE_METADATA_PERIOD_INDEX)->getLocalizedLongString(); $newReport->addTable($enhancedSimpleDataTable, $period); $rowsMetadata->addTable($rowMetadata, $period); } diff --git a/plugins/Actions/API.php b/plugins/Actions/API.php index 0bd3aa66d6..0ed86ca251 100644 --- a/plugins/Actions/API.php +++ b/plugins/Actions/API.php @@ -351,11 +351,11 @@ class API extends \Piwik\Plugin\API foreach ($customVariableDatatables as $key => $customVariableTableForDate) { // we do not enter the IF, in the case idSite=1,3 AND period=day&date=datefrom,dateto, if ($customVariableTableForDate instanceof DataTable - && $customVariableTableForDate->getMetadata('period') + && $customVariableTableForDate->getMetadata(Archive\DataTableFactory::TABLE_METADATA_PERIOD_INDEX) ) { $row = $customVariableTableForDate->getRowFromLabel($customVarNameToLookFor); if ($row) { - $dateRewrite = $customVariableTableForDate->getMetadata('period')->getDateStart()->toString(); + $dateRewrite = $customVariableTableForDate->getMetadata(Archive\DataTableFactory::TABLE_METADATA_PERIOD_INDEX)->getDateStart()->toString(); $idSubtable = $row->getIdSubDataTable(); $categories = APICustomVariables::getInstance()->getCustomVariablesValuesFromNameId($idSite, $period, $dateRewrite, $idSubtable, $segment); $dataTable->addTable($categories, $key); diff --git a/plugins/CoreVisualizations/JqplotDataGenerator/Evolution.php b/plugins/CoreVisualizations/JqplotDataGenerator/Evolution.php index 14ac12d496..1a97bae80d 100644 --- a/plugins/CoreVisualizations/JqplotDataGenerator/Evolution.php +++ b/plugins/CoreVisualizations/JqplotDataGenerator/Evolution.php @@ -11,6 +11,7 @@ namespace Piwik\Plugins\CoreVisualizations\JqplotDataGenerator; +use Piwik\Archive\DataTableFactory; use Piwik\Common; use Piwik\DataTable; use Piwik\DataTable\Row; @@ -40,7 +41,7 @@ class Evolution extends JqplotDataGenerator // the X label is extracted from the 'period' object in the table's metadata $xLabels = array(); foreach ($dataTable->getDataTables() as $metadataDataTable) { - $xLabels[] = $metadataDataTable->getMetadata('period')->getLocalizedShortString(); // eg. "Aug 2009" + $xLabels[] = $metadataDataTable->getMetadata(DataTableFactory::TABLE_METADATA_PERIOD_INDEX)->getLocalizedShortString(); // eg. "Aug 2009" } $units = $this->getUnitsForColumnsToDisplay(); @@ -75,12 +76,12 @@ class Evolution extends JqplotDataGenerator if ($this->isLinkEnabled()) { $idSite = Common::getRequestVar('idSite', null, 'int'); - $periodLabel = reset($dataTables)->getMetadata('period')->getLabel(); + $periodLabel = reset($dataTables)->getMetadata(DataTableFactory::TABLE_METADATA_PERIOD_INDEX)->getLabel(); $axisXOnClick = array(); $queryStringAsHash = $this->getQueryStringAsHash(); foreach ($dataTable->getDataTables() as $idDataTable => $metadataDataTable) { - $dateInUrl = $metadataDataTable->getMetadata('period')->getDateStart(); + $dateInUrl = $metadataDataTable->getMetadata(DataTableFactory::TABLE_METADATA_PERIOD_INDEX)->getDateStart(); $parameters = array( 'idSite' => $idSite, 'period' => $periodLabel, diff --git a/plugins/DBStats/MySQLMetadataProvider.php b/plugins/DBStats/MySQLMetadataProvider.php index fe7d722fd4..a7d2bd95bc 100755 --- a/plugins/DBStats/MySQLMetadataProvider.php +++ b/plugins/DBStats/MySQLMetadataProvider.php @@ -230,8 +230,7 @@ class MySQLMetadataProvider // if option exists && !$forceCache, use the cached data, otherwise create the $cachedData = Option::get($dataTableOptionName); if ($cachedData !== false && !$forceCache) { - $table = new DataTable(); - $table->addRowsFromSerializedArray($cachedData); + $table = DataTable::fromSerializedArray($cachedData); } else { // otherwise, create data table & cache it $sql = "SELECT name as 'label', COUNT(*) as 'row_count'$extraCols FROM {$status['Name']} GROUP BY name"; diff --git a/plugins/Goals/API.php b/plugins/Goals/API.php index cde6e9317c..3e718604db 100644 --- a/plugins/Goals/API.php +++ b/plugins/Goals/API.php @@ -254,9 +254,9 @@ class API extends \Piwik\Plugin\API // we do not enter the IF // if case idSite=1,3 AND period=day&date=datefrom,dateto, if ($customVariableTableForDate instanceof DataTable - && $customVariableTableForDate->getMetadata('period') + && $customVariableTableForDate->getMetadata(Archive\DataTableFactory::TABLE_METADATA_PERIOD_INDEX) ) { - $dateRewrite = $customVariableTableForDate->getMetadata('period')->getDateStart()->toString(); + $dateRewrite = $customVariableTableForDate->getMetadata(Archive\DataTableFactory::TABLE_METADATA_PERIOD_INDEX)->getDateStart()->toString(); $row = $customVariableTableForDate->getRowFromLabel($customVarNameToLookFor); if ($row) { $idSubtable = $row->getIdSubDataTable(); diff --git a/plugins/ImageGraph/API.php b/plugins/ImageGraph/API.php index f6e703ebd4..a16167dd8c 100644 --- a/plugins/ImageGraph/API.php +++ b/plugins/ImageGraph/API.php @@ -11,6 +11,7 @@ namespace Piwik\Plugins\ImageGraph; use Exception; +use Piwik\Archive\DataTableFactory; use Piwik\Common; use Piwik\Filesystem; use Piwik\Period; @@ -439,7 +440,7 @@ class API extends \Piwik\Plugin\API } } - $rowId = $periodsData[$i]->getMetadata('period')->getLocalizedShortString(); + $rowId = $periodsData[$i]->getMetadata(DataTableFactory::TABLE_METADATA_PERIOD_INDEX)->getLocalizedShortString(); $abscissaSeries[] = Common::unsanitizeInputValue($rowId); } } diff --git a/tests/PHPUnit/Core/DataTableTest.php b/tests/PHPUnit/Core/DataTableTest.php index 0eee3c7a77..d112746730 100644 --- a/tests/PHPUnit/Core/DataTableTest.php +++ b/tests/PHPUnit/Core/DataTableTest.php @@ -527,6 +527,8 @@ class DataTableTest extends PHPUnit_Framework_TestCase $subsubtableAfter = new DataTable; $subsubtableAfter->addRowsFromSerializedArray($serialized[$idsubsubtable]); $this->assertEquals($subsubtable->getRows(), $subsubtableAfter->getRows()); + $this->assertEquals($subsubtable->getRows(), DataTable::fromSerializedArray($serialized[$idsubsubtable])->getRows()); + $this->assertTrue($subsubtable->getRowsCount() > 0); $this->assertEquals($table, Manager::getInstance()->getTable($idtable)); $this->assertEquals($subsubtable, Manager::getInstance()->getTable($idsubsubtable)); |