Robbo
Well-known member
The commented out code would run much faster as it is just one query and not creating and executing a new data writer for every image.
Is there some way I can do this with the data writers? Or should I just be using that query?
I don't care if this code is slow as it will rarely be executed but was just wondering anyway.
PHP:
public function moveImages($oldId, $newId)
{
if (!$this->getCategoryById($newId))
return;
$images = $this->getImages($oldId);
foreach ($images as $image)
{
$dw = XenForo_DataWriter::create('Merc_DataWriter_GalleryLite_Image');
$dw->setExistingData($image);
$dw->set('cat_id', $newId);
$dw->save();
}
/*$this->_getDb()->query('
UPDATE merc_gallerylite_image
SET cat_id = ? WHERE cat_id = ?',
array($newId, $oldId)
);*/
}
Is there some way I can do this with the data writers? Or should I just be using that query?
I don't care if this code is slow as it will rarely be executed but was just wondering anyway.