Skip to content

Commit

Permalink
Making PHPCS changes
Browse files Browse the repository at this point in the history
  • Loading branch information
snake14 committed Oct 17, 2024
1 parent c93aa0b commit 96e7066
Show file tree
Hide file tree
Showing 22 changed files with 50 additions and 25 deletions.
3 changes: 2 additions & 1 deletion Commands/Migrate.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* Matomo - free/libre analytics platform
*
Expand Down Expand Up @@ -132,6 +133,6 @@ private function makeTargetDb()

private function confirmMigration($idSite): bool
{
return $this->askForConfirmation('<question>Are you sure you want to migrate the data for idSite '.(int) $idSite.'. (y/N)</question>');
return $this->askForConfirmation('<question>Are you sure you want to migrate the data for idSite ' . (int) $idSite . '. (y/N)</question>');
}
}
1 change: 1 addition & 0 deletions Db/BatchQuery.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* Matomo - free/libre analytics platform
*
Expand Down
1 change: 1 addition & 0 deletions Migration.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* Matomo - free/libre analytics platform
*
Expand Down
15 changes: 12 additions & 3 deletions Migrations.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* Matomo - free/libre analytics platform
*
Expand Down Expand Up @@ -41,7 +42,11 @@ public function migrate($migrations, Request $request, TargetDb $targetDb)
$this->log('Processed ' . $migration->getName());
}
} catch (\Exception $e) {
//Since php8, PDO::inTransaction() now reports the actual transaction state of the connection, rather than an approximation maintained by PDO. If a query that is subject to "implicit commit" is executed, PDO::inTransaction() will subsequently return false, as a transaction is no longer active
/**
* Since php8, PDO::inTransaction() now reports the actual transaction state of the connection, rather than
* an approximation maintained by PDO. If a query that is subject to "implicit commit" is executed,
* PDO::inTransaction() will subsequently return false, as a transaction is no longer active
*/
//inTransaction check fixes warning raised due to implicit commit change
if ($this->isInTransaction($targetDb)) {
$targetDb->rollBack();
Expand All @@ -51,7 +56,11 @@ public function migrate($migrations, Request $request, TargetDb $targetDb)
}
throw $e;
}
//Since php8, PDO::inTransaction() now reports the actual transaction state of the connection, rather than an approximation maintained by PDO. If a query that is subject to "implicit commit" is executed, PDO::inTransaction() will subsequently return false, as a transaction is no longer active
/**
* Since php8, PDO::inTransaction() now reports the actual transaction state of the connection, rather than an
* approximation maintained by PDO. If a query that is subject to "implicit commit" is executed,
* PDO::inTransaction() will subsequently return false, as a transaction is no longer active
*/
//inTransaction check fixes warning raised due to implicit commit change
if ($this->isInTransaction($targetDb)) {
$targetDb->commit();
Expand All @@ -72,7 +81,7 @@ public function onLog($callback)

private function isInTransaction($targetDb)
{
$inTransactionMethodExists = method_exists($targetDb->getDb()->getConnection(),'inTransaction');
$inTransactionMethodExists = method_exists($targetDb->getDb()->getConnection(), 'inTransaction');

return (!$inTransactionMethodExists || $targetDb->getDb()->getConnection()->inTransaction());
}
Expand Down
1 change: 1 addition & 0 deletions Migrations/AnnotationsMigration.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* Matomo - free/libre analytics platform
*
Expand Down
2 changes: 1 addition & 1 deletion Migrations/ArchiveMigration.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* Matomo - free/libre analytics platform
*
Expand All @@ -9,7 +10,6 @@
namespace Piwik\Plugins\Migration\Migrations;

use Piwik\Common;
use Piwik\Config;
use Piwik\DataAccess\ArchiveTableCreator;
use Piwik\Plugins\Migration\Db\BatchQuery;
use Piwik\Plugins\Migration\TargetDb;
Expand Down
3 changes: 2 additions & 1 deletion Migrations/BaseMigration.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* Matomo - free/libre analytics platform
*
Expand Down Expand Up @@ -33,7 +34,7 @@ abstract public function migrate(Request $request, TargetDb $targetDb);

protected function migrateEntities(Request $request, TargetDb $targetDb, $tableUnprefixed, $entityName, $unsetId = null, $idSiteColumnName = 'idsite')
{
$rows = Db::fetchAll('SELECT * FROM ' . Common::prefixTable($tableUnprefixed) . ' WHERE '.$idSiteColumnName.' = ?', array($request->sourceIdSite));
$rows = Db::fetchAll('SELECT * FROM ' . Common::prefixTable($tableUnprefixed) . ' WHERE ' . $idSiteColumnName . ' = ?', array($request->sourceIdSite));

$this->log(sprintf('Found %s %s', count($rows), $entityName));

Expand Down
1 change: 1 addition & 0 deletions Migrations/CustomDimensionMigration.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* Matomo - free/libre analytics platform
*
Expand Down
1 change: 1 addition & 0 deletions Migrations/GoalsMigration.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* Matomo - free/libre analytics platform
*
Expand Down
1 change: 1 addition & 0 deletions Migrations/LogActionMigration.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* Matomo - free/libre analytics platform
*
Expand Down
10 changes: 5 additions & 5 deletions Migrations/LogMigration.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* Matomo - free/libre analytics platform
*
Expand Down Expand Up @@ -41,7 +42,7 @@ public function migrate(Request $request, TargetDb $targetDb)

$loggedAt = array(0.05, 0.1, 0.2, 0.4, 0.6, 0.8, 0.9);

foreach ($batchQuery->generateQuery('SELECT * FROM ' . Common::prefixTable('log_visit') . ' WHERE idsite = ? ORDER BY idvisit ASC', array($request->sourceIdSite)) as $visitRows) {
foreach ($batchQuery->generateQuery('SELECT * FROM ' . Common::prefixTable('log_visit') . ' WHERE idsite = ? ORDER BY idvisit ASC', array($request->sourceIdSite)) as $visitRows) {
$count += count($visitRows);
$this->migrateVisits($visitRows, $request, $logActionMigration, $targetDb);

Expand Down Expand Up @@ -74,7 +75,7 @@ private function migrateVisits($visitRows, Request $request, LogActionMigration
$visitorIds = implode(',', $visitorIds);

$batchQuery = new BatchQuery();
foreach ($batchQuery->generateQuery('SELECT * FROM ' . Common::prefixTable('log_link_visit_action') . ' WHERE idvisit in ('.$visitorIds.') ORDER BY idlink_va ASC') as $actionRows) {
foreach ($batchQuery->generateQuery('SELECT * FROM ' . Common::prefixTable('log_link_visit_action') . ' WHERE idvisit in (' . $visitorIds . ') ORDER BY idlink_va ASC') as $actionRows) {
foreach ($actionRows as $row) {
$oldIdLinkAction = $row['idlink_va'];
$row['idvisit'] = $visitorIdMap[$row['idvisit']];
Expand All @@ -91,7 +92,7 @@ private function migrateVisits($visitRows, Request $request, LogActionMigration
}
unset($actionRows);

$rows = Db::fetchAll('SELECT * FROM ' . Common::prefixTable('log_conversion') . ' WHERE idvisit in ('.$visitorIds.')');
$rows = Db::fetchAll('SELECT * FROM ' . Common::prefixTable('log_conversion') . ' WHERE idvisit in (' . $visitorIds . ')');
foreach ($rows as $row) {
$row['idvisit'] = $visitorIdMap[$row['idvisit']];
if (isset($row['idlink_va'])) {
Expand All @@ -106,7 +107,7 @@ private function migrateVisits($visitRows, Request $request, LogActionMigration

unset($rows);

$rows = Db::fetchAll('SELECT * FROM ' . Common::prefixTable('log_conversion_item') . ' WHERE idvisit in ('.$visitorIds.')');
$rows = Db::fetchAll('SELECT * FROM ' . Common::prefixTable('log_conversion_item') . ' WHERE idvisit in (' . $visitorIds . ')');
foreach ($rows as $row) {
$row['idvisit'] = $visitorIdMap[$row['idvisit']];
$row['idsite'] = $request->targetIdSite;
Expand Down Expand Up @@ -136,5 +137,4 @@ private function migrateVisits($visitRows, Request $request, LogActionMigration

unset($visitRows);
}

}
7 changes: 5 additions & 2 deletions Migrations/Provider.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* Matomo - free/libre analytics platform
*
Expand Down Expand Up @@ -29,8 +30,10 @@ public function getAllMigrations($skipLogs, $skipArchives)
];

$pluginManager = Plugin\Manager::getInstance();
if ($pluginManager->isPluginActivated('CustomDimensions')
&& $pluginManager->isPluginLoaded('CustomDimensions')) {
if (
$pluginManager->isPluginActivated('CustomDimensions')
&& $pluginManager->isPluginLoaded('CustomDimensions')
) {
$migrations[] = new CustomDimensionMigration();
}

Expand Down
2 changes: 1 addition & 1 deletion Migrations/Request.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* Matomo - free/libre analytics platform
*
Expand All @@ -19,5 +20,4 @@ class Request
* @var int
*/
public $targetIdSite;

}
1 change: 1 addition & 0 deletions Migrations/SegmentsMigration.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* Matomo - free/libre analytics platform
*
Expand Down
1 change: 1 addition & 0 deletions Migrations/SiteMigration.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* Matomo - free/libre analytics platform
*
Expand Down
1 change: 1 addition & 0 deletions Migrations/SiteSettingMigration.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* Matomo - free/libre analytics platform
*
Expand Down
1 change: 1 addition & 0 deletions Migrations/SiteUrlMigration.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* Matomo - free/libre analytics platform
*
Expand Down
1 change: 1 addition & 0 deletions TargetDb.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* Matomo - free/libre analytics platform
*
Expand Down
15 changes: 8 additions & 7 deletions tests/Fixtures/MigrationFixture.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* Matomo - free/libre analytics platform
*
Expand Down Expand Up @@ -31,7 +32,7 @@ class MigrationFixture extends Fixture
public $dateTime = '2013-01-23 01:23:45';
public $idSite = 1;

const TARGET_DB_PREFIX = 'targetdb_';
public const TARGET_DB_PREFIX = 'targetdb_';

private $goals = array(
array('name' => 'Download Software', 'match' => 'url', 'pattern' => 'download', 'patternType' => 'contains', 'revenue' => 0.10),
Expand Down Expand Up @@ -64,7 +65,7 @@ public function setUp(): void
$this->trackSecondVisit();

// make sure to archive data
Request::processRequest('API.get',array(
Request::processRequest('API.get', array(
'period' => 'year',
'date' => '2013-01-23',
'idSite' => $this->idSite
Expand All @@ -74,9 +75,9 @@ public function setUp(): void
private function setUpCustomDimensions()
{
$configuration = new Configuration();
$configuration->configureNewDimension($this->idSite, 'MyName1', CustomDimensions::SCOPE_VISIT, 1, $active = true, $extractions = array(), $caseSensitive = true);
$configuration->configureNewDimension($this->idSite, 'MyName2', CustomDimensions::SCOPE_ACTION, 1, $active = true, $extractions = array(), $caseSensitive = true);
$configuration->configureNewDimension($this->idSite, 'MyName3', CustomDimensions::SCOPE_ACTION, 2, $active = false, $extractions = array(), $caseSensitive = true);
$configuration->configureNewDimension($this->idSite, 'MyName1', CustomDimensions::SCOPE_VISIT, 1, $active = true, $extractions = array(), $caseSensitive = true);
$configuration->configureNewDimension($this->idSite, 'MyName2', CustomDimensions::SCOPE_ACTION, 1, $active = true, $extractions = array(), $caseSensitive = true);
$configuration->configureNewDimension($this->idSite, 'MyName3', CustomDimensions::SCOPE_ACTION, 2, $active = false, $extractions = array(), $caseSensitive = true);
}

private function setUpSegments()
Expand Down Expand Up @@ -109,7 +110,7 @@ public static function copyTableStructure(TargetDb $targetDb)

$row = Db::fetchRow('SHOW CREATE TABLE `' . $table . '`');
$sql = $row['Create Table'];
$sql = str_replace('`'.$table.'`', '`'.$tablePrefixed.'`', $sql);
$sql = str_replace('`' . $table . '`', '`' . $tablePrefixed . '`', $sql);
$targetDb->getDb()->query($sql);
}
}
Expand Down Expand Up @@ -190,4 +191,4 @@ protected function trackSecondVisit()
$t->addEcommerceItem($sku = 'SKU_ID2', $name = 'A durable item', $category = 'Best seller', $price = 321);
self::checkResponse($t->doTrackEcommerceCartUpdate($grandTotal = 33 * 77));
}
}
}
2 changes: 1 addition & 1 deletion tests/Integration/Migrations/LogActionMigrationTest.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* Matomo - free/libre analytics platform
*
Expand Down Expand Up @@ -76,5 +77,4 @@ public function test_migrateAction()
$targetId3 = $this->migration->migrateAction($id3, $this->targetDb);
$this->assertEquals(3, $targetId3);
}

}
2 changes: 1 addition & 1 deletion tests/Integration/TargetDbTest.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* Matomo - free/libre analytics platform
*
Expand Down Expand Up @@ -136,5 +137,4 @@ public function test_update()
array ('idsite' => '4', 'url' => 'https://www.foobaz.com'),
), $urls);
}

}
3 changes: 1 addition & 2 deletions tests/System/Commands/MigrateTest.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* Matomo - free/libre analytics platform
*
Expand All @@ -10,7 +11,6 @@

use Piwik\Access;
use Piwik\Db;
use Piwik\Piwik;
use Piwik\Plugins\Migration\tests\Fixtures\MigrationFixture;
use Piwik\Config;
use Piwik\Tests\Framework\Mock\FakeAccess;
Expand Down Expand Up @@ -291,7 +291,6 @@ public static function getPathToTestDirectory()
{
return dirname(__FILE__) . '/..';
}

}

MigrateTest::$fixture = new MigrationFixture();

0 comments on commit 96e7066

Please sign in to comment.