public function safeUp()
 {
     MigrationHelper::dropForeignKeyIfExists('market_orders', ['typeId']);
     MigrationHelper::dropIndexIfExists('market_orders', ['typeId']);
     $this->dropColumn('market_orders', 'typeId');
     // find everything that is not 'order'
     $ids = craft()->db->createCommand()->select('id')->from('market_ordertypes')->where("handle != 'order'")->queryColumn();
     // delete 'em
     $this->delete('market_ordertypes', array('in', 'id', $ids));
     $table = MigrationHelper::getTable('market_ordertypes');
     MigrationHelper::dropAllForeignKeysOnTable($table);
     $this->renameTable('market_ordertypes', 'market_ordersettings');
     $this->addForeignKey('market_ordersettings', 'fieldLayoutId', 'fieldlayouts', 'id', 'SET NULL');
     $orderSettings = craft()->db->createCommand()->select('*')->from('market_ordersettings')->where("handle = 'order'")->queryScalar();
     if (!$orderSettings) {
         craft()->db->createCommand()->insert('market_ordersettings', ['name' => 'Order', 'handle' => 'order', 'fieldLayoutId' => null]);
     }
     return true;
 }
    public function safeUp()
    {
        $all = <<<EOT
select
vv.id as idx,
vv.variantId as variantId,
v.productId as variantProductId,
p.typeId as productTypeId,
ot.handle as optionTypeName,
ov.id as optionValueId,
ov.name as optionValueName,
ov.displayName as optionValueDisplayName
from craft_market_variant_optionvalues vv
\tleft join craft_market_variants v
\t\ton vv.variantId = v.id
\tleft join craft_market_products p
\t\ton v.productId = p.id
\tleft join craft_market_optionvalues ov
\t\ton vv.optionValueId = ov.id
\tleft join craft_market_optiontypes ot
\t\ton ov.optionTypeId = ot.id
EOT;
        $allData = craft()->db->createCommand($all)->queryAll();
        if (!empty($allData)) {
            craft()->db->createCommand()->createTable('market_variantoptionvaluesbackup', ['idx' => ['column' => 'varchar', 'maxLength' => 255], 'variantId' => ['column' => 'varchar', 'maxLength' => 255], 'variantProductId' => ['column' => 'varchar', 'maxLength' => 255], 'productTypeId' => ['column' => 'varchar', 'maxLength' => 255], 'optionTypeName' => ['column' => 'varchar', 'maxLength' => 255], 'optionValueId' => ['column' => 'varchar', 'maxLength' => 255], 'optionValueName' => ['column' => 'varchar', 'maxLength' => 255], 'optionValueDisplayName' => ['column' => 'varchar', 'maxLength' => 255]], null, false);
            foreach ($allData as $row) {
                $this->insert('market_variantoptionvaluesbackup', $row);
            }
        }
        $market_optionvalues = MigrationHelper::getTable('market_optionvalues');
        $market_optiontypes = MigrationHelper::getTable('market_optiontypes');
        $market_product_optiontypes = MigrationHelper::getTable('market_product_optiontypes');
        $market_variant_optionvalues = MigrationHelper::getTable('market_variant_optionvalues');
        MigrationHelper::dropAllForeignKeysOnTable($market_optionvalues);
        MigrationHelper::dropAllForeignKeysOnTable($market_optiontypes);
        MigrationHelper::dropAllForeignKeysOnTable($market_product_optiontypes);
        MigrationHelper::dropAllForeignKeysOnTable($market_variant_optionvalues);
        $this->dropTable('market_optionvalues');
        $this->dropTable('market_optiontypes');
        $this->dropTable('market_product_optiontypes');
        $this->dropTable('market_variant_optionvalues');
        return true;
    }
Exemplo n.º 3
0
 /**
  * Drops the foreign keys from the model's table.
  *
  * @return null
  */
 public function dropForeignKeys()
 {
     $tableName = $this->getTableName();
     // Does the table exist?
     if (craft()->db->tableExists($tableName, true)) {
         $table = MigrationHelper::getTable($tableName);
         MigrationHelper::dropAllForeignKeysOnTable($table);
     }
 }