Skip to content

Commit

Permalink
Fix output in csv file (#867)
Browse files Browse the repository at this point in the history
* Fix output in csv file

* Update changelog
  • Loading branch information
rosalieper authored Aug 23, 2024
1 parent 432d8d8 commit e15eea6
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 17 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
16 changes: 3 additions & 13 deletions app/Http/Controllers/DeletedWikiMetricsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace App\Http\Controllers;

use App\Wiki;
use App\WikiManager;
use Carbon\CarbonImmutable;
use Illuminate\Http\Request;

Expand All @@ -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',
Expand All @@ -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
];
Expand Down
5 changes: 1 addition & 4 deletions tests/Routes/Wiki/DeletedWikiMetricsControllerTest.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?php

namespace Tests\Routes\Wiki;
use App\Http\Controllers\DeletedWikiMetricsController;
use App\User;
use App\WikiManager;
use Carbon\CarbonImmutable;
Expand Down Expand Up @@ -82,7 +81,6 @@ public function testOutputHasCorrectContent()
$this->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)
Expand All @@ -101,15 +99,14 @@ 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,
]);
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]);
Expand Down

0 comments on commit e15eea6

Please sign in to comment.