Code Duplication    Length = 21-22 lines in 2 locations

code/Controllers/CMSMain.php 2 locations

@@ 1213-1233 (lines=21) @@
1210
	 * @return HTTPResponse
1211
	 * @throws HTTPResponse_Exception
1212
	 */
1213
	public function delete($data, $form) {
1214
		$id = $data['ID'];
1215
		$record = SiteTree::get()->byID($id);
1216
		if($record && !$record->canDelete()) {
1217
			return Security::permissionFailure();
1218
		}
1219
		if(!$record || !$record->ID) {
1220
			throw new HTTPResponse_Exception("Bad record ID #$id", 404);
1221
		}
1222
1223
		// Delete record
1224
		$record->delete();
1225
1226
		$this->getResponse()->addHeader(
1227
			'X-Status',
1228
			rawurlencode(sprintf(_t('CMSMain.REMOVEDPAGEFROMDRAFT',"Removed '%s' from the draft site"), $record->Title))
1229
		);
1230
1231
		// Even if the record has been deleted from stage and live, it can be viewed in "archive mode"
1232
		return $this->getResponseNegotiator()->respond($this->getRequest());
1233
	}
1234
1235
	/**
1236
	 * Delete this page from both live and stage
@@ 1243-1264 (lines=22) @@
1240
	 * @return HTTPResponse
1241
	 * @throws HTTPResponse_Exception
1242
	 */
1243
	public function archive($data, $form) {
1244
		$id = $data['ID'];
1245
		/** @var SiteTree $record */
1246
		$record = SiteTree::get()->byID($id);
1247
		if(!$record || !$record->exists()) {
1248
			throw new HTTPResponse_Exception("Bad record ID #$id", 404);
1249
		}
1250
		if(!$record->canArchive()) {
1251
			return Security::permissionFailure();
1252
		}
1253
1254
		// Archive record
1255
		$record->doArchive();
1256
1257
		$this->getResponse()->addHeader(
1258
			'X-Status',
1259
			rawurlencode(sprintf(_t('CMSMain.ARCHIVEDPAGE',"Archived page '%s'"), $record->Title))
1260
		);
1261
1262
		// Even if the record has been deleted from stage and live, it can be viewed in "archive mode"
1263
		return $this->getResponseNegotiator()->respond($this->getRequest());
1264
	}
1265
1266
	public function publish($data, $form) {
1267
		$data['publish'] = '1';