Skip to content
Extraits de code Groupes Projets
Valider 26cd0c6f rédigé par Thomas Steur's avatar Thomas Steur
Parcourir les fichiers

Merge pull request #6523 from mgazdzik/addExampleArchiver

Add example archiver and CoreConsole task to generate Archiver into plugin.
parents 368be0a9 26cffc32
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
<?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\CoreConsole\Commands;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
/**
*/
class GenerateArchiver extends GeneratePluginBase
{
protected function configure()
{
$this->setName('generate:archiver')
->setDescription('Adds an Archiver to an existing plugin')
->addOption('pluginname', null, InputOption::VALUE_REQUIRED, 'The name of an existing plugin which does not have an Archiver yet');
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$pluginName = $this->getPluginName($input, $output);
$this->checkAndUpdateRequiredPiwikVersion($pluginName, $output);
$exampleFolder = PIWIK_INCLUDE_PATH . '/plugins/ExamplePlugin';
$replace = array('ExamplePlugin' => ucfirst($pluginName), 'EXAMPLEPLUGIN' => strtoupper($pluginName));
$whitelistFiles = array('/Archiver.php');
$this->copyTemplateToPlugin($exampleFolder, $pluginName, $replace, $whitelistFiles);
$this->writeSuccessMessage($output, array(
sprintf('Archiver.php for %s generated.', $pluginName),
'You can now start implementing Archiver methods',
'Enjoy!'
));
}
/**
* @param InputInterface $input
* @param OutputInterface $output
* @return array
* @throws \RuntimeException
*/
protected function getPluginName(InputInterface $input, OutputInterface $output)
{
$pluginNames = $this->getPluginNamesHavingNotSpecificFile('Archiver.php');
$invalidName = 'You have to enter the name of an existing plugin which does not already have an Archiver';
return $this->askPluginNameAndValidate($input, $output, $pluginNames, $invalidName);
}
}
<?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\ExamplePlugin;
/**
* Class Archiver
* @package Piwik\Plugins\ExamplePlugin
*
* Archiver is class processing raw data into ready ro read reports.
* It must implement two methods for aggregating daily reports
* aggregateDayReport() and other for summing daily reports into periods
* like week, month, year or custom range aggregateMultipleReports().
*
* For more detailed information about Archiver please visit Piwik developer guide
* http://developer.piwik.org/api-reference/Piwik/Plugin/Archiver
*
*/
class Archiver extends \Piwik\Plugin\Archiver
{
/**
* It is a good practice to store your archive names (reports stored in database)
* in Archiver class constants. You can define as many record names as you want
* for your plugin.
*
* Also important thing is that record name must be prefixed with plugin name.
*
* This is only an example record name, so feel free to change it to suit your needs.
*/
const EXAMPLEPLUGIN_ARCHIVE_RECORD = "ExamplePlugin_archive_record";
public function aggregateDayReport()
{
/**
* inside this method you can implement your LogAggreagator usage
* to process daily reports, this one uses idvisitor to group results.
*
* $visitorMetrics = $this
* ->getLogAggregator()
* ->getMetricsFromVisitByDimension('idvisitor')
* ->asDataTable();
* $visitorReport = $visitorMetrics->getSerialized();
* $this->getProcessor()->insertBlobRecord(self::EXAMPLEPLUGIN_ARCHIVE_RECORD, $visitorReport);
*/
}
public function aggregateMultipleReports()
{
/**
* Inside this method you can simply point daily records
* to be summed. This work for most cases.
* However if needed, also custom queries can be implemented
* for periods to achieve more acurrate results.
*
* $this->getProcessor()->aggregateDataTableRecords(self::EXAMPLEPLUGIN_ARCHIVE_RECORD);
*/
}
}
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter