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 $this->startSetup();
00029 $table = $this->getTable('catalog/category');
00030 $tableTmp = $table . "_tmp";
00031 $this->run("DROP TABLE IF EXISTS `{$tableTmp}`");
00032
00033 $this->run("CREATE TABLE `{$tableTmp}` (
00034 `entity_id` int(10) unsigned NOT NULL auto_increment,
00035 `children_count` int(11) NOT NULL,
00036 PRIMARY KEY (`entity_id`)
00037 ) ENGINE=InnoDB;
00038 ");
00039
00040 $this->run("INSERT INTO {$tableTmp} (SELECT e.entity_id, COUNT( ee.entity_id ) as children_count
00041 FROM `{$table}` e
00042 INNER JOIN `{$table}` ee ON ee.path LIKE CONCAT( e.path, '/%' )
00043 GROUP BY e.entity_id)");
00044
00045 $this->run("UPDATE {$table}, {$tableTmp}
00046 SET {$table}.children_count = {$tableTmp}.children_count
00047 WHERE {$table}.entity_id = {$tableTmp}.entity_id");
00048
00049 $this->run("DROP TABLE `{$tableTmp}`");
00050
00051 $this->endSetup();