Code Duplication    Length = 22-27 lines in 3 locations

code/Controllers/CMSMain.php 3 locations

@@ 1754-1779 (lines=26) @@
1751
     * @return HTTPResponse
1752
     * @throws HTTPResponse_Exception
1753
     */
1754
    public function delete($data, $form)
1755
    {
1756
        $id = $data['ID'];
1757
        $record = SiteTree::get()->byID($id);
1758
        if ($record && !$record->canDelete()) {
1759
            return Security::permissionFailure();
1760
        }
1761
        if (!$record || !$record->ID) {
1762
            throw new HTTPResponse_Exception("Bad record ID #$id", 404);
1763
        }
1764
1765
        // Delete record
1766
        $record->delete();
1767
1768
        $this->getResponse()->addHeader(
1769
            'X-Status',
1770
            rawurlencode(_t(
1771
                __CLASS__ . '.REMOVEDPAGEFROMDRAFT',
1772
                "Removed '{title}' from the draft site",
1773
                ['title' => $record->Title]
1774
            ))
1775
        );
1776
1777
        // Even if the record has been deleted from stage and live, it can be viewed in "archive mode"
1778
        return $this->getResponseNegotiator()->respond($this->getRequest());
1779
    }
1780
1781
    /**
1782
     * Delete this page from both live and stage
@@ 1789-1815 (lines=27) @@
1786
     * @return HTTPResponse
1787
     * @throws HTTPResponse_Exception
1788
     */
1789
    public function archive($data, $form)
1790
    {
1791
        $id = $data['ID'];
1792
        /** @var SiteTree $record */
1793
        $record = SiteTree::get()->byID($id);
1794
        if (!$record || !$record->exists()) {
1795
            throw new HTTPResponse_Exception("Bad record ID #$id", 404);
1796
        }
1797
        if (!$record->canArchive()) {
1798
            return Security::permissionFailure();
1799
        }
1800
1801
        // Archive record
1802
        $record->doArchive();
1803
1804
        $this->getResponse()->addHeader(
1805
            'X-Status',
1806
            rawurlencode(_t(
1807
                __CLASS__ . '.ARCHIVEDPAGE',
1808
                "Archived page '{title}'",
1809
                ['title' => $record->Title]
1810
            ))
1811
        );
1812
1813
        // Even if the record has been deleted from stage and live, it can be viewed in "archive mode"
1814
        return $this->getResponseNegotiator()->respond($this->getRequest());
1815
    }
1816
1817
    public function publish($data, $form)
1818
    {
@@ 1824-1845 (lines=22) @@
1821
        return $this->save($data, $form);
1822
    }
1823
1824
    public function unpublish($data, $form)
1825
    {
1826
        $className = $this->config()->get('tree_class');
1827
        /** @var SiteTree $record */
1828
        $record = DataObject::get_by_id($className, $data['ID']);
1829
1830
        if ($record && !$record->canUnpublish()) {
1831
            return Security::permissionFailure($this);
1832
        }
1833
        if (!$record || !$record->ID) {
1834
            throw new HTTPResponse_Exception("Bad record ID #" . (int)$data['ID'], 404);
1835
        }
1836
1837
        $record->doUnpublish();
1838
1839
        $this->getResponse()->addHeader(
1840
            'X-Status',
1841
            rawurlencode(_t('SilverStripe\\CMS\\Controllers\\CMSMain.REMOVEDPAGE', "Removed '{title}' from the published site", array('title' => $record->Title)))
1842
        );
1843
1844
        return $this->getResponseNegotiator()->respond($this->getRequest());
1845
    }
1846
1847
    /**
1848
     * @return HTTPResponse