結局、magento関数の1つを少し変更して、回避策を作成する必要がありました。
/**
* Updates product categories
*
* @param Mage_Catalog_Model_Product $product
* @param array $categoryIds
* @return MagentoImporter
*/
protected function updateCategories(&$product, $categoryIds)
{
/** @var Varien_Db_Adapter_Pdo_Mysql **/
$dbw = Mage::getSingleton('core/resource')->getConnection('core_write');
$productCategoryTable = Mage::getSingleton('core/resource')->getTableName('catalog/category_product');
$oldCategoryIds = $product->getCategoryIds();
$insert = array_diff($categoryIds, $oldCategoryIds);
$delete = array_diff($oldCategoryIds, $categoryIds);
if (!empty($insert)) {
$data = array();
foreach ($insert as $categoryId) {
if (empty($categoryId)) {
continue;
}
$data[] = array(
'category_id' => (int)$categoryId,
'product_id' => (int)$product->getId(),
'position' => 1
);
}
if ($data) {
$ris = $dbw->insertMultiple($productCategoryTable, $data);
}
}
if (!empty($delete)) {
foreach ($delete as $categoryId) {
$where = array(
'product_id = ?' => (int)$product->getId(),
'category_id = ?' => (int)$categoryId,
);
$ris = $dbw->delete($productCategoryTable, $where);
}
}
return $this;
}
category_idsについての事実を指摘してくれたbixiに感謝します。奇妙なことに、属性ではありませんが、eav_attributeテーブルにcategory_idsというエントリがあり、magentoはこのコードで属性モデルを読み込んでいますが、属性を保存しようとするとクラッシュします。たぶん、category_ids属性を完全に削除したほうがよいので、人々はそれがバグだとは思わないでしょう。
インデックスについて:関数を使用した後の場合に備えて、おそらくすべてのデータのインデックスを再作成する必要があります。使用による製品の節約updateAttributes
は9秒から0.75になっているため、大したことではありません。