Code Duplication    Length = 21-22 lines in 2 locations

code/Controllers/CMSMain.php 2 locations

@@ 1699-1719 (lines=21) @@
1696
     * @return HTTPResponse
1697
     * @throws HTTPResponse_Exception
1698
     */
1699
    public function delete($data, $form)
1700
    {
1701
        $id = $data['ID'];
1702
        $record = SiteTree::get()->byID($id);
1703
        if ($record && !$record->canDelete()) {
1704
            return Security::permissionFailure();
1705
        }
1706
        if (!$record || !$record->ID) {
1707
            throw new HTTPResponse_Exception("Bad record ID #$id", 404);
1708
        }
1709
1710
        // Delete record
1711
        $record->delete();
1712
1713
        $this->getResponse()->addHeader(
1714
            'X-Status',
1715
            rawurlencode(sprintf(_t('SilverStripe\\CMS\\Controllers\\CMSMain.REMOVEDPAGEFROMDRAFT', "Removed '%s' from the draft site"), $record->Title))
1716
        );
1717
1718
        // Even if the record has been deleted from stage and live, it can be viewed in "archive mode"
1719
        return $this->getResponseNegotiator()->respond($this->getRequest());
1720
    }
1721
1722
    /**
@@ 1730-1751 (lines=22) @@
1727
     * @return HTTPResponse
1728
     * @throws HTTPResponse_Exception
1729
     */
1730
    public function archive($data, $form)
1731
    {
1732
        $id = $data['ID'];
1733
        /** @var SiteTree $record */
1734
        $record = SiteTree::get()->byID($id);
1735
        if (!$record || !$record->exists()) {
1736
            throw new HTTPResponse_Exception("Bad record ID #$id", 404);
1737
        }
1738
        if (!$record->canArchive()) {
1739
            return Security::permissionFailure();
1740
        }
1741
1742
        // Archive record
1743
        $record->doArchive();
1744
1745
        $this->getResponse()->addHeader(
1746
            'X-Status',
1747
            rawurlencode(sprintf(_t('SilverStripe\\CMS\\Controllers\\CMSMain.ARCHIVEDPAGE', "Archived page '%s'"), $record->Title))
1748
        );
1749
1750
        // Even if the record has been deleted from stage and live, it can be viewed in "archive mode"
1751
        return $this->getResponseNegotiator()->respond($this->getRequest());
1752
    }
1753
1754
    public function publish($data, $form)