function migrate_db()
{
    try {
        $path = makeMigrationsDir();
        $migration = new Doctrine_Migration($path);
        $migration->migrate();
        $account = db_get_account('alice');
        if (!$account) {
            $account = array('login' => 'alice', 'crypted_password' => 'b6263bb14858294c08e4bdfceba90363e10d72b4', 'name' => 'Alice Yamada', 'name_ja_kana_jp' => 'ヤマダアリサ', 'name_ja_hani_jp' => '山田亜理紗', 'given_name' => 'Alice', 'given_name_ja_kana_jp' => 'アリサ', 'given_name_ja_hani_jp' => '亜理紗', 'family_name' => 'Yamada', 'family_name_ja_kana_jp' => 'ヤマダ', 'family_name_ja_hani_jp' => '山田', 'nickname' => 'Alice Nickname', 'preferred_username' => 'AlicePreferred', 'profile' => 'http://www.wonderland.com/alice', 'picture' => 'smiling_woman.jpg', 'website' => 'http://www.wonderland.com', 'email' => '*****@*****.**', 'email_verified' => 1, 'gender' => 'Female', 'birthdate' => '2000-01-01', 'zoneinfo' => 'america/Los Angeles', 'locale' => 'en', 'phone_number' => '123-456-7890', 'phone_number_verified' => 1, 'address' => '123 Wonderland Way', 'updated_at' => time());
            db_save_account('alice', $account);
        }
        $account = db_get_account('bob');
        if (!$account) {
            $account = array('login' => 'bob', 'crypted_password' => 'cc8684eed2b6544e89242558df73a7208c9391b4', 'name' => 'Bob Ikeda', 'name_ja_kana_jp' => 'イケダボブ', 'name_ja_hani_jp' => '池田保夫', 'given_name' => 'Bob', 'given_name_ja_kana_jp' => 'ボブ', 'given_name_ja_hani_jp' => '保夫', 'family_name' => 'Ikeda', 'family_name_ja_kana_jp' => 'イケダ', 'family_name_ja_hani_jp' => '池田', 'nickname' => 'Bob Nickname', 'preferred_username' => 'BobPreferred', 'profile' => 'http://www.underland.com/bob', 'picture' => 'smiling_man.jpg', 'website' => 'http://www.underland.com', 'email' => '*****@*****.**', 'email_verified' => 1, 'gender' => 'Male', 'birthdate' => '1980-02-09', 'zoneinfo' => 'France/Paris', 'locale' => 'fr', 'phone_number' => '987-234-1234', 'phone_number_verified' => 1, 'address' => '456 Underland Ct.', 'updated_at' => time());
            db_save_account('bob', $account);
        }
    } catch (Doctrine_Migration_Exception $e) {
        if (strstr($e->getMessage(), "Already at version") === false) {
            throw $e;
        }
    } catch (Doctrine_Connection_Exception $e) {
        printf("migration exception %s\n", $e);
        die(2);
    }
}
/**
 * Show Confirmation Dialogue for Attributes.
 * @param  String $r     Request String (JSON)
 * @return String HTML to be shown.
 */
function confirm_userinfo()
{
    $req = $_SESSION['rpfA'];
    $scopes = explode(' ', $req['scope']);
    $response_types = explode(' ', $req['response_type']);
    $offline_access = in_array('offline_access', $scopes) && in_array('code', $response_types) ? 'YES' : 'NO';
    $axlabel = get_default_claims();
    $requested_claims = get_all_requested_claims($req, $req['scope']);
    log_info('requested claims = %s', print_r($requested_claims, true));
    $attributes = '';
    $account = db_get_account($_SESSION['username']);
    foreach ($requested_claims as $claim => $required) {
        if ($required == 1) {
            $star = "<font color='red'>*</font>";
        } else {
            $star = '';
        }
        $claim_label = "{$axlabel[$claim]}{$star}";
        $claim_value = $account[$claim];
        $attributes .= "<tr><td>{$claim_label}</td><td>{$claim_value}</td><td></td></tr>\n";
    }
    $attribute_form_template = <<<EOF
  <div class='persona'>
  <form method="POST" action="{$_SERVER['SCRIPT_NAME']}/confirm_userinfo">
  <input type="hidden" name="mode" value="ax_confirm">
  <table cellspacing="0" cellpadding="0" width="600">
  <thead><tr><th>Attribute</th><th>Value</th><th>Confirm</th></tr></thead>
  {$attributes}
  <tr><td colspan="3">&nbsp;</td></tr>
  <thead><tr><td><b>Offline Access Requested</b></td><td>{$offline_access}</td><td></td></tr></thead>
  <tr><td colspan="3">&nbsp;</td></tr>
  <tr><td colspan="3">&nbsp;</td></tr>
  <tr><td colspan="3"><input type="checkbox" name="agreed" value="1" checked>I Agree to provide the above information. <br/>
  <input type="radio" name="trust" value="once" checked>Trust this site this time only <br />
  <input type="radio" name="trust" value="always" >Trust this site always <br/>
  </td></tr>
  <tr><td colspan="3"><input type="submit" name="confirm" value="confirmed"> </td></tr></table>
  </form>
  </div>
EOF;
    $styles = <<<EOF

    <style type="text/css">
      /*demo page css*/
      body{ font: 80% "Trebuchet MS", sans-serif; margin: 50px;}
      .persona table{ font: 100% "verdana", san-serif; }
      .persona td { font: 100% "verdana", san-serif;}
    </style>
EOF;
    $str = '
  <html>
  <head><title>' . OP_SERVER_NAME . ' AX Confirm</title>
  <meta name="viewport" content="width=620">' . $styles . '
  </head>
  <body style="background-color:#FFEEEE;">
  <h1>' . OP_SERVER_NAME . ' AX Confirm</h1>
  <h2>RP requests following AX values...</h2>' . $attribute_form_template . '
  </body>
  </html>
  ';
    return $str;
}
function db_save_account($username, $account_values)
{
    if (!is_array($account_values) || !$username) {
        return false;
    }
    $account = db_get_account($username);
    if ($account) {
        $account->merge($account_values);
        $account->save();
    } else {
        db_save_object('Account', 'login', $username, $account_values);
    }
    return true;
}