| 1 |
<?php |
| 2 |
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
| 3 |
|
| 4 |
if ( ! class_exists( 'WPPM_Install' ) ) : |
| 5 |
|
| 6 |
final class WPPM_Install { |
| 7 |
public function __construct() { |
| 8 |
$this->check_version(); |
| 9 |
} |
| 10 |
/** |
| 11 |
* Check version of Taskbuilder |
| 12 |
*/ |
| 13 |
public function check_version(){ |
| 14 |
$installed_version = get_option( 'wppm_version' ); |
| 15 |
if( $installed_version != WPPM_VERSION ){ |
| 16 |
$this->create_db_tables(); |
| 17 |
add_action( 'init', array($this,'upgrade'), 101 ); |
| 18 |
} |
| 19 |
} |
| 20 |
/**** Create mysql tables****/ |
| 21 |
public function create_db_tables() { |
| 22 |
global $wpdb; |
| 23 |
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); |
| 24 |
$sql = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}wppm_project ( |
| 25 |
id integer NOT NULL AUTO_INCREMENT, |
| 26 |
created_by integer, |
| 27 |
project_name VARCHAR( 200 ) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, |
| 28 |
description LONGTEXT CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, |
| 29 |
start_date datetime, |
| 30 |
end_date datetime, |
| 31 |
status integer, |
| 32 |
cat_id integer, |
| 33 |
users VARCHAR( 200 ) NULL DEFAULT '0', |
| 34 |
date_created datetime, |
| 35 |
PRIMARY KEY (id) |
| 36 |
);"; |
| 37 |
dbDelta( $sql ); |
| 38 |
|
| 39 |
$sql = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}wppm_project_meta ( |
| 40 |
id integer NOT NULL AUTO_INCREMENT, |
| 41 |
project_id integer, |
| 42 |
meta_key LONGTEXT NULL DEFAULT NULL, |
| 43 |
meta_value LONGTEXT NULL DEFAULT NULL, |
| 44 |
PRIMARY KEY (id) |
| 45 |
);"; |
| 46 |
dbDelta( $sql ); |
| 47 |
|
| 48 |
$sql = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}wppm_project_categories ( |
| 49 |
id integer NOT NULL AUTO_INCREMENT, |
| 50 |
name TINYTEXT CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, |
| 51 |
load_order int(11) NOT NULL DEFAULT '1', |
| 52 |
PRIMARY KEY (id) |
| 53 |
);"; |
| 54 |
dbDelta( $sql ); |
| 55 |
|
| 56 |
$sql = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}wppm_project_statuses ( |
| 57 |
id bigint(20) NOT NULL AUTO_INCREMENT, |
| 58 |
name varchar(200) COLLATE utf8mb4_unicode_520_ci NOT NULL, |
| 59 |
color varchar(50) COLLATE utf8mb4_unicode_520_ci NOT NULL, |
| 60 |
bg_color varchar(50) COLLATE utf8mb4_unicode_520_ci NOT NULL, |
| 61 |
load_order int(11) NOT NULL DEFAULT '1', |
| 62 |
PRIMARY KEY (id) |
| 63 |
);"; |
| 64 |
dbDelta( $sql ); |
| 65 |
|
| 66 |
$sql = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}wppm_task_statuses ( |
| 67 |
id bigint(20) NOT NULL AUTO_INCREMENT, |
| 68 |
name varchar(200) COLLATE utf8mb4_unicode_520_ci NOT NULL, |
| 69 |
color varchar(50) COLLATE utf8mb4_unicode_520_ci NOT NULL, |
| 70 |
bg_color varchar(50) COLLATE utf8mb4_unicode_520_ci NOT NULL, |
| 71 |
load_order int(11) NOT NULL DEFAULT '1', |
| 72 |
PRIMARY KEY (id) |
| 73 |
);"; |
| 74 |
dbDelta( $sql ); |
| 75 |
|
| 76 |
$sql = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}wppm_task_priorities ( |
| 77 |
id bigint(20) NOT NULL AUTO_INCREMENT, |
| 78 |
name varchar(200) COLLATE utf8mb4_unicode_520_ci NOT NULL, |
| 79 |
color varchar(50) COLLATE utf8mb4_unicode_520_ci NOT NULL, |
| 80 |
bg_color varchar(50) COLLATE utf8mb4_unicode_520_ci NOT NULL, |
| 81 |
load_order int(11) NOT NULL DEFAULT '1', |
| 82 |
PRIMARY KEY (id) |
| 83 |
);"; |
| 84 |
dbDelta( $sql ); |
| 85 |
|
| 86 |
$sql = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}wppm_task ( |
| 87 |
id integer NOT NULL AUTO_INCREMENT, |
| 88 |
created_by integer, |
| 89 |
task_name VARCHAR( 200 ) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, |
| 90 |
description LONGTEXT CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, |
| 91 |
project integer, |
| 92 |
start_date datetime, |
| 93 |
end_date datetime, |
| 94 |
status integer, |
| 95 |
priority integer, |
| 96 |
users VARCHAR( 200 ) NULL DEFAULT '0', |
| 97 |
date_created datetime, |
| 98 |
task_auth_code LONGTEXT NULL DEFAULT NULL, |
| 99 |
active int(11) DEFAULT 1, |
| 100 |
PRIMARY KEY (id) |
| 101 |
);"; |
| 102 |
dbDelta( $sql ); |
| 103 |
|
| 104 |
$sql = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}wppm_task_meta ( |
| 105 |
id integer NOT NULL AUTO_INCREMENT, |
| 106 |
task_id integer, |
| 107 |
meta_key LONGTEXT NULL DEFAULT NULL, |
| 108 |
meta_value LONGTEXT NULL DEFAULT NULL, |
| 109 |
PRIMARY KEY (id) |
| 110 |
);"; |
| 111 |
dbDelta( $sql ); |
| 112 |
|
| 113 |
$sql = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}wppm_checklist ( |
| 114 |
id integer NOT NULL AUTO_INCREMENT, |
| 115 |
task_id integer, |
| 116 |
checklist_name VARCHAR( 200 ) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, |
| 117 |
created_by integer, |
| 118 |
PRIMARY KEY (id) |
| 119 |
);"; |
| 120 |
dbDelta( $sql ); |
| 121 |
|
| 122 |
$sql = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}wppm_checklist_items ( |
| 123 |
id integer NOT NULL AUTO_INCREMENT, |
| 124 |
checklist_id integer, |
| 125 |
item_name VARCHAR( 200 ) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, |
| 126 |
checked integer, |
| 127 |
members VARCHAR( 200 ) NULL DEFAULT '0', |
| 128 |
due_date datetime, |
| 129 |
PRIMARY KEY (id) |
| 130 |
);"; |
| 131 |
dbDelta( $sql ); |
| 132 |
|
| 133 |
$sql = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}wppm_task_comment ( |
| 134 |
id integer NOT NULL AUTO_INCREMENT, |
| 135 |
task_id integer, |
| 136 |
body LONGTEXT CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, |
| 137 |
attachment_ids TINYTEXT CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, |
| 138 |
create_time datetime, |
| 139 |
created_by integer, |
| 140 |
PRIMARY KEY (id) |
| 141 |
);"; |
| 142 |
dbDelta( $sql ); |
| 143 |
$sql = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}wppm_attachments ( |
| 144 |
id BIGINT NOT NULL AUTO_INCREMENT, |
| 145 |
name VARCHAR(200) NOT NULL, |
| 146 |
file_name VARCHAR(200) NOT NULL, |
| 147 |
file_path VARCHAR(500) NOT NULL, |
| 148 |
is_image INT(1) NOT NULL DEFAULT 0, |
| 149 |
is_active INT(1) NOT NULL DEFAULT 0, |
| 150 |
is_uploaded INT(1) NOT NULL DEFAULT 0, |
| 151 |
date_created DATETIME NOT NULL, |
| 152 |
PRIMARY KEY (id) |
| 153 |
);"; |
| 154 |
dbDelta( $sql ); |
| 155 |
$sql = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}wppm_project_users ( |
| 156 |
id BIGINT NOT NULL AUTO_INCREMENT, |
| 157 |
proj_id integer, |
| 158 |
user_id integer, |
| 159 |
role_id integer, |
| 160 |
assigned_by integer, |
| 161 |
PRIMARY KEY (id) |
| 162 |
);"; |
| 163 |
dbDelta( $sql ); |
| 164 |
} |
| 165 |
|
| 166 |
public function upgrade(){ |
| 167 |
global $wpdb; |
| 168 |
$installed_version = get_option( 'wppm_version' ); |
| 169 |
$installed_version = $installed_version ? $installed_version : 0; |
| 170 |
if($installed_version < '1.0.0'){ |
| 171 |
//User Roles |
| 172 |
$user_role = get_option('wppm_user_role'); |
| 173 |
if(empty($user_role)){ |
| 174 |
$user_role = array( |
| 175 |
1 => array( |
| 176 |
'label' => __('manager','taskbuilder'), |
| 177 |
), |
| 178 |
2 => array( |
| 179 |
'label' => __('co-worker','taskbuilder'), |
| 180 |
) |
| 181 |
); |
| 182 |
update_option('wppm_user_role',$user_role); |
| 183 |
} |
| 184 |
|
| 185 |
$wppm_email_notificatins = get_option('wppm_email_notification'); |
| 186 |
if(empty($wppm_email_notificatins)){ |
| 187 |
$wppm_email_notificatins = array( |
| 188 |
1=>array( |
| 189 |
'type'=>'new_project', |
| 190 |
'subject'=>__('New project has been created:{project_name}','taskbuilder'), |
| 191 |
'body'=>__('<p><strong>{user_name}</strong> assigned project to you.</p> <p>Below are details of the project :</p><p><strong> Assign to:-</strong>{project_assigned_users}</p><p><strong> Start Date:-</strong>{project_start_date} </p><p> <strong> End Date:- </strong> {project_end_date} </p> <p><strong>Description:-</strong>{project_description}</p>','taskbuilder'), |
| 192 |
'recipients'=>array(1,2) |
| 193 |
), |
| 194 |
2=>array( |
| 195 |
'type'=>'new_task', |
| 196 |
'subject'=>__('New task has been created: {task_name}','taskbuilder'), |
| 197 |
'body'=>__('<p><strong>{user_name}</strong> assigned task to you.</p><p>Below are details of the task :</p> <p><strong>Assign to:-</strong>{task_assigned_users} </p><p><strong> Start Date:-</strong>{task_start_date}</p><p><strong>End Date:-</strong>{task_end_date} </p><p> <strong>Description:-</strong>{task_description}</p>','taskbuilder'), |
| 198 |
'recipients'=>array(1,2) |
| 199 |
), |
| 200 |
3=>array( |
| 201 |
'type'=>'change_project_status', |
| 202 |
'subject'=>__('{project_name} Project\'s status has been changed from {old_project_status} to {new_project_status}','taskbuilder'), |
| 203 |
'body'=>__('<p><strong>{user_name}</strong> changed project\'s status to <strong>{new_project_status}</strong> </p> <p>Below are details of the project:</p><p><strong>Assign to:- </strong> {project_assigned_users}</p><p><strong>Start Date:-</strong>{project_start_date} </p> <p><strong>End Date:-</strong>{project_end_date} </p> <p><strong>Description:-</strong>{project_description}</p>','taskbuilder'), |
| 204 |
'recipients'=>array(1,2) |
| 205 |
), |
| 206 |
4=>array( |
| 207 |
'type'=>'change_task_status', |
| 208 |
'subject'=>__('{task_name} Task\'s status has been changed from {old_task_status} to {new_task_status}','taskbuilder'), |
| 209 |
'body'=>__('<p><strong>{user_name}</strong> changed task status to <strong>{new_task_status} </strong><p> Below are details of the task:</p> <p><strong>Assign to:-</strong>{task_assigned_users} </p> <p><strong>Start Date:-</strong>{task_start_date}</p><p><strong>End Date:-</strong>{task_end_date} </p> <p><strong>Description:-</strong>{task_description}</p>','taskbuilder'), |
| 210 |
'recipients'=>array(1,2) |
| 211 |
), |
| 212 |
5=>array( |
| 213 |
'type'=>'change_project_assign_users', |
| 214 |
'subject'=>__('{project_name} Project\'s assigned users changed from {previously_assigned_project_users} to {project_assigned_users}','taskbuilder'), |
| 215 |
'body'=>__('<p><strong>{user_name}</strong> changed project\'s assign users to <strong> {project_assigned_users}</strong></p> <p>Below are details of the project :</p><p><strong> Assign to:-</strong>{project_assigned_users}</p><p><strong> Start Date:-</strong>{project_start_date} </p><p> <strong> End Date:- </strong> {project_end_date} </p> <p><strong>Description:-</strong>{project_description}</p>','taskbuilder'), |
| 216 |
'recipients'=>array(1,2) |
| 217 |
), |
| 218 |
6=>array( |
| 219 |
'type'=>'change_task_assign_users', |
| 220 |
'subject'=>__('{task_name} Task\'s assigned users change from {previously_assigned_task_users} to {task_assigned_users}','taskbuilder'), |
| 221 |
'body'=>__('<p><strong>{user_name}</strong> changed task\'s assign users to <strong>{task_assigned_users}</strong></p><p>Below are details of the task :</p> <p><strong>Assign to:-</strong>{task_assigned_users} </p><p><strong> Start Date:-</strong>{task_start_date}</p><p><strong>End Date:-</strong>{task_end_date} </p><p> <strong>Description:-</strong>{task_description}</p>','taskbuilder'), |
| 222 |
'recipients'=>array(1,2) |
| 223 |
), |
| 224 |
7=>array( |
| 225 |
'type'=>'new_discussion', |
| 226 |
'subject'=>__('[{project_name}][{task_name}] {last_comment_user_name} started new discussion:','taskbuilder'), |
| 227 |
'body'=>__('<p><strong>{last_comment_user_name}</strong> wrote:</p> <p>{comment_body}</p>','taskbuilder'), |
| 228 |
'recipients'=>array(1,2) |
| 229 |
) |
| 230 |
); |
| 231 |
update_option('wppm_email_notification',$wppm_email_notificatins); |
| 232 |
} |
| 233 |
|
| 234 |
update_option('wppm_default_task_list_view',1); |
| 235 |
|
| 236 |
$default_statuses = $wpdb->get_var("select count(*) from {$wpdb->prefix}wppm_project_statuses"); |
| 237 |
if (empty($default_statuses)) { |
| 238 |
$wpdb->insert($wpdb->prefix . "wppm_project_statuses", array('id' => 1,'name' => __('New','taskbuilder'),'color'=>'#ffffff','bg_color'=>'#306EFF','load_order'=>1)); |
| 239 |
$wpdb->insert($wpdb->prefix . "wppm_project_statuses", array('id' => 2,'name' => __('In Progress','taskbuilder'),'color'=>'#ffffff','bg_color'=>'#FCD12A','load_order'=>2)); |
| 240 |
$wpdb->insert($wpdb->prefix . "wppm_project_statuses", array('id' => 3,'name' => __('Hold','taskbuilder'),'color'=>'#ffffff','bg_color'=>'#D3D3D3','load_order'=>3)); |
| 241 |
$wpdb->insert($wpdb->prefix . "wppm_project_statuses", array('id' => 4,'name' => __('Completed','taskbuilder'),'color'=>'#ffffff','bg_color'=>'#5cb85c','load_order'=>4)); |
| 242 |
} |
| 243 |
$wppm_default_project_status = get_option('wppm_default_project_status',true); |
| 244 |
if($wppm_default_project_status == ''){ |
| 245 |
update_option('wppm_default_project_status',1); |
| 246 |
} |
| 247 |
$default_task_statuses = $wpdb->get_var("select count(*) from {$wpdb->prefix}wppm_task_statuses"); |
| 248 |
if (empty($default_task_statuses)) { |
| 249 |
$wpdb->insert($wpdb->prefix . "wppm_task_statuses",array('id' => 1,'name' => __('Todo','taskbuilder'),'color'=>'#ffffff','bg_color'=>'#306EFF','load_order'=>1)); |
| 250 |
$wpdb->insert($wpdb->prefix . "wppm_task_statuses",array('id' => 2,'name' => __('In Progress','taskbuilder'),'color'=>'#ffffff','bg_color'=>'#FCD12A','load_order'=>2)); |
| 251 |
$wpdb->insert($wpdb->prefix . "wppm_task_statuses",array('id' => 3,'name' => __('Hold','taskbuilder'),'color'=>'#ffffff','bg_color'=>'#D3D3D3','load_order'=>3)); |
| 252 |
$wpdb->insert($wpdb->prefix . "wppm_task_statuses",array('id' => 4,'name' => __('Completed','taskbuilder'),'color'=>'#ffffff','bg_color'=>'#5cb85c','load_order'=>4)); |
| 253 |
} |
| 254 |
$wppm_default_task_status = get_option('wppm_default_task_status',true); |
| 255 |
if($wppm_default_task_status == ''){ |
| 256 |
update_option('wppm_default_task_status',1); |
| 257 |
} |
| 258 |
} |
| 259 |
// update wppm_version option to plugin version |
| 260 |
update_option( 'wppm_version', WPPM_VERSION ); |
| 261 |
} |
| 262 |
} |
| 263 |
|
| 264 |
endif; |
| 265 |
|
| 266 |
new WPPM_Install(); |