From e15eea6f08599a893ed637d80ba2d40c62e293d9 Mon Sep 17 00:00:00 2001 From: Perside Rosalie Date: Fri, 23 Aug 2024 09:30:12 +0200 Subject: [PATCH] Fix output in csv file (#867) * Fix output in csv file * Update changelog --- CHANGELOG.md | 3 +++ .../Controllers/DeletedWikiMetricsController.php | 16 +++------------- .../Wiki/DeletedWikiMetricsControllerTest.php | 5 +---- 3 files changed, 7 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4cf7a71f..2921d700 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # api +## 10x.15.1 - 23 August 2024 +- Fix output in csv file for deleted wiki metrics + ## 10x.15.0 - 15 August 2024 - Fix deleted wiki metrics download diff --git a/app/Http/Controllers/DeletedWikiMetricsController.php b/app/Http/Controllers/DeletedWikiMetricsController.php index 4cacb222..390ae56b 100644 --- a/app/Http/Controllers/DeletedWikiMetricsController.php +++ b/app/Http/Controllers/DeletedWikiMetricsController.php @@ -3,7 +3,6 @@ namespace App\Http\Controllers; use App\Wiki; -use App\WikiManager; use Carbon\CarbonImmutable; use Illuminate\Http\Request; @@ -28,8 +27,6 @@ private function returnCsv( $output ) { fputcsv($handle, [ 'domain_name_for_wiki', 'wiki_deletion_reason', - 'number_of_wikibases_owned_by_owners_of_this_wiki', - 'number_of_entities_for_wiki', 'number_of_wiki_edits_for_wiki', 'number_of_wiki_pages_for_wiki', 'number_of_users_for_wiki', @@ -49,19 +46,12 @@ private function createOutput($wikis): array { $output = []; foreach ($wikis as $wiki) { - $wikiManagers = $wiki->wikiManagers()->get(); - $usersIds = []; - foreach($wikiManagers as $wikiManager) { - $usersIds[] = $wikiManager->pivot->user_id; - } - $allWikiIdsOwnedByAllOwners = WikiManager::whereIn('user_id', $usersIds)->pluck('wiki_id')->all(); $output[] = [ 'domain_name_for_wiki' => $wiki->domain, 'wiki_deletion_reason' => $wiki->wiki_deletion_reason, - 'number_of_wikibases_owned_by_owners_of_this_wiki' => count(array_unique($allWikiIdsOwnedByAllOwners)), - 'number_of_entities_for_wiki' => "No value available for now", - 'number_of_wiki_pages_for_wiki' => $wiki->wikiSiteStats()->get()['pages'] ?? null, - 'number_of_users_for_wiki' => $wiki->wikiSiteStats()->get()['úsers'] ?? null, + 'number_of_wiki_edits_for_wiki' => $wiki->wikiSiteStats()->first()->edits ?? null, + 'number_of_wiki_pages_for_wiki' => $wiki->wikiSiteStats()->first()->pages ?? null, + 'number_of_users_for_wiki' => $wiki->wikiSiteStats()->first()->users ?? null, 'wiki_creation_time' => $wiki->created_at, 'wiki_deletion_time' => $wiki->deleted_at ]; diff --git a/tests/Routes/Wiki/DeletedWikiMetricsControllerTest.php b/tests/Routes/Wiki/DeletedWikiMetricsControllerTest.php index 2cbdbfa7..83543e35 100644 --- a/tests/Routes/Wiki/DeletedWikiMetricsControllerTest.php +++ b/tests/Routes/Wiki/DeletedWikiMetricsControllerTest.php @@ -1,7 +1,6 @@ assertSame('one.wikibase.cloud', $output[1][0]); $this->assertSame('two.wikibase.cloud', $output[2][0]); $this->assertSame('Some Reason',$output[2][1]); - $this->assertSame(2, intval($output[1][2])); } private function createUserWithPrivileges($userPrivilege) @@ -101,7 +99,7 @@ private function createAndDeleteTestWiki($domain, $user_id, $wikiDeletionReason, $current_date = CarbonImmutable::now(); $wiki = Wiki::factory()->create([ - 'domain' => $domain, 'sitename' => 'bsite' + 'domain' => $domain, 'sitename' => 'bsite', 'created_at' => $current_date->subWeeks($createdWeeksAgo), ]); WikiManager::factory()->create([ 'wiki_id' => $wiki->id, 'user_id' => $user_id, @@ -109,7 +107,6 @@ private function createAndDeleteTestWiki($domain, $user_id, $wikiDeletionReason, WikiSiteStats::factory()->create([ 'wiki_id' => $wiki->id, 'pages' => 77, 'users' => $wiki_users ]); - $wiki->created_at = $current_date->subWeeks($createdWeeksAgo); $wiki->save(); $wiki->update(['wiki_deletion_reason' => $wikiDeletionReason]);