| @@ -1,610 +1,639 @@ | ||
| 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_project_comment ( | |
| 144 | - id integer NOT NULL AUTO_INCREMENT, | |
| 145 | - proj_id integer, | |
| 146 | - body LONGTEXT NULL DEFAULT NULL, | |
| 147 | - attachment_ids TINYTEXT NULL DEFAULT NULL, | |
| 148 | - create_time datetime, | |
| 149 | - created_by integer, | |
| 150 | - PRIMARY KEY (id) | |
| 151 | - );"; | |
| 152 | - dbDelta( $sql ); | |
| 153 | - $sql = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}wppm_attachments ( | |
| 154 | - id BIGINT NOT NULL AUTO_INCREMENT, | |
| 155 | - name VARCHAR(200) NOT NULL, | |
| 156 | - file_name VARCHAR(200) NOT NULL, | |
| 157 | - file_path VARCHAR(500) NOT NULL, | |
| 158 | - is_image INT(1) NOT NULL DEFAULT 0, | |
| 159 | - is_active INT(1) NOT NULL DEFAULT 0, | |
| 160 | - is_uploaded INT(1) NOT NULL DEFAULT 0, | |
| 161 | - date_created DATETIME NOT NULL, | |
| 162 | - PRIMARY KEY (id) | |
| 163 | - );"; | |
| 164 | - dbDelta( $sql ); | |
| 165 | - $sql = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}wppm_project_users ( | |
| 166 | - id BIGINT NOT NULL AUTO_INCREMENT, | |
| 167 | - proj_id integer, | |
| 168 | - user_id integer, | |
| 169 | - role_id integer, | |
| 170 | - assigned_by integer, | |
| 171 | - PRIMARY KEY (id) | |
| 172 | - );"; | |
| 173 | - dbDelta( $sql ); | |
| 174 | - $sql = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}wppm_project_comment_meta ( | |
| 175 | - id BIGINT NOT NULL AUTO_INCREMENT, | |
| 176 | - proj_id integer, | |
| 177 | - comment_id integer, | |
| 178 | - comment_type VARCHAR(200) NOT NULL, | |
| 179 | - PRIMARY KEY (id) | |
| 180 | - );"; | |
| 181 | - dbDelta( $sql ); | |
| 182 | - $sql = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}wppm_task_comment_meta ( | |
| 183 | - id BIGINT NOT NULL AUTO_INCREMENT, | |
| 184 | - task_id integer, | |
| 185 | - comment_id integer, | |
| 186 | - comment_type VARCHAR(200) NOT NULL, | |
| 187 | - PRIMARY KEY (id) | |
| 188 | - );"; | |
| 189 | - dbDelta( $sql ); | |
| 190 | - $sql = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}wppm_notifications ( | |
| 191 | - id BIGINT AUTO_INCREMENT PRIMARY KEY, | |
| 192 | - user_id INT, | |
| 193 | - message TEXT, | |
| 194 | - link TEXT, | |
| 195 | - is_read TINYINT DEFAULT 0, | |
| 196 | - notification_type VARCHAR(200) NOT NULL, | |
| 197 | - created_at DATETIME DEFAULT CURRENT_TIMESTAMP | |
| 198 | - );"; | |
| 199 | - dbDelta( $sql ); | |
| 200 | - } | |
| 201 | - | |
| 202 | - public function upgrade(){ | |
| 203 | - global $wpdb,$wppmfunction; | |
| 204 | - $installed_version = get_option( 'wppm_version' ); | |
| 205 | - $installed_version = $installed_version ? $installed_version : 0; | |
| 206 | - if($installed_version < '1.0.0'){ | |
| 207 | - //User Roles | |
| 208 | - $user_role = get_option('wppm_user_role'); | |
| 209 | - if(empty($user_role)){ | |
| 210 | - $user_role = array( | |
| 211 | - 1 => array( | |
| 212 | - 'label' => esc_html__('manager','taskbuilder'), | |
| 213 | - ), | |
| 214 | - 2 => array( | |
| 215 | - 'label' => esc_html__('co-worker','taskbuilder'), | |
| 216 | - ) | |
| 217 | - ); | |
| 218 | - update_option('wppm_user_role',$user_role); | |
| 219 | - } | |
| 220 | - | |
| 221 | - $wppm_email_notificatins = get_option('wppm_email_notification'); | |
| 222 | - if(empty($wppm_email_notificatins)){ | |
| 223 | - $wppm_email_notificatins = array( | |
| 224 | - 1=>array( | |
| 225 | - 'type'=>'new_project', | |
| 226 | - 'subject'=>esc_html__('New project has been created:{project_name}','taskbuilder'), | |
| 227 | - 'body'=>esc_html__('<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'), | |
| 228 | - 'recipients'=>array(1,2) | |
| 229 | - ), | |
| 230 | - 2=>array( | |
| 231 | - 'type'=>'new_task', | |
| 232 | - 'subject'=>esc_html__('New task has been created: {task_name}','taskbuilder'), | |
| 233 | - 'body'=>esc_html__('<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'), | |
| 234 | - 'recipients'=>array(1,2) | |
| 235 | - ), | |
| 236 | - 3=>array( | |
| 237 | - 'type'=>'change_project_status', | |
| 238 | - 'subject'=>esc_html__('{project_name} Project\'s status has been changed from {old_project_status} to {new_project_status}','taskbuilder'), | |
| 239 | - 'body'=>esc_html__('<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'), | |
| 240 | - 'recipients'=>array(1,2) | |
| 241 | - ), | |
| 242 | - 4=>array( | |
| 243 | - 'type'=>'change_task_status', | |
| 244 | - 'subject'=>esc_html__('{task_name} Task\'s status has been changed from {old_task_status} to {new_task_status}','taskbuilder'), | |
| 245 | - 'body'=>esc_html__('<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'), | |
| 246 | - 'recipients'=>array(1,2) | |
| 247 | - ), | |
| 248 | - 5=>array( | |
| 249 | - 'type'=>'change_project_assign_users', | |
| 250 | - 'subject'=>esc_html__('{project_name} Project\'s assigned users changed from {previously_assigned_project_users} to {project_assigned_users}','taskbuilder'), | |
| 251 | - 'body'=>esc_html__('<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'), | |
| 252 | - 'recipients'=>array(1,2) | |
| 253 | - ), | |
| 254 | - 6=>array( | |
| 255 | - 'type'=>'change_task_assign_users', | |
| 256 | - 'subject'=>esc_html__('{task_name} Task\'s assigned users change from {previously_assigned_task_users} to {task_assigned_users}','taskbuilder'), | |
| 257 | - 'body'=>esc_html__('<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'), | |
| 258 | - 'recipients'=>array(1,2) | |
| 259 | - ), | |
| 260 | - 7=>array( | |
| 261 | - 'type'=>'new_discussion', | |
| 262 | - 'subject'=>esc_html__('[{project_name}][{task_name}] {last_comment_user_name} started new discussion:','taskbuilder'), | |
| 263 | - 'body'=>esc_html__('<p><strong>{last_comment_user_name}</strong> wrote:</p> <p>{comment_body}</p>','taskbuilder'), | |
| 264 | - 'recipients'=>array(1,2) | |
| 265 | - ) | |
| 266 | - ); | |
| 267 | - update_option('wppm_email_notification',$wppm_email_notificatins); | |
| 268 | - } | |
| 269 | - | |
| 270 | - update_option('wppm_default_task_list_view',1); | |
| 271 | - | |
| 272 | - $default_statuses = $wpdb->get_var("select count(*) from {$wpdb->prefix}wppm_project_statuses"); | |
| 273 | - if (empty($default_statuses)) { | |
| 274 | - $wpdb->insert($wpdb->prefix . "wppm_project_statuses", array('id' => 1,'name' => esc_html__('New','taskbuilder'),'color'=>'#ffffff','bg_color'=>'#306EFF','load_order'=>1)); | |
| 275 | - $wpdb->insert($wpdb->prefix . "wppm_project_statuses", array('id' => 2,'name' => esc_html__('In Progress','taskbuilder'),'color'=>'#ffffff','bg_color'=>'#FCD12A','load_order'=>2)); | |
| 276 | - $wpdb->insert($wpdb->prefix . "wppm_project_statuses", array('id' => 3,'name' => esc_html__('Hold','taskbuilder'),'color'=>'#ffffff','bg_color'=>'#D3D3D3','load_order'=>3)); | |
| 277 | - $wpdb->insert($wpdb->prefix . "wppm_project_statuses", array('id' => 4,'name' => esc_html__('Completed','taskbuilder'),'color'=>'#ffffff','bg_color'=>'#5cb85c','load_order'=>4)); | |
| 278 | - } | |
| 279 | - $wppm_default_project_status = get_option('wppm_default_project_status',true); | |
| 280 | - if($wppm_default_project_status == ''){ | |
| 281 | - update_option('wppm_default_project_status',1); | |
| 282 | - } | |
| 283 | - $default_task_statuses = $wpdb->get_var("select count(*) from {$wpdb->prefix}wppm_task_statuses"); | |
| 284 | - if (empty($default_task_statuses)) { | |
| 285 | - $wpdb->insert($wpdb->prefix . "wppm_task_statuses",array('id' => 1,'name' => esc_html__('Todo','taskbuilder'),'color'=>'#ffffff','bg_color'=>'#306EFF','load_order'=>1)); | |
| 286 | - $wpdb->insert($wpdb->prefix . "wppm_task_statuses",array('id' => 2,'name' => esc_html__('In Progress','taskbuilder'),'color'=>'#ffffff','bg_color'=>'#FCD12A','load_order'=>2)); | |
| 287 | - $wpdb->insert($wpdb->prefix . "wppm_task_statuses",array('id' => 3,'name' => esc_html__('Hold','taskbuilder'),'color'=>'#ffffff','bg_color'=>'#D3D3D3','load_order'=>3)); | |
| 288 | - $wpdb->insert($wpdb->prefix . "wppm_task_statuses",array('id' => 4,'name' => esc_html__('Completed','taskbuilder'),'color'=>'#ffffff','bg_color'=>'#5cb85c','load_order'=>4)); | |
| 289 | - } | |
| 290 | - $wppm_default_task_status = get_option('wppm_default_task_status',true); | |
| 291 | - if($wppm_default_task_status == ''){ | |
| 292 | - update_option('wppm_default_task_status',1); | |
| 293 | - } | |
| 294 | - } | |
| 295 | - if($installed_version < '1.0.2'){ | |
| 296 | - update_option('wppm_project_time', 1); | |
| 297 | - } | |
| 298 | - if($installed_version < '2.0.0'){ | |
| 299 | - update_option('wppm_default_project_date', 1); | |
| 300 | - update_option('wppm_default_task_date', 1); | |
| 301 | - } | |
| 302 | - if($installed_version < '2.0.2'){ | |
| 303 | - update_option('wppm_default_edit_tasks_permission', 0); | |
| 304 | - } | |
| 305 | - if($installed_version < '2.0.4'){ | |
| 306 | - update_option('wppm_public_projects_permission',0); | |
| 307 | - } | |
| 308 | - if($installed_version < '2.0.8'){ | |
| 309 | - update_option('wppm_task_time',1); | |
| 310 | - } | |
| 311 | - if($installed_version < '3.0.0'){ | |
| 312 | - $wppm_email_notificatins = get_option('wppm_email_notification'); | |
| 313 | - if(!empty($wppm_email_notificatins) && !isset($wppm_email_notificatins[8])){ | |
| 314 | - $wppm_email_notificatins[8] = array( | |
| 315 | - 'type'=>'new_proj_discussion', | |
| 316 | - 'subject'=>esc_html__('[{project_name}] {last_proj_comment_user_name} started new discussion:','taskbuilder'), | |
| 317 | - 'body'=>esc_html__('<p><strong>{last_proj_comment_user_name}</strong> wrote:</p> <p>{proj_comment_body}</p>','taskbuilder'), | |
| 318 | - 'recipients'=>array(1,2) | |
| 319 | - ); | |
| 320 | - update_option('wppm_email_notification',$wppm_email_notificatins); | |
| 321 | - } | |
| 322 | - update_option( | |
| 323 | - 'wppm-ap-project-list', | |
| 324 | - array( | |
| 325 | - 'list-header-background-color' => '#304FFE', | |
| 326 | - 'list-header-text-color' => '#fff', | |
| 327 | - 'list-item-odd-background-color' => '#fff', | |
| 328 | - 'list-item-odd-text-color' => '#2C3E50', | |
| 329 | - 'list-item-even-background-color' => '#F2F2F2', | |
| 330 | - 'list-item-even-text-color' => '#2C3E50', | |
| 331 | - 'list-item-hover-background-color' => '#F5F5F5', | |
| 332 | - 'list-item-hover-text-color' => '#2C3E50' | |
| 333 | - ) | |
| 334 | - ); | |
| 335 | - update_option( | |
| 336 | - 'wppm-ap-task-list', | |
| 337 | - array( | |
| 338 | - 'list-header-button-background-color'=>'#0052CC', | |
| 339 | - 'list-header-button-hover-color' =>'#0065ff', | |
| 340 | - 'list-header-button-text-color' =>'#fff', | |
| 341 | - 'list-header-background-color' => '#304FFE', | |
| 342 | - 'list-header-text-color' => '#fff', | |
| 343 | - 'list-item-odd-background-color' => '#fff', | |
| 344 | - 'list-item-odd-text-color' => '#2C3E50', | |
| 345 | - 'list-item-even-background-color' => '#F2F2F2', | |
| 346 | - 'list-item-even-text-color' => '#2C3E50', | |
| 347 | - 'list-item-hover-background-color' => '#F5F5F5', | |
| 348 | - 'list-item-hover-text-color' => '#2C3E50', | |
| 349 | - ) | |
| 350 | - ); | |
| 351 | - update_option( | |
| 352 | - 'wppm-ap-individual-project', | |
| 353 | - array( | |
| 354 | - 'menu-button-bg-color' =>'#0052CC', | |
| 355 | - 'menu-button-hover-color' =>'#0065ff', | |
| 356 | - 'menu-button-text-color' =>'#fff', | |
| 357 | - 'comment-primary-color' => '#000000', | |
| 358 | - 'comment-secondary-color' => '#4e4e4e', | |
| 359 | - 'comment-date-color' => '#a8aeb5', | |
| 360 | - 'comment-date-hover-color' => '#000000', | |
| 361 | - 'comment-send-btn-bg-color' => '#5067c5', | |
| 362 | - 'comment-send-btn-color' => '#ffffff', | |
| 363 | - 'widget-header-bg-color' => '#ffffff', | |
| 364 | - 'widget-header-text-color' => '#2C3E50', | |
| 365 | - 'widget-body-bg-color' => '#ffffff', | |
| 366 | - 'widget-body-label-color' => '#9c9c9c', | |
| 367 | - 'widget-body-text-color' => '#2C3E50', | |
| 368 | - ) | |
| 369 | - ); | |
| 370 | - update_option( | |
| 371 | - 'wppm-ap-individual-task', | |
| 372 | - array( | |
| 373 | - 'comment-primary-color' => '#000000', | |
| 374 | - 'comment-secondary-color' => '#4e4e4e', | |
| 375 | - 'comment-date-color' => '#a8aeb5', | |
| 376 | - 'comment-date-hover-color' => '#000000', | |
| 377 | - 'comment-send-btn-bg-color' => '#5067c5', | |
| 378 | - 'comment-send-btn-color' => '#ffffff', | |
| 379 | - 'widget-header-bg-color' => '#ffffff', | |
| 380 | - 'widget-header-text-color' => '#2C3E50', | |
| 381 | - 'widget-body-bg-color' => '#ffffff', | |
| 382 | - 'widget-body-label-color' => '#9c9c9c', | |
| 383 | - 'widget-body-text-color' => '#2C3E50', | |
| 384 | - ) | |
| 385 | - ); | |
| 386 | - update_option( | |
| 387 | - 'wppm-ap-modal', | |
| 388 | - array( | |
| 389 | - 'header-bg-color' => '#ffffff', | |
| 390 | - 'header-text-color' => '#3c434a', | |
| 391 | - 'body-bg-color' => '#fff', | |
| 392 | - 'body-label-color' => '#3c434a', | |
| 393 | - 'body-text-color' => '#555', | |
| 394 | - 'footer-bg-color' => '#F6F6F6', | |
| 395 | - 'action-btn-bg-color' =>'#306EFF', | |
| 396 | - 'action-btn-text-color'=>'#fff', | |
| 397 | - 'z-index' => 900000000, | |
| 398 | - ) | |
| 399 | - ); | |
| 400 | - update_option( | |
| 401 | - 'wppm-ap-grid-view', | |
| 402 | - array( | |
| 403 | - 'menu-button-bg-color' =>'#0052CC', | |
| 404 | - 'menu-button-hover-color' =>'#0065ff', | |
| 405 | - 'menu-button-text-color' =>'#fff', | |
| 406 | - 'grid-background-color' => '#fff', | |
| 407 | - 'grid-header-text-color' => '#2C3E50' | |
| 408 | - ) | |
| 409 | - ); | |
| 410 | - update_option( | |
| 411 | - 'wppm-ap-settings', | |
| 412 | - array( | |
| 413 | - 'tab-background-color' => '#0052CC', | |
| 414 | - 'tab-text-color' => '#fff', | |
| 415 | - 'add-new-button-bg-color' =>'#0052CC', | |
| 416 | - 'add-new-button-text-color' =>'#fff', | |
| 417 | - 'add-new-button-hover-color'=>'#0065ff', | |
| 418 | - 'save-changes-button-bg-color'=>'#306EFF', | |
| 419 | - 'save-changes-button-text-color'=>'#fff' | |
| 420 | - ) | |
| 421 | - ); | |
| 422 | - } | |
| 423 | - if($installed_version < '3.0.1'){ | |
| 424 | - update_option('wppm_default_project_status', 1); | |
| 425 | - update_option('wppm_default_task_status', 1); | |
| 426 | - } | |
| 427 | - if($installed_version < '3.0.5'){ | |
| 428 | - update_option('wppm_tinymce_visibility_open_task',0); | |
| 429 | - update_option('wppm_tinymce_visibility_open_project',0); | |
| 430 | - update_option('wppm_default_email_notification_to_current_user', 1); | |
| 431 | - } | |
| 432 | - if($installed_version < '3.0.6'){ | |
| 433 | - update_option('wppm_allow_coworkers_create_task',1); | |
| 434 | - update_option('wppm_allow_coworkers_add_checklist',1); | |
| 435 | - update_option('wppm_allow_coworkers_assign_users', 0); | |
| 436 | - update_option('wppm_allow_coworkers_change_status', 1); | |
| 437 | - } | |
| 438 | - if($installed_version < '3.0.9'){ | |
| 439 | - update_option('wppm_rich_text_editor',1); | |
| 440 | - update_option( | |
| 441 | - 'wppm_toolbar_actions', | |
| 442 | - array( | |
| 443 | - 'bold' => '1', | |
| 444 | - 'italic' => '1', | |
| 445 | - 'underline' =>'1', | |
| 446 | - 'blockquote' =>'1', | |
| 447 | - 'align'=>'1', | |
| 448 | - 'bullist'=>'1', | |
| 449 | - 'numlist'=>'1', | |
| 450 | - 'rtl'=>'1', | |
| 451 | - 'link'=>'1', | |
| 452 | - 'wppm_insert_editor_img'=>'1', | |
| 453 | - 'forecolor'=>'0', | |
| 454 | - 'backcolor' => '0', | |
| 455 | - 'strikethrough' => '0' | |
| 456 | - ) | |
| 457 | - ); | |
| 458 | - } | |
| 459 | - | |
| 460 | - if($installed_version < '4.0.0'){ | |
| 461 | - update_option( | |
| 462 | - 'wppm-page-settings', | |
| 463 | - array( | |
| 464 | - 'task-url-page' => 0, | |
| 465 | - 'project-url-page' => 0 | |
| 466 | - ) | |
| 467 | - ); | |
| 468 | - } | |
| 469 | - | |
| 470 | - if($installed_version < '4.0.4'){ | |
| 471 | - update_option('wppm_date_setting','Y-m-d h:i:sa'); | |
| 472 | - } | |
| 473 | - | |
| 474 | - if($installed_version < '4.0.5'){ | |
| 475 | - update_option('wppm_hide_completed_status_proj','1'); | |
| 476 | - update_option('wppm_hide_completed_status_task','1'); | |
| 477 | - update_option('wppm_hide_proj_statuses_from_frontend','0'); | |
| 478 | - update_option('wppm_hide_task_statuses_from_frontend','0'); | |
| 479 | - update_option('wppm_proj_hide_comment_section','1'); | |
| 480 | - update_option('wppm_task_hide_comment_section','1'); | |
| 481 | - } | |
| 482 | - | |
| 483 | - if($installed_version < '5.0.0'){ | |
| 484 | - $wppm_print_settings = array( | |
| 485 | - 'wppm_print_body_font_size' => 10); | |
| 486 | - update_option('wppm_print_settings',$wppm_print_settings); | |
| 487 | - } | |
| 488 | - if($installed_version < '5.0.2'){ | |
| 489 | - $table_name = $wpdb->prefix . 'wppm_checklist_items'; | |
| 490 | - $column_name = 'load_order'; | |
| 491 | - $column_type = 'INT(11) NOT NULL DEFAULT 1'; | |
| 492 | - | |
| 493 | - $column_exists = $wpdb->get_var( | |
| 494 | - $wpdb->prepare( | |
| 495 | - "SHOW COLUMNS FROM `$table_name` LIKE %s", | |
| 496 | - $column_name | |
| 497 | - ) | |
| 498 | - ); | |
| 499 | - | |
| 500 | - if ( null === $column_exists ) { | |
| 501 | - | |
| 502 | - // Column name and type are hardcoded, not user input. | |
| 503 | - // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared | |
| 504 | - $wpdb->query( | |
| 505 | - "ALTER TABLE `$table_name` | |
| 506 | - ADD `$column_name` $column_type" | |
| 507 | - ); | |
| 508 | - } | |
| 509 | - $table_name = $wpdb->prefix . 'wppm_task'; | |
| 510 | - $cl_name = 'is_archived'; | |
| 511 | - $cl_type = 'TINYINT(1) DEFAULT 0'; | |
| 512 | - | |
| 513 | - $cl_exists = $wpdb->get_var( | |
| 514 | - $wpdb->prepare( | |
| 515 | - "SHOW COLUMNS FROM `$table_name` LIKE %s", | |
| 516 | - $cl_name | |
| 517 | - ) | |
| 518 | - ); | |
| 519 | - | |
| 520 | - if ( null === $cl_exists ) { | |
| 521 | - | |
| 522 | - $sql = sprintf( | |
| 523 | - 'ALTER TABLE `%s` ADD `%s` %s', | |
| 524 | - $table_name, | |
| 525 | - $cl_name, | |
| 526 | - $cl_type | |
| 527 | - ); | |
| 528 | - | |
| 529 | - // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared -- Safe: identifiers are hardcoded. | |
| 530 | - $wpdb->query( $sql ); | |
| 531 | - } | |
| 532 | - } | |
| 533 | - if($installed_version < '5.0.3'){ | |
| 534 | - update_option('wppm_display_time_duration_project',0); | |
| 535 | - update_option('wppm_display_time_duration_task',0); | |
| 536 | - | |
| 537 | - } | |
| 538 | - if($installed_version < '5.0.6'){ | |
| 539 | - update_option('wppm_show_update_notice', 1); | |
| 540 | - $user_role = get_option('wppm_user_role'); | |
| 541 | - if (!isset($user_role[3])) { | |
| 542 | - $user_role[3] = array( | |
| 543 | - 'label' => esc_html__('Client', 'taskbuilder'), | |
| 544 | - ); | |
| 545 | - } | |
| 546 | - update_option('wppm_user_role', $user_role); | |
| 547 | - } | |
| 548 | - if($installed_version < '6.0.0'){ | |
| 549 | - $table_name = $wpdb->prefix . 'wppm_project'; | |
| 550 | - $column_name = 'project_auth_code'; | |
| 551 | - $column_type = 'LONGTEXT NULL DEFAULT NULL'; | |
| 552 | - $column_exists = $wpdb->get_var( | |
| 553 | - $wpdb->prepare( | |
| 554 | - "SHOW COLUMNS FROM `$table_name` LIKE %s", | |
| 555 | - $column_name | |
| 556 | - ) | |
| 557 | - ); | |
| 558 | - if ( empty( $column_exists ) ) { | |
| 559 | - // Column name and type are hardcoded, not user input. | |
| 560 | - // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared | |
| 561 | - $wpdb->query( | |
| 562 | - "ALTER TABLE `$table_name` | |
| 563 | - ADD `$column_name` $column_type" | |
| 564 | - ); | |
| 565 | - } | |
| 566 | - $projects = $wpdb->get_results( | |
| 567 | - "SELECT id FROM {$wpdb->prefix}wppm_project | |
| 568 | - WHERE project_auth_code IS NULL OR project_auth_code = ''" | |
| 569 | - ); | |
| 570 | - foreach ( $projects as $project ) { | |
| 571 | - $wpdb->update( | |
| 572 | - "{$wpdb->prefix}wppm_project", | |
| 573 | - array( | |
| 574 | - 'project_auth_code' => $wppmfunction->getRandomString(10), | |
| 575 | - ), | |
| 576 | - array( | |
| 577 | - 'id' => $project->id, | |
| 578 | - ), | |
| 579 | - array('%s'), | |
| 580 | - array('%d') | |
| 581 | - ); | |
| 582 | - } | |
| 583 | - $table_name = $wpdb->prefix . 'wppm_project'; | |
| 584 | - $cl_name = 'is_archived'; | |
| 585 | - $cl_type = 'TINYINT(1) DEFAULT 0'; | |
| 586 | - $cl_exists = $wpdb->get_var( | |
| 587 | - $wpdb->prepare( | |
| 588 | - "SHOW COLUMNS FROM `$table_name` LIKE %s", | |
| 589 | - $cl_name | |
| 590 | - ) | |
| 591 | - ); | |
| 592 | - if ( empty( $cl_exists ) ) { | |
| 593 | - $sql = sprintf( | |
| 594 | - 'ALTER TABLE `%s` ADD `%s` %s', | |
| 595 | - $table_name, | |
| 596 | - $cl_name, | |
| 597 | - $cl_type | |
| 598 | - ); | |
| 599 | - // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared -- Safe: identifiers are hardcoded. | |
| 600 | - $wpdb->query( $sql ); | |
| 601 | - } | |
| 602 | - } | |
| 603 | - // update wppm_version option to plugin version | |
| 604 | - update_option( 'wppm_version', WPPM_VERSION ); | |
| 605 | - } | |
| 606 | -} | |
| 607 | - | |
| 608 | -endif; | |
| 609 | - | |
| 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 | + parent_task_id integer NOT NULL DEFAULT 0, | |
| 101 | + PRIMARY KEY (id) | |
| 102 | + );"; | |
| 103 | + dbDelta( $sql ); | |
| 104 | + | |
| 105 | + $sql = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}wppm_task_meta ( | |
| 106 | + id integer NOT NULL AUTO_INCREMENT, | |
| 107 | + task_id integer, | |
| 108 | + meta_key LONGTEXT NULL DEFAULT NULL, | |
| 109 | + meta_value LONGTEXT NULL DEFAULT NULL, | |
| 110 | + PRIMARY KEY (id) | |
| 111 | + );"; | |
| 112 | + dbDelta( $sql ); | |
| 113 | + | |
| 114 | + $sql = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}wppm_checklist ( | |
| 115 | + id integer NOT NULL AUTO_INCREMENT, | |
| 116 | + task_id integer, | |
| 117 | + checklist_name VARCHAR( 200 ) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, | |
| 118 | + created_by integer, | |
| 119 | + PRIMARY KEY (id) | |
| 120 | + );"; | |
| 121 | + dbDelta( $sql ); | |
| 122 | + | |
| 123 | + $sql = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}wppm_checklist_items ( | |
| 124 | + id integer NOT NULL AUTO_INCREMENT, | |
| 125 | + checklist_id integer, | |
| 126 | + item_name VARCHAR( 200 ) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, | |
| 127 | + checked integer, | |
| 128 | + members VARCHAR( 200 ) NULL DEFAULT '0', | |
| 129 | + due_date datetime, | |
| 130 | + PRIMARY KEY (id) | |
| 131 | + );"; | |
| 132 | + dbDelta( $sql ); | |
| 133 | + | |
| 134 | + $sql = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}wppm_task_comment ( | |
| 135 | + id integer NOT NULL AUTO_INCREMENT, | |
| 136 | + task_id integer, | |
| 137 | + body LONGTEXT CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, | |
| 138 | + attachment_ids TINYTEXT CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, | |
| 139 | + create_time datetime, | |
| 140 | + created_by integer, | |
| 141 | + PRIMARY KEY (id) | |
| 142 | + );"; | |
| 143 | + dbDelta( $sql ); | |
| 144 | + $sql = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}wppm_project_comment ( | |
| 145 | + id integer NOT NULL AUTO_INCREMENT, | |
| 146 | + proj_id integer, | |
| 147 | + body LONGTEXT NULL DEFAULT NULL, | |
| 148 | + attachment_ids TINYTEXT NULL DEFAULT NULL, | |
| 149 | + create_time datetime, | |
| 150 | + created_by integer, | |
| 151 | + PRIMARY KEY (id) | |
| 152 | + );"; | |
| 153 | + dbDelta( $sql ); | |
| 154 | + $sql = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}wppm_attachments ( | |
| 155 | + id BIGINT NOT NULL AUTO_INCREMENT, | |
| 156 | + name VARCHAR(200) NOT NULL, | |
| 157 | + file_name VARCHAR(200) NOT NULL, | |
| 158 | + file_path VARCHAR(500) NOT NULL, | |
| 159 | + is_image INT(1) NOT NULL DEFAULT 0, | |
| 160 | + is_active INT(1) NOT NULL DEFAULT 0, | |
| 161 | + is_uploaded INT(1) NOT NULL DEFAULT 0, | |
| 162 | + date_created DATETIME NOT NULL, | |
| 163 | + PRIMARY KEY (id) | |
| 164 | + );"; | |
| 165 | + dbDelta( $sql ); | |
| 166 | + $sql = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}wppm_project_users ( | |
| 167 | + id BIGINT NOT NULL AUTO_INCREMENT, | |
| 168 | + proj_id integer, | |
| 169 | + user_id integer, | |
| 170 | + role_id integer, | |
| 171 | + assigned_by integer, | |
| 172 | + PRIMARY KEY (id) | |
| 173 | + );"; | |
| 174 | + dbDelta( $sql ); | |
| 175 | + $sql = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}wppm_project_comment_meta ( | |
| 176 | + id BIGINT NOT NULL AUTO_INCREMENT, | |
| 177 | + proj_id integer, | |
| 178 | + comment_id integer, | |
| 179 | + comment_type VARCHAR(200) NOT NULL, | |
| 180 | + PRIMARY KEY (id) | |
| 181 | + );"; | |
| 182 | + dbDelta( $sql ); | |
| 183 | + $sql = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}wppm_task_comment_meta ( | |
| 184 | + id BIGINT NOT NULL AUTO_INCREMENT, | |
| 185 | + task_id integer, | |
| 186 | + comment_id integer, | |
| 187 | + comment_type VARCHAR(200) NOT NULL, | |
| 188 | + PRIMARY KEY (id) | |
| 189 | + );"; | |
| 190 | + dbDelta( $sql ); | |
| 191 | + $sql = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}wppm_notifications ( | |
| 192 | + id BIGINT AUTO_INCREMENT PRIMARY KEY, | |
| 193 | + user_id INT, | |
| 194 | + message TEXT, | |
| 195 | + link TEXT, | |
| 196 | + is_read TINYINT DEFAULT 0, | |
| 197 | + notification_type VARCHAR(200) NOT NULL, | |
| 198 | + created_at DATETIME DEFAULT CURRENT_TIMESTAMP | |
| 199 | + );"; | |
| 200 | + dbDelta( $sql ); | |
| 201 | + } | |
| 202 | + | |
| 203 | + public function upgrade(){ | |
| 204 | + global $wpdb,$wppmfunction; | |
| 205 | + $installed_version = get_option( 'wppm_version' ); | |
| 206 | + $installed_version = $installed_version ? $installed_version : 0; | |
| 207 | + if($installed_version < '1.0.0'){ | |
| 208 | + //User Roles | |
| 209 | + $user_role = get_option('wppm_user_role'); | |
| 210 | + if(empty($user_role)){ | |
| 211 | + $user_role = array( | |
| 212 | + 1 => array( | |
| 213 | + 'label' => esc_html__('manager','taskbuilder'), | |
| 214 | + ), | |
| 215 | + 2 => array( | |
| 216 | + 'label' => esc_html__('co-worker','taskbuilder'), | |
| 217 | + ) | |
| 218 | + ); | |
| 219 | + update_option('wppm_user_role',$user_role); | |
| 220 | + } | |
| 221 | + | |
| 222 | + $wppm_email_notificatins = get_option('wppm_email_notification'); | |
| 223 | + if(empty($wppm_email_notificatins)){ | |
| 224 | + $wppm_email_notificatins = array( | |
| 225 | + 1=>array( | |
| 226 | + 'type'=>'new_project', | |
| 227 | + 'subject'=>esc_html__('New project has been created:{project_name}','taskbuilder'), | |
| 228 | + 'body'=>esc_html__('<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'), | |
| 229 | + 'recipients'=>array(1,2) | |
| 230 | + ), | |
| 231 | + 2=>array( | |
| 232 | + 'type'=>'new_task', | |
| 233 | + 'subject'=>esc_html__('New task has been created: {task_name}','taskbuilder'), | |
| 234 | + 'body'=>esc_html__('<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'), | |
| 235 | + 'recipients'=>array(1,2) | |
| 236 | + ), | |
| 237 | + 3=>array( | |
| 238 | + 'type'=>'change_project_status', | |
| 239 | + 'subject'=>esc_html__('{project_name} Project\'s status has been changed from {old_project_status} to {new_project_status}','taskbuilder'), | |
| 240 | + 'body'=>esc_html__('<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'), | |
| 241 | + 'recipients'=>array(1,2) | |
| 242 | + ), | |
| 243 | + 4=>array( | |
| 244 | + 'type'=>'change_task_status', | |
| 245 | + 'subject'=>esc_html__('{task_name} Task\'s status has been changed from {old_task_status} to {new_task_status}','taskbuilder'), | |
| 246 | + 'body'=>esc_html__('<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'), | |
| 247 | + 'recipients'=>array(1,2) | |
| 248 | + ), | |
| 249 | + 5=>array( | |
| 250 | + 'type'=>'change_project_assign_users', | |
| 251 | + 'subject'=>esc_html__('{project_name} Project\'s assigned users changed from {previously_assigned_project_users} to {project_assigned_users}','taskbuilder'), | |
| 252 | + 'body'=>esc_html__('<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'), | |
| 253 | + 'recipients'=>array(1,2) | |
| 254 | + ), | |
| 255 | + 6=>array( | |
| 256 | + 'type'=>'change_task_assign_users', | |
| 257 | + 'subject'=>esc_html__('{task_name} Task\'s assigned users change from {previously_assigned_task_users} to {task_assigned_users}','taskbuilder'), | |
| 258 | + 'body'=>esc_html__('<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'), | |
| 259 | + 'recipients'=>array(1,2) | |
| 260 | + ), | |
| 261 | + 7=>array( | |
| 262 | + 'type'=>'new_discussion', | |
| 263 | + 'subject'=>esc_html__('[{project_name}][{task_name}] {last_comment_user_name} started new discussion:','taskbuilder'), | |
| 264 | + 'body'=>esc_html__('<p><strong>{last_comment_user_name}</strong> wrote:</p> <p>{comment_body}</p>','taskbuilder'), | |
| 265 | + 'recipients'=>array(1,2) | |
| 266 | + ) | |
| 267 | + ); | |
| 268 | + update_option('wppm_email_notification',$wppm_email_notificatins); | |
| 269 | + } | |
| 270 | + | |
| 271 | + update_option('wppm_default_task_list_view',1); | |
| 272 | + | |
| 273 | + $default_statuses = $wpdb->get_var("select count(*) from {$wpdb->prefix}wppm_project_statuses"); | |
| 274 | + if (empty($default_statuses)) { | |
| 275 | + $wpdb->insert($wpdb->prefix . "wppm_project_statuses", array('id' => 1,'name' => esc_html__('New','taskbuilder'),'color'=>'#ffffff','bg_color'=>'#306EFF','load_order'=>1)); | |
| 276 | + $wpdb->insert($wpdb->prefix . "wppm_project_statuses", array('id' => 2,'name' => esc_html__('In Progress','taskbuilder'),'color'=>'#ffffff','bg_color'=>'#FCD12A','load_order'=>2)); | |
| 277 | + $wpdb->insert($wpdb->prefix . "wppm_project_statuses", array('id' => 3,'name' => esc_html__('Hold','taskbuilder'),'color'=>'#ffffff','bg_color'=>'#D3D3D3','load_order'=>3)); | |
| 278 | + $wpdb->insert($wpdb->prefix . "wppm_project_statuses", array('id' => 4,'name' => esc_html__('Completed','taskbuilder'),'color'=>'#ffffff','bg_color'=>'#5cb85c','load_order'=>4)); | |
| 279 | + } | |
| 280 | + $wppm_default_project_status = get_option('wppm_default_project_status',true); | |
| 281 | + if($wppm_default_project_status == ''){ | |
| 282 | + update_option('wppm_default_project_status',1); | |
| 283 | + } | |
| 284 | + $default_task_statuses = $wpdb->get_var("select count(*) from {$wpdb->prefix}wppm_task_statuses"); | |
| 285 | + if (empty($default_task_statuses)) { | |
| 286 | + $wpdb->insert($wpdb->prefix . "wppm_task_statuses",array('id' => 1,'name' => esc_html__('Todo','taskbuilder'),'color'=>'#ffffff','bg_color'=>'#306EFF','load_order'=>1)); | |
| 287 | + $wpdb->insert($wpdb->prefix . "wppm_task_statuses",array('id' => 2,'name' => esc_html__('In Progress','taskbuilder'),'color'=>'#ffffff','bg_color'=>'#FCD12A','load_order'=>2)); | |
| 288 | + $wpdb->insert($wpdb->prefix . "wppm_task_statuses",array('id' => 3,'name' => esc_html__('Hold','taskbuilder'),'color'=>'#ffffff','bg_color'=>'#D3D3D3','load_order'=>3)); | |
| 289 | + $wpdb->insert($wpdb->prefix . "wppm_task_statuses",array('id' => 4,'name' => esc_html__('Completed','taskbuilder'),'color'=>'#ffffff','bg_color'=>'#5cb85c','load_order'=>4)); | |
| 290 | + } | |
| 291 | + $wppm_default_task_status = get_option('wppm_default_task_status',true); | |
| 292 | + if($wppm_default_task_status == ''){ | |
| 293 | + update_option('wppm_default_task_status',1); | |
| 294 | + } | |
| 295 | + } | |
| 296 | + if($installed_version < '1.0.2'){ | |
| 297 | + update_option('wppm_project_time', 1); | |
| 298 | + } | |
| 299 | + if($installed_version < '2.0.0'){ | |
| 300 | + update_option('wppm_default_project_date', 1); | |
| 301 | + update_option('wppm_default_task_date', 1); | |
| 302 | + } | |
| 303 | + if($installed_version < '2.0.2'){ | |
| 304 | + update_option('wppm_default_edit_tasks_permission', 0); | |
| 305 | + } | |
| 306 | + if($installed_version < '2.0.4'){ | |
| 307 | + update_option('wppm_public_projects_permission',0); | |
| 308 | + } | |
| 309 | + if($installed_version < '2.0.8'){ | |
| 310 | + update_option('wppm_task_time',1); | |
| 311 | + } | |
| 312 | + if($installed_version < '3.0.0'){ | |
| 313 | + $wppm_email_notificatins = get_option('wppm_email_notification'); | |
| 314 | + if(!empty($wppm_email_notificatins) && !isset($wppm_email_notificatins[8])){ | |
| 315 | + $wppm_email_notificatins[8] = array( | |
| 316 | + 'type'=>'new_proj_discussion', | |
| 317 | + 'subject'=>esc_html__('[{project_name}] {last_proj_comment_user_name} started new discussion:','taskbuilder'), | |
| 318 | + 'body'=>esc_html__('<p><strong>{last_proj_comment_user_name}</strong> wrote:</p> <p>{proj_comment_body}</p>','taskbuilder'), | |
| 319 | + 'recipients'=>array(1,2) | |
| 320 | + ); | |
| 321 | + update_option('wppm_email_notification',$wppm_email_notificatins); | |
| 322 | + } | |
| 323 | + update_option( | |
| 324 | + 'wppm-ap-project-list', | |
| 325 | + array( | |
| 326 | + 'list-header-button-background-color' => '#0052CC', | |
| 327 | + 'list-header-button-hover-color' => '#0065ff', | |
| 328 | + 'list-header-button-text-color' => '#fff', | |
| 329 | + 'list-header-background-color' => '#304FFE', | |
| 330 | + 'list-header-text-color' => '#fff', | |
| 331 | + 'list-item-odd-background-color' => '#fff', | |
| 332 | + 'list-item-odd-text-color' => '#2C3E50', | |
| 333 | + 'list-item-even-background-color' => '#F2F2F2', | |
| 334 | + 'list-item-even-text-color' => '#2C3E50', | |
| 335 | + 'list-item-hover-background-color' => '#F5F5F5', | |
| 336 | + 'list-item-hover-text-color' => '#2C3E50' | |
| 337 | + ) | |
| 338 | + ); | |
| 339 | + update_option( | |
| 340 | + 'wppm-ap-task-list', | |
| 341 | + array( | |
| 342 | + 'list-header-button-background-color'=>'#0052CC', | |
| 343 | + 'list-header-button-hover-color' =>'#0065ff', | |
| 344 | + 'list-header-button-text-color' =>'#fff', | |
| 345 | + 'list-header-background-color' => '#304FFE', | |
| 346 | + 'list-header-text-color' => '#fff', | |
| 347 | + 'list-item-odd-background-color' => '#fff', | |
| 348 | + 'list-item-odd-text-color' => '#2C3E50', | |
| 349 | + 'list-item-even-background-color' => '#F2F2F2', | |
| 350 | + 'list-item-even-text-color' => '#2C3E50', | |
| 351 | + 'list-item-hover-background-color' => '#F5F5F5', | |
| 352 | + 'list-item-hover-text-color' => '#2C3E50', | |
| 353 | + ) | |
| 354 | + ); | |
| 355 | + update_option( | |
| 356 | + 'wppm-ap-individual-project', | |
| 357 | + array( | |
| 358 | + 'menu-button-bg-color' =>'#0052CC', | |
| 359 | + 'menu-button-hover-color' =>'#0065ff', | |
| 360 | + 'menu-button-text-color' =>'#fff', | |
| 361 | + 'comment-primary-color' => '#000000', | |
| 362 | + 'comment-secondary-color' => '#4e4e4e', | |
| 363 | + 'comment-date-color' => '#a8aeb5', | |
| 364 | + 'comment-date-hover-color' => '#000000', | |
| 365 | + 'comment-send-btn-bg-color' => '#5067c5', | |
| 366 | + 'comment-send-btn-color' => '#ffffff', | |
| 367 | + 'widget-header-bg-color' => '#ffffff', | |
| 368 | + 'widget-header-text-color' => '#2C3E50', | |
| 369 | + 'widget-body-bg-color' => '#ffffff', | |
| 370 | + 'widget-body-label-color' => '#9c9c9c', | |
| 371 | + 'widget-body-text-color' => '#2C3E50', | |
| 372 | + ) | |
| 373 | + ); | |
| 374 | + update_option( | |
| 375 | + 'wppm-ap-individual-task', | |
| 376 | + array( | |
| 377 | + 'comment-primary-color' => '#000000', | |
| 378 | + 'comment-secondary-color' => '#4e4e4e', | |
| 379 | + 'comment-date-color' => '#a8aeb5', | |
| 380 | + 'comment-date-hover-color' => '#000000', | |
| 381 | + 'comment-send-btn-bg-color' => '#5067c5', | |
| 382 | + 'comment-send-btn-color' => '#ffffff', | |
| 383 | + 'widget-header-bg-color' => '#ffffff', | |
| 384 | + 'widget-header-text-color' => '#2C3E50', | |
| 385 | + 'widget-body-bg-color' => '#ffffff', | |
| 386 | + 'widget-body-label-color' => '#9c9c9c', | |
| 387 | + 'widget-body-text-color' => '#2C3E50', | |
| 388 | + ) | |
| 389 | + ); | |
| 390 | + update_option( | |
| 391 | + 'wppm-ap-modal', | |
| 392 | + array( | |
| 393 | + 'header-bg-color' => '#ffffff', | |
| 394 | + 'header-text-color' => '#3c434a', | |
| 395 | + 'body-bg-color' => '#fff', | |
| 396 | + 'body-label-color' => '#3c434a', | |
| 397 | + 'body-text-color' => '#555', | |
| 398 | + 'footer-bg-color' => '#F6F6F6', | |
| 399 | + 'action-btn-bg-color' =>'#306EFF', | |
| 400 | + 'action-btn-text-color'=>'#fff', | |
| 401 | + 'z-index' => 900000000, | |
| 402 | + ) | |
| 403 | + ); | |
| 404 | + update_option( | |
| 405 | + 'wppm-ap-grid-view', | |
| 406 | + array( | |
| 407 | + 'menu-button-bg-color' =>'#0052CC', | |
| 408 | + 'menu-button-hover-color' =>'#0065ff', | |
| 409 | + 'menu-button-text-color' =>'#fff', | |
| 410 | + 'grid-background-color' => '#fff', | |
| 411 | + 'grid-header-text-color' => '#2C3E50' | |
| 412 | + ) | |
| 413 | + ); | |
| 414 | + update_option( | |
| 415 | + 'wppm-ap-settings', | |
| 416 | + array( | |
| 417 | + 'tab-background-color' => '#0052CC', | |
| 418 | + 'tab-text-color' => '#fff', | |
| 419 | + 'add-new-button-bg-color' =>'#0052CC', | |
| 420 | + 'add-new-button-text-color' =>'#fff', | |
| 421 | + 'add-new-button-hover-color'=>'#0065ff', | |
| 422 | + 'save-changes-button-bg-color'=>'#306EFF', | |
| 423 | + 'save-changes-button-text-color'=>'#fff' | |
| 424 | + ) | |
| 425 | + ); | |
| 426 | + } | |
| 427 | + if($installed_version < '3.0.1'){ | |
| 428 | + update_option('wppm_default_project_status', 1); | |
| 429 | + update_option('wppm_default_task_status', 1); | |
| 430 | + } | |
| 431 | + if($installed_version < '3.0.5'){ | |
| 432 | + update_option('wppm_tinymce_visibility_open_task',0); | |
| 433 | + update_option('wppm_tinymce_visibility_open_project',0); | |
| 434 | + update_option('wppm_default_email_notification_to_current_user', 1); | |
| 435 | + } | |
| 436 | + if($installed_version < '3.0.6'){ | |
| 437 | + update_option('wppm_allow_coworkers_create_task',1); | |
| 438 | + update_option('wppm_allow_coworkers_add_checklist',1); | |
| 439 | + update_option('wppm_allow_coworkers_assign_users', 0); | |
| 440 | + update_option('wppm_allow_coworkers_change_status', 1); | |
| 441 | + } | |
| 442 | + if($installed_version < '3.0.9'){ | |
| 443 | + update_option('wppm_rich_text_editor',1); | |
| 444 | + update_option( | |
| 445 | + 'wppm_toolbar_actions', | |
| 446 | + array( | |
| 447 | + 'bold' => '1', | |
| 448 | + 'italic' => '1', | |
| 449 | + 'underline' =>'1', | |
| 450 | + 'blockquote' =>'1', | |
| 451 | + 'align'=>'1', | |
| 452 | + 'bullist'=>'1', | |
| 453 | + 'numlist'=>'1', | |
| 454 | + 'rtl'=>'1', | |
| 455 | + 'link'=>'1', | |
| 456 | + 'wppm_insert_editor_img'=>'1', | |
| 457 | + 'forecolor'=>'0', | |
| 458 | + 'backcolor' => '0', | |
| 459 | + 'strikethrough' => '0' | |
| 460 | + ) | |
| 461 | + ); | |
| 462 | + } | |
| 463 | + | |
| 464 | + if($installed_version < '4.0.0'){ | |
| 465 | + update_option( | |
| 466 | + 'wppm-page-settings', | |
| 467 | + array( | |
| 468 | + 'task-url-page' => 0, | |
| 469 | + 'project-url-page' => 0 | |
| 470 | + ) | |
| 471 | + ); | |
| 472 | + } | |
| 473 | + | |
| 474 | + if($installed_version < '4.0.4'){ | |
| 475 | + update_option('wppm_date_setting','Y-m-d h:i:sa'); | |
| 476 | + } | |
| 477 | + | |
| 478 | + if($installed_version < '4.0.5'){ | |
| 479 | + update_option('wppm_hide_completed_status_proj','1'); | |
| 480 | + update_option('wppm_hide_completed_status_task','1'); | |
| 481 | + update_option('wppm_hide_proj_statuses_from_frontend','0'); | |
| 482 | + update_option('wppm_hide_task_statuses_from_frontend','0'); | |
| 483 | + update_option('wppm_proj_hide_comment_section','1'); | |
| 484 | + update_option('wppm_task_hide_comment_section','1'); | |
| 485 | + } | |
| 486 | + | |
| 487 | + if($installed_version < '5.0.0'){ | |
| 488 | + $wppm_print_settings = array( | |
| 489 | + 'wppm_print_body_font_size' => 10); | |
| 490 | + update_option('wppm_print_settings',$wppm_print_settings); | |
| 491 | + } | |
| 492 | + if($installed_version < '5.0.2'){ | |
| 493 | + $table_name = $wpdb->prefix . 'wppm_checklist_items'; | |
| 494 | + $column_name = 'load_order'; | |
| 495 | + $column_type = 'INT(11) NOT NULL DEFAULT 1'; | |
| 496 | + | |
| 497 | + $column_exists = $wpdb->get_var( | |
| 498 | + $wpdb->prepare( | |
| 499 | + "SHOW COLUMNS FROM `$table_name` LIKE %s", | |
| 500 | + $column_name | |
| 501 | + ) | |
| 502 | + ); | |
| 503 | + | |
| 504 | + if ( null === $column_exists ) { | |
| 505 | + | |
| 506 | + // Column name and type are hardcoded, not user input. | |
| 507 | + // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared | |
| 508 | + $wpdb->query( | |
| 509 | + "ALTER TABLE `$table_name` | |
| 510 | + ADD `$column_name` $column_type" | |
| 511 | + ); | |
| 512 | + } | |
| 513 | + $table_name = $wpdb->prefix . 'wppm_task'; | |
| 514 | + $cl_name = 'is_archived'; | |
| 515 | + $cl_type = 'TINYINT(1) DEFAULT 0'; | |
| 516 | + | |
| 517 | + $cl_exists = $wpdb->get_var( | |
| 518 | + $wpdb->prepare( | |
| 519 | + "SHOW COLUMNS FROM `$table_name` LIKE %s", | |
| 520 | + $cl_name | |
| 521 | + ) | |
| 522 | + ); | |
| 523 | + | |
| 524 | + if ( null === $cl_exists ) { | |
| 525 | + | |
| 526 | + $sql = sprintf( | |
| 527 | + 'ALTER TABLE `%s` ADD `%s` %s', | |
| 528 | + $table_name, | |
| 529 | + $cl_name, | |
| 530 | + $cl_type | |
| 531 | + ); | |
| 532 | + | |
| 533 | + // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared -- Safe: identifiers are hardcoded. | |
| 534 | + $wpdb->query( $sql ); | |
| 535 | + } | |
| 536 | + } | |
| 537 | + if($installed_version < '5.0.3'){ | |
| 538 | + update_option('wppm_display_time_duration_project',0); | |
| 539 | + update_option('wppm_display_time_duration_task',0); | |
| 540 | + | |
| 541 | + } | |
| 542 | + if($installed_version < '5.0.6'){ | |
| 543 | + update_option('wppm_show_update_notice', 1); | |
| 544 | + $user_role = get_option('wppm_user_role'); | |
| 545 | + if (!isset($user_role[3])) { | |
| 546 | + $user_role[3] = array( | |
| 547 | + 'label' => esc_html__('Client', 'taskbuilder'), | |
| 548 | + ); | |
| 549 | + } | |
| 550 | + update_option('wppm_user_role', $user_role); | |
| 551 | + } | |
| 552 | + if($installed_version < '6.0.0'){ | |
| 553 | + $table_name = $wpdb->prefix . 'wppm_project'; | |
| 554 | + $column_name = 'project_auth_code'; | |
| 555 | + $column_type = 'LONGTEXT NULL DEFAULT NULL'; | |
| 556 | + $column_exists = $wpdb->get_var( | |
| 557 | + $wpdb->prepare( | |
| 558 | + "SHOW COLUMNS FROM `$table_name` LIKE %s", | |
| 559 | + $column_name | |
| 560 | + ) | |
| 561 | + ); | |
| 562 | + if ( empty( $column_exists ) ) { | |
| 563 | + // Column name and type are hardcoded, not user input. | |
| 564 | + // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared | |
| 565 | + $wpdb->query( | |
| 566 | + "ALTER TABLE `$table_name` | |
| 567 | + ADD `$column_name` $column_type" | |
| 568 | + ); | |
| 569 | + } | |
| 570 | + $projects = $wpdb->get_results( | |
| 571 | + "SELECT id FROM {$wpdb->prefix}wppm_project | |
| 572 | + WHERE project_auth_code IS NULL OR project_auth_code = ''" | |
| 573 | + ); | |
| 574 | + foreach ( $projects as $project ) { | |
| 575 | + $wpdb->update( | |
| 576 | + "{$wpdb->prefix}wppm_project", | |
| 577 | + array( | |
| 578 | + 'project_auth_code' => $wppmfunction->getRandomString(10), | |
| 579 | + ), | |
| 580 | + array( | |
| 581 | + 'id' => $project->id, | |
| 582 | + ), | |
| 583 | + array('%s'), | |
| 584 | + array('%d') | |
| 585 | + ); | |
| 586 | + } | |
| 587 | + $table_name = $wpdb->prefix . 'wppm_project'; | |
| 588 | + $cl_name = 'is_archived'; | |
| 589 | + $cl_type = 'TINYINT(1) DEFAULT 0'; | |
| 590 | + $cl_exists = $wpdb->get_var( | |
| 591 | + $wpdb->prepare( | |
| 592 | + "SHOW COLUMNS FROM `$table_name` LIKE %s", | |
| 593 | + $cl_name | |
| 594 | + ) | |
| 595 | + ); | |
| 596 | + if ( empty( $cl_exists ) ) { | |
| 597 | + $sql = sprintf( | |
| 598 | + 'ALTER TABLE `%s` ADD `%s` %s', | |
| 599 | + $table_name, | |
| 600 | + $cl_name, | |
| 601 | + $cl_type | |
| 602 | + ); | |
| 603 | + // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared -- Safe: identifiers are hardcoded. | |
| 604 | + $wpdb->query( $sql ); | |
| 605 | + } | |
| 606 | + } | |
| 607 | + if($installed_version < '6.0.6'){ | |
| 608 | + update_option('wppm_default_global_mention_comment_notification', 1); | |
| 609 | + $project_list_settings = get_option( 'wppm-ap-project-list', array() ); | |
| 610 | + $project_list_settings['list-header-button-background-color'] = '#0052CC'; | |
| 611 | + $project_list_settings['list-header-button-hover-color'] = '#0065ff'; | |
| 612 | + $project_list_settings['list-header-button-text-color'] = '#fff'; | |
| 613 | + update_option( 'wppm-ap-project-list', $project_list_settings ); | |
| 614 | + $table_name = $wpdb->prefix . 'wppm_task'; | |
| 615 | + $column_name = 'parent_task_id'; | |
| 616 | + $column_type = 'INT(11) NOT NULL DEFAULT 0'; | |
| 617 | + $column_exists = $wpdb->get_var( | |
| 618 | + $wpdb->prepare( | |
| 619 | + "SHOW COLUMNS FROM `$table_name` LIKE %s", | |
| 620 | + $column_name | |
| 621 | + ) | |
| 622 | + ); | |
| 623 | + if ( empty( $column_exists ) ) { | |
| 624 | + // Column name and type are hardcoded, not user input. | |
| 625 | + // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared | |
| 626 | + $wpdb->query( | |
| 627 | + "ALTER TABLE `$table_name` | |
| 628 | + ADD `$column_name` $column_type" | |
| 629 | + ); | |
| 630 | + } | |
| 631 | + } | |
| 632 | + // update wppm_version option to plugin version | |
| 633 | + update_option( 'wppm_version', WPPM_VERSION ); | |
| 634 | + } | |
| 635 | +} | |
| 636 | + | |
| 637 | +endif; | |
| 638 | + | |
| 610 | 639 | new WPPM_Install(); |