Пример #1
0
 static function update($schema = 'Myisam')
 {
     // force regeneration of cache files following #648
     Piwik::setUserIsSuperUser();
     $allSiteIds = API::getInstance()->getAllSitesId();
     Cache::regenerateCacheWebsiteAttributes($allSiteIds);
 }
Пример #2
0
 /**
  * Returns array containing data about the website: goals, URLs, etc.
  *
  * @param int $idSite
  * @return array
  */
 static function getCacheWebsiteAttributes($idSite)
 {
     if ($idSite == 'all') {
         return array();
     }
     $idSite = (int) $idSite;
     if ($idSite <= 0) {
         return array();
     }
     $cache = self::getInstance();
     if (($cacheContent = $cache->get($idSite)) !== false) {
         return $cacheContent;
     }
     Tracker::initCorePiwikInTrackerMode();
     // save current user privilege and temporarily assume super user privilege
     $isSuperUser = Piwik::isUserIsSuperUser();
     Piwik::setUserIsSuperUser();
     $content = array();
     /**
      * Triggered to get the attributes of a site entity that might be used by the
      * Tracker.
      * 
      * Plugins add new site attributes for use in other tracking events must
      * use this event to put those attributes in the Tracker Cache.
      * 
      * **Example**
      * 
      *     public function getSiteAttributes($content, $idSite)
      *     {
      *         $sql = "SELECT info FROM " . Common::prefixTable('myplugin_extra_site_info') . " WHERE idsite = ?";
      *         $content['myplugin_site_data'] = Db::fetchOne($sql, array($idSite));
      *     }
      * 
      * @param array &$content Array mapping of site attribute names with values.
      * @param int $idSite The site ID to get attributes for.
      */
     Piwik::postEvent('Tracker.Cache.getSiteAttributes', array(&$content, $idSite));
     // restore original user privilege
     Piwik::setUserIsSuperUser($isSuperUser);
     // if nothing is returned from the plugins, we don't save the content
     // this is not expected: all websites are expected to have at least one URL
     if (!empty($content)) {
         $cache->set($idSite, $content);
     }
     return $content;
 }
Пример #3
0
 static function update()
 {
     $obsoleteFiles = array(PIWIK_INCLUDE_PATH . '/core/Db/Mysqli.php');
     foreach ($obsoleteFiles as $obsoleteFile) {
         if (file_exists($obsoleteFile)) {
             @unlink($obsoleteFile);
         }
     }
     $obsoleteDirectories = array(PIWIK_INCLUDE_PATH . '/core/Db/Pdo');
     foreach ($obsoleteDirectories as $dir) {
         if (file_exists($dir)) {
             Filesystem::unlinkRecursive($dir, true);
         }
     }
     // force regeneration of cache files
     Piwik::setUserIsSuperUser();
     $allSiteIds = API::getInstance()->getAllSitesId();
     Cache::regenerateCacheWebsiteAttributes($allSiteIds);
 }
Пример #4
0
 /**
  * Get user information
  *
  * @param string $loginMail user login or email address
  * @return array ("login" => '...', "email" => '...', "password" => '...') or null, if user not found
  */
 protected function getUserInformation($loginMail)
 {
     Piwik::setUserIsSuperUser();
     $user = null;
     if ($loginMail == Piwik::getSuperUserEmail() || $loginMail == Config::getInstance()->superuser['login']) {
         $user = array('login' => Config::getInstance()->superuser['login'], 'email' => Piwik::getSuperUserEmail(), 'password' => Config::getInstance()->superuser['password']);
     } else {
         if (API::getInstance()->userExists($loginMail)) {
             $user = API::getInstance()->getUser($loginMail);
         } else {
             if (API::getInstance()->userEmailExists($loginMail)) {
                 $user = API::getInstance()->getUserByEmail($loginMail);
             }
         }
     }
     return $user;
 }
Пример #5
0
 /**
  * Tracker requests will automatically trigger the Scheduled tasks.
  * This is useful for users who don't setup the cron,
  * but still want daily/weekly/monthly PDF reports emailed automatically.
  *
  * This is similar to calling the API CoreAdminHome.runScheduledTasks (see misc/cron/archive.php)
  */
 protected static function runScheduledTasks()
 {
     $now = time();
     // Currently, there are no hourly tasks. When there are some,
     // this could be too aggressive minimum interval (some hours would be skipped in case of low traffic)
     $minimumInterval = Config::getInstance()->Tracker['scheduled_tasks_min_interval'];
     // If the user disabled browser archiving, he has already setup a cron
     // To avoid parallel requests triggering the Scheduled Tasks,
     // Get last time tasks started executing
     $cache = Cache::getCacheGeneral();
     if ($minimumInterval <= 0 || empty($cache['isBrowserTriggerArchivingEnabled'])) {
         Common::printDebug("-> Scheduled tasks not running in Tracker: Browser archiving is disabled.");
         return;
     }
     $nextRunTime = $cache['lastTrackerCronRun'] + $minimumInterval;
     if (isset($GLOBALS['PIWIK_TRACKER_DEBUG_FORCE_SCHEDULED_TASKS']) && $GLOBALS['PIWIK_TRACKER_DEBUG_FORCE_SCHEDULED_TASKS'] || $cache['lastTrackerCronRun'] === false || $nextRunTime < $now) {
         $cache['lastTrackerCronRun'] = $now;
         Cache::setCacheGeneral($cache);
         self::initCorePiwikInTrackerMode();
         Option::set('lastTrackerCronRun', $cache['lastTrackerCronRun']);
         Common::printDebug('-> Scheduled Tasks: Starting...');
         // save current user privilege and temporarily assume super user privilege
         $isSuperUser = Piwik::isUserIsSuperUser();
         // Scheduled tasks assume Super User is running
         Piwik::setUserIsSuperUser();
         // While each plugins should ensure that necessary languages are loaded,
         // we ensure English translations at least are loaded
         Translate::loadEnglishTranslation();
         $resultTasks = TaskScheduler::runTasks();
         // restore original user privilege
         Piwik::setUserIsSuperUser($isSuperUser);
         Common::printDebug($resultTasks);
         Common::printDebug('Finished Scheduled Tasks.');
     } else {
         Common::printDebug("-> Scheduled tasks not triggered.");
     }
     Common::printDebug("Next run will be from: " . date('Y-m-d H:i:s', $nextRunTime) . ' UTC');
 }
Пример #6
0
 /**
  * Instantiate access and log objects
  */
 protected function initObjectsToCallAPI()
 {
     // connect to the database using the DB infos currently in the session
     $this->createDbFromSessionInformation();
     Piwik::setUserIsSuperUser();
 }
Пример #7
0
 public function init()
 {
     // Note: the order of methods call matters here.
     $this->displayHelp();
     $this->initPiwikHost();
     $this->initLog();
     $this->initCore();
     $this->initTokenAuth();
     $this->initCheckCli();
     $this->initStateFromParameters();
     Piwik::setUserIsSuperUser(true);
     $this->logInitInfo();
     $this->checkPiwikUrlIsValid();
     $this->logArchiveTimeoutInfo();
     $this->segments = $this->initSegmentsToArchive();
     $this->allWebsites = APISitesManager::getInstance()->getAllSitesId();
     $websitesIds = $this->initWebsiteIds();
     $this->filterWebsiteIds($websitesIds);
     $this->websites = $websitesIds;
     if ($this->shouldStartProfiler) {
         \Piwik\Profiler::setupProfilerXHProf($mainRun = true);
         $this->log("XHProf profiling is enabled.");
     }
 }
<?php

// Script that creates 100 websites, then outputs a IMG that records a pageview in each website
// Used initially to test how to handle cookies for this use case (see http://dev.piwik.org/trac/ticket/409)
use Piwik\Common;
use Piwik\FrontController;
use Piwik\Piwik;
use Piwik\Plugins\SitesManager\API;
exit;
define('PIWIK_INCLUDE_PATH', '../..');
define('PIWIK_ENABLE_DISPATCH', false);
define('PIWIK_ENABLE_ERROR_HANDLER', false);
define('PIWIK_ENABLE_SESSION_START', false);
require_once PIWIK_INCLUDE_PATH . "/index.php";
require_once PIWIK_INCLUDE_PATH . "/core/API/Request.php";
require_once PIWIK_INCLUDE_PATH . "/libs/PiwikTracker/PiwikTracker.php";
FrontController::getInstance()->init();
Piwik::setUserIsSuperUser();
$count = 100;
for ($i = 0; $i <= $count; $i++) {
    $id = API::getInstance()->addSite(Common::getRandomString(), 'http://piwik.org');
    $t = new PiwikTracker($id, 'http://localhost/trunk/piwik.php');
    echo $id . " <img width=100 height=10 border=1 src='" . $t->getUrlTrackPageView('title') . "'><br/>";
}