We ended up using this code. Place in shell or other protected subdirectory from root and run from web. Remember to remove when you are done.
- does not truncate table
- looks for existing reviews and copies them on a per store basis
- carefully preventing duplicate creation
- option to output the SQL code for manual execution
!!! PLEASE BACKUP YOUR REVIEW TABLE BEFORE EXECUTING
- when you are done, open up all reviews in Magento
- Filter on Approved
- Select all -the mass update Set Status => approved
- This will trigger aggregation and make them available in counts too
Good luck!
<?php
error_reporting(~0); ini_set('display_errors', 1);
// adjust for where your file is, ours is in protected subdirectory of /
define('MAGENTO_ROOT', dirname(dirname(__FILE__)));
$mageFilename = MAGENTO_ROOT . '/app/Mage.php';
require_once $mageFilename;
umask(0);
Mage::app();
$resource = Mage::getSingleton('core/resource');
$adapter = $resource->getConnection('core_write');
$prefix = Mage::getConfig()->getTablePrefix();
$tableName = $prefix.'review_store';
$values = array();
$query = 'SELECT * FROM ' . $tableName;
$ids = $adapter->fetchAll($query);
// copy_reviews_tostore(idlist,valuelist,from_storeid_here,to_storeid_array_here)
copy_reviews_tostore($ids,$values,1,array(8));
copy_reviews_tostore($ids,$values,7,array(2,8));
copy_reviews_tostore($ids,$values,2,array(8));
try {
foreach ($values as $value) { $result .= "(".$value['review_id'].",".$value['store_id'].")".",\n"; }
$result=substr($result, 0, -2);
$query="INSERT INTO $tableName (`review_id`,`store_id`) VALUES $result;";
// if you want to copy-paste manual to PhpMyadmin
echo($query);
// if you want to execute directly
//$adapter->beginTransaction();
//$adapter->query($query);
//$adapter->commit();
echo "OK\n";
} catch (Exception $e) {
$adapter->rollBack();
print_r($e->getTrace());
}
function copy_reviews_tostore ($ids, &$values, $from_store, $to_stores) {
foreach ($ids as $id) {
$review_id = $id['review_id'];
$store_id = $id['store_id'];
if($store_id != $from_store) { continue; }
foreach ($to_stores as $store) {
// do not write to same store
if($store_id == $store) { continue; }
// check for already existing review/store value in DB
if (check_review_exists($ids, $store, $review_id)) { continue; }
// check for already existing review/store in write buffer (from previous cycle)
$skip = false;
foreach ($values as $value) {
if (empty($values) || ($id['review_id'] == $value['review_id'] && $store == $value['store_id']))
{ $skip = true; }
}
if (!$skip) { $values[]= array("review_id" => $review_id,"store_id" => $store); }
}
}
}
function check_review_exists ($ids, $find_store_id, $find_review_id) {
$ret = false;
foreach ($ids as $id) {
$review_id = $id['review_id'];
$store_id = $id['store_id'];
if ($review_id == $find_review_id && $store_id == $find_store_id) { $ret = true; }
}
return $ret;
}