Feat: Updating ShopifyExportImporter and WipeCatalogCommand to handle images
This commit is contained in:
@@ -245,7 +245,23 @@ class ShopifyExportImporter implements Importer
|
||||
|
||||
$existing = ImportMapping::resolve(self::SOURCE, 'image', $externalId);
|
||||
|
||||
if ($existing instanceof Media) {
|
||||
// ImportMapping is a durable record of "we already imported this,"
|
||||
// but the Media row it points at can go stale — e.g. Command\
|
||||
// WipeCatalogCommand deletes every Product (media included, via
|
||||
// Spatie's own model-delete cleanup) without knowing this mapping
|
||||
// exists, since the mapping ISN'T scoped to a single Product to
|
||||
// clean up alongside it. Re-running an import afterward used to
|
||||
// trust the cached Media object unconditionally — it still existed
|
||||
// as a PHP object even though its underlying row (and file) were
|
||||
// long gone, so every re-imported product silently got zero
|
||||
// media, no error, no warning. Falls through to a fresh import
|
||||
// whenever the mapping doesn't resolve to a real, still-attached
|
||||
// Media row.
|
||||
if ($existing instanceof Media
|
||||
&& Media::whereKey($existing->getKey())->exists()
|
||||
&& $existing->model_type === $product->getMorphClass()
|
||||
&& (int) $existing->model_id === $product->id
|
||||
) {
|
||||
return $existing;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user