Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions app/Helper/MWTimestampHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@
namespace App\Helper;

use Carbon\CarbonImmutable;
use Carbon\Exceptions\InvalidFormatException;

class MWTimestampHelper {
private const MWTimestampFormat = 'YmdHis';

public static function getCarbonFromMWTimestamp(string $MWTimestamp): CarbonImmutable {
$carbon = CarbonImmutable::createFromFormat(self::MWTimestampFormat, $MWTimestamp);
if ($carbon === false) {
throw new \Exception('Unable to create Carbon object');
if ($carbon === null) {
throw new InvalidFormatException('Unable to create Carbon object');
}

return $carbon;
Expand Down
11 changes: 8 additions & 3 deletions app/Http/Controllers/ConversionMetricController.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,17 @@ public function index(Request $request) {
}
$time_before_wiki_abandoned_days = null;
$time_to_engage_days = null;
$daysSinceLastEdit = null;

if (!is_null($wikiLastEditedTime) && ($wikiLastEditedTime->diffInDays($current_date, false) >= 90)) {
$time_before_wiki_abandoned_days = $wiki->created_at->diffInDays($wikiLastEditedTime, false);
if ($wikiLastEditedTime !== null) {
$daysSinceLastEdit = (int) $wikiLastEditedTime->diffInDays($current_date, false);
}

if ($daysSinceLastEdit !== null && $daysSinceLastEdit >= 90) {
$time_before_wiki_abandoned_days = (int) $wiki->created_at->diffInDays($wikiLastEditedTime, false);
}
if ($wikiFirstEditedTime !== null) {
$time_to_engage_days = $wiki->created_at->diffInDays($wikiFirstEditedTime, false);
$time_to_engage_days = (int) $wiki->created_at->diffInDays($wikiFirstEditedTime, false);
}
$wiki_number_of_editors = $wiki->wikiSiteStats()->first()['activeusers'] ?? null;

Expand Down
2 changes: 1 addition & 1 deletion app/Jobs/PlatformStatsSummaryJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public function prepareStats(array $allStats, $wikis): array {
// is it edited in the last 90 days?
if (!is_null($stats['lastEdit'])) {
$lastTimestamp = MWTimestampHelper::getCarbonFromMWTimestamp(intval($stats['lastEdit']));
$diff = $lastTimestamp->diffInSeconds($currentTime);
$diff = (int) $lastTimestamp->diffInSeconds($currentTime, true);

if ($diff <= $this->inactiveThreshold) {
$editedLast90DaysWikis[] = $wiki;
Expand Down
2 changes: 1 addition & 1 deletion app/Jobs/SendEmptyWikiNotificationsJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function checkIfWikiIsOldAndEmpty(Wiki $wiki) {
$emptyDaysThreshold = config('wbstack.wiki_empty_notification_threshold');
$createdAt = $wiki->created_at;
$now = CarbonImmutable::now();
$emptyWikiDays = $createdAt->diffInDays($now);
$emptyWikiDays = (int) $createdAt->diffInDays($now, true);

$firstEdited = $wiki->wikiLifecycleEvents->first_edited;

Expand Down
Loading