{"record":{"id":"77f3e24171b88bdc","repo":"nextcloud/server","slug":"can-not-restore-calendar-id-because-a-calendar-ob","errorCode":null,"errorMessage":"Can not restore calendar $id because a calendar object with the URI $restoreUri already exists","messagePattern":"Can not restore calendar \\$id because a calendar object with the URI \\$restoreUri already exists","errorType":"exception","errorClass":"Sabre\\DAV\\Exception\\Forbidden","httpStatus":403,"severity":"error","filePath":"apps/dav/lib/CalDAV/CalDavBackend.php","lineNumber":1866,"sourceCode":"\t\t}, $this->db);\n\t}\n\n\t/**\n\t * @param mixed $objectData\n\t *\n\t * @throws Forbidden\n\t */\n\tpublic function restoreCalendarObject(array $objectData): void {\n\t\t$this->cachedObjects = [];\n\t\t$this->atomic(function () use ($objectData): void {\n\t\t\t$id = (int)$objectData['id'];\n\t\t\t$restoreUri = str_replace('-deleted.ics', '.ics', $objectData['uri']);\n\t\t\t$targetObject = $this->getCalendarObject(\n\t\t\t\t$objectData['calendarid'],\n\t\t\t\t$restoreUri\n\t\t\t);\n\t\t\tif ($targetObject !== null) {\n\t\t\t\tthrow new Forbidden(\"Can not restore calendar $id because a calendar object with the URI $restoreUri already exists\");\n\t\t\t}\n\n\t\t\t$qb = $this->db->getQueryBuilder();\n\t\t\t$update = $qb->update('calendarobjects')\n\t\t\t\t->set('uri', $qb->createNamedParameter($restoreUri))\n\t\t\t\t->set('deleted_at', $qb->createNamedParameter(null))\n\t\t\t\t->where($qb->expr()->eq('id', $qb->createNamedParameter($id, IQueryBuilder::PARAM_INT), IQueryBuilder::PARAM_INT));\n\t\t\t$update->executeStatement();\n\n\t\t\t// Make sure this change is tracked in the changes table\n\t\t\t$qb2 = $this->db->getQueryBuilder();\n\t\t\t$selectObject = $qb2->select('calendardata', 'uri', 'calendarid', 'calendartype')\n\t\t\t\t->selectAlias('componenttype', 'component')\n\t\t\t\t->from('calendarobjects')\n\t\t\t\t->where($qb2->expr()->eq('id', $qb2->createNamedParameter($id, IQueryBuilder::PARAM_INT), IQueryBuilder::PARAM_INT));\n\t\t\t$result = $selectObject->executeQuery();\n\t\t\t$row = $result->fetchAssociative();\n\t\t\t$result->closeCursor();","sourceCodeStart":1848,"sourceCodeEnd":1884,"githubUrl":"https://github.com/nextcloud/server/blob/ecdeb153ffdf227235c9a7e2d13dbe0f9c817bc3/apps/dav/lib/CalDAV/CalDavBackend.php#L1848-L1884","documentation":"Error \"Can not restore calendar $id because a calendar object with the URI $restoreUri already exists\" thrown in nextcloud/server.","triggerScenarios":"Thrown at apps/dav/lib/CalDAV/CalDavBackend.php:1866 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"ecdeb153ffdf227235c9a7e2d13dbe0f9c817bc3","analyzedAt":"2026-08-17T01:36:13.386Z","schemaVersion":2},"datasetVersion":"2026-08-17T04:17:16.089Z"}