nextcloud / nextcloud/server

Uninstall class and <uninstall> block ignored in Nextcloud app removal

Open
#56,690 7 comments 0 reactions 1 assignee View on GitHub

@come-nc is already working on this.

Since Nov 27, 2025.

feature: apps management
Dominant language
PHP
Stars
36.9k
Forks
5.2k
Avg merge
2d 3h
Merged PRs (30d)
713

Description

Description

I am developing a Nextcloud app (emailbridge) and trying to remove it completely, including all database tables, when the app is uninstalled.

I have tried multiple approaches:

  1. Using the <uninstall> block in info.xml with a class implementing run(array $options).
  2. Using the appinfo/uninstall.php script.

However, when I remove the app via CLI or web interface:
sudo -u www-data php occ app:remove emailbridge

  • The app is disabled and removed, but database tables remain.
  • No log messages from uninstall.php or Uninstall class appear.
Files

info.xml

<info...>
    <id>emailbridge</id>
    <name>Email Bridge</name>
    ...
    <migrations>
        <migration version="20251020">OCA\EmailBridge\Migration\Version20251020</migration>
    </migrations>
    <uninstall>
        <class>OCA\EmailBridge\AppInfo\Uninstall</class>
        <step>1</step>
    </uninstall>
</info>

appinfo/uninstall.php

<?php

if (!empty($_['keepData']) && $_['keepData'] === true) {
    return;
}

$tables = [
    'oc_emailbridge_stats',
    'oc_emailbridge_envoi',
    'oc_emailbridge_inscription',
    'oc_emailbridge_sequence',
    'oc_emailbridge_form',
    'oc_emailbridge_liste',
    'oc_emailbridge_parcours'
];

$connection = \OC::$server->getDatabaseConnection();
$logger     = \OC::$server->getLogger();

$logger->warning("EmailBridge uninstall.php : suppression des données");

foreach ($tables as $table) {
    try {
        $connection->executeStatement("DROP TABLE IF EXISTS `$table`");
        $logger->warning("EmailBridge : table supprimée → $table");
    } catch (\Throwable $e) {
        $logger->error("EmailBridge : erreur DROP $table → " . $e->getMessage());
    }
}
appinfo/Uninstall.php
<?php

namespace OCA\EmailBridge\AppInfo;

use OCP\IDBConnection;
use Psr\Log\LoggerInterface;

class Uninstall
{
    private IDBConnection $db;
    private LoggerInterface $logger;

    public function __construct(IDBConnection $db, LoggerInterface $logger)
    {
        $this->db = $db;
        $this->logger = $logger;
    }

    public function run(array $options): void
    {
        $keepData = $options['keepData'] ?? false;

        if ($keepData) {
            $this->logger->info("EmailBridge uninstall: keepData=true → aucune suppression");
            return;
        }

        $this->logger->warning("EmailBridge uninstall: déclenché (classe Uninstall)");
    }
}
Steps to reproduce
  1. Install the app either via Nextcloud App Store or manually via tar.gz.
  2. Execute CLI uninstall:
    sudo -u www-data php occ app:remove emailbridge
    or remove via the web interface.
  3. Check database tables — they remain.
  4. No log messages appear in nextcloud.log.
Expected behavior
  • Either appinfo/uninstall.php or class should execute.
  • Tables should be dropped if keepData=false.
  • Logs should appear confirming execution.
Nextcloud version
  • 32.x (tested on local instance)
  • App version: 1.0.0 béta

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.