php Piwik-Tracker类(方法)实例源码

下面列出了php Piwik-Tracker 类(方法)源码代码实例,从而了解它的用法。

作者:a4tunad    项目:piwi   
protected function sendRequest($url, $method = 'GET', $data = null, $force = false)
 {
     // if doing a bulk request, store the url
     if ($this->doBulkRequests && !$force) {
         $this->storedTrackingActions[] = $url;
         return true;
     }
     if ($method == 'POST') {
         $requests = array();
         foreach ($this->storedTrackingActions as $action) {
             $requests[] = $this->parseUrl($action);
         }
         $testEnvironmentArgs = array();
     } else {
         $testEnvironmentArgs = $this->parseUrl($url);
         $requests = array($testEnvironmentArgs);
     }
     // unset cached values
     Cache::$trackerCache = null;
     Tracker::setForceIp(null);
     Tracker::setForceDateTime(null);
     // save some values
     $plugins = Config::getInstance()->Plugins['Plugins'];
     $oldTrackerConfig = Config::getInstance()->Tracker;
     \Piwik\Plugin\Manager::getInstance()->unloadPlugins();
     // modify config
     $GLOBALS['PIWIK_TRACKER_MODE'] = true;
     $GLOBALS['PIWIK_TRACKER_LOCAL_TRACKING'] = true;
     Tracker::$initTrackerMode = false;
     Tracker::setTestEnvironment($testEnvironmentArgs, $method);
     // set language
     $oldLang = isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) ? $_SERVER['HTTP_ACCEPT_LANGUAGE'] : '';
     $_SERVER['HTTP_ACCEPT_LANGUAGE'] = $this->acceptLanguage;
     // set user agent
     $oldUserAgent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '';
     $_SERVER['HTTP_USER_AGENT'] = $this->userAgent;
     // set cookie
     $oldCookie = $_COOKIE;
     //        parse_str(parse_url($this->requestCookie, PHP_URL_QUERY), $_COOKIE);
     // do tracking and capture output
     ob_start();
     $localTracker = new Tracker();
     $localTracker->main($requests);
     $output = ob_get_contents();
     ob_end_clean();
     // restore vars
     Config::getInstance()->Tracker = $oldTrackerConfig;
     $_SERVER['HTTP_ACCEPT_LANGUAGE'] = $oldLang;
     $_SERVER['HTTP_USER_AGENT'] = $oldUserAgent;
     $_COOKIE = $oldCookie;
     $GLOBALS['PIWIK_TRACKER_LOCAL_TRACKING'] = false;
     $GLOBALS['PIWIK_TRACKER_MODE'] = false;
     unset($_GET['bots']);
     // reload plugins
     \Piwik\Plugin\Manager::getInstance()->loadPlugins($plugins);
     return $output;
 }

作者:cem    项目:piwi   
public function shouldRun(Tracker $tracker)
 {
     if (Common::isPhpCliMode()) {
         // don't run scheduled tasks in CLI mode from Tracker, this is the case
         // where we bulk load logs & don't want to lose time with tasks
         return false;
     }
     return $tracker->shouldRecordStatistics();
 }

作者:ruchitram    项目:plugin-QueuedTrackin   
public function process(Tracker $tracker, RequestSet $requestSet)
 {
     $queueManager = $this->getQueueManager();
     $queueManager->addRequestSetToQueues($requestSet);
     $tracker->setCountOfLoggedRequests($requestSet->getNumberOfRequests());
     $this->sendResponseNow($tracker, $requestSet);
     if ($this->isAllowedToProcessInTrackerMode() && $queueManager->canAcquireMoreLocks()) {
         $this->processQueue($queueManager);
     }
 }

作者:KiwiJuice    项目:handball-dacha   
/**
  * Returns the database connection and creates it if it hasn't been already.
  *
  * @return \Piwik\Tracker\Db|\Piwik\Db\AdapterInterface|\Piwik\Db
  */
 public static function get()
 {
     if (!empty($GLOBALS['PIWIK_TRACKER_MODE'])) {
         return Tracker::getDatabase();
     }
     if (self::$connection === null) {
         self::createDatabaseObject();
     }
     return self::$connection;
 }

作者:FluentDevelopmen    项目:piwi   
/**
  * Returns the database connection and creates it if it hasn't been already.
  *
  * @return \Piwik\Tracker\Db|\Piwik\Db\AdapterInterface|\Piwik\Db
  */
 public static function get()
 {
     if (SettingsServer::isTrackerApiRequest()) {
         return Tracker::getDatabase();
     }
     if (!self::hasDatabaseObject()) {
         self::createDatabaseObject();
     }
     return self::$connection;
 }

作者:pombredann    项目:ArcherSy   
/**
  * @return array names of plugins that have been loaded
  */
 public function loadTrackerPlugins()
 {
     $this->unloadPlugins();
     $pluginsTracker = PiwikConfig::getInstance()->Plugins_Tracker['Plugins_Tracker'];
     if (empty($pluginsTracker)) {
         return array();
     }
     $pluginsTracker = array_diff($pluginsTracker, Tracker::getPluginsNotToLoad());
     $this->doNotLoadAlwaysActivatedPlugins();
     $this->loadPlugins($pluginsTracker);
     return $pluginsTracker;
 }

作者:carriercom    项目:piwi   
/**
  * @return array names of plugins that have been loaded
  */
 public function loadTrackerPlugins()
 {
     $this->unloadPlugins();
     $pluginsTracker = PiwikConfig::getInstance()->Plugins_Tracker['Plugins_Tracker'];
     if (empty($pluginsTracker)) {
         return array();
     }
     $pluginsTracker = array_diff($pluginsTracker, Tracker::getPluginsNotToLoad());
     if (defined('PIWIK_TEST_MODE')) {
         $pluginsTracker = array_intersect($pluginsTracker, $this->getPluginsToLoadDuringTests());
     }
     $this->doNotLoadAlwaysActivatedPlugins();
     $this->loadPlugins($pluginsTracker);
     return $pluginsTracker;
 }

作者:ruchitram    项目:plugin-QueuedTrackin   
protected function execute(InputInterface $input, OutputInterface $output)
 {
     $systemCheck = new SystemCheck();
     $systemCheck->checkRedisIsInstalled();
     $trackerEnvironment = new Environment('tracker');
     $trackerEnvironment->init();
     Log::unsetInstance();
     $trackerEnvironment->getContainer()->get('Piwik\\Access')->setSuperUserAccess(false);
     $trackerEnvironment->getContainer()->get('Piwik\\Plugin\\Manager')->setTrackerPluginsNotToLoad(array('Provider'));
     Tracker::loadTrackerEnvironment();
     if (OutputInterface::VERBOSITY_VERY_VERBOSE <= $output->getVerbosity()) {
         $GLOBALS['PIWIK_TRACKER_DEBUG'] = true;
     }
     $backend = Queue\Factory::makeBackend();
     $queueManager = Queue\Factory::makeQueueManager($backend);
     if (!$queueManager->canAcquireMoreLocks()) {
         $trackerEnvironment->destroy();
         $this->writeSuccessMessage($output, array("Nothing to proccess. Already max number of workers in process."));
         return;
     }
     $shouldProcess = false;
     foreach ($queueManager->getAllQueues() as $queue) {
         if ($queue->shouldProcess()) {
             $shouldProcess = true;
             break;
         }
     }
     if (!$shouldProcess) {
         $trackerEnvironment->destroy();
         $this->writeSuccessMessage($output, array("No queue currently needs processing"));
         return;
     }
     $output->writeln("<info>Starting to process request sets, this can take a while</info>");
     register_shutdown_function(function () use($queueManager) {
         $queueManager->unlock();
     });
     $startTime = microtime(true);
     $processor = new Processor($queueManager);
     $processor->setNumberOfMaxBatchesToProcess(1000);
     $tracker = $processor->process();
     $neededTime = microtime(true) - $startTime;
     $numRequestsTracked = $tracker->getCountOfLoggedRequests();
     $requestsPerSecond = $this->getNumberOfRequestsPerSecond($numRequestsTracked, $neededTime);
     Piwik::postEvent('Tracker.end');
     $trackerEnvironment->destroy();
     $this->writeSuccessMessage($output, array(sprintf('This worker finished queue processing with %sreq/s (%s requests in %02.2f seconds)', $requestsPerSecond, $numRequestsTracked, $neededTime)));
 }

作者:FluentDevelopmen    项目:piwi   
public function test_rowCount_whenUpdating_returnsAllMatchedRowsNotOnlyUpdatedRows()
 {
     $db = Tracker::getDatabase();
     // insert one record
     $db->query("INSERT INTO `" . Common::prefixTable('option') . "` VALUES ('rowid', '1', false)");
     // We will now UPDATE this table and check rowCount() value
     $sqlUpdate = "UPDATE `" . Common::prefixTable('option') . "` SET option_value = 2";
     // when no record was updated, return 0
     $result = $db->query($sqlUpdate . " WHERE option_name = 'NOT FOUND'");
     $this->assertSame(0, $db->rowCount($result));
     // when one record was found and updated, returns 1
     $result = $db->query($sqlUpdate . " WHERE option_name = 'rowid'");
     $this->assertSame(1, $db->rowCount($result));
     // when one record was found but NOT actually updated (as values have not changed), we make sure to return 1
     // testing for MYSQLI_CLIENT_FOUND_ROWS and MYSQL_ATTR_FOUND_ROWS
     $result = $db->query($sqlUpdate . " WHERE option_name = 'rowid'");
     $this->assertSame(1, $db->rowCount($result));
 }

作者:bossrabbi    项目:piwi   
/**
  * 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
  */
 public 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 = TrackerConfig::getConfigValue('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['isBrowserTriggerEnabled'])) {
         Common::printDebug("-> Scheduled tasks not running in Tracker: Browser archiving is disabled.");
         return;
     }
     $nextRunTime = $cache['lastTrackerCronRun'] + $minimumInterval;
     if (defined('DEBUG_FORCE_SCHEDULED_TASKS') && DEBUG_FORCE_SCHEDULED_TASKS || $cache['lastTrackerCronRun'] === false || $nextRunTime < $now) {
         $cache['lastTrackerCronRun'] = $now;
         Cache::setCacheGeneral($cache);
         Tracker::initCorePiwikInTrackerMode();
         Option::set('lastTrackerCronRun', $cache['lastTrackerCronRun']);
         Common::printDebug('-> Scheduled Tasks: Starting...');
         // save current user privilege and temporarily assume Super User privilege
         $isSuperUser = Piwik::hasUserSuperUserAccess();
         // Scheduled tasks assume Super User is running
         Piwik::setUserHasSuperUserAccess();
         $tokens = CronArchive::getSuperUserTokenAuths();
         $tokenAuth = reset($tokens);
         $invokeScheduledTasksUrl = SettingsPiwik::getPiwikUrl() . "?module=API&format=csv&convertToUnicode=0&method=CoreAdminHome.runScheduledTasks&trigger=archivephp&token_auth={$tokenAuth}";
         $cliMulti = new CliMulti();
         $responses = $cliMulti->request(array($invokeScheduledTasksUrl));
         $resultTasks = reset($responses);
         // restore original user privilege
         Piwik::setUserHasSuperUserAccess($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');
 }

作者:FluentDevelopmen    项目:piwi   
private function getDb()
 {
     return Tracker::getDatabase();
 }

作者:FluentDevelopmen    项目:piwi   
require_once PIWIK_INCLUDE_PATH . '/core/Db/DAO/Base.php';
require_once PIWIK_INCLUDE_PATH . '/core/Db/DAO/Generic.php';
require_once PIWIK_INCLUDE_PATH . '/core/Db/DAO/Mysql/Generic.php';
require_once PIWIK_INCLUDE_PATH . '/core/Db/DAO/Pgsql/Generic.php';
require_once PIWIK_INCLUDE_PATH . '/core/Db/DAO/Mysql/LogAction.php';
require_once PIWIK_INCLUDE_PATH . '/core/Db/DAO/Pgsql/LogAction.php';
require_once PIWIK_INCLUDE_PATH . '/core/Db/DAO/Mysql/LogVisit.php';
require_once PIWIK_INCLUDE_PATH . '/core/Db/DAO/Pgsql/LogVisit.php';
require_once PIWIK_INCLUDE_PATH . '/core/Db/DAO/Mysql/LogLinkVisitAction.php';
require_once PIWIK_INCLUDE_PATH . '/core/Db/DAO/Pgsql/LogLinkVisitAction.php';
// TODO should move to Tracker application class later. currently needed for environment validation.
SettingsServer::setIsTrackerApiRequest();
$environment = new \Piwik\Application\Environment('tracker');
$environment->init();
Tracker::loadTrackerEnvironment();
$tracker = new Tracker();
$requestSet = new RequestSet();
ob_start();
try {
    $handler = Handler\Factory::make();
    $response = $tracker->main($handler, $requestSet);
    if (!is_null($response)) {
        echo $response;
    }
} catch (Exception $e) {
    echo "Error:" . $e->getMessage();
    exit(1);
}
if (ob_get_level() > 1) {
    ob_end_flush();
}

作者:jos    项目:CGE-File-Sharin   
private static function queryIdsAction($actionsNameAndType)
 {
     $sql = TableLogAction::getSqlSelectActionId();
     $bind = array();
     $i = 0;
     foreach ($actionsNameAndType as &$actionNameType) {
         list($name, $type, $urlPrefix) = $actionNameType;
         if (empty($name)) {
             continue;
         }
         if ($i > 0) {
             $sql .= " OR ( hash = CRC32(?) AND name = ? AND type = ? ) ";
         }
         $bind[] = $name;
         $bind[] = $name;
         $bind[] = $type;
         $i++;
     }
     // Case URL & Title are empty
     if (empty($bind)) {
         return false;
     }
     $actionIds = Tracker::getDatabase()->fetchAll($sql, $bind);
     return $actionIds;
 }

作者:bossrabbi    项目:piwi   
private function outputApiResponse(Tracker $tracker)
 {
     if ($tracker->isDebugModeEnabled()) {
         return;
     }
     if ($this->hasAlreadyPrintedOutput()) {
         return;
     }
     $request = $_GET + $_POST;
     if (array_key_exists('send_image', $request) && $request['send_image'] === '0') {
         Common::sendResponseCode(204);
         return;
     }
     $this->outputTransparentGif();
 }

作者:FluentDevelopmen    项目:piwi   
/**
  * Print profiling report for the tracker
  *
  * @param \Piwik\Db $db Tracker database object (or null)
  */
 public static function displayDbTrackerProfile($db = null)
 {
     if (is_null($db)) {
         $db = Tracker::getDatabase();
     }
     $LogProfiling = Factory::getDAO('log_profiling', $db);
     $all = $LogProfiling->getAll();
     if ($all === false) {
         return;
     }
     uasort($all, 'self::maxSumMsFirst');
     $infoIndexedByQuery = array();
     foreach ($all as $infoQuery) {
         $query = $infoQuery['query'];
         $count = $infoQuery['count'];
         $sum_time_ms = $infoQuery['sum_time_ms'];
         $infoIndexedByQuery[$query] = array('count' => $count, 'sumTimeMs' => $sum_time_ms);
     }
     self::getSqlProfilingQueryBreakdownOutput($infoIndexedByQuery);
 }

作者:carriercom    项目:piwi   
/**
  * Gather fields=>values that needs to be updated for the existing visit in log_visit
  *
  * @param $action
  * @param $visitIsConverted
  * @return array
  */
 protected function getExistingVisitFieldsToUpdate($action, $visitIsConverted)
 {
     $valuesToUpdate = array();
     if ($action) {
         $idActionUrl = $action->getIdActionUrlForEntryAndExitIds();
         $idActionName = $action->getIdActionNameForEntryAndExitIds();
         $actionType = $action->getActionType();
         if ($idActionName !== false) {
             $valuesToUpdate['visit_exit_idaction_name'] = $idActionName;
         }
         $incrementActions = false;
         if ($idActionUrl !== false) {
             $valuesToUpdate['visit_exit_idaction_url'] = $idActionUrl;
             $incrementActions = true;
         }
         if ($actionType == Action::TYPE_SITE_SEARCH) {
             $valuesToUpdate['visit_total_searches'] = 'visit_total_searches + 1';
             $incrementActions = true;
         } else {
             if ($actionType == Action::TYPE_EVENT) {
                 $valuesToUpdate['visit_total_events'] = 'visit_total_events + 1';
                 $incrementActions = true;
             }
         }
         if ($incrementActions) {
             $valuesToUpdate['visit_total_actions'] = 'visit_total_actions + 1';
         }
     }
     $datetimeServer = Tracker::getDatetimeFromTimestamp($this->request->getCurrentTimestamp());
     $valuesToUpdate['visit_last_action_time'] = $datetimeServer;
     // Add 1 so it's always > 0
     $visitTotalTime = 1 + $this->request->getCurrentTimestamp() - $this->visitorInfo['visit_first_action_time'];
     $valuesToUpdate['visit_total_time'] = self::cleanupVisitTotalTime($visitTotalTime);
     // Goal conversion
     if ($visitIsConverted) {
         $valuesToUpdate['visit_goal_converted'] = 1;
         // If a pageview and goal conversion in the same second, with previously a goal conversion recorded
         // the request would not "update" the row since all values are the same as previous
         // therefore the request below throws exception, instead we make sure the UPDATE will affect the row
         $valuesToUpdate['visit_total_time'] = self::cleanupVisitTotalTime($valuesToUpdate['visit_total_time'] + $this->goalManager->idGoal + 2);
     }
     // Might update the idvisitor when it was forced or overwritten for this visit
     if (strlen($this->visitorInfo['idvisitor']) == Tracker::LENGTH_BINARY_ID) {
         $valuesToUpdate['idvisitor'] = $this->visitorInfo['idvisitor'];
     }
     // Ecommerce buyer status
     $visitEcommerceStatus = $this->goalManager->getBuyerType($this->visitorInfo['visit_goal_buyer']);
     if ($visitEcommerceStatus != GoalManager::TYPE_BUYER_NONE && $visitEcommerceStatus != $this->visitorInfo['visit_goal_buyer']) {
         $valuesToUpdate['visit_goal_buyer'] = $visitEcommerceStatus;
     }
     // Custom Variables overwrite previous values on each page view
     $valuesToUpdate = array_merge($valuesToUpdate, $this->visitorCustomVariables);
     return $valuesToUpdate;
 }

作者:dorelljame    项目:piwi   
public function performSetUp($setupEnvironmentOnly = false)
 {
     // TODO: don't use static var, use test env var for this
     TestingEnvironmentManipulator::$extraPluginsToLoad = $this->extraPluginsToLoad;
     $this->dbName = $this->getDbName();
     if ($this->persistFixtureData) {
         $this->dropDatabaseInSetUp = false;
         $this->dropDatabaseInTearDown = false;
         $this->overwriteExisting = false;
         $this->removeExistingSuperUser = false;
     }
     $testEnv = $this->getTestEnvironment();
     $testEnv->testCaseClass = $this->testCaseClass;
     $testEnv->fixtureClass = get_class($this);
     $testEnv->dbName = $this->dbName;
     $testEnv->extraDiEnvironments = $this->extraDiEnvironments;
     foreach ($this->extraTestEnvVars as $name => $value) {
         $testEnv->{$name} = $value;
     }
     $testEnv->save();
     $this->createEnvironmentInstance();
     if ($this->dbName === false) {
         // must be after test config is created
         $this->dbName = self::getConfig()->database['dbname'];
     }
     try {
         static::connectWithoutDatabase();
         if ($this->dropDatabaseInSetUp || $this->resetPersistedFixture) {
             $this->dropDatabase();
         }
         DbHelper::createDatabase($this->dbName);
         DbHelper::disconnectDatabase();
         Tracker::disconnectCachedDbConnection();
         // reconnect once we're sure the database exists
         self::getConfig()->database['dbname'] = $this->dbName;
         Db::createDatabaseObject();
         Db::get()->query("SET wait_timeout=28800;");
         DbHelper::createTables();
         self::getPluginManager()->unloadPlugins();
     } catch (Exception $e) {
         static::fail("TEST INITIALIZATION FAILED: " . $e->getMessage() . "\n" . $e->getTraceAsString());
     }
     include "DataFiles/Providers.php";
     if (!$this->isFixtureSetUp()) {
         DbHelper::truncateAllTables();
     }
     // We need to be SU to create websites for tests
     Access::getInstance()->setSuperUserAccess();
     Cache::deleteTrackerCache();
     self::resetPluginsInstalledConfig();
     $testEnvironment = $this->getTestEnvironment();
     static::loadAllPlugins($testEnvironment, $this->testCaseClass, $this->extraPluginsToLoad);
     self::updateDatabase();
     self::installAndActivatePlugins($testEnvironment);
     $_GET = $_REQUEST = array();
     $_SERVER['HTTP_REFERER'] = '';
     FakeAccess::$superUserLogin = 'superUserLogin';
     File::$invalidateOpCacheBeforeRead = true;
     if ($this->configureComponents) {
         IPAnonymizer::deactivate();
         $dntChecker = new DoNotTrackHeaderChecker();
         $dntChecker->deactivate();
     }
     if ($this->createSuperUser) {
         self::createSuperUser($this->removeExistingSuperUser);
         if (!Access::getInstance() instanceof FakeAccess) {
             $this->loginAsSuperUser();
         }
         APILanguageManager::getInstance()->setLanguageForUser('superUserLogin', 'en');
     }
     SettingsPiwik::overwritePiwikUrl(self::getTestRootUrl());
     if ($setupEnvironmentOnly) {
         return;
     }
     PiwikCache::getTransientCache()->flushAll();
     if ($this->overwriteExisting || !$this->isFixtureSetUp()) {
         $this->setUp();
         $this->markFixtureSetUp();
         $this->log("Database {$this->dbName} marked as successfully set up.");
     } else {
         $this->log("Using existing database {$this->dbName}.");
     }
 }

作者:dorelljame    项目:piwi   
public function sendReport($reportType, $report, $contents, $filename, $prettyDate, $reportSubject, $reportTitle, $additionalFiles, Period $period = null, $force)
 {
     if (!self::manageEvent($reportType)) {
         return;
     }
     // Safeguard against sending the same report twice to the same email (unless $force is true)
     if (!$force && $this->reportAlreadySent($report, $period)) {
         Log::warning('Preventing the same scheduled report from being sent again (report #%s for period "%s")', $report['idreport'], $prettyDate);
         return;
     }
     $periods = self::getPeriodToFrequencyAsAdjective();
     $message = Piwik::translate('ScheduledReports_EmailHello');
     $subject = Piwik::translate('General_Report') . ' ' . $reportTitle . " - " . $prettyDate;
     $mail = new Mail();
     $mail->setDefaultFromPiwik();
     $mail->setSubject($subject);
     $attachmentName = $subject;
     $this->setReplyToAsSender($mail, $report);
     $displaySegmentInfo = false;
     $segmentInfo = null;
     $segment = API::getSegment($report['idsegment']);
     if ($segment != null) {
         $displaySegmentInfo = true;
         $segmentInfo = Piwik::translate('ScheduledReports_SegmentAppliedToReports', $segment['name']);
     }
     $messageFindAttached = Piwik::translate('ScheduledReports_PleaseFindAttachedFile', array($periods[$report['period']], $reportTitle));
     $messageFindBelow = Piwik::translate('ScheduledReports_PleaseFindBelow', array($periods[$report['period']], $reportTitle));
     $messageSentFrom = '';
     $piwikUrl = SettingsPiwik::getPiwikUrl();
     if (!empty($piwikUrl)) {
         $messageSentFrom = Piwik::translate('ScheduledReports_SentFromX', $piwikUrl);
     }
     switch ($report['format']) {
         case 'html':
             // Needed when using images as attachment with cid
             $mail->setType(Zend_Mime::MULTIPART_RELATED);
             $message .= "<br/>{$messageFindBelow}<br/>{$messageSentFrom}";
             if ($displaySegmentInfo) {
                 $message .= " " . $segmentInfo;
             }
             $mail->setBodyHtml($message . "<br/><br/>" . $contents);
             break;
         case 'csv':
             $message .= "\n{$messageFindAttached}\n{$messageSentFrom}";
             if ($displaySegmentInfo) {
                 $message .= " " . $segmentInfo;
             }
             $mail->setBodyText($message);
             $mail->createAttachment($contents, 'application/csv', Zend_Mime::DISPOSITION_INLINE, Zend_Mime::ENCODING_BASE64, $attachmentName . '.csv');
             break;
         default:
         case 'pdf':
             $message .= "\n{$messageFindAttached}\n{$messageSentFrom}";
             if ($displaySegmentInfo) {
                 $message .= " " . $segmentInfo;
             }
             $mail->setBodyText($message);
             $mail->createAttachment($contents, 'application/pdf', Zend_Mime::DISPOSITION_INLINE, Zend_Mime::ENCODING_BASE64, $attachmentName . '.pdf');
             break;
     }
     foreach ($additionalFiles as $additionalFile) {
         $fileContent = $additionalFile['content'];
         $at = $mail->createAttachment($fileContent, $additionalFile['mimeType'], Zend_Mime::DISPOSITION_INLINE, $additionalFile['encoding'], $additionalFile['filename']);
         $at->id = $additionalFile['cid'];
         unset($fileContent);
     }
     // Get user emails and languages
     $reportParameters = $report['parameters'];
     $emails = array();
     if (isset($reportParameters[self::ADDITIONAL_EMAILS_PARAMETER])) {
         $emails = $reportParameters[self::ADDITIONAL_EMAILS_PARAMETER];
     }
     if ($reportParameters[self::EMAIL_ME_PARAMETER] == 1) {
         if (Piwik::getCurrentUserLogin() == $report['login']) {
             $emails[] = Piwik::getCurrentUserEmail();
         } else {
             try {
                 $user = APIUsersManager::getInstance()->getUser($report['login']);
             } catch (Exception $e) {
                 return;
             }
             $emails[] = $user['email'];
         }
     }
     if (!$force) {
         $this->markReportAsSent($report, $period);
     }
     foreach ($emails as $email) {
         if (empty($email)) {
             continue;
         }
         $mail->addTo($email);
         try {
             $mail->send();
         } catch (Exception $e) {
             // If running from piwik.php with debug, we ignore the 'email not sent' error
             $tracker = new Tracker();
             if (!$tracker->isDebugModeEnabled()) {
                 throw new Exception("An error occured while sending '{$filename}' " . " to " . implode(', ', $mail->getRecipients()) . ". Error was '" . $e->getMessage() . "'");
             }
//.........这里部分代码省略.........

作者:jos    项目:CGE-File-Sharin   
protected function updateExistingConversion($newGoal, $updateWhere)
 {
     $updateParts = $sqlBind = $updateWhereParts = array();
     foreach ($newGoal as $name => $value) {
         $updateParts[] = $name . " = ?";
         $sqlBind[] = $value;
     }
     foreach ($updateWhere as $name => $value) {
         $updateWhereParts[] = $name . " = ?";
         $sqlBind[] = $value;
     }
     $sql = 'UPDATE  ' . Common::prefixTable('log_conversion') . "\n\t\t\t\t\tSET " . implode($updateParts, ', ') . "\n\t\t\t\t\t\tWHERE " . implode($updateWhereParts, ' AND ');
     try {
         Tracker::getDatabase()->query($sql, $sqlBind);
     } catch (Exception $e) {
         Common::printDebug("There was an error while updating the Conversion: " . $e->getMessage());
         return false;
     }
     return true;
 }

作者:bossrabbi    项目:piwi   
/**
  * Print profiling report for the tracker
  *
  * @param \Piwik\Db $db Tracker database object (or null)
  */
 public static function displayDbTrackerProfile($db = null)
 {
     if (is_null($db)) {
         $db = Tracker::getDatabase();
     }
     $tableName = Common::prefixTable('log_profiling');
     $all = $db->fetchAll('SELECT * FROM ' . $tableName);
     if ($all === false) {
         return;
     }
     uasort($all, 'self::maxSumMsFirst');
     $infoIndexedByQuery = array();
     foreach ($all as $infoQuery) {
         $query = $infoQuery['query'];
         $count = $infoQuery['count'];
         $sum_time_ms = $infoQuery['sum_time_ms'];
         $infoIndexedByQuery[$query] = array('count' => $count, 'sumTimeMs' => $sum_time_ms);
     }
     self::getSqlProfilingQueryBreakdownOutput($infoIndexedByQuery);
 }


问题


面经


文章

微信
公众号

扫码关注公众号