Code Duplication    Length = 21-22 lines in 2 locations

code/Controllers/CMSMain.php 2 locations

@@ 1176-1196 (lines=21) @@
1173
	 * @return SS_HTTPResponse
1174
	 * @throws SS_HTTPResponse_Exception
1175
	 */
1176
	public function delete($data, $form) {
1177
		$id = $data['ID'];
1178
		$record = SiteTree::get()->byID($id);
1179
		if($record && !$record->canDelete()) {
1180
			return Security::permissionFailure();
1181
		}
1182
		if(!$record || !$record->ID) {
1183
			throw new SS_HTTPResponse_Exception("Bad record ID #$id", 404);
1184
		}
1185
1186
		// Delete record
1187
		$record->delete();
1188
1189
		$this->getResponse()->addHeader(
1190
			'X-Status',
1191
			rawurlencode(sprintf(_t('CMSMain.REMOVEDPAGEFROMDRAFT',"Removed '%s' from the draft site"), $record->Title))
1192
		);
1193
1194
		// Even if the record has been deleted from stage and live, it can be viewed in "archive mode"
1195
		return $this->getResponseNegotiator()->respond($this->getRequest());
1196
	}
1197
1198
	/**
1199
	 * Delete this page from both live and stage
@@ 1206-1227 (lines=22) @@
1203
	 * @return SS_HTTPResponse
1204
	 * @throws SS_HTTPResponse_Exception
1205
	 */
1206
	public function archive($data, $form) {
1207
		$id = $data['ID'];
1208
		/** @var SiteTree $record */
1209
		$record = SiteTree::get()->byID($id);
1210
		if(!$record || !$record->exists()) {
1211
			throw new SS_HTTPResponse_Exception("Bad record ID #$id", 404);
1212
		}
1213
		if(!$record->canArchive()) {
1214
			return Security::permissionFailure();
1215
		}
1216
1217
		// Archive record
1218
		$record->doArchive();
1219
1220
		$this->getResponse()->addHeader(
1221
			'X-Status',
1222
			rawurlencode(sprintf(_t('CMSMain.ARCHIVEDPAGE',"Archived page '%s'"), $record->Title))
1223
		);
1224
1225
		// Even if the record has been deleted from stage and live, it can be viewed in "archive mode"
1226
		return $this->getResponseNegotiator()->respond($this->getRequest());
1227
	}
1228
1229
	public function publish($data, $form) {
1230
		$data['publish'] = '1';