1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Uninstall Error

Discussion in 'XenForo Development Discussions' started by Robust, May 4, 2015.

  1. Robust

    Robust Well-Known Member

    So, I installed the add-on but it didn't alter the tables, so I'm trying to uninstall it and made some changes for it to work hopefully. It's giving an error now

    Code:
    Mysqli prepare error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'bestanswer' at line 1
    
    Zend_Db_Statement_Mysqli->_prepare() in /Applications/MAMP/htdocs/xenforo/library/Zend/Db/Statement.php at line 115
    Zend_Db_Statement->__construct() in /Applications/MAMP/htdocs/xenforo/library/Zend/Db/Adapter/Mysqli.php at line 381
    Zend_Db_Adapter_Mysqli->prepare() in /Applications/MAMP/htdocs/xenforo/library/Zend/Db/Adapter/Abstract.php at line 478
    Zend_Db_Adapter_Abstract->query() in /Applications/MAMP/htdocs/xenforo/library/Zend/Db/Adapter/Abstract.php at line 825
    Zend_Db_Adapter_Abstract->fetchOne() in /Applications/MAMP/htdocs/xenforo/library/BestAnswer/Installer.php at line 57
    BestAnswer_Installer::uninstall()
    call_user_func() in /Applications/MAMP/htdocs/xenforo/library/XenForo/DataWriter/AddOn.php at line 200
    XenForo_DataWriter_AddOn->_postDelete() in /Applications/MAMP/htdocs/xenforo/library/XenForo/DataWriter.php at line 1779
    XenForo_DataWriter->delete() in /Applications/MAMP/htdocs/xenforo/library/XenForo/ControllerAdmin/AddOn.php at line 122
    XenForo_ControllerAdmin_AddOn->actionDelete() in /Applications/MAMP/htdocs/xenforo/library/XenForo/FrontController.php at line 347
    XenForo_FrontController->dispatch() in /Applications/MAMP/htdocs/xenforo/library/XenForo/FrontController.php at line 134
    XenForo_FrontController->run() in /Applications/MAMP/htdocs/xenforo/admin.php at line 13
    PHP:
    <?php

    class BestAnswer_Installer
    {
        protected static 
    $_alters = array(
            array(
                
    'checkColumnExists' => 'SHOW COLUMNS FROM `xf_thread` LIKE bestanswer',
                
    'install' => 'ALTER TABLE `xf_thread` ADD COLUMN bestanswer int(10) unsigned',
                
    'uninstall' => 'ALTER TABLE `xf_thread` DROP COLUMN bestanswer'
            
    ),
            array(
                
    'checkColumnExists' => 'SHOW COLUMNS FROM `xf_user` LIKE bestanswers',
                
    'install' => 'ALTER TABLE `xf_user` ADD COLUMN bestanswers int(10) UNSIGNED NOT NULL DEFAULT 0',
                
    'uninstall' => 'ALTER TABLE `xf_user` DROP COLUMN bestanswers'
            
    )
        );

        public static function 
    install()
        {
            
    $db XenForo_Application::getDb();

            foreach(
    self::$_alters as $alter)
            {
                
    $checkColumnExists $db->fetchOne($alter['checkColumnExists']);
                if(empty(
    $checkColumnExists))
                {
                    
    $db->query($alter['install']);
                }
            }

            foreach(
    self::$_tables as $table)
            {
                
    $db->query($table['install']);
            }
        }

        public static function 
    uninstall()
        {
            
    $db XenForo_Application::getDb();

            foreach(
    self::$_alters as $alter)
            {
                
    $checkColumnExists $db->fetchOne($alter['checkColumnExists']);
                if(!empty(
    $checkColumnExists))
                {
                    
    $db->query($alter['uninstall']);
                }
            }

            foreach(
    self::$_tables as $table)
            {
                
    $db->query($table['uninstall']);
            }
        }
    }
    I might be overlooking something, but I don't see what's wrong.
     
  2. Chris D

    Chris D XenForo Developer Staff Member

    You are looping through a $_tables property that doesn't exist. But the error is happening near 'bestanswer' the syntax there isn't valid. Should be LIKE 'bestanswer' (note the quotes around bestanswer)
     
    Robust likes this.
  3. Robust

    Robust Well-Known Member

    Fixed, I noticed it at about the same time as you posted. The tables field I still need to code up. I was upgrading my development installation to 1.4.6 from 1.4.3 (I think) and I hit replace all, thinking it would replace files that already exist. Boy, was that wrong. It replaced the entire library folder with a new library folder, so I lost all of the code with it. So it's all from scratch again. Guess that's better though, some parts of my old code were horribly inefficient, should be better this time around.
     
  4. Chris D

    Chris D XenForo Developer Staff Member

    Mac right?

    How Apple fixed the horribly ridiculous copy files/replace files system in Finder I'll never know.

    For future reference there is a terminal command "ditto" that copies the files from one directory to another and overwrites duplicates only e.g it works how you would expect Finder to.l (and how Windows has worked forever).
     
  5. Robust

    Robust Well-Known Member

    Yeah, Mac. I tried recovery software after as well (little luck), I really didn't know if I wanted to bother with it again. Few days later, started it again. I hate doing the exact same thing again if I've done it recently. I was considering placing my add-ons in my Documents and symlink them to /library in XenForo, but that didn't really work out the way I imagined. 'ditto' should do the trick next time. I really don't understand why the wording is so poor on the dialog and why on earth it even works like that.
     

Share This Page