mirror of
https://github.com/FOSSBilling/FOSSBilling.git
synced 2026-11-30 12:18:43 +09:00
Remove spamchecker extension row (#3637)
This commit is contained in:
1 parent
3bd35f5b29
commit
6c0fc7ead4
2 files changed
+73
-5
No files matched your search
@@ -1048,11 +1048,7 @@ class UpdatePatcher implements InjectionAwareInterface
|
||||
|
||||
$this->executeSql("DELETE FROM extension_meta WHERE extension = 'mod_spamchecker' AND meta_key = 'config'");
|
||||
|
||||
$spamcheckerExt = $extService->findExtension('mod', 'spamchecker');
|
||||
if ($spamcheckerExt instanceof \Model_Extension) {
|
||||
$extService->deactivate($spamcheckerExt);
|
||||
$extService->uninstall('mod', 'spamchecker');
|
||||
}
|
||||
$this->executeSql("DELETE FROM extension WHERE type = 'mod' AND name = 'spamchecker'");
|
||||
|
||||
$this->di['cache']->delete('config_mod_spamchecker');
|
||||
$this->di['cache']->delete('config_mod_antispam');
|
||||
|
||||
@@ -33,4 +33,76 @@ final class UpdatePatcherTest extends PHPUnit\Framework\TestCase
|
||||
self::assertSame($di['pdo'], $pdo);
|
||||
self::assertFalse($di->offsetExists('dbal'));
|
||||
}
|
||||
|
||||
public function testSpamcheckerPatchRemovesExtensionRecordWithoutUninstallingModule(): void
|
||||
{
|
||||
$pdo = new PDO('sqlite::memory:');
|
||||
$pdo->exec('CREATE TABLE extension (type TEXT, name TEXT)');
|
||||
$pdo->exec('CREATE TABLE extension_meta (extension TEXT, rel_type TEXT, rel_id TEXT, meta_key TEXT, meta_value TEXT)');
|
||||
$pdo->exec("INSERT INTO extension (type, name) VALUES ('mod', 'spamchecker')");
|
||||
|
||||
$extensionService = new class {
|
||||
public array $savedConfig = [];
|
||||
|
||||
public function getConfig(string $extension): array
|
||||
{
|
||||
return match ($extension) {
|
||||
'mod_spamchecker' => [
|
||||
'ext' => 'mod_spamchecker',
|
||||
'captcha_enabled' => true,
|
||||
],
|
||||
'mod_antispam' => [
|
||||
'ext' => 'mod_antispam',
|
||||
],
|
||||
default => ['ext' => $extension],
|
||||
};
|
||||
}
|
||||
|
||||
public function setConfig(array $data): bool
|
||||
{
|
||||
$this->savedConfig = $data;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function __call(string $name, array $arguments): mixed
|
||||
{
|
||||
throw new RuntimeException("Unexpected extension service call: {$name}");
|
||||
}
|
||||
};
|
||||
|
||||
$hookService = new class {
|
||||
public function batchConnect(string $module): void
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
$cache = new class {
|
||||
public function delete(string $key): void
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
$di = new Pimple\Container();
|
||||
$di['pdo'] = $pdo;
|
||||
$di['mod_service'] = $di->protect(fn (string $module): object => match ($module) {
|
||||
'extension' => $extensionService,
|
||||
'hook' => $hookService,
|
||||
});
|
||||
$di['cache'] = $cache;
|
||||
|
||||
$patcher = new UpdatePatcher();
|
||||
$patcher->setDi($di);
|
||||
|
||||
$method = new ReflectionMethod(UpdatePatcher::class, 'patch55');
|
||||
$method->invoke($patcher);
|
||||
|
||||
$remainingSpamcheckerExtensions = $pdo
|
||||
->query("SELECT COUNT(*) FROM extension WHERE type = 'mod' AND name = 'spamchecker'")
|
||||
->fetchColumn();
|
||||
|
||||
self::assertSame(0, (int) $remainingSpamcheckerExtensions);
|
||||
self::assertSame('mod_antispam', $extensionService->savedConfig['ext']);
|
||||
self::assertTrue($extensionService->savedConfig['captcha_enabled']);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user