nasrulhazim
12/22/2017 - 12:23 PM

Import WordPress Command

Import WordPress Command

<?php

namespace OSI\Console\Commands;

use Illuminate\Console\Command;

class ImportWp extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'import:wp {domain}';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Import WordPress User, Post, Category, Tag, and Media.';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        $domain = $this->argument('domain') . '/wp-json/wp/v2/';

        collect(['posts', 'pages', 'categories', 'tags', 'media'])->each(function ($fetch) use ($domain) {
            \OSI\Services\WordPress::make($domain)->setUri($fetch)->handle();
        });
    }
}