Code Duplication    Length = 21-22 lines in 2 locations

code/Controllers/CMSMain.php 2 locations

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