public function run($request) {
		$units = array ('seconds', 'hours', 'minutes', 'days', 'weeks', 'months', 'years');
		$unit = $request->requestVar('unit');
		if(!$unit || !in_array($unit, $units)) {
			throw new RuntimeException("Please specify a 'unit' parameter. Possible values: ".implode(', ', $units));
		}

		$count = $request->requestVar('count');
		if(!$count) {
			throw new RuntimeException("Please specify a 'count' parameter for the number of $unit you want to to keep.");
		}

		$stamp = strtotime("-{$count} $unit");
		$date = date('Y-m-d H:i:s');

		$count = SentEmail::get()->filter(array(
			'Created:LessThan' => $date
		))->count();
		
		DB::query("DELETE FROM \"SentEmail\" WHERE Created < '$date'");

		echo "Deleted $count records.";
	}
public function run($request) {
		$units = array ('seconds', 'hours', 'minutes', 'days', 'weeks', 'months', 'years');
		$unit = $request->requestVar('unit');
		if(!$unit || !in_array($unit, $units)) {
			throw new RuntimeException("Please specify a 'unit' parameter. Possible values: ".implode(', ', $units));
		}

		$count = $request->requestVar('count');
		if(!$count) {
			throw new RuntimeException("Please specify a 'count' parameter for the number of $unit you want to to keep.");
		}

		$stamp = strtotime("-{$count} $unit");
		$date = date('Y-m-d H:i:s');

		$count = SentEmail::get()->filter(array(
			'Created:LessThan' => $date
		))->count();
		
		DB::query("DELETE FROM \"SentEmail\" WHERE Created < '$date'");

		echo "Deleted $count records.";
	}
public function run ( $ request ) { $ units = array ( 'seconds' , 'hours' , 'minutes' , 'days' , 'weeks' , 'months' , 'years' ) ; $ unit = $ request -> requestVar ( 'unit' ) ; if ( ! $ unit || ! in_array ( $ unit , $ units ) ) { throw new RuntimeException ( "Please specify a 'unit' parameter. Possible values: " . implode ( ', ' , $ units ) ) ; } $ count = $ request -> requestVar ( 'count' ) ; if ( ! $ count ) { throw new RuntimeException ( "Please specify a 'count' parameter for the number of $unit you want to to keep." ) ; } $ stamp = strtotime ( "-{$count} $unit" ) ; $ date = date ( 'Y-m-d H:i:s' ) ; $ count = SentEmail :: get ( ) -> filter ( array ( 'Created:LessThan' => $ date ) ) -> count ( ) ; DB :: query ( "DELETE FROM \"SentEmail\" WHERE Created < '$date'" ) ; echo "Deleted $count records." ; }
Execute the task
Execute the task