SeoPanel - Removing Plugins

Discuss about Seo Panel development - classes,plugins,common function etc

Moderators: hellow0rld, eugene, sendtogeo

SeoPanel - Removing Plugins

Postby Sidriel » Thu Mar 10, 2016 1:14 am

Developing plugins for SeoPanel led to quite a bit of trial runs to get the Plugin Installation functionality perfected, in doing this, I found it way too tedious to have to edit the database each time I wanted to completely wipe a plugin and re-install it. In addition, as the plugins catalog grows it may be beneficial to have a system of deleting plugins without a need to touch the database, below is the method I took to extend the inherent functionality and add plugin removal.

seo-plugins-manager.php - Line 64
Code: Select all
      case "reinstall":
         $controller->reInstallSeoPlugin($_GET['pid']);
         break;
           
      case "delete":
         $controller->deleteSeoPlugin($_GET['pid']);
         break;

      default:
         $controller->listSeoPlugins();
         break;

Defines Handler for 'delete'

/themes/theme/views/seoplugins/listplugins.ctp.php - Line 45 (Doesn't utilize the `texts` database for translation :oops: )
Code: Select all
                  <option value="upgrade"><?=$spText['label']['Upgrade']?></option>
                  <option value="reinstall"><?=$spText['label']['Re-install']?></option>
                  <option value="delete">Remove</option>
               </select>

Implement option to trigger 'delete'

/controllers/seoplugins.ctrl.php - Within Class wrapper
Code: Select all
    function removePluginInfo($pluginId){      
        $pluginId = intval($pluginId);
        $sql = "delete from seoplugins
            where id=$pluginId";
        $this->db->query($sql);
    }

    function removePluginFiles($dir){
        if (is_dir($dir)) {
            $objects = scandir($dir);
            foreach ($objects as $object) {
                if ($object != "." && $object != "..") {
                    if (filetype($dir."/".$object) == "dir") {
                        $this->removePluginFiles($dir."/".$object);
                    } else {
                        unlink($dir."/".$object);
                    }
                }
            }
            reset($objects);
            rmdir($dir);
        } else {
            return 'FAIL';
        }
    }

    function deleteSeoPlugin($pluginId){
      $pluginInfo = $this->__getSeoPluginInfo($pluginId);
              
        if(file_exists(SP_PLUGINPATH."/".$pluginInfo['name'])){
            $this->removePluginInfo($pluginId);
            $fileStatus = $this->removePluginFiles(SP_PLUGINPATH."/".$pluginInfo['name']);
           
            # parse plugin info
            $pluginInfo = $this->parsePluginInfoFile($pluginInfo['name']);
           
            if ($fileStatus === 'FAIL') {
                $this->__changeInstallStatus($pluginId, 0);
                $this->listSeoPlugins("Plugin <b>{$pluginInfo['label']}</b> removal failed!", true);
                return false;
            }
           
            $this->listSeoPlugins("Plugin <b>{$pluginInfo['label']}</b> removed successfully!");   
        }else{
            $this->__changeInstallStatus($pluginId, 0);
            $this->listSeoPlugins("Plugin <b>{$pluginInfo['label']}</b> removal failed!", true);
        }
    }

Define function to remove a plugin from the database, this does not remove table associated with that plugin.
Define function to remove a plugin directory.
Define function to carry out Database and File operations and handle errors.

Until a native handle is added to the SeoPanel core, this seems to be the easiest, and most effective "fix" for the missing feature. Hopefully it helps.
Sidriel
 
Posts: 1
Joined: Wed Mar 09, 2016 2:44 am

Re: SeoPanel - Removing Plugins

Postby kamild » Wed Jul 13, 2016 7:53 am

It helps. Thanx a lot for it :)
kamild
 
Posts: 3
Joined: Wed Jul 13, 2016 7:38 am

Re: SeoPanel - Removing Plugins

Postby seopanel_forum » Fri Jul 22, 2016 7:52 pm

Thanks a lot for the suggestion and fix.

We will add it in next version.

Thanks for the support.
Thanks,
Seo Panel Team
http://www.seopanel.in
seopanel_forum
Site Admin
 
Posts: 1354
Joined: Sat Apr 17, 2010 6:42 pm
Location: India

Re: SeoPanel - Removing Plugins

Postby seopanel_forum » Fri Jul 22, 2016 7:53 pm

https://github.com/seopanel/Seo-Panel/issues/55
Thanks,
Seo Panel Team
http://www.seopanel.in
seopanel_forum
Site Admin
 
Posts: 1354
Joined: Sat Apr 17, 2010 6:42 pm
Location: India


Return to Seo Panel Development

Who is online

Users browsing this forum: No registered users and 1 guest