99
1010namespace Piwik \Plugins \Goals \DataTable \Filter ;
1111
12+ use Piwik \Context ;
1213use Piwik \Plugins \Goals \Archiver as GoalsArchiver ;
1314use Piwik \Archive ;
1415use Piwik \DataTable \BaseFilter ;
@@ -79,16 +80,16 @@ public function filter($table)
7980 */
8081 private function getGoalTotalConversions (DataTable $ table , array $ goalIds ): array
8182 {
82- $ goalTotals = [];
83+
8384
8485 if (empty ($ goalIds )) {
85- return $ goalTotals ;
86+ return [] ;
8687 }
8788
88- /** @var Site $site */
89+ /** @var Site|false $site */
8990 $ site = $ table ->getMetadata ('site ' );
9091 if (empty ($ site )) {
91- return $ goalTotals ;
92+ return [] ;
9293 }
9394 $ idSite = $ site ->getId ();
9495
@@ -97,19 +98,26 @@ private function getGoalTotalConversions(DataTable $table, array $goalIds): arra
9798 $ date = $ period ->getDateStart ()->toString ();
9899 $ date = ($ periodName === 'range ' ? $ date . ', ' . $ period ->getDateEnd ()->toString () : $ date );
99100 $ segment = $ table ->getMetadata ('segment ' );
100- $ archive = Archive::build ($ idSite , $ periodName , $ date , $ segment );
101101
102102 $ names = [];
103103 foreach ($ goalIds as $ idGoal => $ g ) {
104104 $ names [$ idGoal ] = GoalsArchiver::getRecordName ('nb_conversions ' , $ idGoal );
105105 }
106106
107- $ sum = $ archive ->getNumeric ($ names );
107+ $ sum = Context::executeWithQueryParameters (['requestedReport ' => '' ], function () use ($ idSite , $ periodName , $ date , $ segment , $ names ) {
108+ $ archive = Archive::build ($ idSite , $ periodName , $ date , $ segment );
109+ return $ archive ->getNumeric ($ names );
110+ });
111+
112+ if (count ($ names ) === 1 ) {
113+ return [key ($ names ) => $ sum ];
114+ }
115+
116+ $ goalTotals = [];
117+
108118 foreach ($ names as $ idGoal => $ name ) {
109- if (is_array ( $ sum ) && array_key_exists ($ name , $ sum ) && is_numeric ($ sum [$ name ])) {
119+ if (array_key_exists ($ name , $ sum ) && is_numeric ($ sum [$ name ])) {
110120 $ goalTotals [$ idGoal ] = $ sum [$ name ];
111- } elseif (is_numeric ($ sum )) {
112- $ goalTotals [$ idGoal ] = $ sum ;
113121 }
114122 }
115123
0 commit comments