-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from kevinmeijer97/master
Refactored Product import and added separate delete job
- Loading branch information
Showing
11 changed files
with
215 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
namespace Rapidez\Statamic\Commands; | ||
|
||
use Illuminate\Console\Command; | ||
use Illuminate\Support\Carbon; | ||
use Rapidez\Statamic\Jobs\DeleteProductsJob; | ||
|
||
class DeleteProductsCommand extends Command | ||
{ | ||
protected $signature = 'rapidez:statamic:delete:products {store?}'; | ||
|
||
protected $description = 'Delete products that only exist in Statamic.'; | ||
|
||
public function handle(): int | ||
{ | ||
/** @var ?string $store */ | ||
$store = $this->argument('store'); | ||
|
||
DeleteProductsJob::dispatch($store); | ||
|
||
return static::SUCCESS; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
namespace Rapidez\Statamic\Http\Controllers; | ||
|
||
use Illuminate\Http\Request; | ||
use Statamic\Facades\Entry; | ||
use Illuminate\Support\Facades\View; | ||
use Statamic\Exceptions\NotFoundHttpException; | ||
|
||
class StatamicRewriteController | ||
{ | ||
public function __invoke(Request $request) | ||
{ | ||
$storeCode = config()->get('rapidez.store_code'); | ||
|
||
$entry = Entry::query() | ||
->where('collection', 'pages') | ||
->where('locale', $storeCode) | ||
->where('slug', $request->path() == '/' ? 'home' : $request->path()) | ||
->first(); | ||
|
||
if (!$entry) { | ||
throw new NotFoundHttpException(); | ||
} | ||
|
||
$template = View::exists($entry->template()) ? $entry->template() : $entry->blueprint->handle(); | ||
|
||
echo view($template, ['entry' => $entry]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
namespace Rapidez\Statamic\Jobs; | ||
|
||
use Illuminate\Bus\Queueable; | ||
use Illuminate\Contracts\Queue\ShouldBeUnique; | ||
use Illuminate\Contracts\Queue\ShouldQueue; | ||
use Illuminate\Foundation\Bus\Dispatchable; | ||
use Illuminate\Queue\InteractsWithQueue; | ||
use Illuminate\Support\Carbon; | ||
use Illuminate\Support\Enumerable; | ||
use Rapidez\Statamic\Actions\Products\CreateProducts; | ||
use Rapidez\Statamic\Actions\Products\ImportProducts; | ||
|
||
class CreateProductsJob implements ShouldQueue, ShouldBeUnique | ||
{ | ||
use Dispatchable; | ||
use InteractsWithQueue; | ||
use Queueable; | ||
|
||
public function __construct( | ||
public Enumerable $products, | ||
public ?string $siteHandle = null, | ||
){ | ||
} | ||
|
||
public function handle(CreateProducts $createProducts): void | ||
{ | ||
if (!$this->products || !$this->siteHandle) { | ||
return; | ||
} | ||
|
||
$createProducts->create($this->products, $this->siteHandle); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
namespace Rapidez\Statamic\Jobs; | ||
|
||
use Illuminate\Bus\Queueable; | ||
use Illuminate\Contracts\Queue\ShouldBeUnique; | ||
use Illuminate\Contracts\Queue\ShouldQueue; | ||
use Illuminate\Foundation\Bus\Dispatchable; | ||
use Illuminate\Queue\InteractsWithQueue; | ||
use Illuminate\Support\Carbon; | ||
use Rapidez\Statamic\Actions\Products\ImportProducts; | ||
|
||
class DeleteProductsJob implements ShouldQueue, ShouldBeUnique | ||
{ | ||
use Dispatchable; | ||
use InteractsWithQueue; | ||
use Queueable; | ||
|
||
public function __construct( | ||
public ?string $store = null, | ||
){ | ||
} | ||
|
||
public function handle(ImportProducts $importProducts): void | ||
{ | ||
$importProducts->delete($this->store); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters