Fixed \XF\Import\Data\AbstractEntityData :: preSave - retainIds needs to set PK using forceSet

DragonByte Tech

Well-known member
InvalidArgumentException: Column 'resource_id' is read only, can only be set with forceSet in src/XF/Mvc/Entity/Entity.php at line 550
  1. XF\Mvc\Entity\Entity->set() insrc/addons/DBTech/T2WRailsImport/Import/Data/Book.php at line 87
  2. DBTech\T2WRailsImport\Import\Data\Book->preSave() insrc/XF/Import/Data/AbstractData.php at line 112
  3. XF\Import\Data\AbstractData->save() insrc/XF/Import/Data/AbstractEntityData.php at line 77
  4. XF\Import\Data\AbstractEntityData->save() insrc/addons/DBTech/T2WRailsImport/Import/Importer/ResourceManager.php at line 728
  5. DBTech\T2WRailsImport\Import\Importer\ResourceManager->stepBooks() 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 line 88
  10. XF\Mvc\Dispatcher->dispatchLoop() in src/XF/Mvc/Dispatcher.php at line 41
  11. XF\Mvc\Dispatcher->run() in src/XF/App.php at line 1931
  12. XF\App->run() in src/XF.php at line 329
  13. XF::runApp() in admin.php at line 13

Fix:
In AbstractEntityData find:
PHP:
$this->entity->set($primaryKey, $oldId);
Replace with:
PHP:
$this->entity->set($primaryKey, $oldId, ['forceSet' => true]);

(The stack trace shows my custom importer data class instead of AbstractEntityData because I had to copy the preSave function to fix the retainIds bug below.)


Fillip
 
Back
Top Bottom