Uninstall class and <uninstall> block ignored in Nextcloud app removal
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:
- Using the
<uninstall>block ininfo.xmlwith a class implementingrun(array $options). - Using the
appinfo/uninstall.phpscript.
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
- Install the app either via Nextcloud App Store or manually via tar.gz.
- Execute CLI uninstall: sudo -u www-data php occ app:remove emailbridge or remove via the web interface.
- Check database tables — they remain.
- 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
See https://github.com/nextcloud/server/issues/5539
<migrations>
<migration version="20251020">OCA\EmailBridge\Migration\Version20251020</migration>
</migrations>
<uninstall>
<class>OCA\EmailBridge\AppInfo\Uninstall</class>
<step>1</step>
</uninstall>
uninstall should be under repair-steps like here AFAIK: https://github.com/nextcloud/server/blob/673815b86aa146dad5a4b9e6603a8f5cbc79da6d/apps/user_ldap/appinfo/info.xml#L45-L47
Though there may be some user experience surprises since it'll run by default; some apps implement an explicit command for wiping data.
As said by @joshtrichards and can be seen in the documentation at https://docs.nextcloud.com/server/latest/developer_manual/app_development/info.html , the <uninstall> bloc is under the <repair-steps> bloc. Also your class should implement \OCP\Migration\IRepairStep.
appinfo/uninstall.php is not a thing, I cannot find any reference in the documentation, maybe it existed in the past, not sure where you found a reference to that. But this is not something that Nextcloud supports.
Okay, thanks for your feedback.
So I implemented the <repair-steps> interface and removed all references to uninstall. But where did I find that information? It's a long story...
<repair-steps>
<uninstall>
<step>OCA\EmailBridge\Migration\MyRepairStep</step>
</uninstall>
</repair-steps>
Anyway, I can't seem to use the checkbox correctly to delete or not delete data when the app is uninstalled. With this method, whether it's active or not makes no difference; the data is either erased when I place my repair-step, or it remains if the code isn't there.
Which checkbox? The step should get executed when the app is disabled.
The checkbox "Delete data during uninstallation" appears when you deactivate an app. It's not completely removed. There's a step involved in deleting or reactivating the app. You can check it at that point. I can't get this function to work properly.
The checkbox "Delete data during uninstallation" appears when you deactivate an app. It's not completely removed. There's a step involved in deleting or reactivating the app. You can check it at that point. I can't get this function to work properly.
Ah, I found it. This checkbox was added in https://github.com/nextcloud/server/pull/48665 but I believe it’s specific to app_api it should not show up for normal applications. @julien-nc Can you look into this?