@@ -65,24 +65,20 @@ public function deleteDataSubjectsForDeletedSites($allExistingIdSites)
6565
6666 $ idSitesNoLongerExisting = array_diff ($ idSitesUsed , $ allExistingIdSites );
6767
68- if (empty ($ idSitesNoLongerExisting )) {
69- // nothing to be deleted... if there is no entry for that table in log_visit or log_link_visit_action
70- // then there shouldn't be anything to be deleted in other tables either
71- return [];
72- }
73-
74- $ logTables = $ this ->getLogTablesToDeleteFrom ();
75- // It's quicker to call the delete queries one site at a time instead of using the IN operator and potentially
76- // creating a huge result set
77- foreach ($ idSitesNoLongerExisting as $ idSiteNoLongerExisting ) {
78- $ r = $ this ->deleteLogDataFrom ($ logTables , function ($ tableToSelectFrom ) use ($ idSiteNoLongerExisting ) {
79- return [$ tableToSelectFrom . '.idsite = ' . $ idSiteNoLongerExisting , []];
80- });
81- foreach ($ r as $ k => $ v ) {
82- if (!array_key_exists ($ k , $ results )) {
83- $ results [$ k ] = 0 ;
68+ if (!empty ($ idSitesNoLongerExisting )) {
69+ $ logTables = $ this ->getLogTablesToDeleteFrom ();
70+ // It's quicker to call the delete queries one site at a time instead of using the IN operator and potentially
71+ // creating a huge result set
72+ foreach ($ idSitesNoLongerExisting as $ idSiteNoLongerExisting ) {
73+ $ r = $ this ->deleteLogDataFrom ($ logTables , function ($ tableToSelectFrom ) use ($ idSiteNoLongerExisting ) {
74+ return [$ tableToSelectFrom . '.idsite = ' . $ idSiteNoLongerExisting , []];
75+ });
76+ foreach ($ r as $ k => $ v ) {
77+ if (!array_key_exists ($ k , $ results )) {
78+ $ results [$ k ] = 0 ;
79+ }
80+ $ results [$ k ] += $ v ;
8481 }
85- $ results [$ k ] += $ v ;
8682 }
8783 }
8884
@@ -94,16 +90,18 @@ public function deleteDataSubjectsForDeletedSites($allExistingIdSites)
9490 *
9591 * **Example**
9692 *
97- * public function deleteDataSubjectsForDeletedSites(&$result, $idSitesNoLongerExisting )
93+ * public function deleteDataSubjectsForDeletedSites(&$result)
9894 * {
99- * $numDeletes = $this->deleteDataForSites($idSitesNoLongerExisting)
95+ * $existingSiteIds = SitesManager\API::getInstance()->getAllSitesId();
96+ * $idSitesInTable = $this->>getAllSiteIdsInLogTable();
97+ * $idSitesNoLongerExisting = array_diff($existingSiteIds, $idSitesInTable);
98+ * $numDeletes = $this->deleteDataForSites($idSitesNoLongerExisting);
10099 * $result['myplugin'] = $numDeletes;
101100 * }
102101 *
103102 * @param array &$results An array storing the result of how much data was deleted for.
104- * @param array &$idSitesNoLongerExisting An array with multiple site ids that were removed
105103 */
106- Piwik::postEvent ('PrivacyManager.deleteDataSubjectsForDeletedSites ' , [&$ results , $ idSitesNoLongerExisting ]);
104+ Piwik::postEvent ('PrivacyManager.deleteDataSubjectsForDeletedSites ' , [&$ results , $ allExistingIdSites ]);
107105
108106 krsort ($ results ); // make sure test results are always in same order
109107 return $ results ;
0 commit comments