00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 $this->startSetup();
00033
00034
00035 $this->run("
00036 ALTER TABLE `{$this->getTable('rating_option_vote_aggregated')}`
00037 ADD COLUMN `percent_approved` tinyint(3) NULL DEFAULT 0 AFTER `percent`;
00038 ");
00039
00040 try {
00041
00042 $resource = Mage::getResourceSingleton('review/review');
00043
00044 $total = $this->getConnection()->select()->from($this->getTable('review'), 'count(*)');
00045 $total = intval($this->getConnection()->fetchOne($total));
00046 for ($i = 0; $i < $total; $i += 100) {
00047 $select = $this->getConnection()->select()
00048 ->from($this->getTable('review'), array('review_id', 'entity_pk_value'))
00049 ->limit(100, $i)
00050 ;
00051 $rows = $this->getConnection()->fetchAll($select);
00052 foreach ($rows as $row) {
00053 $resource->reAggregateReview($row['review_id'], $row['entity_pk_value']);
00054 }
00055 }
00056 }
00057 catch (Exception $e) {
00058 $this->run("ALTER TABLE `{$this->getTable('rating_option_vote_aggregated')}` DROP COLUMN `percent_approved`;");
00059 throw $e;
00060 }
00061
00062 $this->endSetup();