createAccessoryIfNotExists(); } /** * Create an accessory if a duplicate does not exist * * @author Daniel Melzter * @since 3.0 */ public function createAccessoryIfNotExists() { $accessory = Accessory::where('name', $this->item['name'])->first(); if ($accessory) { if (!$this->updating) { $this->log('A matching Accessory ' . $this->item["name"] . ' already exists. '); return; } $this->log('Updating Accessory'); $accessory->update($this->sanitizeItemForUpdating($accessory)); if (!$this->testRun) { $accessory->save(); } return; } $this->log("No Matching Accessory, Creating a new one"); $accessory = new Accessory(); $accessory->fill($this->sanitizeItemForStoring($accessory)); if ($this->testRun) { $this->log('TEST RUN - Accessory ' . $this->item["name"] . ' not created'); return; } if ($accessory->save()) { $accessory->logCreate('Imported using CSV Importer'); $this->log('Accessory ' . $this->item["name"] . ' was created'); return; } $this->logError($accessory, 'Accessory'); } }