Code Duplication    Length = 17-20 lines in 2 locations

admin_pages/events/Events_Admin_Page.core.php 1 location

@@ 1137-1156 (lines=20) @@
1134
		$old_tickets = isset( $old_tickets[0] ) && $old_tickets[0] == '' ? array() : $old_tickets;
1135
		$tickets_removed = array_diff( $old_tickets, array_keys( $saved_tickets ) );
1136
1137
		foreach ( $tickets_removed as $id ) {
1138
			$id = absint( $id );
1139
1140
			//get the ticket for this id
1141
			$tkt_to_remove = EE_Registry::instance()->load_model('Ticket')->get_one_by_ID($id);
1142
1143
			//need to get all the related datetimes on this ticket and remove from every single one of them (remember this process can ONLY kick off if there are NO tkts_sold)
1144
			$dtts = $tkt_to_remove->get_many_related('Datetime');
1145
1146
			foreach( $dtts as $dtt ) {
1147
				$tkt_to_remove->_remove_relation_to($dtt, 'Datetime');
1148
			}
1149
1150
			//need to do the same for prices (except these prices can also be deleted because again, tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived))
1151
			$tkt_to_remove->delete_related_permanently('Price');
1152
1153
1154
			//finally let's delete this ticket (which should not be blocked at this point b/c we've removed all our relationships)
1155
			$tkt_to_remove->delete_permanently();
1156
		}
1157
		return array( $saved_dtt, $saved_tickets );
1158
	}
1159

caffeinated/admin/new/pricing/espresso_events_Pricing_Hooks.class.php 1 location

@@ 281-297 (lines=17) @@
278
279
		if ( is_array( $old_datetimes ) ) {
280
			$dtts_to_delete = array_diff( $old_datetimes, $saved_dtt_ids );
281
			foreach ( $dtts_to_delete as $id ) {
282
				$id = absint( $id );
283
				if ( empty( $id ) )
284
					continue;
285
286
				$dtt_to_remove = EE_Registry::instance()->load_model('Datetime')->get_one_by_ID($id);
287
288
				//remove tkt relationships.
289
				$related_tickets = $dtt_to_remove->get_many_related('Ticket');
290
				foreach ( $related_tickets as $tkt ) {
291
					$dtt_to_remove->_remove_relation_to($tkt, 'Ticket');
292
				}
293
294
				$evt_obj->_remove_relation_to( $id, 'Datetime' );
295
				$dtt_to_remove->refresh_cache_of_related_objects();
296
297
			}
298
		}
299
300
		return $saved_dtt_objs;