public function test_CheckIfMethodComment_DoesNotContainHideAnnotation() { $annotation = '@not found here'; EventDispatcher::getInstance()->addObserver('API.DocumentationGenerator.@hello', function (&$hide) { $hide = true; }); $this->assertEquals(Proxy::getInstance()->shouldHideAPIMethod($annotation), false); }
protected function configureFooterMessage(ViewDataTable $view) { if ($this->isSubtableReport) { // no footer message for subtables return; } $out = ''; EventDispatcher::getInstance()->postEvent('Template.afterEventsReport', array(&$out)); $view->config->show_footer_message = $out; }
/** * Load the plugins classes installed. * Register the observers for every plugin. */ private function reloadActivatedPlugins() { $pluginsToPostPendingEventsTo = array(); foreach ($this->pluginsToLoad as $pluginName) { if (!$this->isPluginLoaded($pluginName) && !$this->isPluginThirdPartyAndBogus($pluginName)) { $newPlugin = $this->loadPlugin($pluginName); if ($newPlugin === null) { continue; } if ($newPlugin->hasMissingDependencies()) { $this->deactivatePlugin($pluginName); continue; } $pluginsToPostPendingEventsTo[] = $newPlugin; } } // post pending events after all plugins are successfully loaded foreach ($pluginsToPostPendingEventsTo as $plugin) { EventDispatcher::getInstance()->postPendingEventsTo($plugin); } }
public function performTearDown() { // Note: avoid run SQL in the *tearDown() metohds because it randomly fails on Travis CI // with error Error while sending QUERY packet. PID=XX $this->tearDown(); self::unloadAllPlugins(); if ($this->dropDatabaseInTearDown) { $this->dropDatabase(); } DataTableManager::getInstance()->deleteAll(); Option::clearCache(); Site::clearCache(); Cache::deleteTrackerCache(); Config::getInstance()->clear(); ArchiveTableCreator::clear(); \Piwik\Plugins\ScheduledReports\API::$cache = array(); \Piwik\Registry::unsetInstance(); \Piwik\EventDispatcher::getInstance()->clearAllObservers(); $_GET = $_REQUEST = array(); Translate::unloadEnglishTranslation(); Config::unsetInstance(); \Piwik\Config::getInstance()->Plugins; // make sure Plugins exists in a config object for next tests that use Plugin\Manager // since Plugin\Manager uses getFromGlobalConfig which doesn't init the config object }
/** * Register an observer to an event. * * **_Note: Observers should normally be defined in plugin objects. It is unlikely that you will * need to use this function._** * * @param string $eventName The event name. * @param callable|array $function The observer. * @api */ public static function addAction($eventName, $function) { EventDispatcher::getInstance()->addObserver($eventName, $function); }
public function clearInMemoryCaches() { DataTableManager::getInstance()->deleteAll(); Option::clearCache(); Site::clearCache(); Cache::deleteTrackerCache(); Config::getInstance()->clear(); ArchiveTableCreator::clear(); \Piwik\Plugins\ScheduledReports\API::$cache = array(); \Piwik\Registry::unsetInstance(); \Piwik\EventDispatcher::getInstance()->clearAllObservers(); $_GET = $_REQUEST = array(); Translate::unloadEnglishTranslation(); Config::unsetInstance(); \Piwik\Config::getInstance()->Plugins; // make sure Plugins exists in a config object for next tests that use Plugin\Manager // since Plugin\Manager uses getFromGlobalConfig which doesn't init the config object }
public function tearDown() { EventDispatcher::getInstance()->clearObservers('Tracker.Request.getIdSite'); parent::tearDown(); }
/** * @group Core * * @dataProvider testRunTasksTestCases */ public function testRunTasks($expectedTimetable, $expectedExecutedTasks, $timetableBeforeTaskExecution, $configuredTasks) { // temporarily unload plugins $plugins = \Piwik\Plugin\Manager::getInstance()->getLoadedPlugins(); $plugins = array_map(function ($p) { return $p->getPluginName(); }, $plugins); \Piwik\Plugin\Manager::getInstance()->unloadPlugins(); // make sure the get tasks event returns our configured tasks \Piwik\Piwik::addAction(TaskScheduler::GET_TASKS_EVENT, function (&$tasks) use($configuredTasks) { $tasks = $configuredTasks; }); // stub the piwik option object to control the returned option value self::stubPiwikOption(serialize($timetableBeforeTaskExecution)); TaskScheduler::unsetInstance(); // execute tasks $executionResults = TaskScheduler::runTasks(); // assert methods are executed $executedTasks = array(); foreach ($executionResults as $executionResult) { $executedTasks[] = $executionResult['task']; $this->assertNotEmpty($executionResult['output']); } $this->assertEquals($expectedExecutedTasks, $executedTasks); // assert the timetable is correctly updated $timetable = new ScheduledTaskTimetable(); $this->assertEquals($expectedTimetable, $timetable->getTimetable()); // restore loaded plugins & piwik options EventDispatcher::getInstance()->clearObservers(TaskScheduler::GET_TASKS_EVENT); \Piwik\Plugin\Manager::getInstance()->loadPlugins($plugins); self::resetPiwikOption(); }
/** * Load the plugins classes installed. * Register the observers for every plugin. */ private function reloadActivatedPlugins() { $pluginsToPostPendingEventsTo = array(); foreach ($this->pluginsToLoad as $pluginName) { if (!$this->isPluginLoaded($pluginName) && !$this->isPluginThirdPartyAndBogus($pluginName)) { $newPlugin = $this->loadPlugin($pluginName); if ($newPlugin === null) { continue; } if ($newPlugin->hasMissingDependencies()) { $this->deactivatePlugin($pluginName); // at this state we do not know yet whether current user has super user access. We do not even know // if someone is actually logged in. $message = Piwik::translate('CorePluginsAdmin_WeDeactivatedThePluginAsItHasMissingDependencies', array($pluginName, $newPlugin->getMissingDependenciesAsString())); $message .= ' '; $message .= Piwik::translate('General_PleaseContactYourPiwikAdministrator'); $notification = new Notification($message); $notification->context = Notification::CONTEXT_ERROR; Notification\Manager::notify('PluginManager_PluginDeactivated', $notification); continue; } $pluginsToPostPendingEventsTo[] = $newPlugin; } } // post pending events after all plugins are successfully loaded foreach ($pluginsToPostPendingEventsTo as $plugin) { EventDispatcher::getInstance()->postPendingEventsTo($plugin); } }
/** * Load the plugins classes installed. * Register the observers for every plugin. */ private function reloadActivatedPlugins() { $pluginsToPostPendingEventsTo = array(); foreach ($this->pluginsToLoad as $pluginName) { if (!$this->isPluginLoaded($pluginName) && !$this->isPluginThirdPartyAndBogus($pluginName)) { $newPlugin = $this->loadPlugin($pluginName); if ($newPlugin === null) { continue; } if ($newPlugin->hasMissingDependencies()) { $this->deactivatePlugin($pluginName); // add this state we do not know yet whether current user has super user access. We do not even know // if someone is actually logged in. $message = sprintf('We disabled the plugin %s as it has missing dependencies.', $pluginName); $message .= ' Please contact your Piwik administrator.'; $notification = new Notification($message); $notification->context = Notification::CONTEXT_ERROR; Notification\Manager::notify('PluginManager_PluginDeactivated', $notification); continue; } $pluginsToPostPendingEventsTo[] = $newPlugin; } } // post pending events after all plugins are successfully loaded foreach ($pluginsToPostPendingEventsTo as $plugin) { EventDispatcher::getInstance()->postPendingEventsTo($plugin); } }
/** * Load the plugins classes installed. * Register the observers for every plugin. */ private function reloadPlugins() { if ($this->doLoadAlwaysActivatedPlugins) { $this->pluginsToLoad = array_merge($this->pluginsToLoad, $this->pluginToAlwaysActivate); } $this->pluginsToLoad = array_unique($this->pluginsToLoad); foreach ($this->pluginsToLoad as $pluginName) { if (!$this->isPluginLoaded($pluginName) && !$this->isPluginThirdPartyAndBogus($pluginName)) { $newPlugin = $this->loadPlugin($pluginName); if ($newPlugin === null) { continue; } EventDispatcher::getInstance()->postPendingEventsTo($newPlugin); } } }