Delete sql table after plugin uninstallation

  • Hello,


    i just created a plugin which create a table on the database, but this table is not deleted when i uninstall this plugin.


    Do you have an idea for this ?


    Thanks

  • Please show us the install.sql file. Normally it should throw an exception if it does not know how to destroy it.

    return null;


    Browser: Firefox Nightly (64bit)

    Betriebssystem: Windows 10

  • Hello,


    thank you.


    My install.sql file is pretty simple, and contain only one line :


    INSERT INTO `wcf1_language` (`languageID`, `languageCode`, `languageName`, `countryCode`, `isDefault`, `hasContent`, `isDisabled`) VALUES (NULL, 'fr', 'Français', 'it', '0', '0', '0');

  • To delete a database table row during uninstallation you need to create a php file under files\acp\uninstall\ and name it after your package identifier e.g.

    files\acp\uninstall\com.example.package.php. In order to delete the row you need to put the following code into the php file.


    PHP
    <?php
    use wcf\system\WCF;
    $sql = "DELETE FROM wcf".WCF_N."_language
    WHERE languageCode = ?";
    $statement = WCF::getDB()->prepareStatement($sql);
    $statement->execute(['fr']);
  • You actually did not create a table in the database but rather inserted a row in the wcf1_language table. INSERT operations are not reversed by the system after uninstalling a package. I am also not sure if you should really remove the row again but you can use a uninstall PHP script to delete the row: If your package is called com.example.wcf.french, deliver a file acp/uninstall/com.example.wcf.french.php using the file package installation plugin in which you can use PHP to delete the row.


    Also: You do not need the backticks ` here.


    PS: Way too slow writing this post :sleeping:

  • I succeeded to delete the language when i uninstall the plugin, but only if i know the exact ID..


    But i don't know how to get the correct ID of this language, so i tried ti use another column (languageCode, or countryName for example), but it doens't work ( error cannot prepare statement)


    Any idea for this ?


    Thanks :)

  • \wcf\system\language\LanguageFactory::getInstance()->getLanguageByCode('fr')->languageID;

    Thank you !

    But i don't know how to insert it in my code :


    PHP
    <?php
    use wcf\system\WCF;
    $sql = "DELETE FROM wcf".WCF_N."_language WHERE languageCode = ?";
    $statement = WCF::getDB()--->prepareStatement($sql);
    $statement->execute(['fr']);

    This actual code seems worked, it deleted the concerned language.


    Thanks :)

  • To delete a database table row during uninstallation you need to create a php file under files\acp\uninstall\ and name it after your package identifier e.g.

    files\acp\uninstall\com.example.package.php. In order to delete the row you need to put the following code into the php file.


    PHP
    <?php
    use wcf\system\WCF;
    $sql = "DELETE FROM wcf".WCF_N."_language
    WHERE languageCode = ?";
    $statement = WCF::getDB()->prepareStatement($sql);
    $statement->execute(['fr']);

    It's exactly that, i didn't read your message attentively :P. Thank you very much !

  • This actual code seems worked, it deleted the concerned language.

    I thought you had something like DELETE FROM [...] WHERE languageID = 1 with a hard-coded ID. The code is correct.

    The code I postes gives you the ID of the language matching the fr language code.

  • I thought you had something like DELETE FROM [...] WHERE languageID = 1 with a hard-coded ID. The code is correct.

    The code I postes gives you the ID of the language matching the fr language code.

    Yes i had this code like that, but didn't work (and i don't know how to use your solution), so by adding "?" and "fr" in statement execute, it works great.


    Could you explain me please ? So i'll learn another thing :)

  • Whatever you do, DO NOT create a language by inserting a new row into wcf1_language, all the variables will be missing and will cause major disruption among the phrase-related tools.


    You must add the language through your ACP to have it properly created and populated.

    Alexander Ebert
    Senior Developer WoltLab® GmbH

  • Whatever you do, DO NOT create a language by inserting a new row into wcf1_language, all the variables will be missing and will cause major disruption among the phrase-related tools.


    You must add the language through your ACP to have it properly created and populated.

    Ok, so there is no properly way to add a language without using the ACP ?