static function get_instance()
 {
     if (!self::$instance) {
         self::$instance = new self();
     }
     return self::$instance;
 }
Exemplo n.º 2
0
 /**
  * load data needed for board's javascript
  * @param  string $template the passed in template path
  * @return string           the same template path
  */
 static function send_page_data_to_template($template)
 {
     if (!isset(Kanban_Template::get_instance()->slug) || Kanban_Template::get_instance()->slug != self::$slug) {
         return $template;
     }
     global $wp_query;
     $wp_query->query_vars['kanban'] = (object) array();
     $wp_query->query_vars['kanban']->board = (object) array();
     // // get all data for the javascript
     $wp_query->query_vars['kanban']->board->allowed_users = Kanban_User::get_allowed_users();
     $wp_query->query_vars['kanban']->board->estimates = Kanban_Terms::terms_in_order('task', 'estimate');
     $wp_query->query_vars['kanban']->board->status_tax_key = Kanban_Utils::format_key('task', 'status');
     $wp_query->query_vars['kanban']->board->status_color_field_name = sprintf('%s_colors', $wp_query->query_vars['kanban']->board->status_tax_key);
     $wp_query->query_vars['kanban']->board->status_colors = Kanban_Settings::get_option($wp_query->query_vars['kanban']->board->status_color_field_name, null, array());
     $wp_query->query_vars['kanban']->board->statuses = Kanban_Terms::terms_in_order('task', 'status');
     foreach ($wp_query->query_vars['kanban']->board->statuses as $status) {
         if (!isset($wp_query->query_vars['kanban']->board->status_colors[$status->term_id])) {
             continue;
         }
         $status->color = $wp_query->query_vars['kanban']->board->status_colors[$status->term_id];
     }
     $wp_query->query_vars['kanban']->board->projects = Kanban_Project::get_all();
     $wp_query->query_vars['kanban']->board->tasks = Kanban_Task::get_all();
     $current_user_id = get_current_user_id();
     $wp_query->query_vars['kanban']->board->current_user = get_user_by('id', $current_user_id);
     unset($wp_query->query_vars['kanban']->board->current_user->data->user_pass);
     $wp_query->query_vars['kanban']->board->current_user->data->long_name_email = Kanban_User::format_user_name($wp_query->query_vars['kanban']->board->current_user);
     $wp_query->query_vars['kanban']->board->current_user->data->short_name = Kanban_User::format_user_name($wp_query->query_vars['kanban']->board->current_user, TRUE);
     $wp_query->query_vars['kanban']->board->current_user->data->initials = Kanban_User::get_initials($wp_query->query_vars['kanban']->board->current_user);
     $wp_query->query_vars['kanban']->board->col_percent_w = count($wp_query->query_vars['kanban']->board->statuses) > 0 ? 100 / count($wp_query->query_vars['kanban']->board->statuses) : 100;
     $wp_query->query_vars['kanban']->board->sidebar_w = count($wp_query->query_vars['kanban']->board->statuses) > 0 ? 100 / (count($wp_query->query_vars['kanban']->board->statuses) - 2) : 0;
     return $template;
 }
Exemplo n.º 3
0
    /**
     * load data needed for board's javascript
     * @param  string $template the passed in template path
     * @return string           the same template path
     */
    static function send_page_data_to_template($template)
    {
        // make sure we're looking at the board
        if (!isset(Kanban_Template::get_instance()->slug) || Kanban_Template::get_instance()->slug != self::$slug) {
            return $template;
        }
        // make sure they don't need to upgrade
        if (Kanban::get_instance()->settings->records_to_move > 0) {
            ?>
			<p>
			<?php 
            echo sprintf(__('We\'ve found %s kanban records that need to be migrated for the latest version of Kanban for WordPress!', 'kanban'), Kanban::get_instance()->settings->records_to_move);
            ?>
			</p>
			<p>
			<?php 
            echo sprintf(__('Please visit the <a href="%s">Kanban welcome page</a> to migrate your data.', 'kanban'), add_query_arg('page', 'kanban_welcome', admin_url('admin.php')));
            ?>
			<?php 
            exit;
        }
        // get the template data
        global $wp_query;
        // attach our object to the template data
        $wp_query->query_vars['kanban'] = (object) array();
        $wp_query->query_vars['kanban']->board = (object) array();
        // add default filters
        $wp_query->query_vars['kanban']->board->filters = array('user' => (object) array(), 'project' => (object) array());
        // add passed alert
        $wp_query->query_vars['kanban']->board->alert = !empty($_GET['alert']) ? stripcslashes($_GET['alert']) : '';
        // get all data for the javascript
        $wp_query->query_vars['kanban']->board->settings = Kanban_Option::get_all();
        $wp_query->query_vars['kanban']->board->allowed_users = Kanban_User::get_allowed_users();
        $wp_query->query_vars['kanban']->board->estimates = Kanban_Estimate::get_all();
        $wp_query->query_vars['kanban']->board->statuses = Kanban_Status::get_all();
        $wp_query->query_vars['kanban']->board->projects = Kanban_Project::get_all();
        $wp_query->query_vars['kanban']->board->tasks = Kanban_Task::get_all();
        // get the current user from the allowed users
        $current_user_id = get_current_user_id();
        $wp_query->query_vars['kanban']->board->current_user = $wp_query->query_vars['kanban']->board->allowed_users[$current_user_id];
        // figure out percentages here (easier, quicker than in js)
        $wp_query->query_vars['kanban']->board->col_percent_w = count($wp_query->query_vars['kanban']->board->statuses) > 0 ? 100 / count($wp_query->query_vars['kanban']->board->statuses) : 100;
        $wp_query->query_vars['kanban']->board->sidebar_w = count($wp_query->query_vars['kanban']->board->statuses) > 0 ? 100 / (count($wp_query->query_vars['kanban']->board->statuses) - 2) : 0;
        apply_filters('kanban_board_query_vars', $wp_query->query_vars['kanban']->board);
        return $template;
    }
Exemplo n.º 4
0
 /**
  * move users
  * move terms (not deleted, as we need them for tasks)
  * move projects
  * move tasks
  * move comments
  * delete projects
  * delete terms
  * clean up
  * @return [type] [description]
  */
 static function ajax_migrate_records()
 {
     global $wpdb;
     // build response
     $response = array('posts_remaining' => Kanban::get_instance()->settings->records_to_move, 'continue' => FALSE, 'done' => FALSE);
     // check for users to move
     $is_users_moved = get_option('kanban_migrate_users_moved');
     if (!$is_users_moved) {
         $sql = "SELECT\n\t\t\t\t\t{$wpdb->prefix}options.option_value\n\t\t\t\t\tFROM {$wpdb->prefix}options\n\t\t\t\t\tWHERE `option_name` = 'kanban_user'\n\t\t\t;";
         $users = $wpdb->get_var($sql);
         if (!empty($users)) {
             $users = unserialize($users);
             $data = array('name' => 'allowed_users', 'value' => serialize($users['allowed_users']));
             Kanban_Option::_replace($data);
             delete_option('kanban_user');
         }
         update_option('kanban_migrate_users_moved', TRUE);
         $response['posts_remaining'] = $response['posts_remaining'] - 1;
         $response['continue'] = TRUE;
         $response['message'] = 'Allowed users moved';
         wp_send_json_success($response);
     }
     // check for terms to move
     $is_terms_moved = get_option('kanban_migrate_terms_moved');
     if (!$is_terms_moved) {
         $sql = "SELECT\n\t\t\t\t\t{$wpdb->prefix}term_taxonomy.`taxonomy`\n\t\t\t\t\t, {$wpdb->prefix}term_taxonomy.`term_taxonomy_id`\n\t\t\t\t\t, {$wpdb->prefix}terms.`term_id`\n\t\t\t\t\t, {$wpdb->prefix}terms.`name`\n\t\t\t\t\t, {$wpdb->prefix}terms.`slug`\n\t\t\t\t\tFROM {$wpdb->prefix}terms\n\t\t\t\t\tJOIN {$wpdb->prefix}term_taxonomy\n\t\t\t\t\tON {$wpdb->prefix}terms.`term_id` = {$wpdb->prefix}term_taxonomy.`term_id`\n\t\t\t;";
         $terms = $wpdb->get_results($sql);
         // if we need to move terms
         if (!empty($terms)) {
             // get settings
             $kanban_task_status_order = get_option('kanban_task_status_order');
             $kanban_task_status_colors = get_option('kanban_task_status_colors');
             $kanban_task_estimate_order = get_option('kanban_task_estimate_order');
             // get statuses for matching
             $status_table = Kanban_Status::table_name();
             $sql = "SELECT * FROM {$status_table};";
             $statuses = $wpdb->get_results($sql);
             $status_arr = array();
             foreach ($statuses as $status) {
                 $status_arr[$status->title] = $status->id;
             }
             // get estimates for matching
             $estimates_table = Kanban_Estimate::table_name();
             $sql = "SELECT * FROM {$estimates_table};";
             $estimates = $wpdb->get_results($sql);
             $estimate_arr = array();
             foreach ($estimates as $estimate) {
                 $estimate_arr[$estimate->title] = $estimate->id;
             }
             // add each term
             foreach ($terms as $term) {
                 switch ($term->taxonomy) {
                     case 'kanban_task_status':
                         if (isset($status_arr[$term->name])) {
                             continue;
                         }
                         $data = array('title' => $term->name, 'color_hex' => $kanban_task_status_colors[$term->term_id], 'position' => $kanban_task_status_order[$term->term_id]);
                         $success = Kanban_Status::replace($data);
                         break;
                     case 'kanban_task_estimate':
                         if (isset($estimate_arr[$term->name])) {
                             continue;
                         }
                         $data = array('title' => $term->name, 'hours' => $term->slug, 'position' => $kanban_task_estimate_order[$term->term_id]);
                         $success = Kanban_Estimate::replace($data);
                         break;
                 }
             }
         }
         update_option('kanban_migrate_terms_moved', TRUE);
         $response['posts_remaining'] = $response['posts_remaining'] - 2;
         $response['continue'] = TRUE;
         $response['message'] = 'statuses and estimates updated';
         wp_send_json_success($response);
     }
     // is_terms_moved
     // move projects
     $sql = "SELECT posts.ID as id\n\t\t\t, posts.post_title as title\n\t\t\t, posts.post_modified_gmt as modified_dt_gmt\n\t\t\t, posts.post_date_gmt as created_dt_gmt\n\t\t\t, posts.post_author as user_id_author\n\n\t\t\tFROM {$wpdb->prefix}posts posts\n\n\t\t\tWHERE posts.`post_type` = 'kanban_project'\n\t\t\tAND posts.`post_status` = 'publish'\n\t\t\tLIMIT 1\n\t\t;";
     $projects = $wpdb->get_results($sql);
     if (!empty($projects)) {
         foreach ($projects as $post) {
             $data = array('title' => $post->title, 'created_dt_gmt' => $post->created_dt_gmt, 'modified_dt_gmt' => $post->modified_dt_gmt, 'user_id_author' => $post->user_id_author, 'is_active' => 1);
             $success = Kanban_Project::replace($data);
             if ($success) {
                 $wpdb->update("{$wpdb->prefix}posts", array('post_status' => 'trash'), array('ID' => $post->id));
             }
         }
         // projects
         $response['posts_remaining'] = $response['posts_remaining'] - 3;
         $response['continue'] = TRUE;
         $response['message'] = sprintf('project %s moved', $post->id);
         wp_send_json_success($response);
     }
     // projects
     // move tasks
     $sql = "SELECT posts.ID as id\n\t\t\t, posts.post_title as title\n\t\t\t, posts.post_modified_gmt as modified_dt_gmt\n\t\t\t, posts.post_date_gmt as created_dt_gmt\n\t\t\t, posts.post_author as user_id_author\n\t\t\t, p_project_name.post_title as project_name\n\t\t\t, pm_user_id_assigned.meta_value as user_id_assigned\n\t\t\t, pm_work_hour_count.meta_value as work_hour_count\n\n\t\t\tFROM {$wpdb->prefix}posts posts\n\n\t\t\tJOIN {$wpdb->prefix}postmeta pm_project_id\n\t\t\t\tON pm_project_id.post_id = posts.ID\n\t\t\t\tAND pm_project_id.meta_key = 'kanban_task_project_id'\n\n\t\t\tJOIN {$wpdb->prefix}posts p_project_name\n\t\t\t\tON pm_project_id.meta_value = p_project_name.ID\n\n\t\t\tJOIN {$wpdb->prefix}postmeta pm_user_id_assigned\n\t\t\t\tON pm_user_id_assigned.post_id = posts.ID\n\t\t\t\tAND pm_user_id_assigned.meta_key = 'kanban_task_user_id_assigned'\n\n\t\t\tJOIN {$wpdb->prefix}postmeta pm_work_hour_count\n\t\t\t\tON pm_work_hour_count.post_id = posts.ID\n\t\t\t\tAND pm_work_hour_count.meta_key = 'kanban_task_work_hour_count'\n\n\t\t\tWHERE posts.`post_type` = 'kanban_task'\n\t\t\tAND posts.`post_status` = 'publish'\n\t\t\tLIMIT 1\n\t\t;";
     $tasks = $wpdb->get_results($sql);
     if (!empty($tasks)) {
         // get statuses for matching
         $status_table = Kanban_Status::table_name();
         $sql = "SELECT * FROM {$status_table};";
         $statuses = $wpdb->get_results($sql);
         $status_arr = array();
         foreach ($statuses as $status) {
             $status_arr[$status->title] = $status->id;
         }
         // get estimates for matching
         $estimates_table = Kanban_Estimate::table_name();
         $sql = "SELECT * FROM {$estimates_table};";
         $estimates = $wpdb->get_results($sql);
         $estimate_arr = array();
         foreach ($estimates as $estimate) {
             $estimate_arr[$estimate->title] = $estimate->id;
         }
         // get projects for matching
         $projects_table = Kanban_Project::table_name();
         $sql = "SELECT * FROM {$projects_table};";
         $projects = $wpdb->get_results($sql);
         // build look up array by name
         $projects_arr = array();
         if (!empty($projects)) {
             foreach ($projects as $project) {
                 $projects_arr[$project->title] = $project->id;
             }
         }
         $estimate_arr = array();
         foreach ($estimates as $estimate) {
             $estimate_arr[$estimate->title] = $estimate->id;
         }
         foreach ($tasks as $post) {
             // get terms for this task
             $sql = "SELECT\n\t\t\t\t\t\t{$wpdb->prefix}terms.name\n\t\t\t\t\t\t, {$wpdb->prefix}term_taxonomy.`taxonomy`\n\t\t\t\t\t\tFROM {$wpdb->prefix}terms\n\t\t\t\t\t\tJOIN {$wpdb->prefix}term_taxonomy\n\t\t\t\t\t\tON {$wpdb->prefix}terms.term_id = {$wpdb->prefix}term_taxonomy.term_id\n\t\t\t\t\t\tJOIN {$wpdb->prefix}term_relationships\n\t\t\t\t\t\tON {$wpdb->prefix}term_taxonomy.term_taxonomy_id = {$wpdb->prefix}term_relationships.term_taxonomy_id\n\t\t\t\t\t\tWHERE {$wpdb->prefix}term_relationships.object_id = %s\n\t\t\t\t;";
             $terms = $wpdb->get_results($wpdb->prepare($sql, $post->id));
             $terms_arr = array();
             foreach ($terms as $term_data) {
                 $terms_arr[$term_data->taxonomy] = $term_data->name;
             }
             if (isset($terms_arr['kanban_task_status']) && isset($status_arr[$terms_arr['kanban_task_status']])) {
                 $status_id = $status_arr[$terms_arr['kanban_task_status']];
             } else {
                 $status_id = 0;
             }
             if (isset($terms_arr['kanban_task_estimate']) && isset($estimate_arr[$terms_arr['kanban_task_estimate']])) {
                 $estimate_id = $estimate_arr[$terms_arr['kanban_task_estimate']];
             } else {
                 $estimate_id = 0;
             }
             if (isset($projects_arr[$post->project_name])) {
                 $project_id = $projects_arr[$post->project_name];
             } else {
                 $project_id = 0;
             }
             // build task data to save
             $data = array('title' => $post->title, 'created_dt_gmt' => $post->created_dt_gmt, 'modified_dt_gmt' => $post->modified_dt_gmt, 'user_id_author' => $post->user_id_author, 'user_id_assigned' => $post->user_id_assigned, 'status_id' => $status_id, 'project_id' => $project_id, 'estimate_id' => $estimate_id, 'is_active' => 1);
             $success = Kanban_Task::replace($data);
             $task_id = self::_insert_id();
             if ($success) {
                 $wpdb->update("{$wpdb->prefix}posts", array('post_status' => 'trash'), array('ID' => $post->id));
             }
             $response['message'] = sprintf('task %s moved', $post->id);
             // get comments for task
             $sql = "SELECT *\n\t\t\t\t\t\tFROM {$wpdb->prefix}posts posts\n\t\t\t\t\t\tWHERE posts.`post_type` = 'kanban_task_comment'\n\t\t\t\t\t\tAND posts.`post_parent` = {$post->id}\n\t\t\t\t\t\tAND posts.`post_status` = 'publish'\n\t\t\t\t\t\t;";
             $comments = $wpdb->get_results($sql);
             if (count($comments) > 0) {
                 foreach ($comments as $comment) {
                     $data = array('description' => $comment->post_content, 'created_dt_gmt' => $comment->post_date_gmt, 'modified_dt_gmt' => $comment->post_modified_gmt, 'comment_type' => 'system', 'task_id' => $task_id, 'user_id_author' => $comment->post_author);
                     $success = Kanban_Comment::insert($data);
                     // mark as trash
                     if ($success) {
                         $wpdb->update("{$wpdb->prefix}posts", array('post_status' => 'trash'), array('ID' => $comment->ID));
                     }
                     // add task hour
                     if (strpos($comment->post_content, 'hour of work') !== FALSE) {
                         $data = array('task_id' => $task_id, 'created_dt_gmt' => $comment->post_date_gmt, 'hours' => 1, 'status_id' => $status_id, 'user_id_author' => $comment->post_author, 'user_id_worked' => $comment->post_author);
                         $success = Kanban_Task_Hour::insert($data);
                     }
                 }
                 $response['message'] .= sprintf('. %s comments moved', count($comments));
             }
             // $comments
         }
         // $tasks
         $response['posts_remaining'] = Kanban::get_instance()->settings->records_to_move - 4;
         $response['continue'] = TRUE;
         wp_send_json_success($response);
     }
     // task
     // $is_posts_deleted = get_option('kanban_migrate_posts_deleted');
     // if ( !$is_posts_deleted )
     // {
     // 	// delete any orphaned posts
     // 	$success = $wpdb->query("DELETE FROM $wpdb->posts
     // 		WHERE post_type LIKE 'kanban%'
     // 		OR post_type LIKE 'kbwp%'
     // 		;"
     // 	);
     // 	update_option('kanban_migrate_posts_deleted', TRUE);
     // 	$response['posts_remaining'] = Kanban::get_instance()->settings->records_to_move;
     // 	$response['continue'] = TRUE;
     // 	$response['message'] = sprintf('%s posts cleaned up', count($success));
     // 	wp_send_json_success($response);
     // }
     // // delete terms
     // $sql = "SELECT
     // 		{$wpdb->prefix}term_taxonomy.`taxonomy`
     // 		, {$wpdb->prefix}term_taxonomy.`term_taxonomy_id`
     // 		, {$wpdb->prefix}terms.`term_id`
     // 		, {$wpdb->prefix}terms.`name`
     // 		, {$wpdb->prefix}terms.`slug`
     // 		FROM {$wpdb->prefix}terms
     // 		JOIN {$wpdb->prefix}term_taxonomy
     // 		ON {$wpdb->prefix}terms.`term_id` = {$wpdb->prefix}term_taxonomy.`term_id`
     // ;";
     // $terms = $wpdb->get_results($sql);
     // // if we need to delete terms
     // if ( !empty($terms) )
     // {
     // 	// add each term
     // 	foreach ($terms as $term)
     // 	{
     // 		$wpdb->delete(
     // 			sprintf('%sterms', $wpdb->prefix),
     // 			array('term_id' => $term->term_id)
     // 		);
     // 		$wpdb->delete(
     // 			sprintf('%sterm_relationships', $wpdb->prefix),
     // 			array('term_taxonomy_id' => $term->term_taxonomy_id)
     // 		);
     // 		$wpdb->delete(
     // 			sprintf('%sterm_taxonomy', $wpdb->prefix),
     // 			array('term_taxonomy_id' => $term->term_taxonomy_id)
     // 		);
     // 	}
     // 	$response['continue'] = TRUE;
     // 	$response['message'] = 'statuses and estimates removed';
     // 	wp_send_json_success($response);
     // }
     // cleanup records
     $wpdb->update("{$wpdb->prefix}posts", array('post_status' => 'trash'), array('post_status' => 'publish', 'post_type' => 'kanban_task'));
     $wpdb->update("{$wpdb->prefix}posts", array('post_status' => 'trash'), array('post_status' => 'publish', 'post_type' => 'kanban_project'));
     $wpdb->update("{$wpdb->prefix}posts", array('post_status' => 'trash'), array('post_status' => 'publish', 'post_type' => 'kanban_task_comment'));
     // clean up temp values
     delete_option('kanban_migrate_users_moved');
     delete_option('kanban_migrate_terms_moved');
     delete_option('kanban_migrate_posts_deleted');
     // clean up old data
     // delete_option('kanban_task_status_order');
     // delete_option('kanban_task_status_colors');
     // delete_option('kanban_task_estimate_order');
     Kanban_Db::add_defaults();
     $response['done'] = TRUE;
     wp_send_json_success($response);
 }