aboutsummaryrefslogtreecommitdiff
path: root/install
diff options
context:
space:
mode:
authorCamil Staps2016-07-28 09:37:48 +0200
committerCamil Staps2016-07-28 09:47:04 +0200
commit4f84eb2b09bf51eabdc29b5eeec101e0260b1cb7 (patch)
tree82722787d4018373720c66933f475bb2b1708c92 /install
parentSplit Calculatable in trait and interface (diff)
Braintree integration: first version
Diffstat (limited to 'install')
-rw-r--r--install/index.php6
-rw-r--r--install/upgrade.php18
2 files changed, 20 insertions, 4 deletions
diff --git a/install/index.php b/install/index.php
index dbea375..d40959f 100644
--- a/install/index.php
+++ b/install/index.php
@@ -81,7 +81,8 @@ if (isset($_GET['create_tables'])) {
`end_date` date NOT NULL,
`invoice_date` date NOT NULL,
`accepted` tinyint(1) unsigned NOT NULL DEFAULT '0',
- `invoice_fileId` smallint(5) unsigned DEFAULT NULL,
+ `invoice_fileId` smallint(5) unsigned DEFAULT NULL,
+ `payment_key` varchar(63) DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `invoice_fileId` (`invoice_fileId`),
KEY `contactId` (`contactId`),
@@ -93,6 +94,8 @@ if (isset($_GET['create_tables'])) {
`id` smallint(5) unsigned NOT NULL AUTO_INCREMENT,
`offerId` smallint(5) unsigned NOT NULL,
`date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
+ `braintree_id` varchar(36) DEFAULT NULL,
+ `braintree_status` varchar(63) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;");
@@ -116,6 +119,7 @@ if (isset($_GET['create_tables'])) {
ADD CONSTRAINT `offer_ibfk_1` FOREIGN KEY (`invoice_fileId`) REFERENCES `".Constants::db_prefix."file` (`id`),
ADD CONSTRAINT `offer_ibfk_2` FOREIGN KEY (`contactId`) REFERENCES `".Constants::db_prefix."contact` (`id`)");
+ $_pdo->query("CREATE UNIQUE INDEX `payment_uniq_1` ON `".Constants::db_prefix."payment` (`offerId`);");
$_pdo->query("ALTER TABLE `payment`
ADD CONSTRAINT `payment_ibfk_1` FOREIGN KEY (`offerId`) REFERENCES `offer` (`id`);");
diff --git a/install/upgrade.php b/install/upgrade.php
index aea97ce..8ead230 100644
--- a/install/upgrade.php
+++ b/install/upgrade.php
@@ -97,9 +97,8 @@ if (isset($_GET['upgrade'])) {
$offers = $_pdo->query("SELECT `id`,`payment_received` FROM `".Constants::db_prefix."offer` WHERE `payment_received` IS NOT NULL");
$offers = $offers->fetchAll(PDO::FETCH_ASSOC);
foreach ($offers as $offer) {
- $received = $offer['payment_received'];
- $offer = new Offer($_pdo, $offer['id']);
- $offer->createPayment($received);
+ $stmt = $_pdo->prepare("INSERT IGNORE INTO `".Constants::db_prefix."payment` (`offerId`,`date`) VALUES (?,?)");
+ $stmt->execute($offer['id'], $offer['payment_received']);
}
$_pdo->query("ALTER TABLE `".Constants::db_prefix."offer` DROP `payment_received`;");
@@ -108,6 +107,19 @@ if (isset($_GET['upgrade'])) {
}
}
+ if (lower_version($_GET['upgrade'], '0.5')) {
+ try {
+ $_pdo->query("ALTER TABLE `".Constants::db_prefix."offer`
+ ADD `payment_key` VARCHAR(63) DEFAULT NULL;");
+ $_pdo->query("ALTER TABLE `".Constants::db_prefix."payment`
+ ADD `braintree_id` VARCHAR(36) DEFAULT NULL,
+ ADD `braintree_status` VARCHAR (63) NULL DEFAULT NULL;");
+ $_pdo->query("CREATE UNIQUE INDEX `payment_uniq_1` ON `".Constants::db_prefix."payment` (`offerId`);");
+ } catch (PDOException $e) {
+ echo "Altering the database structure failed with a PDOException ({$e->getCode()}): {$e->getMessage()}<br/>" . $e->getTraceAsString();
+ }
+ }
+
echo "<br/>All done.";
}
?>