HTML
1 year ago
views
5 months ago
Apply.php
6 months ago
Cron.php
1 year ago
CronJob.php
8 months ago
CronJobs.php
2 months ago
Crypt.php
2 months ago
DownloadStats.php
5 months ago
Email.php
1 week ago
EmailCron.php
1 year ago
FileSystem.php
1 year ago
Installer.php
3 days ago
Messages.php
1 year ago
Query.php
4 months ago
Session.php
3 days ago
Settings.php
5 years ago
SimpleMath.php
5 years ago
TempStorage.php
3 days ago
Template.php
5 months ago
UI.php
6 months ago
Updater.php
4 years ago
UserAgent.php
2 years ago
__.php
2 months ago
__MailUI.php
3 years ago
Installer.php
214 lines
| 1 | <?php |
| 2 | |
| 3 | namespace WPDM\__; |
| 4 | |
| 5 | // Exit if accessed directly |
| 6 | if (!defined('ABSPATH')) { |
| 7 | exit; |
| 8 | } |
| 9 | |
| 10 | class Installer |
| 11 | { |
| 12 | /** |
| 13 | * @var float |
| 14 | */ |
| 15 | private $dbVersion = 535.4; |
| 16 | |
| 17 | function __construct() |
| 18 | { |
| 19 | |
| 20 | } |
| 21 | |
| 22 | /** |
| 23 | * @return float |
| 24 | */ |
| 25 | public static function dbVersion(){ |
| 26 | $inst = new Installer(); |
| 27 | return $inst->dbVersion; |
| 28 | } |
| 29 | |
| 30 | public static function dbUpdateRequired(){ |
| 31 | return (Installer::dbVersion() !== (double)get_option('__wpdm_db_version')); |
| 32 | } |
| 33 | |
| 34 | public static function init(){ |
| 35 | self::updateDB(); |
| 36 | } |
| 37 | |
| 38 | public static function updateDB() |
| 39 | { |
| 40 | |
| 41 | global $wpdb; |
| 42 | |
| 43 | delete_option('wpdm_latest'); |
| 44 | |
| 45 | require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); |
| 46 | |
| 47 | $sqls[] = "CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}ahm_download_stats` ( |
| 48 | `id` bigint(20) NOT NULL AUTO_INCREMENT, |
| 49 | `pid` bigint(20) NOT NULL, |
| 50 | `uid` int(11) NOT NULL, |
| 51 | `oid` varchar(100) NOT NULL, |
| 52 | `year` int(4) NOT NULL, |
| 53 | `month` int(2) NOT NULL, |
| 54 | `day` int(2) NOT NULL, |
| 55 | `timestamp` int(11) NOT NULL, |
| 56 | `ip` varchar(255) NOT NULL, |
| 57 | `filename` text, |
| 58 | `agent` text, |
| 59 | PRIMARY KEY (`id`) |
| 60 | )"; |
| 61 | |
| 62 | $sqls[] = "CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}ahm_emails` ( |
| 63 | `id` bigint(20) NOT NULL AUTO_INCREMENT, |
| 64 | `email` varchar(255) NOT NULL, |
| 65 | `pid` bigint(20) NOT NULL, |
| 66 | `date` int(11) NOT NULL, |
| 67 | `custom_data` text NOT NULL, |
| 68 | `request_status` INT( 1 ) NOT NULL, |
| 69 | PRIMARY KEY (`id`) |
| 70 | )"; |
| 71 | |
| 72 | $sqls[] = "CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}ahm_social_conns` ( |
| 73 | `ID` bigint(20) NOT NULL AUTO_INCREMENT, |
| 74 | `pid` bigint(20) NOT NULL, |
| 75 | `email` varchar(200) NOT NULL, |
| 76 | `name` varchar(200) NOT NULL, |
| 77 | `user_data` text NOT NULL, |
| 78 | `access_token` text NOT NULL, |
| 79 | `refresh_token` text NOT NULL, |
| 80 | `source` varchar(200) NOT NULL, |
| 81 | `timestamp` int(11) NOT NULL, |
| 82 | `processed` tinyint(1) NOT NULL DEFAULT '0', |
| 83 | PRIMARY KEY (`ID`) |
| 84 | )"; |
| 85 | |
| 86 | $sqls[] = "CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}ahm_assets` ( |
| 87 | `ID` bigint(20) NOT NULL AUTO_INCREMENT, |
| 88 | `path` text NOT NULL, |
| 89 | `owner` int(11) NOT NULL, |
| 90 | `activities` text NOT NULL, |
| 91 | `comments` text NOT NULL, |
| 92 | `access` text NOT NULL, |
| 93 | `metadata` text NOT NULL, |
| 94 | PRIMARY KEY (`ID`) |
| 95 | )"; |
| 96 | |
| 97 | $sqls[] = "CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}ahm_asset_links` ( |
| 98 | `ID` bigint(20) NOT NULL AUTO_INCREMENT, |
| 99 | `asset_ID` bigint(20) NOT NULL, |
| 100 | `asset_key` varchar(255) NOT NULL, |
| 101 | `access` text NOT NULL, |
| 102 | `time` int(11) NOT NULL, |
| 103 | PRIMARY KEY (`ID`) |
| 104 | )"; |
| 105 | |
| 106 | $sqls[] = "CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}ahm_sessions` ( |
| 107 | `ID` bigint(20) NOT NULL AUTO_INCREMENT, |
| 108 | `deviceID` varchar(255) NOT NULL, |
| 109 | `name` varchar(255) NOT NULL, |
| 110 | `value` text NOT NULL, |
| 111 | `lastAccess` int(11) NOT NULL, |
| 112 | `expire` int(11) NOT NULL, |
| 113 | PRIMARY KEY (`ID`), |
| 114 | KEY `name_device` (`name`(150),`deviceID`(40)), |
| 115 | KEY `expire` (`expire`) |
| 116 | )"; |
| 117 | |
| 118 | $sqls[] = "CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}ahm_user_download_counts` ( |
| 119 | `ID` int(11) NOT NULL AUTO_INCREMENT, |
| 120 | `user` varchar(255) NOT NULL, |
| 121 | `package_id` int(11) NOT NULL, |
| 122 | `download_count` int(11) NOT NULL, |
| 123 | PRIMARY KEY (`ID`) |
| 124 | )"; |
| 125 | |
| 126 | $sqls[] = "CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}ahm_cron_jobs` ( |
| 127 | `ID` int(11) NOT NULL AUTO_INCREMENT, |
| 128 | `code` varchar(255) NOT NULL, |
| 129 | `type` varchar(250) NOT NULL, |
| 130 | `data` json DEFAULT NULL, |
| 131 | `execute_at` int(11) NOT NULL, |
| 132 | `repeat_execution` int(11) NOT NULL DEFAULT '0', |
| 133 | `execution_count` int(11) NOT NULL DEFAULT '0', |
| 134 | `interval` int(11) NOT NULL DEFAULT '0', |
| 135 | `created_at` int(11) NOT NULL DEFAULT '0', |
| 136 | `created_by` int(11) NOT NULL DEFAULT '0', |
| 137 | PRIMARY KEY (`ID`), |
| 138 | UNIQUE KEY `code` (`code`) |
| 139 | ) ENGINE=InnoDB"; |
| 140 | |
| 141 | //$sqls[] = "ALTER TABLE `{$wpdb->prefix}ahm_cron_jobs` ADD UNIQUE KEY `code` (`code`);"; |
| 142 | |
| 143 | foreach ($sqls as $qry) { |
| 144 | $wpdb->query($qry); |
| 145 | } |
| 146 | |
| 147 | $installer = new Installer(); |
| 148 | |
| 149 | $installer->addColumn('ahm_download_stats', 'version', 'varchar(255) NOT NULL'); |
| 150 | $installer->addColumn('ahm_download_stats', 'agent', 'TEXT'); |
| 151 | $installer->addColumn('ahm_download_stats', 'filename', 'TEXT'); |
| 152 | $installer->changeColumn('ahm_download_stats', 'ip', 'ip', 'varchar(255) NOT NULL'); |
| 153 | $installer->addColumn('ahm_emails', 'request_status', "INT(1) NOT NULL"); |
| 154 | $installer->uniqueKey('ahm_asset_links', "asset_key"); |
| 155 | |
| 156 | // Index ahm_sessions for the hot lookup + cleanup paths (existing installs). |
| 157 | $installer->addColumn('ahm_sessions', 'lastAccess', 'int(11) NOT NULL DEFAULT 0'); |
| 158 | $installer->addIndex('ahm_sessions', 'name_device', '`name`(150),`deviceID`(40)'); |
| 159 | $installer->addIndex('ahm_sessions', 'expire', '`expire`'); |
| 160 | |
| 161 | $ach = get_option("__wpdm_activation_history", array()); |
| 162 | $ach = maybe_unserialize($ach); |
| 163 | $ach[] = time(); |
| 164 | update_option("__wpdm_activation_history", $ach, false); |
| 165 | update_option('__wpdm_db_version', $installer->dbVersion, false); |
| 166 | $__wpdm_ui_colors = get_option('__wpdm_ui_colors', false); |
| 167 | if(!$__wpdm_ui_colors) |
| 168 | update_option('__wpdm_ui_colors', 'a:18:{s:7:"primary";s:7:"#4a8eff";s:13:"primary_hover";s:7:"#5998ff";s:14:"primary_active";s:7:"#3281ff";s:9:"secondary";s:7:"#6c757d";s:15:"secondary_hover";s:7:"#6c757d";s:16:"secondary_active";s:7:"#6c757d";s:4:"info";s:7:"#2CA8FF";s:10:"info_hover";s:7:"#2CA8FF";s:11:"info_active";s:7:"#2CA8FF";s:7:"success";s:7:"#018e11";s:13:"success_hover";s:7:"#0aad01";s:14:"success_active";s:7:"#0c8c01";s:7:"warning";s:7:"#FFB236";s:13:"warning_hover";s:7:"#FFB236";s:14:"warning_active";s:7:"#FFB236";s:6:"danger";s:7:"#ff5062";s:12:"danger_hover";s:7:"#ff5062";s:13:"danger_active";s:7:"#ff5062";}', false); |
| 169 | |
| 170 | } |
| 171 | |
| 172 | |
| 173 | function addColumn($table, $column, $type_n_default = 'TEXT NOT NULL') |
| 174 | { |
| 175 | global $wpdb; |
| 176 | $result = $wpdb->get_results("SHOW COLUMNS FROM `{$wpdb->prefix}{$table}` LIKE '$column'"); |
| 177 | $exists = count($result) > 0; |
| 178 | if (!$exists) |
| 179 | $wpdb->query("ALTER TABLE `{$wpdb->prefix}{$table}` ADD `{$column}` {$type_n_default}"); |
| 180 | } |
| 181 | |
| 182 | function changeColumn($table, $column, $newName, $type_n_default = 'TEXT NOT NULL') |
| 183 | { |
| 184 | global $wpdb; |
| 185 | $result = $wpdb->get_results("SHOW COLUMNS FROM `{$wpdb->prefix}{$table}` LIKE '$newName'"); |
| 186 | $exists = count($result) > 0; |
| 187 | if ($exists) |
| 188 | $wpdb->query("ALTER TABLE `{$wpdb->prefix}{$table}` CHANGE `{$column}` `{$newName}` {$type_n_default}"); |
| 189 | } |
| 190 | |
| 191 | function primaryKey($table, $column) |
| 192 | { |
| 193 | global $wpdb; |
| 194 | $wpdb->query("ALTER TABLE `{$wpdb->prefix}{$table}` ADD PRIMARY KEY(`{$column}`)"); |
| 195 | } |
| 196 | |
| 197 | function uniqueKey($table, $column) |
| 198 | { |
| 199 | global $wpdb; |
| 200 | $wpdb->query("ALTER TABLE `{$wpdb->prefix}{$table}` ADD UNIQUE(`{$column}`)"); |
| 201 | } |
| 202 | |
| 203 | function addIndex($table, $indexName, $columns) |
| 204 | { |
| 205 | global $wpdb; |
| 206 | $exists = $wpdb->get_results("SHOW INDEX FROM `{$wpdb->prefix}{$table}` WHERE Key_name = '{$indexName}'"); |
| 207 | if (count($exists) === 0) |
| 208 | $wpdb->query("ALTER TABLE `{$wpdb->prefix}{$table}` ADD KEY `{$indexName}` ({$columns})"); |
| 209 | } |
| 210 | } |
| 211 | |
| 212 | |
| 213 | |
| 214 |