Skip to content

Commit

Permalink
file fixer command
Browse files Browse the repository at this point in the history
  • Loading branch information
apsg committed Feb 20, 2024
1 parent a8f364e commit d2ff624
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
2 changes: 2 additions & 0 deletions app/Console/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use App\Domains\Migration\Commands\AttachImagesCommand;
use App\Domains\Migration\Commands\AttachImagesToTagsCommand;
use App\Domains\Migration\Commands\CopyWpFilesCommand;
use App\Domains\Migration\Commands\FixFilesCommand;
use App\Domains\Migration\Commands\FixLinksInDescription;
use App\Domains\Migration\Commands\MaterialsMergerCommand;
use App\Domains\Migration\Commands\MergeAccountDuplicatesCommand;
Expand Down Expand Up @@ -43,6 +44,7 @@ class Kernel extends ConsoleKernel
MaterialsMergerCommand::class,
MergeAccountDuplicatesCommand::class,
ReattachAttachmentsCommand::class,
FixFilesCommand::class,
];

protected function schedule(Schedule $schedule): void
Expand Down
33 changes: 33 additions & 0 deletions app/Domains/Migration/Commands/FixFilesCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php
namespace App\Domains\Migration\Commands;

use App\Domains\Materials\Models\Material;
use App\Domains\Migration\Models\Attachment;
use App\Domains\Migration\Models\Post;

class FixFilesCommand extends PostsMigrationCommand
{
protected $signature = 'wp:fix_files {wpid}';

protected FileFixerService $service;

public function handle()
{
/** @var Post $post */
$post = Post::find($this->argument('wpid'));

$material = Material::where('wp_id', $post->ID)->first();
$this->attachFiles($post, $material);

// /** @var Attachment $attachment */
// foreach ($post->attachments as $attachment) {
// }
}

protected function generateName(Post $post, Attachment $attachment): string
{
$extension = pathinfo($attachment->guid, PATHINFO_EXTENSION);

return "post{$post->ID}_file{$attachment->ID}.{$extension}";
}
}

0 comments on commit d2ff624

Please sign in to comment.