function old_run($request)
 {
     $classes = VirtualFieldIndex::get_classes_with_vfi();
     ini_set('memory_limit', '1G');
     $start = (int) $request->requestVar('start');
     $n = $start;
     // rebuild the indexes
     foreach ($classes as $c) {
         echo "Rebuilding {$c}...";
         $list = DataObject::get($c);
         $count = $list->count();
         for ($i = $n; $i < $count; $i += 10) {
             $chunk = $list->limit(10, $i);
             if (Controller::curr() instanceof TaskRunner) {
                 echo "Processing VFI #{$i}...\n";
             }
             foreach ($chunk as $rec) {
                 $rec->rebuildVFI();
             }
         }
         VirtualFieldIndex::build($c);
         //			echo "Republishing changed records...";
         //			$list   = DataObject::get($c);
         //			$count  = $list->count();
         //			for ($i = 0; $i < $count; $i += 10) {
         //				$chunk = $list->limit(10, $i);
         //				foreach ($chunk as $rec) {
         //					if ($rec->isPublished()) {
         //						$rec->publish('Stage', 'Live');
         //						$rec->flushCache();
         //					}
         //				}
         //			}
         echo "<br>\n";
     }
     echo "Task complete.\n\n";
 }
 public function testStaticAttributes()
 {
     VirtualFieldIndex::build('Product');
     foreach (Product::get() as $p) {
         $p->publish('Stage', 'Live');
     }
     $c = $this->objFromFixture('ProductCategory', 'c3');
     $c->publish('Stage', 'Live');
     // set up some attributes
     $p1 = $this->objFromFixture('Product', 'p1');
     $p2 = $this->objFromFixture('Product', 'p2');
     $pat1 = $this->objFromFixture('ProductAttributeType', 'pat1');
     $pat1v1 = $this->objFromFixture('ProductAttributeValue', 'pat1v1');
     $pat1v2 = $this->objFromFixture('ProductAttributeValue', 'pat1v2');
     $p1->StaticAttributeTypes()->add($pat1);
     $p1->StaticAttributeValues()->add($pat1v1);
     $p1->StaticAttributeValues()->add($pat1v2);
     $p2->StaticAttributeTypes()->add($pat1);
     $p2->StaticAttributeValues()->add($pat1v1);
     // Should be able to filter by an attribute
     $attkey = 'ATT' . $pat1->ID;
     $prods = FacetHelper::inst()->addFiltersToDataList($c->ProductsShowable(), array($attkey => $pat1v1->ID));
     $this->assertEquals(2, $prods->count(), 'Should be 2 products for v1');
     $prods = FacetHelper::inst()->addFiltersToDataList($c->ProductsShowable(), array($attkey => $pat1v2->ID));
     $this->assertEquals(1, $prods->count(), 'Should be 1 product for v2');
     // Should be able to facet by ATT1 explicitly
     $facets = FacetHelper::inst()->buildFacets($c->ProductsShowable(), array($attkey => array('Label' => 'By Color', 'Type' => ShopSearch::FACET_TYPE_LINK)));
     $this->assertEquals(1, $facets->count(), 'Should be 1 facet');
     $f1 = $facets->First();
     $this->assertEquals(2, $f1->Values->count(), 'Should be 2 values');
     $this->assertEquals('Red', $f1->Values->First()->Label);
     $this->assertEquals(2, $f1->Values->First()->Count);
     $this->assertEquals('Green', $f1->Values->Last()->Label);
     $this->assertEquals(1, $f1->Values->Last()->Count);
     // Should be able to facet by auto_facet_attributes
     $facets = FacetHelper::inst()->buildFacets($c->ProductsShowable(), array(), true);
     $this->assertEquals(1, $facets->count(), 'Should be 1 facet');
     $f1 = $facets->First();
     $this->assertEquals(2, $f1->Values->count(), 'Should be 2 values');
     $this->assertEquals('Red', $f1->Values->First()->Label);
     $this->assertEquals(2, $f1->Values->First()->Count);
     $this->assertEquals('Green', $f1->Values->Last()->Label);
     $this->assertEquals(1, $f1->Values->Last()->Count);
 }