Current status

This commit is contained in:
Kumi 2023-08-05 16:02:22 +00:00
commit bfd08b4443
12 changed files with 172 additions and 0 deletions

38
API.php Normal file
View file

@ -0,0 +1,38 @@
<?php
namespace Piwik\Plugins\ExportImportTool;
use Piwik\API\Request;
class API
{
public function exportSite($idSite)
{
$request = new Request("module=API&method=SitesManager.getSiteFromId&idSite=".$idSite."&format=json");
$result = $request->process();
$site = json_decode($result, true);
if (!$site) {
throw new \Exception('Site with ID ' . $idSite . ' does not exist.');
}
$request = new Request("module=API&method=Live.getLastVisitsDetails&idSite=".$idSite."&period=date&date=1992-01-01,today&filter_limit=-1&format=json");
$result = $request->process();
$visits = json_decode($result, true);
$data = [
'site' => $site,
'visits' => $visits,
];
$jsonData = json_encode($data, JSON_PRETTY_PRINT);
$filePath = '/tmp/' . $idSite . '.json';
file_put_contents($filePath, $jsonData);
return "Export succeeded, file path: " . $filePath;
}
}

3
CHANGELOG.md Normal file
View file

@ -0,0 +1,3 @@
## Changelog
Here goes the changelog text.

34
Commands/ExportSite.php Normal file
View file

@ -0,0 +1,34 @@
<?php
namespace Piwik\Plugins\ExportImportTool\Commands;
use Piwik\Plugin\ConsoleCommand;
use Piwik\Plugins\ExportImportTool\API as ExportImportApi;
class ExportSite extends ConsoleCommand
{
protected function configure()
{
$this->setName('exportimporttool:export-site');
$this->setDescription('Exports a site from Matomo.');
$this->addRequiredArgument('idSite', 'The ID of the site you want to export.');
}
protected function doExecute(): int
{
$input = $this->getInput();
$idSite = $input->getArgument('idSite');
// Call your Export API method here
$api = new ExportImportApi;
$result = $api->exportSite($idSite);
$output = $this->getOutput();
$output->writeln($result);
return self::SUCCESS;
}
}

31
Commands/ImportSite.php Normal file
View file

@ -0,0 +1,31 @@
<?php
namespace Piwik\Plugins\ExportImportTool\Commands;
use Piwik\Plugin\ConsoleCommand;
use Piwik\Plugins\ExportImportTool\API as ExportImportApi;
class ImportSite extends ConsoleCommand
{
protected function configure()
{
$this->setName('exportimporttool:import-site');
$this->setDescription('Imports a site into Matomo.');
$this->addRequiredArgument('filePath', 'The path to the site data file.');
}
protected function doExecute(): int
{
$input = $this->getInput();
$output = $this->getOutput();
$filePath = $input->getArgument('filePath');
$result = ExportImportApi::importSite($filePath);
$output->writeln($result);
return self::SUCCESS;
}
}

21
ExportImportTool.php Normal file
View file

@ -0,0 +1,21 @@
<?php
namespace Piwik\Plugins\ExportImportTool;
class ExportImportTool extends \Piwik\Plugin
{
public function registerEvents()
{
return [
'CronArchive.getArchivingAPIMethodForPlugin' => 'getArchivingAPIMethodForPlugin',
];
}
// support archiving just this plugin via core:archive
public function getArchivingAPIMethodForPlugin(&$method, $plugin)
{
if ($plugin == 'ExportImportTool') {
$method = 'ExportImportTool.getExampleArchivedMetric';
}
}
}

6
README.md Normal file
View file

@ -0,0 +1,6 @@
# Matomo ExportImportTool Plugin
## Description
Add your plugin description here.

2
config/config.php Normal file
View file

@ -0,0 +1,2 @@
<?php
return array();

2
config/tracker.php Normal file
View file

@ -0,0 +1,2 @@
<?php
return array();

5
docs/faq.md Normal file
View file

@ -0,0 +1,5 @@
## FAQ
__My question?__
My answer

1
docs/index.md Normal file
View file

@ -0,0 +1 @@
## Documentation

29
plugin.json Normal file
View file

@ -0,0 +1,29 @@
{
"name": "ExportImportTool",
"description": "A plugin allowing you to easily export your site data from one Matomo instance and import it to another",
"version": "0.1.0",
"theme": false,
"require": {
"matomo": ">=5.0.0-b5,<6.0.0-b1"
},
"authors": [
{
"name": "Kumi",
"email": "exportimporttool@kumi.email",
"homepage": "https://kumi.website"
}
],
"support": {
"email": "",
"issues": "",
"forum": "",
"irc": "",
"wiki": "",
"source": "https://kumig.it/kumitterer/ExportImportTool",
"docs": "",
"rss": ""
},
"homepage": "",
"license": "MIT",
"keywords": []
}

0
screenshots/.gitkeep Normal file
View file