mirror of
https://github.com/Poniverse/Pony.fm.git
synced 2024-11-25 22:47:59 +01:00
Fixed zeroed timestamps being recorded for statistics and added a script to fill in the missing data.
This commit is contained in:
parent
97681212a4
commit
451cd699cb
3 changed files with 77 additions and 5 deletions
69
app/Console/Commands/FixYearZeroLogs.php
Normal file
69
app/Console/Commands/FixYearZeroLogs.php
Normal file
|
@ -0,0 +1,69 @@
|
|||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use App\ResourceLogItem;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
class FixYearZeroLogs extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'poni:year-zero';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Fills in missing timestamps in the resource_log_items table.';
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$items = ResourceLogItem::where('created_at', '0000-00-00 00:00:00')->orderBy('id', 'asc')->get();
|
||||
$totalItems = $items->count();
|
||||
|
||||
// calculate the start and end of the logging gap
|
||||
$lastGoodId = (int) $items[0]->id - 1;
|
||||
$lastGoodItem = ResourceLogItem::find($lastGoodId);
|
||||
|
||||
$lastGoodDate = $lastGoodItem->created_at;
|
||||
$now = Carbon::now();
|
||||
|
||||
$secondsDifference = $now->diffInSeconds($lastGoodDate);
|
||||
$oneInterval = $secondsDifference / $totalItems;
|
||||
|
||||
$this->info('Correcting records...');
|
||||
$bar = $this->output->createProgressBar($totalItems);
|
||||
|
||||
foreach ($items as $i => $item) {
|
||||
$bar->advance();
|
||||
$dateOffset = (int) ($oneInterval * $i);
|
||||
$item->created_at = $lastGoodDate->copy()->addSeconds($dateOffset);
|
||||
$item->save();
|
||||
}
|
||||
|
||||
$bar->finish();
|
||||
$this->line('');
|
||||
$this->info('All done!');
|
||||
}
|
||||
}
|
|
@ -18,6 +18,7 @@ class Kernel extends ConsoleKernel
|
|||
\App\Console\Commands\ImportMLPMA::class,
|
||||
\App\Console\Commands\ClassifyMLPMA::class,
|
||||
\App\Console\Commands\RebuildTags::class,
|
||||
\App\Console\Commands\FixYearZeroLogs::class,
|
||||
];
|
||||
|
||||
/**
|
||||
|
|
|
@ -3,14 +3,16 @@
|
|||
namespace App;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Request;
|
||||
use Carbon\Carbon;
|
||||
use Auth;
|
||||
use DB;
|
||||
use Request;
|
||||
|
||||
class ResourceLogItem extends Model
|
||||
{
|
||||
protected $table = 'resource_log_items';
|
||||
public $timestamps = false;
|
||||
protected $dates = ['created_at'];
|
||||
|
||||
const VIEW = 1;
|
||||
const DOWNLOAD = 2;
|
||||
|
@ -22,7 +24,7 @@ class ResourceLogItem extends Model
|
|||
|
||||
$logItem = new ResourceLogItem();
|
||||
$logItem->{$resourceIdColumn} = $resourceId;
|
||||
$logItem->created_at = time();
|
||||
$logItem->created_at = Carbon::now();
|
||||
$logItem->log_type = $logType;
|
||||
$logItem->track_format_id = $formatId;
|
||||
$logItem->ip_address = Request::getClientIp();
|
||||
|
|
Loading…
Reference in a new issue