Scalr\Upgrade\Updates\Update20151207161318::run2 PHP Method

run2() protected method

protected run2 ( )
    protected function run2()
    {
        $this->db->BeginTrans();
        try {
            $this->console->out("Copying properties from farms to farm settings");
            $this->db->Execute("\n                INSERT IGNORE INTO farm_settings (`farmid`, `name`, `value`)\n                SELECT id, ? AS `name`, created_by_id AS `value` FROM farms WHERE created_by_id IS NOT NULL\n                UNION\n                SELECT id, ? AS `name`, created_by_email AS `value` FROM farms WHERE created_by_email IS NOT NULL\n            ", [FarmSetting::CREATED_BY_ID, FarmSetting::CREATED_BY_EMAIL]);
            $this->console->out("Sanitizing farms");
            $this->db->Execute("\n                UPDATE farms f\n                LEFT JOIN account_users au ON au.id = f.created_by_id\n                SET f.created_by_id = NULL\n                WHERE au.id IS NULL\n            ");
            $this->console->out("Adding foreign key 'fk_farms_account_users_id'");
            $this->db->Execute("\n                ALTER TABLE farms\n                ADD CONSTRAINT `fk_farms_account_users_id`\n                FOREIGN KEY (`created_by_id`)\n                REFERENCES `account_users` (`id`)\n                ON DELETE SET NULL ON UPDATE NO ACTION\n            ");
            $this->db->CommitTrans();
        } catch (\Exception $e) {
            $this->db->RollbackTrans();
            throw $e;
        }
    }