bool. */ public function __construct( Module $module, ?callable $can_write = null ) { $this->module = $module; $this->can_write = $can_write; } /** * Report what importing the package would do. * * @param Job $job The import job. * @param string $path Package path. * @param string $strategy Conflict strategy. * @param bool $skip_missing Leave out types this site does not register. * @return Dry_Run_Result|\WP_Error */ public function dry_run( Job $job, string $path, string $strategy = Conflict_Resolver::SKIP, bool $skip_missing = false ) { $reader = new Package_Reader( $path ); $valid = $reader->validate(); if ( is_wp_error( $valid ) ) { return $valid; } try { return $this->importer( $reader, $job, $strategy, $skip_missing )->dry_run(); } finally { $reader->cleanup(); } } /** * Import the package. * * @param Job $job The import job. * @param string $path Package path. * @param string $strategy Conflict strategy. * @param bool $skip_missing Leave out types this site does not register. * @return Report|\WP_Error */ public function import( Job $job, string $path, string $strategy = Conflict_Resolver::SKIP, bool $skip_missing = false ) { $reader = new Package_Reader( $path ); $valid = $reader->validate(); if ( is_wp_error( $valid ) ) { return $valid; } $importer = $this->importer( $reader, $job, $strategy, $skip_missing ); $blockers = $importer->blockers(); if ( array() !== $blockers ) { $reader->cleanup(); return new \WP_Error( 'transtrix_import_blocked', implode( ' ', $blockers ), array( 'blockers' => $blockers ) ); } try { return $importer->run(); } finally { $reader->cleanup(); } } /** * Build the engine for one package. * * @param Package_Reader $reader A validated package. * @param Job $job The import job. * @param string $strategy Conflict strategy. * @param bool $skip_missing Leave out types this site does not register. * @return Three_Pass_Importer */ private function importer( Package_Reader $reader, Job $job, string $strategy, bool $skip_missing ): Three_Pass_Importer { return new Three_Pass_Importer( $reader, $this->module, new Conflict_Resolver( $strategy ), $job, $this->can_write, $skip_missing ); } }