Skip to content

Commit

Permalink
automatic database manipulation
Browse files Browse the repository at this point in the history
  • Loading branch information
btcgear committed Jun 7, 2013
1 parent 74726f8 commit 327f9d4
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
26 changes: 20 additions & 6 deletions upload/admin/controller/payment/bitcoin.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,26 @@ public function index() {
'href' => $this->url->link('payment/bitcoin', 'token=' . $this->session->data['token'], 'SSL'),
'separator' => ' :: '
);

$result = $this->db->query("SHOW COLUMNS FROM ". DB_PREFIX ."order;");
$rows = $result->rows;
$max = $result->num_rows;
$bitcoin_total_in_db = 0;
$bitcoin_address_in_db = 0;
for($i = 0;$i < $max;$i++) {
if($rows[$i]["Field"] == "bitcoin_total") {
$bitcoin_total_in_db = 1;
}
if($rows[$i]["Field"] == "bitcoin_address") {
$bitcoin_address_in_db = 1;
}
}
if(!$bitcoin_total_in_db) {
$this->db->query("ALTER TABLE ". DB_PREFIX ."order ADD bitcoin_total DOUBLE AFTER currency_value;");
}
if(!$bitcoin_address_in_db) {
$this->db->query("ALTER TABLE ". DB_PREFIX ."order ADD bitcoin_address VARCHAR(34) AFTER bitcoin_total;");
}

$this->data['action'] = HTTPS_SERVER . 'index.php?route=payment/'.$this->payment_module_name.'&token=' . $this->session->data['token'];
$this->data['cancel'] = HTTPS_SERVER . 'index.php?route=extension/payment&token=' . $this->session->data['token'];
Expand Down Expand Up @@ -215,10 +235,4 @@ public function index() {
$this->response->setOutput($this->render(TRUE), $this->config->get('config_compression'));
}

public function update_db() {

$this->db->query("ALTER TABLE ". DB_PREFIX ."order ADD bitcoin_total DOUBLE AFTER currency_value;");
$this->db->query("ALTER TABLE ". DB_PREFIX ."order ADD bitcoin_address VARCHAR(34) AFTER bitcoin_total;");

}
}
2 changes: 1 addition & 1 deletion upload/admin/language/english/payment/bitcoin.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
$_['entry_prefix'] = 'The prefix for the address labels:<br /><span class="help">The account will be in the form [prefix]_[order_id]</span>';
$_['entry_order_status'] = 'Status of a new order:';
$_['entry_show_btc'] = 'Show BTC as a store currency:';
$_['entry_blockchain'] = 'Is this a blockchain.info JSON-RPC server?:';
$_['entry_blockchain'] = 'Is this a blockchain.info JSON-RPC server?';
$_['entry_btc_decimal'] = 'Calculate BTC amount to this many decimal places:';
$_['entry_countdown_timer'] = 'Time to complete order:<br /><span class="help">In seconds</span>';
$_['entry_status'] = 'Status:';
Expand Down
3 changes: 0 additions & 3 deletions upload/admin/view/template/payment/bitcoin.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ Copyright (c) 2013 John Atkinson (jga)
<div class="content">
<form action="<?php echo $action; ?>" method="post" enctype="multipart/form-data" id="form">
<table class="form">
<tr>
<td colspan="2"><a href="index.php?route=payment/bitcoin/update_db&token=<?php echo $this->session->data['token']; ?>">Click here the first time you configure this extension to prepare your database.</a></td>
</tr>
<tr>
<td><span class="required">*</span> <?php echo $entry_username; ?></td>
<td><input type="text" name="bitcoin_rpc_username" value="<?php echo $bitcoin_rpc_username; ?>" style="width:300px;" />
Expand Down

0 comments on commit 327f9d4

Please sign in to comment.