Changeset 1153


Ignore:
Timestamp:
02/11/10 14:13:55 (3 years ago)
Author:
nick_ramsay
Message:

[Branch 1.0] Re: Ticket #103 Fix for plugin order being reset when upgrading it (needs testing!)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/1.0/libs/PluginManagement.php

    r1113 r1153  
    275275            return false; 
    276276        } 
    277                      
    278         $sql = "REPLACE INTO " . TABLE_PLUGINS . " (plugin_enabled, plugin_name, plugin_folder, plugin_class, plugin_extends, plugin_type, plugin_desc, plugin_requires, plugin_version, plugin_author, plugin_authorurl, plugin_updateby) VALUES (%d, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %d)"; 
    279         $h->db->query($h->db->prepare($sql, $h->plugin->enabled, $h->plugin->name, $h->plugin->folder, $h->plugin->class, $h->plugin->extends, $h->plugin->type, $h->plugin->desc, $h->plugin->requires, $h->plugin->version, $h->plugin->author, urlencode($h->plugin->authorurl), $h->currentUser->id)); 
    280  
    281         // Get the last order number - doing this after REPLACE INTO because  
    282         // we don't know whether the above will insert or replace. 
    283         $sql = "SELECT plugin_order FROM " . TABLE_PLUGINS . " ORDER BY plugin_order DESC LIMIT 1"; 
    284         $highest_order = $h->db->get_var($h->db->prepare($sql)); 
    285  
    286         // Give the new plugin the order number + 1 
    287         $sql = "UPDATE " . TABLE_PLUGINS . " SET plugin_order = %d WHERE plugin_id = LAST_INSERT_ID()"; 
    288         $h->db->query($h->db->prepare($sql, ($highest_order + 1))); 
     277 
     278        // set a new plugin order if NOT upgrading 
     279        if ($upgrade == 0) { 
     280         
     281            $sql = "REPLACE INTO " . TABLE_PLUGINS . " (plugin_enabled, plugin_name, plugin_folder, plugin_class, plugin_extends, plugin_type, plugin_desc, plugin_requires, plugin_version, plugin_author, plugin_authorurl, plugin_updateby) VALUES (%d, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %d)"; 
     282            $h->db->query($h->db->prepare($sql, $h->plugin->enabled, $h->plugin->name, $h->plugin->folder, $h->plugin->class, $h->plugin->extends, $h->plugin->type, $h->plugin->desc, $h->plugin->requires, $h->plugin->version, $h->plugin->author, urlencode($h->plugin->authorurl), $h->currentUser->id)); 
     283 
     284            // Get the last order number - doing this after REPLACE INTO because  
     285            // we don't know whether the above will insert or replace. 
     286            $sql = "SELECT plugin_order FROM " . TABLE_PLUGINS . " ORDER BY plugin_order DESC LIMIT 1"; 
     287            $highest_order = $h->db->get_var($h->db->prepare($sql)); 
     288     
     289            // Give the new plugin the order number + 1 
     290            $sql = "UPDATE " . TABLE_PLUGINS . " SET plugin_order = %d WHERE plugin_id = LAST_INSERT_ID()"; 
     291            $h->db->query($h->db->prepare($sql, ($highest_order + 1))); 
     292        } else { 
     293            // upgrading: 
     294            $sql = "UPDATE " . TABLE_PLUGINS . " SET plugin_enabled = %d, plugin_name = %s, plugin_folder = %s, plugin_class = %s, plugin_extends = %s, plugin_type = %s, plugin_desc = %s, plugin_requires = %s, plugin_version = %s, plugin_author = %s, plugin_authorurl = %s, plugin_updateby = %d WHERE plugin_folder = %s"; 
     295            $h->db->query($h->db->prepare($sql, $h->plugin->enabled, $h->plugin->name, $h->plugin->folder, $h->plugin->class, $h->plugin->extends, $h->plugin->type, $h->plugin->desc, $h->plugin->requires, $h->plugin->version, $h->plugin->author, urlencode($h->plugin->authorurl), $h->currentUser->id, $h->plugin->folder)); 
     296        } 
    289297         
    290298        // Add any plugin hooks to the hooks table 
     
    405413        $h->deleteFiles(CACHE . 'css_js_cache'); 
    406414 
    407         $h->db->query($h->db->prepare("DELETE FROM " . TABLE_PLUGINS . " WHERE plugin_folder = %s", $h->plugin->folder)); 
     415        if ($upgrade == 0) { // don't delete plugin when we're upgrading 
     416            $h->db->query($h->db->prepare("DELETE FROM " . TABLE_PLUGINS . " WHERE plugin_folder = %s", $h->plugin->folder)); 
     417        } 
     418         
    408419        $h->db->query($h->db->prepare("DELETE FROM " . TABLE_PLUGINHOOKS . " WHERE plugin_folder = %s", $h->plugin->folder)); 
    409420         
     
    590601            // If file version is newer the the current plugin version, then upgrade... 
    591602            if (version_compare($file_version, $db_version, '>')) { 
    592                 $this->upgrade($h); // runs the install function ans hows "upgraded!" message instead of "installed". 
     603                $this->upgrade($h); // runs the install function and shows "upgraded!" message instead of "installed". 
    593604            } else { 
    594605                // else simply show an activated message... 
Note: See TracChangeset for help on using the changeset viewer.