Code Duplication    Length = 21-22 lines in 2 locations

code/Controllers/CMSMain.php 2 locations

@@ 1285-1305 (lines=21) @@
1282
     * @return HTTPResponse
1283
     * @throws HTTPResponse_Exception
1284
     */
1285
    public function delete($data, $form)
1286
    {
1287
        $id = $data['ID'];
1288
        $record = SiteTree::get()->byID($id);
1289
        if ($record && !$record->canDelete()) {
1290
            return Security::permissionFailure();
1291
        }
1292
        if (!$record || !$record->ID) {
1293
            throw new HTTPResponse_Exception("Bad record ID #$id", 404);
1294
        }
1295
1296
        // Delete record
1297
        $record->delete();
1298
1299
        $this->getResponse()->addHeader(
1300
            'X-Status',
1301
            rawurlencode(sprintf(_t('CMSMain.REMOVEDPAGEFROMDRAFT', "Removed '%s' from the draft site"), $record->Title))
1302
        );
1303
1304
        // Even if the record has been deleted from stage and live, it can be viewed in "archive mode"
1305
        return $this->getResponseNegotiator()->respond($this->getRequest());
1306
    }
1307
1308
    /**
@@ 1316-1337 (lines=22) @@
1313
     * @return HTTPResponse
1314
     * @throws HTTPResponse_Exception
1315
     */
1316
    public function archive($data, $form)
1317
    {
1318
        $id = $data['ID'];
1319
        /** @var SiteTree $record */
1320
        $record = SiteTree::get()->byID($id);
1321
        if (!$record || !$record->exists()) {
1322
            throw new HTTPResponse_Exception("Bad record ID #$id", 404);
1323
        }
1324
        if (!$record->canArchive()) {
1325
            return Security::permissionFailure();
1326
        }
1327
1328
        // Archive record
1329
        $record->doArchive();
1330
1331
        $this->getResponse()->addHeader(
1332
            'X-Status',
1333
            rawurlencode(sprintf(_t('CMSMain.ARCHIVEDPAGE', "Archived page '%s'"), $record->Title))
1334
        );
1335
1336
        // Even if the record has been deleted from stage and live, it can be viewed in "archive mode"
1337
        return $this->getResponseNegotiator()->respond($this->getRequest());
1338
    }
1339
1340
    public function publish($data, $form)