コード例 #1
0
 static function migrate()
 {
     global $wpdb;
     $old_table = maxUtils::get_buttons_table_name(true);
     $table = maxUtils::get_buttons_table_name();
     if (!self::maxbuttons_database_table_exists($old_table)) {
         return;
     }
     $sql = "SELECT id from {$table}";
     $result = $wpdb->get_results($sql, ARRAY_A);
     if (count($result) > 0) {
         return;
     }
     // don't do this if table already has data.
     $sql = "SELECT * FROM {$old_table}";
     $rows = $wpdb->get_results($sql, ARRAY_A);
     if (count($rows) == 0) {
         // no button in all table; all is good.
         return true;
     }
     foreach ($rows as $row) {
         $data = static::convertOldFields($row);
         $id = $data["id"];
         global $wpdb;
         $wpdb->insert($table, array("id" => $id));
         //$data = apply_filters("mb-migration-data",$data, $row);
         $button = new maxButton();
         $button->set($id);
         $button->save($data);
     }
 }