예제 #1
0
파일: revisr.php 프로젝트: acchs/test
 /**
  * Installs the database table.
  * @access public
  */
 public static function install()
 {
     $table_name = Revisr::get_table_name();
     $sql = "CREATE TABLE {$table_name} (\n\t\t\tid mediumint(9) NOT NULL AUTO_INCREMENT,\n\t\t\ttime datetime DEFAULT '0000-00-00 00:00:00' NOT NULL,\n\t\t\tmessage TEXT,\n\t\t\tevent VARCHAR(42) NOT NULL,\n\t\t\tuser VARCHAR(60),\n\t\t\tUNIQUE KEY id (id)\n\t\t\t);";
     require_once ABSPATH . 'wp-admin/includes/upgrade.php';
     dbDelta($sql);
     update_option('revisr_db_version', '2.0');
 }
예제 #2
0
 /**
  * Prepares the data for display.
  * @access public
  */
 public function prepare_items()
 {
     global $wpdb;
     $table = Revisr::get_table_name();
     // Number of items per page.
     $per_page = $this->get_items_per_page('edit_revisr_events_per_page', 15);
     // Set up the custom columns.
     $columns = $this->get_columns();
     $hidden = array();
     $sortable = $this->get_sortable_columns();
     // Builds the list of column headers.
     $this->_column_headers = array($columns, $hidden, $sortable);
     // Run any custom filters.
     $where = $this->create_where();
     // Get the data to populate into the table.
     $data = $wpdb->get_results("SELECT message, time, user FROM {$table} {$where}", ARRAY_A);
     // Handle sorting of the data.
     function usort_reorder($a, $b)
     {
         // Default to time for default sort.
         $orderby = isset($_REQUEST['orderby']) ? $_REQUEST['orderby'] : 'time';
         // Default to descending for default sort order.
         $order = isset($_REQUEST['order']) ? $_REQUEST['order'] : 'desc';
         // Determine the sort order and send to usort.
         $result = strcmp($a[$orderby], $b[$orderby]);
         return $order === 'asc' ? $result : -$result;
     }
     usort($data, 'usort_reorder');
     // Pagination.
     $current_page = $this->get_pagenum();
     $total_items = count($data);
     $data = array_slice($data, ($current_page - 1) * $per_page, $per_page);
     $this->items = $data;
     $this->set_pagination_args(array('total_items' => $total_items, 'per_page' => $per_page, 'total_pages' => ceil($total_items / $per_page), 'orderby' => isset($_REQUEST['orderby']) ? $_REQUEST['orderby'] : 'time', 'order' => isset($_REQUEST['order']) ? $_REQUEST['order'] : 'desc'));
 }
예제 #3
0
 /**
  * Tests get_table_name().
  */
 function test_get_table_name()
 {
     $revisr_table_name = Revisr::get_table_name();
     $this->assertContains('revisr', $revisr_table_name);
 }
예제 #4
0
 /**
  * Updates user settings to be compatible with 1.8.
  * @access public
  */
 public function do_upgrade()
 {
     global $wpdb;
     // For users upgrading from 1.7 and older.
     if (get_option('revisr_db_version') === '1.0') {
         // Check for the "auto_push" option and save it to the config.
         if (isset(revisr()->options['auto_push'])) {
             revisr()->git->set_config('revisr', 'auto-push', 'true');
         }
         // Check for the "auto_pull" option and save it to the config.
         if (isset(revisr()->options['auto_pull'])) {
             revisr()->git->set_config('revisr', 'auto-pull', 'true');
         }
         // Check for the "reset_db" option and save it to the config.
         if (isset(revisr()->options['reset_db'])) {
             revisr()->git->set_config('revisr', 'import-checkouts', 'true');
         }
         // Check for the "mysql_path" option and save it to the config.
         if (isset(revisr()->options['mysql_path'])) {
             revisr()->git->set_config('revisr', 'mysql-path', revisr()->options['mysql_path']);
         }
         // Configure the database tracking to use all tables, as this was how it behaved in 1.7.
         revisr()->git->set_config('revisr', 'db_tracking', 'all_tables');
     }
     // Upgrades from the "revisr_commits" custom post type to pure Git.
     $table = Revisr::get_table_name();
     $commits = $wpdb->get_results("SELECT * FROM {$table} WHERE event = 'commit'", ARRAY_A);
     if (is_array($commits) && !empty($commits)) {
         foreach ($commits as $commit) {
             // Get the commit short hash from the message.
             $msg_array = explode('#', $commit['message']);
             $commit_id = substr($msg_array[1], 0, 7);
             // Prepare the new message.
             $new_msg = sprintf(__('Committed <a href="%s">#%s</a> to the local repository.', 'revisr'), get_admin_url() . 'admin.php?page=revisr_view_commit&commit=' . $commit_id, $commit_id);
             // Update the existing message.
             $query = $wpdb->prepare("UPDATE {$table} SET message = %s WHERE id = '%d'", $new_msg, $commit['id']);
             $wpdb->query($query);
         }
     }
     // Update the database schema using dbDelta.
     Revisr::install();
 }