1111use Exception ;
1212use Piwik \Container \StaticContainer ;
1313use Piwik \DataTable ;
14+ use Piwik \Date ;
1415use Piwik \Log ;
1516use Piwik \Metrics ;
17+ use Piwik \Period ;
1618use Psr \Log \LoggerInterface ;
1719
1820/**
@@ -292,7 +294,7 @@ public function sumSubtable(DataTable $subTable)
292294 if ($ this ->isSubtableLoaded ) {
293295 $ thisSubTable = $ this ->getSubtable ();
294296 } else {
295- $ this ->warnIfSubtableAlreadyExists ();
297+ $ this ->warnIfSubtableAlreadyExists ($ subTable );
296298
297299 $ thisSubTable = new DataTable ();
298300 $ this ->setSubtable ($ thisSubTable );
@@ -765,16 +767,33 @@ public static function isEqual(Row $row1, Row $row2)
765767 return true ;
766768 }
767769
768- private function warnIfSubtableAlreadyExists ()
770+ private function warnIfSubtableAlreadyExists (DataTable $ subTable )
769771 {
770772 if (!is_null ($ this ->subtableId )) {
771- $ ex = new \Exception (sprintf (
772- "Row with label '%s' (columns = %s) has already a subtable id=%s but it was not loaded - overwriting the existing sub-table. " ,
773- $ this ->getColumn ('label ' ),
774- implode (", " , $ this ->getColumns ()),
775- $ this ->getIdSubDataTable ()
776- ));
777- StaticContainer::get (LoggerInterface::class)->warning ("{exception} " , ['exception ' => $ ex ]);
773+ // we only print this warning out if the row isn't a summary row, and if the period start date of the
774+ // data is later than the deploy date to cloud for Matomo 4.4.1.
775+ //
776+ // In 4.4.1 two bugs surrounding the serialization of summary rows with subtables were fixed. Previously,
777+ // if a summary row had a subtable when it was inserted into the archive table, this warning would eventually
778+ // get triggered. To properly fix this corrupt data, we'd want to invalidate and reporcess it, BUT, that would
779+ // require a lot of compute resources, just for the subtable of a row most people would not look at.
780+ //
781+ // So instead, we simply ignore this issue for data that is for periods older than the deploy date for 4.4.1. If a user
782+ // wants to see this subtable data, they can invalidate a specific date and reprocess it. For newer data,
783+ // since the bugs were fixed, we don't expect to see the issue. So if the warning gets triggered in this case,
784+ // we log the warning in order to be notified.
785+ $ period = $ subTable ->getMetadata ('period ' );
786+ if (!$ this ->isSummaryRow ()
787+ || $ this ->isStartDateLaterThanCloud441DeployDate ($ period )
788+ ) {
789+ $ ex = new \Exception (sprintf (
790+ "Row with label '%s' (columns = %s) has already a subtable id=%s but it was not loaded - overwriting the existing sub-table. " ,
791+ $ this ->getColumn ('label ' ),
792+ implode (", " , $ this ->getColumns ()),
793+ $ this ->getIdSubDataTable ()
794+ ));
795+ StaticContainer::get (LoggerInterface::class)->warning ("{exception} " , ['exception ' => $ ex ]);
796+ }
778797 }
779798 }
780799
@@ -800,4 +819,18 @@ private function getColumnValueDescriptionForError($value)
800819 }
801820 return $ result ;
802821 }
822+
823+ private function isStartDateLaterThanCloud441DeployDate ($ period )
824+ {
825+ if (empty ($ period )
826+ || !($ period instanceof Period)
827+ ) {
828+ return true ; // sanity check
829+ }
830+
831+ $ periodStartDate = $ period ->getDateStart ();
832+
833+ $ cloudDeployDate = Date::factory ('2021-08-11 12:00:00 ' ); // 2021-08-12 00:00:00 NZST
834+ return $ periodStartDate ->isLater ($ cloudDeployDate );
835+ }
803836}
0 commit comments