Code Duplication    Length = 21-22 lines in 2 locations

code/Controllers/CMSMain.php 2 locations

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