@@ -193,6 +193,91 @@ public function testMarkArchivesAsInvalidatedDoesNotInvalidatePartialArchives()
193
193
$ actualInvalidations = $ this ->getInvalidatedArchiveTableEntries ();
194
194
$ this ->assertEquals ($ expectedInvalidations , $ actualInvalidations );
195
195
}
196
+ public function testMarkArchivesAsInvalidatedDoesHandleInProgressArchivesCorrectly ()
197
+ {
198
+ // Insert an archive/invalidation that is currently in progress
199
+ $ this ->insertArchiveRow (1 , '2020-03-03 ' , 'day ' , $ doneValue = ArchiveWriter::DONE_ERROR , '' , false );
200
+ $ this ->insertInvalidations ([
201
+ ['name ' => 'done ' , 'idsite ' => 1 , 'date1 ' => '2020-03-03 ' , 'date2 ' => '2020-03-03 ' , 'period ' => 1 , 'report ' => null , 'ts_started ' => Date::now ()->getDatetime (), 'status ' => 1 ]
202
+ ]);
203
+
204
+ /** @var ArchiveInvalidator $archiveInvalidator */
205
+ $ archiveInvalidator = self ::$ fixture ->piwikEnvironment ->getContainer ()->get ('Piwik\Archive\ArchiveInvalidator ' );
206
+
207
+ $ archiveInvalidator ->markArchivesAsInvalidated (
208
+ [1 ],
209
+ ['2020-03-03 ' ],
210
+ 'day ' ,
211
+ null ,
212
+ $ cascadeDown = true ,
213
+ false
214
+ );
215
+
216
+ $ invalidatedArchives = $ this ->getAvailableArchives ();
217
+ $ expectedArchives = [
218
+ '2020_03 ' => [
219
+ ['idsite ' => 1 , 'date1 ' => '2020-03-03 ' , 'date2 ' => '2020-03-03 ' , 'period ' => 1 , 'name ' => 'done ' , 'value ' => ArchiveWriter::DONE_ERROR_INVALIDATED ]
220
+ ],
221
+ ];
222
+
223
+ $ this ->assertEquals ($ expectedArchives , $ invalidatedArchives );
224
+
225
+ $ expectedInvalidations = [
226
+ [
227
+ 'idarchive ' => null ,
228
+ 'idsite ' => '1 ' ,
229
+ 'period ' => '1 ' ,
230
+ 'name ' => 'done ' ,
231
+ 'date1 ' => '2020-03-03 ' ,
232
+ 'date2 ' => '2020-03-03 ' ,
233
+ 'report ' => null ,
234
+ 'status ' => '1 '
235
+ ],
236
+ [
237
+ 'idarchive ' => '1 ' ,
238
+ 'idsite ' => '1 ' ,
239
+ 'period ' => '1 ' ,
240
+ 'name ' => 'done ' ,
241
+ 'date1 ' => '2020-03-03 ' ,
242
+ 'date2 ' => '2020-03-03 ' ,
243
+ 'report ' => null ,
244
+ 'status ' => '0 '
245
+ ],
246
+ [
247
+ 'idarchive ' => null ,
248
+ 'idsite ' => '1 ' ,
249
+ 'period ' => '2 ' ,
250
+ 'name ' => 'done ' ,
251
+ 'date1 ' => '2020-03-02 ' ,
252
+ 'date2 ' => '2020-03-08 ' ,
253
+ 'report ' => null ,
254
+ 'status ' => '0 '
255
+ ],
256
+ [
257
+ 'idarchive ' => null ,
258
+ 'idsite ' => '1 ' ,
259
+ 'period ' => '3 ' ,
260
+ 'name ' => 'done ' ,
261
+ 'date1 ' => '2020-03-01 ' ,
262
+ 'date2 ' => '2020-03-31 ' ,
263
+ 'report ' => null ,
264
+ 'status ' => '0 '
265
+ ],
266
+ [
267
+ 'idarchive ' => null ,
268
+ 'idsite ' => '1 ' ,
269
+ 'period ' => '4 ' ,
270
+ 'name ' => 'done ' ,
271
+ 'date1 ' => '2020-01-01 ' ,
272
+ 'date2 ' => '2020-12-31 ' ,
273
+ 'report ' => null ,
274
+ 'status ' => '0 '
275
+ ],
276
+ ];
277
+
278
+ $ actualInvalidations = $ this ->getInvalidatedArchiveTableEntries (true );
279
+ $ this ->assertEquals ($ expectedInvalidations , $ actualInvalidations );
280
+ }
196
281
197
282
public function testReArchiveReportDoesNothingIfIniSettingSetToZero ()
198
283
{
@@ -1203,7 +1288,6 @@ public function getTestDataForMarkArchivesAsInvalidated()
1203
1288
),
1204
1289
),
1205
1290
[
1206
- // TODO: super strange, there are two idarchive = 106 values here
1207
1291
['idarchive ' => '106 ' , 'idsite ' => '1 ' , 'date1 ' => '2015-01-01 ' , 'date2 ' => '2015-01-31 ' , 'period ' => '3 ' , 'name ' => 'done3736b708e4d20cfc10610e816a1b2341 ' , 'report ' => null ],
1208
1292
['idarchive ' => '1 ' , 'idsite ' => '1 ' , 'date1 ' => '2015-01-01 ' , 'date2 ' => '2015-01-01 ' , 'period ' => '1 ' , 'name ' => 'done3736b708e4d20cfc10610e816a1b2341 ' , 'report ' => null ],
1209
1293
['idarchive ' => null , 'idsite ' => '1 ' , 'date1 ' => '2015-01-01 ' , 'date2 ' => '2015-12-31 ' , 'period ' => '4 ' , 'name ' => 'done3736b708e4d20cfc10610e816a1b2341 ' , 'report ' => null ],
@@ -1240,6 +1324,7 @@ public function getTestDataForMarkArchivesAsInvalidated()
1240
1324
['idarchive ' => null , 'idsite ' => '1 ' , 'date1 ' => '2015-01-28 ' , 'date2 ' => '2015-01-28 ' , 'period ' => '1 ' , 'name ' => 'done3736b708e4d20cfc10610e816a1b2341 ' , 'report ' => null ],
1241
1325
['idarchive ' => null , 'idsite ' => '1 ' , 'date1 ' => '2015-01-29 ' , 'date2 ' => '2015-01-29 ' , 'period ' => '1 ' , 'name ' => 'done3736b708e4d20cfc10610e816a1b2341 ' , 'report ' => null ],
1242
1326
['idarchive ' => null , 'idsite ' => '1 ' , 'date1 ' => '2015-01-30 ' , 'date2 ' => '2015-01-30 ' , 'period ' => '1 ' , 'name ' => 'done3736b708e4d20cfc10610e816a1b2341 ' , 'report ' => null ],
1327
+ // archive id 106 occurs a second time as it comes from a different archive table
1243
1328
['idarchive ' => '106 ' , 'idsite ' => '1 ' , 'date1 ' => '2014-12-29 ' , 'date2 ' => '2015-01-04 ' , 'period ' => '2 ' , 'name ' => 'done3736b708e4d20cfc10610e816a1b2341 ' , 'report ' => null ],
1244
1329
['idarchive ' => '91 ' , 'idsite ' => '1 ' , 'date1 ' => '2015-01-31 ' , 'date2 ' => '2015-01-31 ' , 'period ' => '1 ' , 'name ' => 'done3736b708e4d20cfc10610e816a1b2341 ' , 'report ' => null ],
1245
1330
],
@@ -2445,6 +2530,24 @@ private function getInvalidatedIdArchives()
2445
2530
return $ result ;
2446
2531
}
2447
2532
2533
+ private function getAvailableArchives ()
2534
+ {
2535
+ $ result = array ();
2536
+ foreach (ArchiveTableCreator::getTablesArchivesInstalled (ArchiveTableCreator::NUMERIC_TABLE ) as $ table ) {
2537
+ $ date = ArchiveTableCreator::getDateFromTableName ($ table );
2538
+
2539
+ $ sql = "SELECT idsite, date1, date2, period, name, value FROM $ table WHERE name LIKE 'done%' " ;
2540
+
2541
+ $ archiveSpecs = Db::query ($ sql )->fetchAll ();
2542
+ if (empty ($ archiveSpecs )) {
2543
+ continue ;
2544
+ }
2545
+
2546
+ $ result [$ date ] = $ archiveSpecs ;
2547
+ }
2548
+ return $ result ;
2549
+ }
2550
+
2448
2551
private function getInvalidatedArchives ($ anyTsArchived = true )
2449
2552
{
2450
2553
$ result = array ();
@@ -2529,9 +2632,9 @@ private function insertArchiveRow($idSite, $date, $periodLabel, $doneValue = Arc
2529
2632
Db::query ($ sql );
2530
2633
}
2531
2634
2532
- private function getInvalidatedArchiveTableEntries ()
2635
+ private function getInvalidatedArchiveTableEntries ($ includeStatus = false )
2533
2636
{
2534
- return Db::fetchAll ("SELECT idarchive, idsite, date1, date2, period, name, report FROM " . Common::prefixTable ('archive_invalidations ' ));
2637
+ return Db::fetchAll ("SELECT idarchive, idsite, date1, date2, period, name, report " . ( $ includeStatus ? ' , status ' : '' ) . " FROM " . Common::prefixTable ('archive_invalidations ' ));
2535
2638
}
2536
2639
2537
2640
private function assertEqualsSorted (array $ expectedEntries , array $ invalidatedArchiveTableEntries )
@@ -2579,14 +2682,16 @@ private function insertInvalidations(array $invalidations)
2579
2682
{
2580
2683
$ table = Common::prefixTable ('archive_invalidations ' );
2581
2684
foreach ($ invalidations as $ invalidation ) {
2582
- $ sql = "INSERT INTO $ table (name, idsite, date1, date2, period, ts_invalidated, report) VALUES (?, ?, ?, ?, ?, NOW(), ?) " ;
2685
+ $ sql = "INSERT INTO $ table (name, idsite, date1, date2, period, ts_invalidated, report, ts_started, status ) VALUES (?, ?, ?, ?, ?, NOW(), ?, ? , ?) " ;
2583
2686
Db::query ($ sql , [
2584
2687
$ invalidation ['name ' ],
2585
2688
$ invalidation ['idsite ' ],
2586
2689
$ invalidation ['date1 ' ],
2587
2690
$ invalidation ['date2 ' ],
2588
2691
$ invalidation ['period ' ],
2589
2692
$ invalidation ['report ' ],
2693
+ $ invalidation ['ts_started ' ] ?? null ,
2694
+ $ invalidation ['status ' ] ?? 0 ,
2590
2695
]);
2591
2696
}
2592
2697
}
0 commit comments