Exemplo n.º 1
0
 /**
  * @return array
  */
 private function getVisitFieldsPersist()
 {
     if (is_null($this->visitFieldsToSelect)) {
         $fields = array('idvisitor', 'idvisit', 'user_id', 'visit_exit_idaction_url', 'visit_exit_idaction_name', 'visitor_returning', 'visitor_days_since_first', 'visitor_days_since_order', 'visitor_count_visits', 'visit_goal_buyer', 'location_country', 'location_region', 'location_city', 'location_latitude', 'location_longitude', 'referer_name', 'referer_keyword', 'referer_type');
         $dimensions = VisitDimension::getAllDimensions();
         foreach ($dimensions as $dimension) {
             if ($dimension->hasImplementedEvent('onExistingVisit') || $dimension->hasImplementedEvent('onAnyGoalConversion')) {
                 $fields[] = $dimension->getColumnName();
             }
             foreach ($dimension->getRequiredVisitFields() as $field) {
                 $fields[] = $field;
             }
         }
         /**
          * This event collects a list of [visit entity](/guides/persistence-and-the-mysql-backend#visits) properties that should be loaded when reading
          * the existing visit. Properties that appear in this list will be available in other tracking
          * events such as 'onExistingVisit'.
          *
          * Plugins can use this event to load additional visit entity properties for later use during tracking.
          *
          * This event is deprecated, use [Dimensions](http://developer.piwik.org/guides/dimensions) instead.
          *
          * @deprecated
          */
         $this->eventDispatcher->postEvent('Tracker.getVisitFieldsToPersist', array(&$fields));
         array_unshift($fields, 'visit_first_action_time');
         array_unshift($fields, 'visit_last_action_time');
         for ($index = 1; $index <= CustomVariables::getNumUsableCustomVariables(); $index++) {
             $fields[] = 'custom_var_k' . $index;
             $fields[] = 'custom_var_v' . $index;
         }
         $this->visitFieldsToSelect = array_unique($fields);
     }
     return $this->visitFieldsToSelect;
 }
 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);
 }
Exemplo n.º 3
0
Arquivo: Base.php Projeto: piwik/piwik
 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;
 }
Exemplo n.º 4
0
 public function afterRequestProcessed(VisitProperties $visitProperties, Request $request)
 {
     $ip = $visitProperties->getProperty('location_ip');
     /**
      * Triggered after visits are tested for exclusion so plugins can modify the IP address
      * persisted with a visit.
      *
      * This event is primarily used by the **PrivacyManager** plugin to anonymize IP addresses.
      *
      * @param string &$ip The visitor's IP address.
      */
     $this->eventDispatcher->postEvent('Tracker.setVisitorIp', array(&$ip));
     $visitProperties->setProperty('location_ip', $ip);
 }
Exemplo n.º 5
0
 /**
  * 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);
     }
 }
Exemplo n.º 6
0
 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
 }
Exemplo n.º 7
0
 /**
  * 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);
 }
Exemplo n.º 8
0
 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
 }
Exemplo n.º 9
0
 private function setUpPluginManager()
 {
     $this->pluginManager = PluginManagerMock::getInstance();
     Manager::setSingletonInstance($this->pluginManager);
     EventDispatcher::unsetInstance();
     // EventDispatcher stores a reference to Plugin Manager
 }
Exemplo n.º 10
0
 public function tearDown()
 {
     EventDispatcher::getInstance()->clearObservers('Tracker.Request.getIdSite');
     parent::tearDown();
 }
Exemplo n.º 11
0
 /**
  * @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();
 }
Exemplo n.º 12
0
 /**
  * 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);
     }
 }
Exemplo n.º 13
0
 /**
  * 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);
     }
 }
Exemplo n.º 14
0
 /**
  * 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);
         }
     }
 }