function testShoulNotdHaveGlobal()
 {
     $this->schemaGenerator()->dropExistingTables();
     $this->schemaGenerator()->execute(array('year','make','model'));
     $schema = new VF_Schema();
     $this->assertTrue($schema->hasGlobalLevel());
 }
 function execute( VF_Schema $schema, $alphaNumeric=false )
 {
     $this->alphaNumeric = $alphaNumeric;
     $this->schema = $schema;
     
     $levels = $schema->getLevels();
     $c = count( $levels );
     
     $levelFinder = new VF_Level_Finder();
     if( isset( $_GET['front'] ) )
     {
         $product = isset($_GET['product']) ? $_GET['product'] : null;
         if($alphaNumeric)
         {
             $children = $levelFinder->listInUseByTitle( new VF_Level($this->requestLevel()), $this->requestLevels(), $product );
         }
         else
         {
             $children = $levelFinder->listInUse( new VF_Level($this->requestLevel()), $this->requestLevels(), $product );
         }
     }
     else
     {
         $children = $levelFinder->listAll( $this->requestLevel(), $this->requestLevels() );
     }
     
     echo $this->renderChildren($children);
 }
function vafDoLevel( $level, $parent_id = 0 )
{    
    $schema = new VF_Schema();
    $finder = new VF_Level( $level );
    $parentLevel = $schema->getPrevLevel( $level );
    if( $parentLevel )
    {
        $entities = $finder->listInUse( array( $parentLevel => $parent_id ) );
    }
    else
    {
        $entities = $finder->listInUse();
    }
    echo $level . '["' . $parent_id . '"] = new Array();';
    foreach( $entities as $entity )
    {
        ?>
        var obj = new Array();
        obj["title"] = "<?=$entity->getTitle()?>";
        obj["id"] = "<?=$entity->getId()?>";
        <?=$level?>["<?=$parent_id?>"].push( obj );
        <?php
        if( $level != $schema->getLeafLevel() )
        {
            vafDoLevel( $schema->getNextLevel($level), $entity->getId() );
        }
        echo "\n";
    }
    
}
    /**
     * @deprecated
     */
    function getFitForSku($sku, $schema = null)
    {
        if (is_null($schema)) {
            $schema = new VF_Schema;
        }

        $sql = sprintf(
            "SELECT `entity_id` from `test_catalog_product_entity` WHERE `sku` = %s",
            $this->getReadAdapter()->quote($sku)
        );
        $r = $this->query($sql);
        $product_id = $r->fetchColumn();

        $r->closeCursor();

        $sql = sprintf(
            "SELECT `%s_id` from `elite_1_mapping` WHERE `entity_id` = %d AND `universal` = 0",
            $schema->getLeafLevel(),
            $product_id
        );
        $r = $this->query($sql);
        $leaf_id = $r->fetchColumn();
        $r->closeCursor();

        if (!$leaf_id) {
            return false;
        }
        $finder = new VF_Vehicle_Finder($schema);
        return $finder->findByLeaf($leaf_id);
    }
 function testShouldGetSchemaById()
 {
     $schema = VF_Schema::create('foo,bar');
     $schemaID = $schema->id();
     $new_schema = new VF_Schema($schemaID);
     $this->assertEquals(array('foo', 'bar'), $new_schema->getLevels(), 'should look up schema specified by ID passed to constructor');
 }
 protected function saveLeafLevels()
 {
     $schema = new VF_Schema();
     
     $select = $this->getReadAdapter()->select()
         ->from( 'elite_' . $schema->getLeafLevel() );
     $result = $select->query();
     
     $vehicleFinder = new VF_Vehicle_Finder( $schema );
     while( $row = $result->fetchObject() )
     {
         $vehicle = $vehicleFinder->findByLeaf( $row->id );
         $bind = array();
         foreach( $schema->getLevels() as $level )
         {
             $bind[ $level . '_id' ] = $vehicle->getLevel( $level )->getId();
         }
         try
         {
             $this->getReadAdapter()->insert( 'elite_definition', $bind );
         }
         catch( Exception $e )
         {
         }
     }
 }
 function run()
 {
     $schema = new VF_Schema();
     $db = Elite_Vaf_Helper_Data::getInstance()->getReadAdapter();
     foreach ($schema->getLevels() as $level) {
         $db->query('ALTER TABLE `elite_mapping` ADD INDEX ( `entity_id` ) ;');
     }
 }
 function run()
 {
     $schema = new VF_Schema();
     $db = Elite_Vaf_Helper_Data::getInstance()->getReadAdapter();
     foreach ($schema->getLevels() as $level) {
         $db->query('ALTER TABLE `elite_level_' . str_replace(' ', '_', $level) . '` ADD INDEX ( `title` )   ');
     }
 }
 function getSchema()
 {
     $schema = new VF_Schema();
     if (!is_null($this->getConfig())) {
         $schema->setConfig($this->getConfig());
     }
     return $schema;
 }
Пример #10
0
 function getSchema()
 {
     if (isset($this->schema)) {
         return $this->schema;
     }
     $schema = new VF_Schema();
     $schema->setConfig($this->getConfig());
     return $this->schema = $schema;
 }
Пример #11
0
 function testShouldAddSecondSchema()
 {
     $command = __DIR__ . '/vf schema --force --levels="year,make,model"';
     exec($command);
     $command = __DIR__ . '/vf schema --add --levels="foo,bar"';
     exec($command);
     $schema = new VF_Schema(2);
     $this->assertEquals(array('foo', 'bar'), $schema->getLevels(), 'should create second schema');
 }
 function run()
 {
     $schema = new VF_Schema();
     $db = VF_Singleton::getInstance()->getReadAdapter();
     foreach ($schema->getLevels() as $level) {
         $db->query('ALTER TABLE `elite_product_wheel` ADD `offset` FLOAT NOT NULL ');
         $db->query('ALTER TABLE `elite_definition_wheel` ADD `offset` FLOAT NOT NULL ');
     }
 }
 function setSortingLevels()
 {
     $schema = new VF_Schema();
     foreach ($schema->getLevels() as $level) {
         if (isset($_GET[$level . 'Sorting'])) {
             $this->generator()->setSorting($level, $_GET[$level . 'Sorting']);
         }
     }
 }
 function run()
 {
     $schema = new VF_Schema();
     $db = Elite_Vaf_Helper_Data::getInstance()->getReadAdapter();
     foreach ($schema->getLevels() as $level) {
         $old = 'elite_' . $level;
         $new = 'elite_level_' . $level;
         $db->query(sprintf("RENAME TABLE %s TO %s", $old, $new));
     }
 }
 function testShouldSetSchema()
 {
     $schemaGenerator = new VF_Schema_Generator();
     $schemaGenerator->dropExistingTables();
     VF_Schema::$levels = null;
     $command = __DIR__ . '/vfmagento schema --force --levels="year,make,model"';
     exec($command);
     $schema = new VF_Schema();
     $this->assertEquals(array('year', 'make', 'model'), $schema->getLevels(), 'should create default schema of MMY');
 }
 function testOneQueryAcrossInstances()
 {
     $this->getReadAdapter()->getProfiler()->clear();
     $this->getReadAdapter()->getProfiler()->setEnabled(true);
     $schema = new VF_Schema();
     $schema->getLevels();
     $schema = new VF_Schema();
     $schema->getLevels();
     $queries = $this->getReadAdapter()->getProfiler()->getQueryProfiles();
     $this->assertEquals(1, count($queries));
 }
 function levels()
 {
     $params = $this->getRequest()->getParam('vehicle');
     $params = explode("-", $params);
     $schema = new VF_Schema();
     $levels = array();
     foreach ($schema->getLevels() as $level) {
         $levels[$level] = current($params);
         next($params);
     }
     return $levels;
 }
 function addUniqueOnDefinitions()
 {
     $schema = new VF_Schema();
     $db = Elite_Vaf_Helper_Data::getInstance()->getReadAdapter();
     $levels = array();
     foreach ($schema->getLevels() as $level) {
         $levels[] = sprintf('`%s_id`', $level);
     }
     $levels = implode(',', $levels);
     $query = "ALTER TABLE `elite_definition` ADD UNIQUE ( %s );";
     $db->query(sprintf($query, $levels));
 }
    function save()
    {
        if (!(int) $this->product_id)
        {
            throw new Exception('Trying to insert a mapping with no product ID');
        }
        $schema = new VF_Schema;
        $schema->setConfig($this->getConfig());
        $levels = $schema->getLevels();

        $select = $this->getReadAdapter()->select()
                        ->from($schema->mappingsTable(), array('id'));
        foreach ($this->vehicle->toValueArray() as $level => $id)
        {
            $select->where($this->inflect($level) . '_id = ?', $id);
        }
        $select->where('entity_id = ?', $this->product_id);

        $id = (int) $select->query()->fetchColumn();
        if (0 !== $id)
        {
            return $id;
        }

        $columns = '';
        $values = '';
        foreach ($levels as $level)
        {
            $columns .= '`' . $this->inflect($level) . '_id`,';
            $values .= $this->inflect($this->vehicle->getLevel($level)->getId());
            $values .= ',';
        }
        $query = sprintf(
                        '
            INSERT INTO
                `'.$schema->mappingsTable().'`
            (
                ' . $columns . '
                `entity_id`
            )
            VALUES
            (
                ' . $values . '
                %d
            )
            ',
            (int) $this->product_id
        );
        $r = $this->query($query);
        return $this->getReadAdapter()->lastInsertId();
    }
    protected function rowResult()
    {
	$this->getReadAdapter()->getConnection()->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, true);
	$select = $this->getReadAdapter()->select()
			->from($this->schema()->mappingsTable(), array('id', 'universal'));
	foreach ($this->schema->getLevels() as $level)
	{
	    $levelTable = $this->schema()->levelTable($level);
	    $condition = sprintf('%s.id = '.$this->schema()->mappingsTable().'.%s_id', $levelTable, $level);
	    $select->joinLeft($levelTable, $condition, array($level => 'title'));
	}
	$select->joinLeft(array('p' => $this->getProductTable()), 'p.entity_id = '.$this->schema()->mappingsTable().'.entity_id', array('sku'));
	return $this->query($select);
    }
Пример #21
0
 function removeFitments($product)
 {
     $schema = new \VF_Schema();
     if (is_array($this->params()->fromPost('vaf-delete')) && count($this->params()->fromPost('vaf-delete')) >= 1) {
         foreach ($this->params()->fromPost('vaf-delete', array()) as $fit) {
             $fit = explode('-', $fit);
             $level = $fit[0];
             $fit = $fit[1];
             if ($level == $schema->getLeafLevel()) {
                 $product->deleteVafFit($fit);
             }
         }
     }
 }
Пример #22
0
 function removeFitments($request, $product)
 {
     $schema = new VF_Schema();
     if (is_array($request->getParam('vaf-delete')) && count($request->getParam('vaf-delete')) >= 1) {
         foreach ($request->getParam('vaf-delete', array()) as $fit) {
             $fit = explode('-', $fit);
             $level = $fit[0];
             $fit = $fit[1];
             if ($level == $schema->getLeafLevel()) {
                 $product->deleteVafFit($fit);
             }
         }
     }
 }
Пример #23
0
 public function indexAction()
 {
     try {
         $schema = new \VF_Schema();
         $levels = $schema->getLevels();
     } catch (\Zend_Db_Statement_Exception $e) {
         $levels = array();
     }
     if ($this->getRequest()->isPost()) {
         $schemaGenerator = new \VF_Schema_Generator();
         $schemaGenerator->dropExistingTables();
         $schemaGenerator->execute(explode(",", $_POST['schema']));
         $this->flashMessenger()->setNamespace('success')->addMessage('Saved Schema');
     }
     return array('schema' => $levels);
 }
 function testShouldFindInSecondSchema()
 {
     $schema = VF_Schema::create('foo,bar');
     $vehicle = $this->createVehicle(array('foo' => '123', 'bar' => '456'), $schema);
     $found = $this->getFinder($schema)->findOneByLevelIds(array('foo' => $vehicle->getValue('foo')));
     $this->assertEquals($vehicle->getValue('foo'), $found->getValue('foo'), 'should find in second schema');
 }
 function testVehicleExists()
 {
     return $this->markTestIncomplete();
     
     $schema = VF_Schema::create('foo,bar');
     $finder = new VF_Vehicle_Finder($schema);
     $this->assertFalse($finder->vehicleExists(array('foo'=>'test','bar'=>'doesntexist')), 'vehicle should not exist');
 }
 function testSaveParenetheses()
 {
     $schema = VF_Schema::create('foo,bar');
     $vehicle = VF_Vehicle::create($schema, array('foo' => 'valfoo', 'bar' => 'valbar'));
     $vehicle->save();
     $vehicleExists = $this->vehicleExists(array('foo' => 'valfoo', 'bar' => 'valbar'), false, $schema);
     $this->assertTrue($vehicleExists, 'should find vehicles in different schema');
 }
Пример #27
0
 function testShouldSaveMappingInSecondSchema()
 {
     $schema = VF_Schema::create('foo,bar');
     $vehicle = $this->createVehicle(array('foo' => '123', 'bar' => '456'), $schema);
     $mapping = new VF_Mapping(1, $vehicle);
     $id = $mapping->save();
     $this->assertTrue($id > 0, 'should save mapping in second schema');
 }
Пример #28
0
 function testSaveActionNewMultipleSchemas()
 {
     $schema = VF_Schema::create('foo,bar');
     $request = $this->getRequest(array('save' => self::ARBITRARY_STRING, 'title' => '123', 'entity' => 'foo', 'schema' => $schema->id()));
     $controller = $this->definitionsController($request);
     $controller->saveAction();
     $this->assertTrue($this->vehicleExists(array('foo' => '123'), true, $schema));
 }
 function testShouldGenerateMultipleSchemas()
 {
     $this->schemaGenerator()->execute(array('make', 'model', 'year'));
     $schema = VF_Schema::create('foo,bar');
     $expectedTable = 'elite_level_' . $schema->id() . '_foo';
     $tables = $this->getReadAdapter()->listTables();
     $this->assertTrue(in_array($expectedTable, $tables), 'should create table for new schema `elite_level_x_foo`');
 }
Пример #30
0
 protected function switchSchema($levels, $force = false)
 {
     if (!$force) {
         try {
             $schema = new VF_Schema();
             if ($levels == implode(',', $schema->getLevels())) {
                 $this->startTransaction();
                 return;
             }
         } catch (Zend_Db_Statement_Mysqli_Exception $e) {
         } catch (Zend_Db_Statement_Exception $e) {
         }
     }
     $schemaGenerator = new VF_Schema_Generator();
     $schemaGenerator->dropExistingTables();
     $schemaGenerator->execute(explode(',', $levels));
     VF_Schema::reset();
     $this->startTransaction();
 }