Fixed Importer: the "silent" flag to insertMasterPhrase is useless

DragonByte Tech

Well-known member
Affected version
2.0.2
Related to my question here: https://xenforo.com/community/threa...ion-phrases-on-uninstall.143376/#post-1226145

I'm testing an importer, and after receiving an error that a phrase already existed when importing content that uses MasterTitle, I thought I'd bypass by passing the "silent" flag like so:

PHP:
$this->insertMasterPhrase('dbtech_ecommerce_discount_title.' . $newId, $this->title ?: '', [], true);

That shifted the error message:
LogicException: Cannot detach an entity without a valid primary key in src\XF\Mvc\Entity\Manager.php at line 799
  1. XF\Mvc\Entity\Manager->detachEntity() insrc\XF\Import\Data\AbstractData.php at line 236
  2. XF\Import\Data\AbstractData->insertMasterPhrase() in C:\git\dbtech-ecommerce\ecommerce\upload\src\addons\DBTech\eCommerce\Import\Data\Discount.php at line 67
  3. DBTech\eCommerce\Import\Data\Discount->postSave() insrc\XF\Import\Data\AbstractData.php at line 135
  4. XF\Import\Data\AbstractData->save() in C:\git\dbtech-ecommerce\ecommerce\upload\src\addons\DBTech\eCommerce\Import\Importer\vBeCommerce.php at line 709
  5. DBTech\eCommerce\Import\Importer\vBeCommerce->stepDiscounts()in src\XF\Import\Runner.php at line 160
  6. XF\Import\Runner->runStep() in src\XF\Import\Runner.php at line 74
  7. XF\Import\Runner->run() in src\XF\Admin\Controller\Import.php at line232
  8. XF\Admin\Controller\Import->actionRun() in src\XF\Mvc\Dispatcher.phpat line 249
  9. XF\Mvc\Dispatcher->dispatchClass() in src\XF\Mvc\Dispatcher.php at line88
  10. XF\Mvc\Dispatcher->dispatchLoop() in src\XF\Mvc\Dispatcher.php at line41
  11. XF\Mvc\Dispatcher->run() in src\XF\App.php at line 1889
  12. XF\App->run() in src\XF.php at line 328
  13. XF::runApp() in admin.php at line 13

Fix:
Change the relevant lines in AbstractData to
PHP:
if ($phrase->save($silent ? false : true, false))
{
   $this->dataManager->em()->detachEntity($phrase);
}[/php]


Fillip
 
Back
Top Bottom