Code Duplication    Length = 21-22 lines in 2 locations

code/Controllers/CMSMain.php 2 locations

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