Skip to content
Draft
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
346 changes: 346 additions & 0 deletions .git-hooks-matomo/pre-push

Large diffs are not rendered by default.

21 changes: 21 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Plugins CI

on:
pull_request:
types: [opened, synchronize, reopened, edited]
push:
branches:
- '**.x-dev'
workflow_dispatch:

permissions:
actions: read
contents: read
pull-requests: read

jobs:
ci:
uses: matomo-org/plugin-ci-workflows/.github/workflows/plugin-ci.yml@main
with:
plugin-name: DeviceDetectorCache
verify-hook: true
32 changes: 0 additions & 32 deletions .github/workflows/matomo-ai-checklist.yml

This file was deleted.

6 changes: 3 additions & 3 deletions .github/workflows/matomo-tests.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Action for running tests
# This file has been automatically created.
# To recreate it you can run this command
# ./console generate:test-action --plugin="DeviceDetectorCache" --php-versions="8.1,8.5" --schedule-cron="15 3 * * 6"
# ./console generate:test-action --plugin="DeviceDetectorCache" --php-versions="matomo6_min_php,matomo6_max_php" --schedule-cron="15 3 * * 6"

name: Plugin DeviceDetectorCache Tests

Expand Down Expand Up @@ -37,7 +37,7 @@ jobs:
strategy:
fail-fast: false
matrix:
php: [ '8.1', '8.5' ]
php: [ 'matomo6_min_php', 'matomo6_max_php' ]
target: ['minimum_required_matomo', 'maximum_supported_matomo']
database:
- { engine: 'Mysql', version: '8.0' }
Expand All @@ -59,4 +59,4 @@ jobs:
mysql-version: ${{ matrix.database.version }}
matomo-test-branch: ${{ matrix.target }}
artifacts-pass: ${{ secrets.ARTIFACTS_PASS }}
upload-artifacts: ${{ matrix.php == '8.1' && matrix.target == 'maximum_supported_matomo' && matrix.database.engine == 'Mysql' }}
upload-artifacts: ${{ matrix.php == 'matomo6_min_php' && matrix.target == 'maximum_supported_matomo' && matrix.database.engine == 'Mysql' }}
43 changes: 0 additions & 43 deletions .github/workflows/phpcs.yml

This file was deleted.

25 changes: 25 additions & 0 deletions .github/workflows/weekly-branch-sweep.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Dispatches this plugin's build for each maintained branch that is not the default one, because
# GitHub only ever runs `schedule` from the default branch's copy of a workflow file. The logic
# lives in matomo-org/plugin-ci-workflows; see the "Branch sweep" section of its README.md for
# why this dispatches rather than building another branch's source here.

name: Weekly branch sweep

on:
schedule:
# Sunday, so it does not compete with this plugin's own Saturday build. Keeps the minute and
# hour of matomo-tests.yml's cron, so the fleet stays staggered across the window.
- cron: '15 3 * * 0'
workflow_dispatch:

permissions: {}

jobs:
sweep:
# Granted by the caller because permissions can only be maintained or reduced down a call
# chain, never elevated: the called workflow declares these too, but that can only cap them,
# not supply them, so without this block the dispatch is unauthorised.
permissions:
actions: write
contents: read
uses: matomo-org/plugin-ci-workflows/.github/workflows/plugin-branch-sweep.yml@main
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
## Changelog

6.0.0
- Compatibility with Matomo 6.X

5.0.3
- Added plugin category for Marketplace

Expand Down
2 changes: 1 addition & 1 deletion CachedEntry.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class CachedEntry extends DeviceDetector
private static $CACHE_DIR = '';
private static $customCache = null;

public function __construct(string $userAgent, $clientHints, array $values)
public function __construct(string $userAgent, array $clientHints, array $values)
{
$clientHints = $clientHints ? ClientHints::factory($clientHints) : null;
parent::__construct($userAgent, $clientHints);
Expand Down
2 changes: 1 addition & 1 deletion Commands/WarmDeviceDetectorCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ protected function doExecute(): int
if ($i <= 10) {
$this->log('Found user agent ' . $agent . ' count: ' . $val);
}
CachedEntry::writeToCache($agent, []);
CachedEntry::writeToCache($agent);
// sleep 2ms to let CPU do something else
// this will make things about 10m slower for 200K entries but at least sudden CPU increase for instance
// can be prevented when there are only few CPUs available
Expand Down
4 changes: 2 additions & 2 deletions Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,15 @@ public function getAccessLogRegex()
}

/**
* @return string
* @return int
*/
public function getRegexMatchEntry()
{
return (int)$this->getConfigValue(self::KEY_ACCESS_LOG_REGEX_MATCH_ENTRY, self::DEFAULT_ACCESS_LOG_REGEX_MATCH_ENTRY);
}

/**
* @return string
* @return int
*/
public function getNumEntriesToCache()
{
Expand Down
4 changes: 2 additions & 2 deletions lang/zh-tw.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"DeviceDetectorCache": {
"PluginDescription": "從快取內刪除一些裝置、作業系統、機器人、瀏覽器,以便加速追蹤。"
"PluginDescription": "透過快取偵測多種裝置、作業系統、機器人與瀏覽器,加快追蹤速度。"
}
}
}
19 changes: 19 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
parameters:
level: 5
phpVersion: 80100
tmpDir: /tmp/phpstan/DeviceDetectorCache/main
paths:
- .
excludePaths:
- tests/*
# The shared workflow leaves this helper checkout in the workspace, and `paths: .`
# would otherwise analyse it as if it were plugin code.
- github-action-tests/*
bootstrapFiles:
- ../../bootstrap-phpstan.php
universalObjectCratesClasses:
- Piwik\Config
- Piwik\View
- Piwik\ViewDataTable\Config
scanDirectories:
- ../../
6 changes: 6 additions & 0 deletions phpstan/phpstan.created.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
includes:
- ../phpstan.neon
parameters:
# new files carry no pre-existing debt, so hold them to the strictest level
level: 9
tmpDir: /tmp/phpstan/DeviceDetectorCache/created
5 changes: 5 additions & 0 deletions phpstan/phpstan.modified.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
includes:
- ../phpstan.neon
parameters:
level: 5
tmpDir: /tmp/phpstan/DeviceDetectorCache/modified
26 changes: 13 additions & 13 deletions tests/Integration/CachedEntryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,11 @@ public function testGetNumCacheFiles_noneCached()

public function testGetNumCacheFiles()
{
CachedEntry::writeToCache('foo', []);
CachedEntry::writeToCache('foo');
$this->assertEquals(1, CachedEntry::getNumEntriesInCacheDir());
CachedEntry::writeToCache('bar', []);
CachedEntry::writeToCache('bar');
$this->assertEquals(2, CachedEntry::getNumEntriesInCacheDir());
CachedEntry::writeToCache('baz', []);
CachedEntry::writeToCache('baz');
$this->assertEquals(3, CachedEntry::getNumEntriesInCacheDir());
}

Expand All @@ -180,7 +180,7 @@ public function testGetCached_noEntry()

public function test_writeToCache_GetCached()
{
CachedEntry::writeToCache('foo', []);
CachedEntry::writeToCache('foo');
$cacheEntry = CachedEntry::getCached('foo', []);
$this->assertEquals(
[
Expand Down Expand Up @@ -212,7 +212,7 @@ public function test_getCacheDir()

public function test_deleteLeastAccessedFiles_nothingToDelete()
{
$filePath = CachedEntry::writeToCache('file', []);
$filePath = CachedEntry::writeToCache('file');
$this->assertFileExists($filePath);

CachedEntry::deleteLeastAccessedFiles(-1);
Expand All @@ -223,13 +223,13 @@ public function test_deleteLeastAccessedFiles_nothingToDelete()

public function test_deleteLeastAccessedFiles_deletesOnlyOldest()
{
$filePath1 = CachedEntry::writeToCache('file', []);
$filePath1 = CachedEntry::writeToCache('file');
sleep(1); // otherwise without sleep the sorting won't work properly
$filePath2 = CachedEntry::writeToCache('bar', []);
$filePath2 = CachedEntry::writeToCache('bar');
sleep(1);
$filePath3 = CachedEntry::writeToCache('baz', []);
$filePath3 = CachedEntry::writeToCache('baz');
sleep(1);
$filePath4 = CachedEntry::writeToCache('foo', []);
$filePath4 = CachedEntry::writeToCache('foo');
sleep(1);

CachedEntry::deleteLeastAccessedFiles(2);
Expand All @@ -242,13 +242,13 @@ public function test_deleteLeastAccessedFiles_deletesOnlyOldest()

public function test_deleteLeastAccessedFiles_deletesOnlyOldest2()
{
$filePath1 = CachedEntry::writeToCache('file', []);
$filePath1 = CachedEntry::writeToCache('file');
sleep(1);
$filePath2 = CachedEntry::writeToCache('bar', []);
$filePath2 = CachedEntry::writeToCache('bar');
sleep(1);
$filePath3 = CachedEntry::writeToCache('baz', []);
$filePath3 = CachedEntry::writeToCache('baz');
sleep(1);
$filePath4 = CachedEntry::writeToCache('foo', []);
$filePath4 = CachedEntry::writeToCache('foo');
sleep(1);

touch($filePath1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

<pageId>1</pageId>
<bandwidth />
<timeSpent>721</timeSpent>
<timeSpentPretty>12 min 1s</timeSpentPretty>
<timeSpent>360</timeSpent>
<timeSpentPretty>6 min 0s</timeSpentPretty>
<pageviewPosition>1</pageviewPosition>
<title>Viewing homepage</title>
<subtitle>http://example.com/sub/page</subtitle>
Expand Down
Loading