-
Notifications
You must be signed in to change notification settings - Fork 14
/
RecordInserter.php
45 lines (41 loc) · 1.37 KB
/
RecordInserter.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?php
/**
* Piwik - free/libre analytics platform
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/
namespace Piwik\Plugins\GoogleAnalyticsImporter;
use Piwik\DataAccess\ArchiveWriter;
use Piwik\DataTable;
use Piwik\Metrics;
class RecordInserter
{
/**
* @var ArchiveWriter
*/
private $archiveWriter;
public function __construct(ArchiveWriter $writer)
{
$this->archiveWriter = $writer;
}
public function insertRecord($recordName, DataTable $record, $maximumRowsInDataTable = null, $maximumRowsInSubDataTable = null, $columnToSortByBeforeTruncation = null)
{
$record->setMetadata(\Piwik\Plugins\GoogleAnalyticsImporter\RecordImporter::IS_IMPORTED_FROM_GOOGLE_METADATA_NAME, 1);
$blob = $record->getSerialized($maximumRowsInDataTable, $maximumRowsInSubDataTable, $columnToSortByBeforeTruncation);
$this->insertBlobRecord($recordName, $blob);
}
public function insertBlobRecord($name, $values)
{
$this->archiveWriter->insertBlobRecord($name, $values);
}
public function insertNumericRecords(array $values)
{
foreach ($values as $name => $value) {
if (is_numeric($name)) {
$name = Metrics::getReadableColumnName($name);
}
$this->archiveWriter->insertRecord($name, $value);
}
}
}