Skip to content

Commit

Permalink
Refs #4278 Cleanup these Parameters objects
Browse files Browse the repository at this point in the history
  • Loading branch information
mattab committed Nov 5, 2013
1 parent 74b8175 commit 16fb491
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 125 deletions.
7 changes: 2 additions & 5 deletions core/Archive.php
Expand Up @@ -249,10 +249,7 @@ public static function factory(Segment $segment, array $periods, array $idSites,
$forceIndexedByDate = true;
}

$params = new Parameters();
$params->setIdSites($idSites);
$params->setPeriods($periods);
$params->setSegment($segment);
$params = new Parameters($idSites, $periods, $segment);

return new Archive($params, $forceIndexedBySite, $forceIndexedByDate);
}
Expand Down Expand Up @@ -610,7 +607,7 @@ private function cacheArchiveIdsAfterLaunching($archiveGroups, $plugins)
continue;
}

$parameters = new ArchiveProcessor\Parameters($period, $site, $this->params->getSegment());
$parameters = new ArchiveProcessor\Parameters($site, $period, $this->params->getSegment());
$processing = new ArchiveProcessor\Loader($parameters);

// process for each plugin as well
Expand Down
14 changes: 3 additions & 11 deletions core/Archive/Parameters.php
Expand Up @@ -42,8 +42,10 @@ public function getSegment()
return $this->segment;
}

public function setSegment(Segment $segment)
public function __construct($idSites, $periods, Segment $segment)
{
$this->idSites = $this->getAsNonEmptyArray($idSites, 'idSites');
$this->periods = $this->getAsNonEmptyArray($periods, 'periods');
$this->segment = $segment;
}

Expand All @@ -52,21 +54,11 @@ public function getPeriods()
return $this->periods;
}

public function setPeriods($periods)
{
$this->periods = $this->getAsNonEmptyArray($periods, 'periods');
}

public function getIdSites()
{
return $this->idSites;
}

public function setIdSites($idSites)
{
$this->idSites = $this->getAsNonEmptyArray($idSites, 'idSites');
}

private function getAsNonEmptyArray($array, $paramName)
{
if (!is_array($array)) {
Expand Down
122 changes: 61 additions & 61 deletions core/ArchiveProcessor.php
Expand Up @@ -137,67 +137,6 @@ public function getLogAggregator()
return $this->logAggregator;
}

/**
* Caches multiple numeric records in the archive for this processor's site, period
* and segment.
*
* @param array $numericRecords A name-value mapping of numeric values that should be
* archived, eg,
* ```
* array('Referrers_distinctKeywords' => 23, 'Referrers_distinctCampaigns' => 234)
* ```
* @api
*/
public function insertNumericRecords($numericRecords)
{
foreach ($numericRecords as $name => $value) {
$this->insertNumericRecord($name, $value);
}
}

/**
* Caches a single numeric record in the archive for this processor's site, period and
* segment.
*
* Numeric values are not inserted if they equal 0.
*
* @param string $name The name of the numeric value, eg, `'Referrers_distinctKeywords'`.
* @param float $value The numeric value.
* @api
*/
public function insertNumericRecord($name, $value)
{
$value = round($value, 2);
$this->archiveWriter->insertRecord($name, $value);
}

public function getNumberOfVisits()
{
return $this->numberOfVisits;
}

public function getNumberOfVisitsConverted()
{
return $this->numberOfVisitsConverted;
}

/**
* Caches one or more blob records in the archive for this processor's site, period
* and segment.
*
* @param string $name The name of the record, eg, 'Referrers_type'.
* @param string|array $values A blob string or an array of blob strings. If an array
* is used, the first element in the array will be inserted
* with the `$name` name. The others will be inserted with
* `$name . '_' . $index` as the record name (where $index is
* the index of the blob record in `$values`).
* @api
*/
public function insertBlobRecord($name, $values)
{
$this->archiveWriter->insertBlobRecord($name, $values);
}

/**
* Array of (column name before => column name renamed) of the columns for which sum operation is invalid.
* These columns will be renamed as per this mapping.
Expand Down Expand Up @@ -301,6 +240,67 @@ public function aggregateNumericMetrics($columns, $operationToApply = false)
return $results;
}

public function getNumberOfVisits()
{
return $this->numberOfVisits;
}

public function getNumberOfVisitsConverted()
{
return $this->numberOfVisitsConverted;
}

/**
* Caches multiple numeric records in the archive for this processor's site, period
* and segment.
*
* @param array $numericRecords A name-value mapping of numeric values that should be
* archived, eg,
* ```
* array('Referrers_distinctKeywords' => 23, 'Referrers_distinctCampaigns' => 234)
* ```
* @api
*/
public function insertNumericRecords($numericRecords)
{
foreach ($numericRecords as $name => $value) {
$this->insertNumericRecord($name, $value);
}
}

/**
* Caches a single numeric record in the archive for this processor's site, period and
* segment.
*
* Numeric values are not inserted if they equal 0.
*
* @param string $name The name of the numeric value, eg, `'Referrers_distinctKeywords'`.
* @param float $value The numeric value.
* @api
*/
public function insertNumericRecord($name, $value)
{
$value = round($value, 2);
$this->archiveWriter->insertRecord($name, $value);
}

/**
* Caches one or more blob records in the archive for this processor's site, period
* and segment.
*
* @param string $name The name of the record, eg, 'Referrers_type'.
* @param string|array $values A blob string or an array of blob strings. If an array
* is used, the first element in the array will be inserted
* with the `$name` name. The others will be inserted with
* `$name . '_' . $index` as the record name (where $index is
* the index of the blob record in `$values`).
* @api
*/
public function insertBlobRecord($name, $values)
{
$this->archiveWriter->insertBlobRecord($name, $values);
}

/**
* This method selects all DataTables that have the name $name over the period.
* All these DataTables are then added together, and the resulting DataTable is returned.
Expand Down
88 changes: 43 additions & 45 deletions core/ArchiveProcessor/Loader.php
Expand Up @@ -24,7 +24,7 @@
use Piwik\Site;

/**
*
* This class manages the ArchiveProcessor
*/
class Loader
{
Expand Down Expand Up @@ -88,7 +88,6 @@ protected function setNumberOfVisits($visitsMetricCached, $convertedVisitsMetric
}
}


public function getNumberOfVisits()
{
return $this->visitsMetricCached;
Expand Down Expand Up @@ -253,19 +252,6 @@ protected function aggregateMultipleVisitMetrics(ArchiveProcessor $archiveProces
return $metrics;
}

protected static function determineIfArchivePermanent(Date $dateEnd)
{
$now = time();
$endTimestampUTC = strtotime($dateEnd->getDateEndUTC());
if ($endTimestampUTC <= $now) {
// - if the period we are looking for is finished, we look for a ts_archived that
// is greater than the last day of the archive
return $endTimestampUTC;
}
return false;
}


/**
* Returns the minimum archive processed datetime to look at. Only public for tests.
*
Expand All @@ -285,6 +271,18 @@ protected function getMinTimeArchiveProcessed()
return Rules::getMinTimeProcessedForTemporaryArchive($this->params->getDateStart(), $this->params->getPeriod(), $this->params->getSegment(), $this->params->getSite());
}

protected static function determineIfArchivePermanent(Date $dateEnd)
{
$now = time();
$endTimestampUTC = strtotime($dateEnd->getDateEndUTC());
if ($endTimestampUTC <= $now) {
// - if the period we are looking for is finished, we look for a ts_archived that
// is greater than the last day of the archive
return $endTimestampUTC;
}
return false;
}

protected function isArchiveTemporary()
{
if (is_null($this->temporaryArchive)) {
Expand All @@ -293,6 +291,14 @@ protected function isArchiveTemporary()
return $this->temporaryArchive;
}

/**
* @return bool
*/
protected function isDayArchive()
{
return $this->params->getPeriod()->getLabel() == 'day';
}

/**
* @param $requestedPlugin
*/
Expand All @@ -314,6 +320,28 @@ protected function logStatusDebug($requestedPlugin)
);
}

/**
* This methods reads the subperiods if necessary,
* and computes the archive of the current period.
*/
protected function compute($archiveProcessor)
{
$archivers = $this->getPluginArchivers();

foreach($archivers as $pluginName => $archiverClass) {
/** @var Archiver $archiver */
$archiver = new $archiverClass($archiveProcessor);

if($this->shouldProcessReportsForPlugin($pluginName)) {
if($this->isDayArchive()) {
$archiver->aggregateDayReport();
} else {
$archiver->aggregateMultipleReports();
}
}
}
}

/**
* @var Archiver[] $archivers
*/
Expand Down Expand Up @@ -348,36 +376,6 @@ private static function getPluginArchiverClass($pluginName)
return false;
}

/**
* @return bool
*/
protected function isDayArchive()
{
return $this->params->getPeriod()->getLabel() == 'day';
}

/**
* This methods reads the subperiods if necessary,
* and computes the archive of the current period.
*/
protected function compute($archiveProcessor)
{
$archivers = $this->getPluginArchivers();

foreach($archivers as $pluginName => $archiverClass) {
/** @var Archiver $archiver */
$archiver = new $archiverClass($archiveProcessor);

if($this->shouldProcessReportsForPlugin($pluginName)) {
if($this->isDayArchive()) {
$archiver->aggregateDayReport();
} else {
$archiver->aggregateMultipleReports();
}
}
}
}

/**
* Whether the specified plugin's reports should be archived
* @param string $pluginName
Expand Down
2 changes: 1 addition & 1 deletion core/ArchiveProcessor/Parameters.php
Expand Up @@ -37,7 +37,7 @@ class Parameters
*/
private $segment = null;

public function __construct(Period $period, Site $site, Segment $segment)
public function __construct(Site $site, Period $period, Segment $segment)
{
$this->period = $period;
$this->site = $site;
Expand Down
2 changes: 1 addition & 1 deletion plugins/Transitions/API.php
Expand Up @@ -76,7 +76,7 @@ public function getTransitionsForAction($actionName, $actionType, $idSite, $peri
$segment = new Segment($segment, $idSite);
$site = new Site($idSite);
$period = Period::factory($period, $date);
$params = new ArchiveProcessor\Parameters($period, $site, $segment);
$params = new ArchiveProcessor\Parameters($site, $period, $segment);
$logAggregator = new LogAggregator($params);

// prepare the report
Expand Down
2 changes: 1 addition & 1 deletion tests/PHPUnit/Core/ArchiveProcessingTest.php
Expand Up @@ -86,7 +86,7 @@ private function _createArchiveProcessor($periodLabel, $dateLabel, $siteTimezone
$period = Period::factory($periodLabel, $date);
$segment = new Segment('', $site->getId());

$params = new ArchiveProcessor\Parameters($period, $site, $segment);
$params = new ArchiveProcessor\Parameters($site, $period, $segment);
return new \ArchiveProcessorTest($params);
}

Expand Down

0 comments on commit 16fb491

Please sign in to comment.