Code Duplication    Length = 21-22 lines in 2 locations

code/Controllers/CMSMain.php 2 locations

@@ 1158-1178 (lines=21) @@
1155
	 * @return HTTPResponse
1156
	 * @throws HTTPResponse_Exception
1157
	 */
1158
	public function delete($data, $form) {
1159
		$id = $data['ID'];
1160
		$record = SiteTree::get()->byID($id);
1161
		if($record && !$record->canDelete()) {
1162
			return Security::permissionFailure();
1163
		}
1164
		if(!$record || !$record->ID) {
1165
			throw new HTTPResponse_Exception("Bad record ID #$id", 404);
1166
		}
1167
1168
		// Delete record
1169
		$record->delete();
1170
1171
		$this->getResponse()->addHeader(
1172
			'X-Status',
1173
			rawurlencode(sprintf(_t('CMSMain.REMOVEDPAGEFROMDRAFT',"Removed '%s' from the draft site"), $record->Title))
1174
		);
1175
1176
		// Even if the record has been deleted from stage and live, it can be viewed in "archive mode"
1177
		return $this->getResponseNegotiator()->respond($this->getRequest());
1178
	}
1179
1180
	/**
1181
	 * Delete this page from both live and stage
@@ 1188-1209 (lines=22) @@
1185
	 * @return HTTPResponse
1186
	 * @throws HTTPResponse_Exception
1187
	 */
1188
	public function archive($data, $form) {
1189
		$id = $data['ID'];
1190
		/** @var SiteTree $record */
1191
		$record = SiteTree::get()->byID($id);
1192
		if(!$record || !$record->exists()) {
1193
			throw new HTTPResponse_Exception("Bad record ID #$id", 404);
1194
		}
1195
		if(!$record->canArchive()) {
1196
			return Security::permissionFailure();
1197
		}
1198
1199
		// Archive record
1200
		$record->doArchive();
1201
1202
		$this->getResponse()->addHeader(
1203
			'X-Status',
1204
			rawurlencode(sprintf(_t('CMSMain.ARCHIVEDPAGE',"Archived page '%s'"), $record->Title))
1205
		);
1206
1207
		// Even if the record has been deleted from stage and live, it can be viewed in "archive mode"
1208
		return $this->getResponseNegotiator()->respond($this->getRequest());
1209
	}
1210
1211
	public function publish($data, $form) {
1212
		$data['publish'] = '1';