diff options
author | mattpiwik <matthieu.aubry@gmail.com> | 2010-07-23 23:23:51 +0400 |
---|---|---|
committer | mattpiwik <matthieu.aubry@gmail.com> | 2010-07-23 23:23:51 +0400 |
commit | ba603c67351452df7092fc49e68ca3691718c96e (patch) | |
tree | a7860c07daf96ef9c15b33860c4e3a5e4df1a6f6 | |
parent | 08f6047a5de9af46cb72b8c8486549738375c2cb (diff) |
Fixes issue with Goals API throwing errors when called with lastX
git-svn-id: http://dev.piwik.org/svn/trunk@2643 59fd770c-687e-43c8-a1e3-f5a4ff64c105
8 files changed, 103 insertions, 69 deletions
diff --git a/config/global.ini.php b/config/global.ini.php index 78f450f32b..5248994cd7 100644 --- a/config/global.ini.php +++ b/config/global.ini.php @@ -302,3 +302,11 @@ PluginsInstalled[] = Installation [Plugins_Tracker] Plugins_Tracker[] = Provider + +[mail] +transport = ; name of the protocol: smtp +port = 25 ; port of the smtp: by default 25 +host = ; server address example: smtp.gmail.com +type = ; by default: NONE for example: LOGIN +username = ; your username +password = ; your password diff --git a/core/Mail.php b/core/Mail.php index 8daf4d2be7..625b067585 100644 --- a/core/Mail.php +++ b/core/Mail.php @@ -27,5 +27,48 @@ class Piwik_Mail extends Zend_Mail public function __construct($charset = 'utf-8') { parent::__construct($charset); + $this->setTransport(); + } + + + public function setTransport() + { + try + { + $config = Zend_Registry::get('config')->mail; + if ( !empty($config->host) + && !empty($config->port) + && strcmp($config->transport,"smtp") ==0 + ) + { + if ( !empty($config->auth->type) + || !empty($config->auth->username) + || !empty($config->auth->password) + ) + { + $config_param = array('auth' => $config->auth->type, + 'username' => $config->auth->username, + 'password' => $config->auth->password); + } + + $smtp_address = $config->host; + $smtp_port = $config->port; + if(isset($config_param)) + { + $tr = new Zend_Mail_Transport_Smtp("$smtp_address",$config_param); + } + else + { + $tr = new Zend_Mail_Transport_Smtp("$smtp_address"); + } + Piwik_Mail::setDefaultTransport($tr); + ini_set("smtp_port","$smtp_port"); + } + } + catch(Exception $e) + { + throw new Exception("Configuration SMTP error"); + } + } } diff --git a/plugins/Goals/API.php b/plugins/Goals/API.php index 9b63e802a6..4b25e81423 100644 --- a/plugins/Goals/API.php +++ b/plugins/Goals/API.php @@ -165,63 +165,6 @@ class Piwik_Goals_API Piwik_Common::regenerateCacheWebsiteAttributes($idSite); } -// public function getConversionsReturningVisitors( $idSite, $period, $date, $idGoal = false ) -// { -// -// } -// -// public function getConversionsNewVisitors( $idSite, $period, $date, $idGoal = false ) -// { -// -// } - - public function getConversionRateReturningVisitors( $idSite, $period, $date, $idGoal = false ) - { - // visits converted for returning for all goals = call Frequency API - if($idGoal === false) - { - $request = new Piwik_API_Request("method=VisitFrequency.getConvertedVisitsReturning&idSite=$idSite&period=$period&date=$date&format=original"); - $nbVisitsConvertedReturningVisitors = $request->process(); - } - // visits converted for returning = nb conversion for this goal - else - { - $nbVisitsConvertedReturningVisitors = $this->getNumeric($idSite, $period, $date, Piwik_Goals::getRecordName('nb_conversions', $idGoal, 1)); - } - // all returning visits - $request = new Piwik_API_Request("method=VisitFrequency.getVisitsReturning&idSite=$idSite&period=$period&date=$date&format=original"); - $nbVisitsReturning = $request->process(); -// echo $nbVisitsConvertedReturningVisitors; -// echo "<br />". $nbVisitsReturning;exit; - - return Piwik::getPercentageSafe($nbVisitsConvertedReturningVisitors, $nbVisitsReturning, Piwik_Goals::ROUNDING_PRECISION); - } - - public function getConversionRateNewVisitors( $idSite, $period, $date, $idGoal = false ) - { - // new visits converted for all goals = nb visits converted - nb visits converted for returning - if($idGoal == false) - { - $request = new Piwik_API_Request("method=VisitsSummary.getVisitsConverted&idSite=$idSite&period=$period&date=$date&format=original"); - $convertedVisits = $request->process(); - $request = new Piwik_API_Request("method=VisitFrequency.getConvertedVisitsReturning&idSite=$idSite&period=$period&date=$date&format=original"); - $convertedReturningVisits = $request->process(); - $convertedNewVisits = $convertedVisits - $convertedReturningVisits; - } - // new visits converted for a given goal = nb conversion for this goal for new visits - else - { - $convertedNewVisits = $this->getNumeric($idSite, $period, $date, Piwik_Goals::getRecordName('nb_conversions', $idGoal, 0)); - } - // all new visits = all visits - all returning visits - $request = new Piwik_API_Request("method=VisitFrequency.getVisitsReturning&idSite=$idSite&period=$period&date=$date&format=original"); - $nbVisitsReturning = $request->process(); - $request = new Piwik_API_Request("method=VisitsSummary.getVisits&idSite=$idSite&period=$period&date=$date&format=original"); - $nbVisits = $request->process(); - $newVisits = $nbVisits - $nbVisitsReturning; - return Piwik::getPercentageSafe($convertedNewVisits, $newVisits, Piwik_Goals::ROUNDING_PRECISION); - } - /** * Returns Goals data * diff --git a/plugins/Goals/Controller.php b/plugins/Goals/Controller.php index 9c79a69e3f..d42059e10d 100644 --- a/plugins/Goals/Controller.php +++ b/plugins/Goals/Controller.php @@ -69,10 +69,10 @@ class Piwik_Goals_Controller extends Piwik_Controller $view->topSegments = $this->getTopSegments($idGoal); // conversion rate for new and returning visitors - $request = new Piwik_API_Request("method=Goals.getConversionRateReturningVisitors&format=original"); - $view->conversion_rate_returning = round( $request->process(), self::CONVERSION_RATE_PRECISION ); - $request = new Piwik_API_Request("method=Goals.getConversionRateNewVisitors&format=original"); - $view->conversion_rate_new = round( $request->process(), self::CONVERSION_RATE_PRECISION ); + $conversionRateReturning = $this->getConversionRateReturningVisitors($this->idSite, Piwik_Common::getRequestVar('period'), Piwik_Common::getRequestVar('date'), $idGoal); + $view->conversion_rate_returning = round( $conversionRateReturning, self::CONVERSION_RATE_PRECISION ); + $conversionRateNew = $this->getConversionRateNewVisitors($this->idSite, Piwik_Common::getRequestVar('period'), Piwik_Common::getRequestVar('date'), $idGoal); + $view->conversion_rate_new = round( $conversionRateNew, self::CONVERSION_RATE_PRECISION ); return $view; } @@ -248,4 +248,52 @@ class Piwik_Goals_Controller extends Piwik_Controller 'urlSparklineRevenue' => $this->getUrlSparkline('getEvolutionGraph', array('columns' => array('revenue'), 'idGoal' => $idGoal)), ); } + + private function getConversionRateReturningVisitors( $idSite, $period, $date, $idGoal = false ) + { + // visits converted for returning for all goals = call Frequency API + if($idGoal === false) + { + $request = new Piwik_API_Request("method=VisitFrequency.getConvertedVisitsReturning&idSite=$idSite&period=$period&date=$date&format=original"); + $nbVisitsConvertedReturningVisitors = $request->process(); + } + // visits converted for returning = nb conversion for this goal + else + { + $nbVisitsConvertedReturningVisitors = Piwik_Goals_API::getInstance()->getConversions($idSite, $period, $date, $idGoal); + } + // all returning visits + $request = new Piwik_API_Request("method=VisitFrequency.getVisitsReturning&idSite=$idSite&period=$period&date=$date&format=original"); + $nbVisitsReturning = $request->process(); +// echo $nbVisitsConvertedReturningVisitors; +// echo "<br />". $nbVisitsReturning;exit; + + return Piwik::getPercentageSafe($nbVisitsConvertedReturningVisitors, $nbVisitsReturning, Piwik_Goals::ROUNDING_PRECISION); + } + + private function getConversionRateNewVisitors( $idSite, $period, $date, $idGoal = false ) + { + // new visits converted for all goals = nb visits converted - nb visits converted for returning + if($idGoal == false) + { + $request = new Piwik_API_Request("method=VisitsSummary.getVisitsConverted&idSite=$idSite&period=$period&date=$date&format=original"); + $convertedVisits = $request->process(); + $request = new Piwik_API_Request("method=VisitFrequency.getConvertedVisitsReturning&idSite=$idSite&period=$period&date=$date&format=original"); + $convertedReturningVisits = $request->process(); + $convertedNewVisits = $convertedVisits - $convertedReturningVisits; + } + // new visits converted for a given goal = nb conversion for this goal for new visits + else + { + $convertedNewVisits = Piwik_Goals_API::getInstance()->getConversions($idSite, $period, $date, $idGoal); + } + // all new visits = all visits - all returning visits + $request = new Piwik_API_Request("method=VisitFrequency.getVisitsReturning&idSite=$idSite&period=$period&date=$date&format=original"); + $nbVisitsReturning = $request->process(); + $request = new Piwik_API_Request("method=VisitsSummary.getVisits&idSite=$idSite&period=$period&date=$date&format=original"); + $nbVisits = $request->process(); + $newVisits = $nbVisits - $nbVisitsReturning; + return Piwik::getPercentageSafe($convertedNewVisits, $newVisits, Piwik_Goals::ROUNDING_PRECISION); + } + } diff --git a/tests/integration/expected/test_OneVisitorTwoVisits__Goals.getConversionRateNewVisitors_day.xml b/tests/integration/expected/test_OneVisitorTwoVisits__Goals.getConversionRateNewVisitors_day.xml deleted file mode 100644 index dff1089a71..0000000000 --- a/tests/integration/expected/test_OneVisitorTwoVisits__Goals.getConversionRateNewVisitors_day.xml +++ /dev/null @@ -1,2 +0,0 @@ -<?xml version="1.0" encoding="utf-8" ?> -<result>100</result>
\ No newline at end of file diff --git a/tests/integration/expected/test_OneVisitorTwoVisits__Goals.getConversionRateReturningVisitors_day.xml b/tests/integration/expected/test_OneVisitorTwoVisits__Goals.getConversionRateReturningVisitors_day.xml deleted file mode 100644 index dff1089a71..0000000000 --- a/tests/integration/expected/test_OneVisitorTwoVisits__Goals.getConversionRateReturningVisitors_day.xml +++ /dev/null @@ -1,2 +0,0 @@ -<?xml version="1.0" encoding="utf-8" ?> -<result>100</result>
\ No newline at end of file diff --git a/tests/integration/expected/test_noVisit__Goals.getConversionRateNewVisitors_day.xml b/tests/integration/expected/test_noVisit__Goals.getConversionRateNewVisitors_day.xml deleted file mode 100644 index f5722c2b94..0000000000 --- a/tests/integration/expected/test_noVisit__Goals.getConversionRateNewVisitors_day.xml +++ /dev/null @@ -1,2 +0,0 @@ -<?xml version="1.0" encoding="utf-8" ?> -<result>0</result>
\ No newline at end of file diff --git a/tests/integration/expected/test_noVisit__Goals.getConversionRateReturningVisitors_day.xml b/tests/integration/expected/test_noVisit__Goals.getConversionRateReturningVisitors_day.xml deleted file mode 100644 index f5722c2b94..0000000000 --- a/tests/integration/expected/test_noVisit__Goals.getConversionRateReturningVisitors_day.xml +++ /dev/null @@ -1,2 +0,0 @@ -<?xml version="1.0" encoding="utf-8" ?> -<result>0</result>
\ No newline at end of file |