@@ 1775-1800 (lines=26) @@ | ||
1772 | * @return HTTPResponse |
|
1773 | * @throws HTTPResponse_Exception |
|
1774 | */ |
|
1775 | public function delete($data, $form) |
|
1776 | { |
|
1777 | $id = $data['ID']; |
|
1778 | $record = SiteTree::get()->byID($id); |
|
1779 | if ($record && !$record->canDelete()) { |
|
1780 | return Security::permissionFailure(); |
|
1781 | } |
|
1782 | if (!$record || !$record->ID) { |
|
1783 | throw new HTTPResponse_Exception("Bad record ID #$id", 404); |
|
1784 | } |
|
1785 | ||
1786 | // Delete record |
|
1787 | $record->delete(); |
|
1788 | ||
1789 | $this->getResponse()->addHeader( |
|
1790 | 'X-Status', |
|
1791 | rawurlencode(_t( |
|
1792 | __CLASS__ . '.REMOVEDPAGEFROMDRAFT', |
|
1793 | "Removed '{title}' from the draft site", |
|
1794 | ['title' => $record->Title] |
|
1795 | )) |
|
1796 | ); |
|
1797 | ||
1798 | // Even if the record has been deleted from stage and live, it can be viewed in "archive mode" |
|
1799 | return $this->getResponseNegotiator()->respond($this->getRequest()); |
|
1800 | } |
|
1801 | ||
1802 | /** |
|
1803 | * Delete this page from both live and stage |
|
@@ 1810-1836 (lines=27) @@ | ||
1807 | * @return HTTPResponse |
|
1808 | * @throws HTTPResponse_Exception |
|
1809 | */ |
|
1810 | public function archive($data, $form) |
|
1811 | { |
|
1812 | $id = $data['ID']; |
|
1813 | /** @var SiteTree $record */ |
|
1814 | $record = SiteTree::get()->byID($id); |
|
1815 | if (!$record || !$record->exists()) { |
|
1816 | throw new HTTPResponse_Exception("Bad record ID #$id", 404); |
|
1817 | } |
|
1818 | if (!$record->canArchive()) { |
|
1819 | return Security::permissionFailure(); |
|
1820 | } |
|
1821 | ||
1822 | // Archive record |
|
1823 | $record->doArchive(); |
|
1824 | ||
1825 | $this->getResponse()->addHeader( |
|
1826 | 'X-Status', |
|
1827 | rawurlencode(_t( |
|
1828 | __CLASS__ . '.ARCHIVEDPAGE', |
|
1829 | "Archived page '{title}'", |
|
1830 | ['title' => $record->Title] |
|
1831 | )) |
|
1832 | ); |
|
1833 | ||
1834 | // Even if the record has been deleted from stage and live, it can be viewed in "archive mode" |
|
1835 | return $this->getResponseNegotiator()->respond($this->getRequest()); |
|
1836 | } |
|
1837 | ||
1838 | public function publish($data, $form) |
|
1839 | { |
|
@@ 1845-1866 (lines=22) @@ | ||
1842 | return $this->save($data, $form); |
|
1843 | } |
|
1844 | ||
1845 | public function unpublish($data, $form) |
|
1846 | { |
|
1847 | $className = $this->config()->get('tree_class'); |
|
1848 | /** @var SiteTree $record */ |
|
1849 | $record = DataObject::get_by_id($className, $data['ID']); |
|
1850 | ||
1851 | if ($record && !$record->canUnpublish()) { |
|
1852 | return Security::permissionFailure($this); |
|
1853 | } |
|
1854 | if (!$record || !$record->ID) { |
|
1855 | throw new HTTPResponse_Exception("Bad record ID #" . (int)$data['ID'], 404); |
|
1856 | } |
|
1857 | ||
1858 | $record->doUnpublish(); |
|
1859 | ||
1860 | $this->getResponse()->addHeader( |
|
1861 | 'X-Status', |
|
1862 | rawurlencode(_t('SilverStripe\\CMS\\Controllers\\CMSMain.REMOVEDPAGE', "Removed '{title}' from the published site", array('title' => $record->Title))) |
|
1863 | ); |
|
1864 | ||
1865 | return $this->getResponseNegotiator()->respond($this->getRequest()); |
|
1866 | } |
|
1867 | ||
1868 | /** |
|
1869 | * @return HTTPResponse |