public function skuAction() { $repaired = false; $model = new waModel(); $sql = <<<SQL UPDATE `shop_product` `p` LEFT JOIN `shop_product_skus` `s` ON (`s`.`product_id`=`p`.`id`) AND (`s`.`id`=`p`.`sku_id`) SET `p`.`sku_id`=NULL WHERE `s`.`id` IS NULL SQL; $model->query($sql); if ($count = $model->affected()) { $repaired = true; print sprintf("%d product(s) with invalid default SKU ID restored\n", $count); } $sql = <<<SQL UPDATE `shop_product` `p` JOIN `shop_product_skus` `s` ON (`s`.`product_id`=`p`.`id`) SET `p`.`sku_id`=`s`.`id` WHERE `p`.`sku_id` IS NULL SQL; $model->query($sql); if ($count = $model->affected()) { $repaired = true; print sprintf("%d product(s) with missed default SKU ID restored\n", $count); } if (!$repaired) { print "nothing to repair"; } }