42 lines
1.2 KiB
PHP
42 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use Illuminate\Console\Attributes\Description;
|
|
use Illuminate\Console\Attributes\Signature;
|
|
use Illuminate\Console\Command;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
#[Signature('migrate:downloads-count')]
|
|
#[Description('Command description')]
|
|
class MigrateDownloadsCount extends Command
|
|
{
|
|
|
|
public function handle()
|
|
{
|
|
$rows = DB::table('migrations_logs')
|
|
->where('source_system', 'wp')
|
|
->where('source_table', 'wp_posts')
|
|
->where('target_table', 'entries' )
|
|
->get(['source_id', 'target_id'])
|
|
;
|
|
|
|
$updated = 0;
|
|
|
|
foreach ($rows as $row) {
|
|
$downloadCount = DB::connection('old_wp')
|
|
->table('postmeta')
|
|
->where('post_id', $row->source_id)
|
|
->where('meta_key', 'download_counter' )
|
|
->value('meta_value');
|
|
|
|
if( $downloadCount ) {
|
|
DB::table('entries')->where('id', $row->target_id)->update(['old_download_count' => intval($downloadCount)]);
|
|
$updated++;
|
|
}
|
|
}
|
|
|
|
$this->info('All done (' . $updated . '/' . count($rows) .')');
|
|
}
|
|
}
|