/**
  * Cleans everything for the given id, then redoes everything
  *
  * @param integer $id           The id to edit
  */
 function adminProcessEdit($id)
 {
     global $wpdb;
     // If we need to execute a tool action we stop here
     if ($this->adminProcessTools()) {
         return;
     }
     // Delete all to recreate
     $wpdb->query("DELETE FROM {$this->db['campaign_word']} WHERE campaign_id = {$id}");
     $wpdb->query("DELETE FROM {$this->db['campaign_category']} WHERE campaign_id = {$id}");
     // Process categories
     # New
     if (isset($this->campaign_data['categories']['new'])) {
         foreach ($this->campaign_data['categories']['new'] as $category) {
             $this->campaign_data['categories'][] = wp_insert_category(array('cat_name' => $category));
         }
         unset($this->campaign_data['categories']['new']);
     }
     # All
     foreach ($this->campaign_data['categories'] as $category) {
         // Insert
         $wpdb->query(WPOTools::insertQuery($this->db['campaign_category'], array('category_id' => $category, 'campaign_id' => $id)));
     }
     // Process feeds
     # New
     if (isset($this->campaign_data['feeds']['new'])) {
         foreach ($this->campaign_data['feeds']['new'] as $feed) {
             $this->addCampaignFeed($id, $feed);
         }
     }
     if (isset($this->campaign_data['feeds']['move'])) {
         # For each of these we need to set the feed to the new campaign id
         foreach ($this->campaign_data['feeds']['move'] as $fid => $cid) {
             $wpdb->update($this->db['campaign_feed'], array('campaign_id' => $cid), array('id' => $fid), array('%d'), array('%d'));
         }
     }
     //echo "Queries:<pre>";
     //print_r( $wpdb->queries );
     //echo "</pre>";
     # Delete
     if (isset($this->campaign_data['feeds']['delete'])) {
         foreach ($this->campaign_data['feeds']['delete'] as $feed) {
             $wpdb->query("DELETE FROM {$this->db['campaign_feed']} WHERE id = {$feed} ");
         }
     }
     // Process words
     foreach ($this->campaign_data['rewrites'] as $rewrite) {
         $wpdb->query(WPOTools::insertQuery($this->db['campaign_word'], array('word' => $rewrite['origin']['search'], 'regex' => $rewrite['origin']['regex'], 'rewrite' => isset($rewrite['rewrite']), 'rewrite_to' => isset($rewrite['rewrite']) ? $rewrite['rewrite'] : '', 'relink' => isset($rewrite['relink']) ? $rewrite['relink'] : null, 'campaign_id' => $id)));
     }
     // Main
     $main = $this->campaign_data['main'];
     // Fetch author id
     $author = get_userdatabylogin($this->campaign_data['main']['author']);
     $main['authorid'] = $author->ID;
     unset($main['author']);
     // Query
     $query = WPOTools::updateQuery($this->db['campaign'], $main, 'id = ' . intval($id));
     $wpdb->query($query);
 }