Skip to content
This repository was archived by the owner on Jul 19, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions Commands/MigrateSite.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,14 @@ protected function configure()

protected function execute(InputInterface $input, OutputInterface $output)
{
$self = $this;

// Set memory limit to off
@ini_set('memory_limit', -1);
Piwik::doAsSuperUser(function() use ($input, $output){
Piwik::doAsSuperUser(function() use ($input, $output, $self){
$settings = new MigratorSettings();
$settings->idSite = $input->getArgument('idSite');
$settings->site = $this->getSite($settings->idSite);
$settings->site = $self->getSite($settings->idSite);
$settings->dateFrom = $input->getOption('date-from') ? new \DateTime($input->getOption('date-from')) : null;
$settings->dateTo = $input->getOption('date-to') ? new \DateTime($input->getOption('date-to')) : null;
$settings->skipArchiveData = $input->getOption('skip-archive-data');
Expand All @@ -73,7 +75,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$config = Db::getDatabaseConfig();
$startTime = microtime(true);

$this->createTargetDatabaseConfig($input, $output, $config);
$self->createTargetDatabaseConfig($input, $output, $config);

$tmpConfig = $config;
$sourceDb = Db::get();
Expand Down Expand Up @@ -103,7 +105,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
}


protected function getSite($idSite)
public function getSite($idSite)
{
if (!Site::getSite($idSite)) {
throw new \InvalidArgumentException('idSite is not a valid, no such site found');
Expand All @@ -115,7 +117,7 @@ protected function getSite($idSite)
);
}

private function createTargetDatabaseConfig(InputInterface $input, OutputInterface $output, &$config)
public function createTargetDatabaseConfig(InputInterface $input, OutputInterface $output, &$config)
{
$notNullValidator = function ($answer) {
if (strlen(trim($answer)) == 0) {
Expand Down
7 changes: 5 additions & 2 deletions Migrator/ActionMigrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,15 @@ public function ensureActionIsMigrated($idAction)

public function getNewId($idAction)
{
if($idAction == null || $idAction < 1){
return $idAction;
}

if ($this->ensureActionIsMigrated($idAction)) {
return $this->idMap[$idAction];
} else {
return 0;
throw new \InvalidArgumentException('Id ' . $idAction . ' not found in ' . __CLASS__);
}

}

/**
Expand Down
4 changes: 0 additions & 4 deletions Migrator/ConversionItemMigrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,6 @@ protected function translateRow(&$row)
$row['idvisit'] = $this->visitMigrator->getNewId($row['idvisit']);

foreach ($this->actionsToTranslate as $translationKey) {
if ($row[$translationKey] == 0) {
continue;
}

$row[$translationKey] = $this->actionMigrator->getNewId($row[$translationKey]);
}
}
Expand Down
8 changes: 1 addition & 7 deletions Migrator/ConversionMigrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,7 @@ protected function translateRow(&$row)
$row['idlink_va'] = $this->linkVisitActionMigrator->getNewId($row['idlink_va']);
}

if ($row['idaction_url']) {
$row['idaction_url'] = $this->actionMigrator->getNewId(
$row['idaction_url']
);
} else {
$row['idaction_url'] = 0;
}
$row['idaction_url'] = $this->actionMigrator->getNewId( $row['idaction_url']);
}

/**
Expand Down
6 changes: 6 additions & 0 deletions Test/ActionMigratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,12 @@ public function test_loadExistingActions()
$this->assertEquals($this->dummyExistingActions, $this->actionMigrator->getExistingActions());
}

public function test_getNewIdSpecialActionsIds(){
$this->assertNull($this->actionMigrator->getNewId(null));
$this->assertEquals(0, $this->actionMigrator->getNewId(0));
$this->assertEquals(-1, $this->actionMigrator->getNewId(-1));
}

protected function setupEnsureActionIsMigratedMigrationTest($action)
{
$this->setupDbHelperGetAdapter($this->fromDbHelper);
Expand Down
2 changes: 1 addition & 1 deletion Test/ConversionItemMigratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public function test_migrateConversionItems()

$this->siteMigrator->expects($this->once())->method('getNewId')->with(1)->willReturn(2);
$this->visitMigrator->expects($this->once())->method('getNewId')->with(3)->willReturn(4);
$this->actionMigrator->expects($this->exactly(6))->method('getNewId')->will(
$this->actionMigrator->expects($this->exactly(7))->method('getNewId')->will(
$this->onConsecutiveCalls(2, 4, 6, 8, 12, 14, 16, 18, 20)
);

Expand Down