0 ? max( 5, min( 20, $max - 10 ) ) : 15; return (float) apply_filters( 'marchnote_step_seconds', $budget ); } public static function step( Marchnote_Job $job, array $args = array() ) { if ( function_exists( 'set_time_limit' ) ) { set_time_limit( 0 ); // phpcs:ignore Squiz.PHP.DiscouragedFunctions.Discouraged -- each step is time-boxed by its own deadline. } ignore_user_abort( true ); $deadline = microtime( true ) + self::budget(); try { if ( 'export' === $job->data['type'] ) { return Marchnote_Export::step( $job, $deadline ); } return Marchnote_Import::step( $job, $deadline, $args ); } catch ( Throwable $e ) { $job->log( 'ERROR: ' . $e->getMessage() ); self::abort( $job ); return array( 'status' => 'error', 'progress' => 0, 'message' => $e->getMessage(), ); } } /** * Throw away a job and anything half-built. The live site is untouched * for exports and for imports that have not reached the swap step. */ public static function abort( Marchnote_Job $job ) { if ( 'export' === $job->data['type'] ) { wp_delete_file( Marchnote_Storage::backups_dir() . '/' . $job->data['archive'] . '.part' ); } else { try { Marchnote_Database::drop_tmp_tables(); } catch ( Throwable $e ) { $job->log( 'Cleanup failed: ' . $e->getMessage() ); } Marchnote_Storage::set_lock( false ); } $job->destroy(); } }