Skip to content
Extraits de code Groupes Projets
Valider 2957313e rédigé par mattab's avatar mattab
Parcourir les fichiers

Merge remote-tracking branch 'origin/master'

parents 34fe1d75 b457fcc9
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
Affichage de
avec 556 ajouts et 238 suppressions
...@@ -61,42 +61,11 @@ abstract class MenuAbstract extends Singleton ...@@ -61,42 +61,11 @@ abstract class MenuAbstract extends Singleton
return self::$menus; return self::$menus;
} }
$pluginNames = PluginManager::getInstance()->getLoadedPluginsName(); self::$menus = PluginManager::getInstance()->findComponents('Menu', 'Piwik\\Plugin\\Menu');
self::$menus = array();
foreach ($pluginNames as $pluginName) {
$menu = $this->findMenuInPlugin($pluginName);
if (!empty($menu)) {
self::$menus[] = $menu;
}
}
return self::$menus; return self::$menus;
} }
private function findMenuInPlugin($pluginName)
{
$menuFile = PIWIK_INCLUDE_PATH . '/plugins/' . $pluginName . '/Menu.php';
if (!file_exists($menuFile)) {
return;
}
$klassName = sprintf('Piwik\\Plugins\\%s\\Menu', $pluginName);
if (!class_exists($klassName)) {
return;
}
if (!is_subclass_of($klassName, 'Piwik\\Plugin\\Menu')) {
Log::warning(sprintf('Cannot use menu for plugin %s, class %s does not extend Piwik\Plugin\Menu', $pluginName, $klassName));
return;
}
return new $klassName;
}
/** /**
* Adds a new entry to the menu. * Adds a new entry to the menu.
* *
......
...@@ -276,6 +276,44 @@ class Plugin ...@@ -276,6 +276,44 @@ class Plugin
return $this->pluginName; return $this->pluginName;
} }
/**
* Tries to find a component such as a Menu or Tasks within this plugin.
*
* @param string $componentName The name of the component you want to look for. In case you request a
* component named 'Menu' it'll look for a file named 'Menu.php' within the
* root of the plugin folder that implements a class named
* Piwik\Plugin\$PluginName\Menu . If such a file exists but does not implement
* this class it'll silently ignored.
* @param string $expectedSubclass If not empty, a check will be performed whether a found file extends the
* given subclass. If the requested file exists but does not extend this class
* a warning will be shown to advice a developer to extend this certain class.
*
* @return \stdClass|null Null if the requested component does not exist or an instance of the found
* component.
*/
public function findComponent($componentName, $expectedSubclass)
{
$componentFile = sprintf('%s/plugins/%s/%s.php', PIWIK_INCLUDE_PATH, $this->pluginName, $componentName);
if (!file_exists($componentFile)) {
return;
}
$klassName = sprintf('Piwik\\Plugins\\%s\\%s', $this->pluginName, $componentName);
if (!class_exists($klassName)) {
return;
}
if (!empty($expectedSubclass) && !is_subclass_of($klassName, $expectedSubclass)) {
Log::warning(sprintf('Cannot use component %s for plugin %s, class %s does not extend %s',
$componentName, $this->pluginName, $klassName, $expectedSubclass));
return;
}
return new $klassName;
}
/** /**
* Detect whether there are any missing dependencies. * Detect whether there are any missing dependencies.
* *
......
...@@ -34,6 +34,7 @@ class Manager extends Singleton ...@@ -34,6 +34,7 @@ class Manager extends Singleton
protected $pluginsToLoad = array(); protected $pluginsToLoad = array();
protected $doLoadPlugins = true; protected $doLoadPlugins = true;
/** /**
* @var Plugin[] * @var Plugin[]
*/ */
...@@ -324,6 +325,37 @@ class Manager extends Singleton ...@@ -324,6 +325,37 @@ class Manager extends Singleton
$this->clearCache($pluginName); $this->clearCache($pluginName);
} }
/**
* Tries to find the given components such as a Menu or Tasks implemented by plugins.
* This method won't cache the found components. If you need to find the same component multiple times you might
* want to cache the result to save a tiny bit of time.
*
* @param string $componentName The name of the component you want to look for. In case you request a
* component named 'Menu' it'll look for a file named 'Menu.php' within the
* root of all plugin folders that implement a class named
* Piwik\Plugin\$PluginName\Menu.
* @param string $expectedSubclass If not empty, a check will be performed whether a found file extends the
* given subclass. If the requested file exists but does not extend this class
* a warning will be shown to advice a developer to extend this certain class.
*
* @return \stdClass[]
*/
public function findComponents($componentName, $expectedSubclass)
{
$plugins = $this->getLoadedPlugins();
$components = array();
foreach ($plugins as $plugin) {
$component = $plugin->findComponent($componentName, $expectedSubclass);
if (!empty($component)) {
$components[] = $component;
}
}
return $components;
}
/** /**
* Uninstalls a Plugin (deletes plugin files from the disk) * Uninstalls a Plugin (deletes plugin files from the disk)
* Only deactivated plugins can be uninstalled * Only deactivated plugins can be uninstalled
......
<?php
/**
* Piwik - Open source web analytics
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*
*/
namespace Piwik\Plugin;
use Piwik\ScheduledTask;
use Piwik\ScheduledTime;
/**
* Base class for all Tasks declarations.
* Tasks are usually meant as scheduled tasks that are executed regularily by Piwik in the background. For instance
* once every hour or every day. This could be for instance checking for updates, sending email reports, etc.
* Please don't mix up tasks with console commands which can be executed on the CLI.
*/
class Tasks
{
/**
* @var ScheduledTask[]
*/
private $tasks = array();
const LOWEST_PRIORITY = ScheduledTask::LOWEST_PRIORITY;
const LOW_PRIORITY = ScheduledTask::LOW_PRIORITY;
const NORMAL_PRIORITY = ScheduledTask::NORMAL_PRIORITY;
const HIGH_PRIORITY = ScheduledTask::HIGH_PRIORITY;
const HIGHEST_PRIORITY = ScheduledTask::HIGHEST_PRIORITY;
/**
* This method is called to collect all schedule tasks. Register all your tasks here that should be executed
* regularily such as daily or monthly.
*/
public function schedule()
{
// eg $this->daily('myMethodName')
}
/**
* @return ScheduledTask[] $tasks
*/
public function getScheduledTasks()
{
return $this->tasks;
}
/**
* Schedule the given tasks/method to run once every hour.
*
* @param string $methodName The name of the method that will be called when the task is being
* exectuted. To make it work you need to create a public method having the
* given method name in your Tasks class.
* @param null|string $methodParameter Can be null if the task does not need any parameter or a string. It is not
* possible to specify multiple parameters as an array etc. If you need to
* pass multiple parameters separate them via any characters such as '###'.
* For instance '$param1###$param2###$param3'
* @param int $priority Can be any constant such as self::LOW_PRIORITY
*
* @return ScheduledTime
* @api
*/
protected function hourly($methodName, $methodParameter = null, $priority = self::NORMAL_PRIORITY)
{
return $this->custom($this, $methodName, $methodParameter, 'hourly', $priority);
}
/**
* Schedule the given tasks/method to run once every day.
*
* See {@link hourly()}
* @api
*/
protected function daily($methodName, $methodParameter = null, $priority = self::NORMAL_PRIORITY)
{
return $this->custom($this, $methodName, $methodParameter, 'daily', $priority);
}
/**
* Schedule the given tasks/method to run once every week.
*
* See {@link hourly()}
* @api
*/
protected function weekly($methodName, $methodParameter = null, $priority = self::NORMAL_PRIORITY)
{
return $this->custom($this, $methodName, $methodParameter, 'weekly', $priority);
}
/**
* Schedule the given tasks/method to run once every month.
*
* See {@link hourly()}
* @api
*/
protected function monthly($methodName, $methodParameter = null, $priority = self::NORMAL_PRIORITY)
{
return $this->custom($this, $methodName, $methodParameter, 'monthly', $priority);
}
/**
* Schedules the given tasks/method to run depending at the given scheduled time. Unlike the convenient methods
* such as {@link hourly()} you need to specify the object on which the given method should be called. This can be
* either an instance of a class or a class name. For more information about these parameters see {@link hourly()}
*
* @param string|object $objectOrClassName
* @param string $methodName
* @param null|string $methodParameter
* @param string|ScheduledTime $time
* @param int $priority
*
* @return ScheduledTime
*
* @throws \Exception If a wrong time format is given. Needs to be either a string such as 'daily', 'weekly', ...
* or an instance of {@link Piwik\ScheduledTime}
*
* @api
*/
protected function custom($objectOrClassName, $methodName, $methodParameter, $time, $priority = self::NORMAL_PRIORITY)
{
if (is_string($time)) {
$time = ScheduledTime::factory($time);
}
if (!($time instanceof ScheduledTime)) {
throw new \Exception('$time should be an instance of ScheduledTime');
}
$this->scheduleTask(new ScheduledTask($objectOrClassName, $methodName, $methodParameter, $time, $priority));
return $time;
}
/**
* In case you need very high flexibility and none of the other convenient methods such as {@link hourly()} or
* {@link custom()} suit you, you can use this method to add a custom scheduled task.
*
* @param ScheduledTask $task
*/
protected function scheduleTask(ScheduledTask $task)
{
$this->tasks[] = $task;
}
}
\ No newline at end of file
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
namespace Piwik; namespace Piwik;
use Exception; use Exception;
use Piwik\Plugin\Manager as PluginManager;
// When set to true, all scheduled tasks will be triggered in all requests (careful!) // When set to true, all scheduled tasks will be triggered in all requests (careful!)
define('DEBUG_FORCE_SCHEDULED_TASKS', false); define('DEBUG_FORCE_SCHEDULED_TASKS', false);
...@@ -52,7 +53,7 @@ define('DEBUG_FORCE_SCHEDULED_TASKS', false); ...@@ -52,7 +53,7 @@ define('DEBUG_FORCE_SCHEDULED_TASKS', false);
*/ */
class TaskScheduler extends Singleton class TaskScheduler extends Singleton
{ {
const GET_TASKS_EVENT = "TaskScheduler.getScheduledTasks"; const GET_TASKS_EVENT = 'TaskScheduler.getScheduledTasks';
private $isRunning = false; private $isRunning = false;
...@@ -81,34 +82,42 @@ class TaskScheduler extends Singleton ...@@ -81,34 +82,42 @@ class TaskScheduler extends Singleton
return self::getInstance()->doRunTasks(); return self::getInstance()->doRunTasks();
} }
private function doRunTasks()
// for backwards compatibility
private function collectTasksRegisteredViaEvent()
{ {
// collect tasks
$tasks = array(); $tasks = array();
/** /**
* Triggered during scheduled task execution. Collects all the tasks to run. * @ignore
*
* Subscribe to this event to schedule code execution on an hourly, daily, weekly or monthly
* basis.
*
* **Example**
*
* public function getScheduledTasks(&$tasks)
* {
* $tasks[] = new ScheduledTask(
* 'Piwik\Plugins\CorePluginsAdmin\MarketplaceApiClient',
* 'clearAllCacheEntries',
* null,
* ScheduledTime::factory('daily'),
* ScheduledTask::LOWEST_PRIORITY
* );
* }
*
* @param ScheduledTask[] &$tasks List of tasks to run periodically.
*/ */
Piwik::postEvent(self::GET_TASKS_EVENT, array(&$tasks)); Piwik::postEvent(self::GET_TASKS_EVENT, array(&$tasks));
/** @var ScheduledTask[] $tasks */
return $tasks;
}
private function getScheduledTasks()
{
/** @var \Piwik\ScheduledTask[] $tasks */
$tasks = $this->collectTasksRegisteredViaEvent();
/** @var \Piwik\Plugin\Tasks[] $pluginTasks */
$pluginTasks = PluginManager::getInstance()->findComponents('Tasks', 'Piwik\\Plugin\\Tasks');
foreach ($pluginTasks as $pluginTask) {
$pluginTask->schedule();
foreach ($pluginTask->getScheduledTasks() as $task) {
$tasks[] = $task;
}
}
return $tasks;
}
private function doRunTasks()
{
$tasks = $this->getScheduledTasks();
// remove from timetable tasks that are not active anymore // remove from timetable tasks that are not active anymore
$this->timetable->removeInactiveTasks($tasks); $this->timetable->removeInactiveTasks($tasks);
......
...@@ -8,9 +8,6 @@ ...@@ -8,9 +8,6 @@
*/ */
namespace Piwik\Updates; namespace Piwik\Updates;
use Faker\Provider\File;
use Piwik\Filesystem;
use Piwik\Plugins\Installation\ServerFilesGenerator;
use Piwik\Updates; use Piwik\Updates;
class Updates_2_4_0_b3 extends Updates class Updates_2_4_0_b3 extends Updates
...@@ -24,6 +21,11 @@ class Updates_2_4_0_b3 extends Updates ...@@ -24,6 +21,11 @@ class Updates_2_4_0_b3 extends Updates
} catch(\Exception $e) { } catch(\Exception $e) {
} }
try {
$pluginManager->deactivatePlugin('Zeitgeist');
} catch(\Exception $e) {
}
try { try {
$pluginManager->uninstallPlugin('Zeitgeist'); $pluginManager->uninstallPlugin('Zeitgeist');
} catch(\Exception $e) { } catch(\Exception $e) {
......
<?php
/**
* Piwik - Open source web analytics
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*
*/
namespace Piwik\Updates;
use Piwik\Updates;
class Updates_2_4_0_b4 extends Updates
{
public static function update()
{
$pluginManager = \Piwik\Plugin\Manager::getInstance();
$pluginNames = $pluginManager->getAllPluginsNames();
if (!in_array('Zeitgeist', $pluginNames)) {
return;
}
try {
$pluginManager->deactivatePlugin('Zeitgeist');
} catch(\Exception $e) {
}
try {
$pluginManager->uninstallPlugin('Zeitgeist');
} catch(\Exception $e) {
}
}
}
...@@ -8,12 +8,7 @@ ...@@ -8,12 +8,7 @@
*/ */
namespace Piwik\Plugins\CoreAdminHome; namespace Piwik\Plugins\CoreAdminHome;
use Piwik\DataAccess\ArchiveSelector;
use Piwik\DataAccess\ArchiveTableCreator;
use Piwik\Date;
use Piwik\Db; use Piwik\Db;
use Piwik\ScheduledTask;
use Piwik\ScheduledTime;
use Piwik\Settings\UserSetting; use Piwik\Settings\UserSetting;
/** /**
...@@ -29,7 +24,6 @@ class CoreAdminHome extends \Piwik\Plugin ...@@ -29,7 +24,6 @@ class CoreAdminHome extends \Piwik\Plugin
return array( return array(
'AssetManager.getStylesheetFiles' => 'getStylesheetFiles', 'AssetManager.getStylesheetFiles' => 'getStylesheetFiles',
'AssetManager.getJavaScriptFiles' => 'getJsFiles', 'AssetManager.getJavaScriptFiles' => 'getJsFiles',
'TaskScheduler.getScheduledTasks' => 'getScheduledTasks',
'UsersManager.deleteUser' => 'cleanupUser' 'UsersManager.deleteUser' => 'cleanupUser'
); );
} }
...@@ -39,25 +33,6 @@ class CoreAdminHome extends \Piwik\Plugin ...@@ -39,25 +33,6 @@ class CoreAdminHome extends \Piwik\Plugin
UserSetting::removeAllUserSettingsForUser($userLogin); UserSetting::removeAllUserSettingsForUser($userLogin);
} }
public function getScheduledTasks(&$tasks)
{
// general data purge on older archive tables, executed daily
$purgeArchiveTablesTask = new ScheduledTask ($this,
'purgeOutdatedArchives',
null,
ScheduledTime::factory('daily'),
ScheduledTask::HIGH_PRIORITY);
$tasks[] = $purgeArchiveTablesTask;
// lowest priority since tables should be optimized after they are modified
$optimizeArchiveTableTask = new ScheduledTask ($this,
'optimizeArchiveTable',
null,
ScheduledTime::factory('daily'),
ScheduledTask::LOWEST_PRIORITY);
$tasks[] = $optimizeArchiveTableTask;
}
public function getStylesheetFiles(&$stylesheets) public function getStylesheetFiles(&$stylesheets)
{ {
$stylesheets[] = "libs/jquery/themes/base/jquery-ui.css"; $stylesheets[] = "libs/jquery/themes/base/jquery-ui.css";
...@@ -85,23 +60,4 @@ class CoreAdminHome extends \Piwik\Plugin ...@@ -85,23 +60,4 @@ class CoreAdminHome extends \Piwik\Plugin
$jsFiles[] = "plugins/CoreAdminHome/javascripts/pluginSettings.js"; $jsFiles[] = "plugins/CoreAdminHome/javascripts/pluginSettings.js";
} }
function purgeOutdatedArchives()
{
$archiveTables = ArchiveTableCreator::getTablesArchivesInstalled();
foreach ($archiveTables as $table) {
$date = ArchiveTableCreator::getDateFromTableName($table);
list($year, $month) = explode('_', $date);
// Somehow we may have archive tables created with older dates, prevent exception from being thrown
if($year > 1990) {
ArchiveSelector::purgeOutdatedArchives(Date::factory("$year-$month-15"));
}
}
}
function optimizeArchiveTable()
{
$archiveTables = ArchiveTableCreator::getTablesArchivesInstalled();
Db::optimizeTables($archiveTables);
}
} }
<?php
/**
* Piwik - Open source web analytics
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*
*/
namespace Piwik\Plugins\CoreAdminHome;
use Piwik\DataAccess\ArchiveSelector;
use Piwik\DataAccess\ArchiveTableCreator;
use Piwik\Date;
use Piwik\Db;
class Tasks extends \Piwik\Plugin\Tasks
{
public function schedule()
{
// general data purge on older archive tables, executed daily
$this->daily('purgeOutdatedArchives', null, self::HIGH_PRIORITY);
// lowest priority since tables should be optimized after they are modified
$this->daily('optimizeArchiveTable', null, self::LOWEST_PRIORITY);
}
public function purgeOutdatedArchives()
{
$archiveTables = ArchiveTableCreator::getTablesArchivesInstalled();
foreach ($archiveTables as $table) {
$date = ArchiveTableCreator::getDateFromTableName($table);
list($year, $month) = explode('_', $date);
// Somehow we may have archive tables created with older dates, prevent exception from being thrown
if($year > 1990) {
ArchiveSelector::purgeOutdatedArchives(Date::factory("$year-$month-15"));
}
}
}
public function optimizeArchiveTable()
{
$archiveTables = ArchiveTableCreator::getTablesArchivesInstalled();
Db::optimizeTables($archiveTables);
}
}
\ No newline at end of file
<?php
/**
* Piwik - Open source web analytics
*
* @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 GenerateScheduledTask extends GeneratePluginBase
{
protected function configure()
{
$this->setName('generate:scheduledtask')
->setDescription('Adds a tasks class to an existing plugin which allows you to specify scheduled tasks')
->addOption('pluginname', null, InputOption::VALUE_REQUIRED, 'The name of an existing plugin which does not have any tasks defined yet');
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$pluginName = $this->getPluginName($input, $output);
$exampleFolder = PIWIK_INCLUDE_PATH . '/plugins/ExamplePlugin';
$replace = array('ExamplePlugin' => $pluginName);
$whitelistFiles = array('/Tasks.php');
$this->copyTemplateToPlugin($exampleFolder, $pluginName, $replace, $whitelistFiles);
$this->writeSuccessMessage($output, array(
sprintf('Tasks.php for %s generated.', $pluginName),
'You can now start specifying your scheduled tasks',
'Enjoy!'
));
}
/**
* @param InputInterface $input
* @param OutputInterface $output
* @return array
* @throws \RunTimeException
*/
protected function getPluginName(InputInterface $input, OutputInterface $output)
{
$pluginNames = $this->getPluginNamesHavingNotSpecificFile('Tasks.php');
$invalidName = 'You have to enter the name of an existing plugin which does not already have any tasks defined';
return $this->askPluginNameAndValidate($input, $output, $pluginNames, $invalidName);
}
}
...@@ -10,12 +10,7 @@ namespace Piwik\Plugins\CorePluginsAdmin; ...@@ -10,12 +10,7 @@ namespace Piwik\Plugins\CorePluginsAdmin;
use Piwik\Config; use Piwik\Config;
use Piwik\Plugin; use Piwik\Plugin;
use Piwik\ScheduledTask;
use Piwik\ScheduledTime;
/**
*
*/
class CorePluginsAdmin extends \Piwik\Plugin class CorePluginsAdmin extends \Piwik\Plugin
{ {
/** /**
...@@ -26,42 +21,10 @@ class CorePluginsAdmin extends \Piwik\Plugin ...@@ -26,42 +21,10 @@ class CorePluginsAdmin extends \Piwik\Plugin
return array( return array(
'AssetManager.getJavaScriptFiles' => 'getJsFiles', 'AssetManager.getJavaScriptFiles' => 'getJsFiles',
'AssetManager.getStylesheetFiles' => 'getStylesheetFiles', 'AssetManager.getStylesheetFiles' => 'getStylesheetFiles',
'TaskScheduler.getScheduledTasks' => 'getScheduledTasks',
'Translate.getClientSideTranslationKeys' => 'getClientSideTranslationKeys' 'Translate.getClientSideTranslationKeys' => 'getClientSideTranslationKeys'
); );
} }
/**
* Gets all scheduled tasks executed by this plugin.
*/
public function getScheduledTasks(&$tasks)
{
$tasks[] = new ScheduledTask(
'Piwik\Plugins\CorePluginsAdmin\MarketplaceApiClient',
'clearAllCacheEntries',
null,
ScheduledTime::factory('daily'),
ScheduledTask::LOWEST_PRIORITY
);
if (self::isMarketplaceEnabled()) {
$sendUpdateNotification = new ScheduledTask ($this,
'sendNotificationIfUpdatesAvailable',
null,
ScheduledTime::factory('daily'),
ScheduledTask::LOWEST_PRIORITY);
$tasks[] = $sendUpdateNotification;
}
}
public function sendNotificationIfUpdatesAvailable()
{
$updateCommunication = new UpdateCommunication();
if ($updateCommunication->isEnabled()) {
$updateCommunication->sendNotificationIfUpdatesAvailable();
}
}
public function getStylesheetFiles(&$stylesheets) public function getStylesheetFiles(&$stylesheets)
{ {
$stylesheets[] = "plugins/CorePluginsAdmin/stylesheets/marketplace.less"; $stylesheets[] = "plugins/CorePluginsAdmin/stylesheets/marketplace.less";
......
<?php
/**
* Piwik - Open source web analytics
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*
*/
namespace Piwik\Plugins\CorePluginsAdmin;
class Tasks extends \Piwik\Plugin\Tasks
{
public function schedule()
{
$this->daily('clearAllCacheEntries', null, self::LOWEST_PRIORITY);
if (CorePluginsAdmin::isMarketplaceEnabled()) {
$this->daily('sendNotificationIfUpdatesAvailable', null, self::LOWEST_PRIORITY);
}
}
public function clearAllCacheEntries()
{
$marketplace = new MarketplaceApiClient();
$marketplace->clearAllCacheEntries();
}
public function sendNotificationIfUpdatesAvailable()
{
$updateCommunication = new UpdateCommunication();
if ($updateCommunication->isEnabled()) {
$updateCommunication->sendNotificationIfUpdatesAvailable();
}
}
}
\ No newline at end of file
...@@ -31,30 +31,10 @@ class CoreUpdater extends \Piwik\Plugin ...@@ -31,30 +31,10 @@ class CoreUpdater extends \Piwik\Plugin
*/ */
public function getListHooksRegistered() public function getListHooksRegistered()
{ {
$hooks = array( return array(
'Request.dispatchCoreAndPluginUpdatesScreen' => 'dispatch', 'Request.dispatchCoreAndPluginUpdatesScreen' => 'dispatch',
'Platform.initialized' => 'updateCheck', 'Platform.initialized' => 'updateCheck',
'TaskScheduler.getScheduledTasks' => 'getScheduledTasks',
); );
return $hooks;
}
public function getScheduledTasks(&$tasks)
{
$sendUpdateNotification = new ScheduledTask($this,
'sendNotificationIfUpdateAvailable',
null,
ScheduledTime::factory('daily'),
ScheduledTask::LOWEST_PRIORITY);
$tasks[] = $sendUpdateNotification;
}
public function sendNotificationIfUpdateAvailable()
{
$coreUpdateCommunication = new UpdateCommunication();
if ($coreUpdateCommunication->isEnabled()) {
$coreUpdateCommunication->sendNotificationIfUpdateAvailable();
}
} }
public static function updateComponents(Updater $updater, $componentsWithUpdateFile) public static function updateComponents(Updater $updater, $componentsWithUpdateFile)
......
<?php
/**
* Piwik - Open source web analytics
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*
*/
namespace Piwik\Plugins\CoreUpdater;
class Tasks extends \Piwik\Plugin\Tasks
{
public function schedule()
{
$this->daily('sendNotificationIfUpdateAvailable', null, self::LOWEST_PRIORITY);
}
public function sendNotificationIfUpdateAvailable()
{
$coreUpdateCommunication = new UpdateCommunication();
if ($coreUpdateCommunication->isEnabled()) {
$coreUpdateCommunication->sendNotificationIfUpdateAvailable();
}
}
}
\ No newline at end of file
...@@ -8,19 +8,13 @@ ...@@ -8,19 +8,13 @@
*/ */
namespace Piwik\Plugins\DBStats; namespace Piwik\Plugins\DBStats;
use Piwik\Date;
use Piwik\Option; use Piwik\Option;
use Piwik\Piwik; use Piwik\Piwik;
use Piwik\Plugin\ViewDataTable; use Piwik\Plugin\ViewDataTable;
use Piwik\Plugins\CoreVisualizations\Visualizations\Graph; use Piwik\Plugins\CoreVisualizations\Visualizations\Graph;
use Piwik\Plugins\CoreVisualizations\Visualizations\HtmlTable; use Piwik\Plugins\CoreVisualizations\Visualizations\HtmlTable;
use Piwik\Plugins\CoreVisualizations\Visualizations\JqplotGraph\Pie; use Piwik\Plugins\CoreVisualizations\Visualizations\JqplotGraph\Pie;
use Piwik\ScheduledTask;
use Piwik\ScheduledTime;
/**
*
*/
class DBStats extends \Piwik\Plugin class DBStats extends \Piwik\Plugin
{ {
const TIME_OF_LAST_TASK_RUN_OPTION = 'dbstats_time_of_last_cache_task_run'; const TIME_OF_LAST_TASK_RUN_OPTION = 'dbstats_time_of_last_cache_task_run';
...@@ -32,42 +26,12 @@ class DBStats extends \Piwik\Plugin ...@@ -32,42 +26,12 @@ class DBStats extends \Piwik\Plugin
{ {
return array( return array(
'AssetManager.getStylesheetFiles' => 'getStylesheetFiles', 'AssetManager.getStylesheetFiles' => 'getStylesheetFiles',
'TaskScheduler.getScheduledTasks' => 'getScheduledTasks',
'ViewDataTable.configure' => 'configureViewDataTable', 'ViewDataTable.configure' => 'configureViewDataTable',
'ViewDataTable.getDefaultType' => 'getDefaultTypeViewDataTable', 'ViewDataTable.getDefaultType' => 'getDefaultTypeViewDataTable',
"TestingEnvironment.addHooks" => 'setupTestEnvironment' "TestingEnvironment.addHooks" => 'setupTestEnvironment'
); );
} }
/**
* Gets all scheduled tasks executed by this plugin.
*/
public function getScheduledTasks(&$tasks)
{
$cacheDataByArchiveNameReportsTask = new ScheduledTask(
$this,
'cacheDataByArchiveNameReports',
null,
ScheduledTime::factory('weekly'),
ScheduledTask::LOWEST_PRIORITY
);
$tasks[] = $cacheDataByArchiveNameReportsTask;
}
/**
* Caches the intermediate DataTables used in the getIndividualReportsSummary and
* getIndividualMetricsSummary reports in the option table.
*/
public function cacheDataByArchiveNameReports()
{
$api = API::getInstance();
$api->getIndividualReportsSummary(true);
$api->getIndividualMetricsSummary(true);
$now = Date::now()->getLocalized("%longYear%, %shortMonth% %day%");
Option::set(self::TIME_OF_LAST_TASK_RUN_OPTION, $now);
}
public function getStylesheetFiles(&$stylesheets) public function getStylesheetFiles(&$stylesheets)
{ {
$stylesheets[] = "plugins/DBStats/stylesheets/dbStatsTable.less"; $stylesheets[] = "plugins/DBStats/stylesheets/dbStatsTable.less";
......
<?php
/**
* Piwik - Open source web analytics
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*
*/
namespace Piwik\Plugins\DBStats;
use Piwik\Date;
use Piwik\Option;
class Tasks extends \Piwik\Plugin\Tasks
{
public function schedule()
{
$this->weekly('cacheDataByArchiveNameReports', null, self::LOWEST_PRIORITY);
}
/**
* Caches the intermediate DataTables used in the getIndividualReportsSummary and
* getIndividualMetricsSummary reports in the option table.
*/
public function cacheDataByArchiveNameReports()
{
$api = API::getInstance();
$api->getIndividualReportsSummary(true);
$api->getIndividualMetricsSummary(true);
$now = Date::now()->getLocalized("%longYear%, %shortMonth% %day%");
Option::set(DBStats::TIME_OF_LAST_TASK_RUN_OPTION, $now);
}
}
\ No newline at end of file
<?php
/**
* Piwik - Open source web analytics
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*
*/
namespace Piwik\Plugins\ExamplePlugin;
class Tasks extends \Piwik\Plugin\Tasks
{
public function schedule()
{
$this->hourly('myTask'); // method will be executed once every hour
$this->daily('myTask'); // method will be executed every daily
$this->weekly('myTask'); // method will be executed once every weekly
$this->monthly('myTask'); // method will be executed once every monthly
// pass a parameter to the task
$this->weekly('myTaskWithParam', 'anystring');
// specify a different priority
$this->monthly('myTask', null, self::LOWEST_PRIORITY);
$this->monthly('myTaskWithParam', 'anystring', self::HIGH_PRIORITY);
}
public function myTask()
{
// do something
}
public function myTaskWithParam($param)
{
// do something
}
}
\ No newline at end of file
...@@ -18,8 +18,6 @@ use Piwik\Option; ...@@ -18,8 +18,6 @@ use Piwik\Option;
use Piwik\Period; use Piwik\Period;
use Piwik\Period\Range; use Piwik\Period\Range;
use Piwik\Plugins\Goals\Archiver; use Piwik\Plugins\Goals\Archiver;
use Piwik\ScheduledTask;
use Piwik\ScheduledTime;
use Piwik\Site; use Piwik\Site;
use Piwik\Tracker\GoalManager; use Piwik\Tracker\GoalManager;
...@@ -137,7 +135,6 @@ class PrivacyManager extends \Piwik\Plugin ...@@ -137,7 +135,6 @@ class PrivacyManager extends \Piwik\Plugin
{ {
return array( return array(
'AssetManager.getJavaScriptFiles' => 'getJsFiles', 'AssetManager.getJavaScriptFiles' => 'getJsFiles',
'TaskScheduler.getScheduledTasks' => 'getScheduledTasks',
'Tracker.setTrackerCacheGeneral' => 'setTrackerCacheGeneral', 'Tracker.setTrackerCacheGeneral' => 'setTrackerCacheGeneral',
'Tracker.isExcludedVisit' => array($this->dntChecker, 'checkHeaderInTracker'), 'Tracker.isExcludedVisit' => array($this->dntChecker, 'checkHeaderInTracker'),
'Tracker.setVisitorIp' => array($this->ipAnonymizer, 'setVisitorIpAddress'), 'Tracker.setVisitorIp' => array($this->ipAnonymizer, 'setVisitorIpAddress'),
...@@ -150,22 +147,6 @@ class PrivacyManager extends \Piwik\Plugin ...@@ -150,22 +147,6 @@ class PrivacyManager extends \Piwik\Plugin
$cacheContent = $config->setTrackerCacheGeneral($cacheContent); $cacheContent = $config->setTrackerCacheGeneral($cacheContent);
} }
public function getScheduledTasks(&$tasks)
{
// both tasks are low priority so they will execute after most others, but not lowest, so
// they will execute before the optimize tables task
$purgeReportDataTask = new ScheduledTask(
$this, 'deleteReportData', null, ScheduledTime::factory('daily'), ScheduledTask::LOW_PRIORITY
);
$tasks[] = $purgeReportDataTask;
$purgeLogDataTask = new ScheduledTask(
$this, 'deleteLogData', null, ScheduledTime::factory('daily'), ScheduledTask::LOW_PRIORITY
);
$tasks[] = $purgeLogDataTask;
}
public function getJsFiles(&$jsFiles) public function getJsFiles(&$jsFiles)
{ {
$jsFiles[] = "plugins/PrivacyManager/javascripts/privacySettings.js"; $jsFiles[] = "plugins/PrivacyManager/javascripts/privacySettings.js";
......
<?php
/**
* Piwik - Open source web analytics
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*
*/
namespace Piwik\Plugins\PrivacyManager;
class Tasks extends \Piwik\Plugin\Tasks
{
public function schedule()
{
$this->daily('deleteReportData', null, self::LOW_PRIORITY);
$this->daily('deleteLogData', null, self::LOW_PRIORITY);
}
public function deleteReportData()
{
$privacyManager = new PrivacyManager();
$privacyManager->deleteReportData();
}
public function deleteLogData()
{
$privacyManager = new PrivacyManager();
$privacyManager->deleteLogData();
}
}
\ No newline at end of file
...@@ -15,12 +15,9 @@ use Piwik\DbHelper; ...@@ -15,12 +15,9 @@ use Piwik\DbHelper;
use Piwik\Mail; use Piwik\Mail;
use Piwik\Piwik; use Piwik\Piwik;
use Piwik\Plugins\MobileMessaging\MobileMessaging; use Piwik\Plugins\MobileMessaging\MobileMessaging;
use Piwik\Plugins\SegmentEditor\API as APISegmentEditor;
use Piwik\Plugins\UsersManager\API as APIUsersManager; use Piwik\Plugins\UsersManager\API as APIUsersManager;
use Piwik\ReportRenderer; use Piwik\ReportRenderer;
use Piwik\ScheduledTask;
use Piwik\ScheduledTime; use Piwik\ScheduledTime;
use Piwik\Site;
use Piwik\View; use Piwik\View;
use Zend_Mime; use Zend_Mime;
...@@ -72,7 +69,6 @@ class ScheduledReports extends \Piwik\Plugin ...@@ -72,7 +69,6 @@ class ScheduledReports extends \Piwik\Plugin
public function getListHooksRegistered() public function getListHooksRegistered()
{ {
return array( return array(
'TaskScheduler.getScheduledTasks' => 'getScheduledTasks',
'AssetManager.getJavaScriptFiles' => 'getJsFiles', 'AssetManager.getJavaScriptFiles' => 'getJsFiles',
'MobileMessaging.deletePhoneNumber' => 'deletePhoneNumber', 'MobileMessaging.deletePhoneNumber' => 'deletePhoneNumber',
'ScheduledReports.getReportParameters' => 'getReportParameters', 'ScheduledReports.getReportParameters' => 'getReportParameters',
...@@ -463,25 +459,6 @@ class ScheduledReports extends \Piwik\Plugin ...@@ -463,25 +459,6 @@ class ScheduledReports extends \Piwik\Plugin
return in_array($reportType, array_keys(self::$managedReportTypes)); return in_array($reportType, array_keys(self::$managedReportTypes));
} }
public function getScheduledTasks(&$tasks)
{
foreach (API::getInstance()->getReports() as $report) {
if (!$report['deleted'] && $report['period'] != ScheduledTime::PERIOD_NEVER) {
$timezone = Site::getTimezoneFor($report['idsite']);
$schedule = ScheduledTime::getScheduledTimeForPeriod($report['period']);
$schedule->setHour($report['hour']);
$schedule->setTimezone($timezone);
$tasks[] = new ScheduledTask (
API::getInstance(),
'sendReport',
$report['idreport'], $schedule
);
}
}
}
public function segmentUpdated($idSegment, $updatedSegment) public function segmentUpdated($idSegment, $updatedSegment)
{ {
$reportsUsingSegment = API::getInstance()->getReports(false, false, false, false, $idSegment); $reportsUsingSegment = API::getInstance()->getReports(false, false, false, false, $idSegment);
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter