WP_CLI

Extractor::copy_overwrite_files()public staticWP-CLI 1.0

Copy files from source directory to destination directory. Source directory must exist.

Метод класса: Extractor{}

Хуков нет.

Возвращает

null. Ничего.

Использование

$result = Extractor::copy_overwrite_files( $source, $dest );
$source(строка) (обязательный)
-
$dest(строка) (обязательный)
-

Код Extractor::copy_overwrite_files() WP-CLI 2.8.0-alpha

public static function copy_overwrite_files( $source, $dest ) {
	$iterator = new RecursiveIteratorIterator(
		new RecursiveDirectoryIterator(
			$source,
			RecursiveDirectoryIterator::SKIP_DOTS
		),
		RecursiveIteratorIterator::SELF_FIRST
	);

	$error = 0;

	if ( ! is_dir( $dest ) ) {
		mkdir( $dest, 0777, true );
	}

	foreach ( $iterator as $item ) {

		$dest_path = $dest . DIRECTORY_SEPARATOR . $iterator->getSubPathName();

		if ( $item->isDir() ) {
			if ( ! is_dir( $dest_path ) ) {
				mkdir( $dest_path );
			}
		} else {
			if ( file_exists( $dest_path ) && is_writable( $dest_path ) ) {
				copy( $item, $dest_path );
			} elseif ( ! file_exists( $dest_path ) ) {
				copy( $item, $dest_path );
			} else {
				$error = 1;
				WP_CLI::warning( "Unable to copy '" . $iterator->getSubPathName() . "' to current directory." );
			}
		}
	}

	if ( $error ) {
		throw new Exception( 'There was an error overwriting existing files.' );
	}
}