-
Notifications
You must be signed in to change notification settings - Fork 0
/
donorpress-upgrade.php
125 lines (107 loc) · 4.04 KB
/
donorpress-upgrade.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<?php
use DonorPress\CustomVariables;
use DonorPress\Donation;
use DonorPress\DonationCategory;
use DonorPress\DonationReceipt;
use DonorPress\Donor;
use DonorPress\DonorTemplate;
use DonorPress\DonorType;
use DonorPress\QuickBooks;
use DonorPress\Paypal;
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
function donorpress_upgrade(){
global $donor_press_db_version;
$current_db_version=get_option( "donor_press_db_version");
if (!$current_db_version || version_compare($current_db_version, '0.0.3', '<')){
donorpress_upgrade_0_0_3();
}
if (version_compare($current_db_version, '0.0.4', '<')){
donorpress_upgrade_0_0_4();
}
if (version_compare($current_db_version, '0.0.5', '<')){
donorpress_upgrade_0_0_5();
}
if (version_compare($current_db_version, '0.0.6', '<')){
donorpress_upgrade_0_0_6();
}
if (version_compare($current_db_version, '0.0.7', '<')){
donorpress_upgrade_0_0_7();
}
if (version_compare($current_db_version, '0.0.8', '<')){
donorpress_upgrade_0_0_8();
}
if (version_compare($current_db_version, '0.0.9', '<')){
donorpress_upgrade_0_0_9();
}
if (version_compare($current_db_version, '0.1.1', '<')){
donorpress_upgrade_0_1_1();
}
if ($current_db_version){
update_option( "donor_press_db_version", $donor_press_db_version );
}else{
add_option( "donor_press_db_version", $donor_press_db_version );
}
Donor::display_notice("Donor Press Database Upgraded from ".$current_db_version." to ".$donor_press_db_version);
}
function donorpress_upgrade_0_0_3(){
DonorType::create_table();
$wpdb=Donor::db();
$aSQL="ALTER TABLE `".Donor::get_table_name()."` ADD COLUMN `TypeId` NOT NULL DEFAULT '0' AFTER `Country`;";
$wpdb->query( $aSQL );
$aSQL="ALTER TABLE `".Donation::get_table_name()."` CHANGE `NotTaxDeductible` `TransactionType` INT NULL DEFAULT '0' COMMENT '0=TaxExempt 1=NotTaxExcempt 2=Service -1=Expense';";
$wpdb->query( $aSQL );
}
function donorpress_upgrade_0_0_4(){
$wpdb=Donor::db();
$aSQL="ALTER TABLE `".DonorType::get_table_name()."` CHANGE `QBAccountId` `QBItemId` INT NULL DEFAULT '0';";
$wpdb->query( $aSQL );
$aSQL="ALTER TABLE `".Donation::get_table_name()."` ADD COLUMN `QBOPaymentId` INT NULL DEFAULT NULL AFTER `QBOInvoiceId`;";
$wpdb->query( $aSQL );
}
function donorpress_upgrade_0_0_5(){
$wpdb=Donor::db();
$aSQL="ALTER TABLE `".Donation::get_table_name()."`
CHANGE COLUMN `Gross` `Gross` DECIMAL(10,2) NOT NULL ,
CHANGE COLUMN `Net` `Net` DECIMAL(10,2) NULL DEFAULT NULL ;";
$wpdb->query( $aSQL );
}
function donorpress_upgrade_0_0_6(){
$wpdb=Donor::db();
$aSQL="ALTER TABLE `".DonationReceipt::get_table_name()."`
ADD COLUMN `Subject` varchar(256);";
$wpdb->query( $aSQL );
}
function donorpress_upgrade_0_0_7(){
$wpdb=Donor::db();
$aSQL="ALTER TABLE `".DonationCategory::get_table_name()."`
ADD COLUMN `TransactionType` INT NULL DEFAULT NULL AFTER `TemplateId`;";
$wpdb->query( $aSQL );
}
function donorpress_upgrade_0_0_8(){
//Transasition expenses to the 100 range.
$wpdb=Donor::db();
$uSQL="UPDATE `".Donation::get_table_name()."` SET TransactionType=100 WHERE TransactionType=2";
$wpdb->query( $uSQL );
}
function donorpress_upgrade_0_0_9(){
$wpdb=Donor::db();
$aSQL="ALTER TABLE `".Donor::get_table_name()."`
ADD COLUMN `AddressStatus` tinyint(4) NOT NULL DEFAULT '1' COMMENT '-2 Unsubscripted -1=Returned 1=Active' AFTER `Country`;";
$wpdb->query( $aSQL );
}
function donorpress_upgrade_0_1_1(){
$wpdb=Donor::db();
$tableNames=donorpress_tables();
foreach($tableNames as $table){
$class="DonorPress\\".$table;
$newTableName=$class::get_table_name();
$oldTableName=str_replace("donorpress_","",$newTableName);
$aSQL="RENAME TABLE `".$oldTableName."` TO `".$newTableName."`;";
$wpdb->query( $aSQL );
}
$aSQL="UPDATE ".$wpdb->prefix."options SET option_name=REPLACE(option_name,'donation_','donorpress_') WHERE option_name LIKE 'donation_%';";
$wpdb->query( $aSQL );
// add an update Donation thank youtemplates
$aSQL="UPDATE ".$wpdb->prefix."posts SET post_type='donorpress' WHERE post_type='donortemplate'";
$wpdb->query( $aSQL );
}