Repository navigation
Resolve relative paths when importing with --skip-copy #266
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -606,6 +606,13 @@ public function import( $args, $assoc_args = array() ) { | |||||||||||
| ++$errors; | ||||||||||||
| continue; | ||||||||||||
| } | ||||||||||||
| // With --skip-copy the path is stored as-is, so a relative one would not resolve against the uploads directory. | ||||||||||||
| if ( Utils\get_flag_value( $assoc_args, 'skip-copy' ) && ! Path::is_absolute( $file ) ) { | ||||||||||||
| $absolute_file = realpath( $file ); | ||||||||||||
| if ( false !== $absolute_file ) { | ||||||||||||
| $file = $absolute_file; | ||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win 🔎 Supported by static analysis🏁 Script executed: set -eu
printf '%s\n' '--- diff ---'
git diff --unified=30 af1ad95295283c1bb6ecf29c5baa57abf544d56f 0baf0ee9ccaeaf4169a0cbb1fdd0f736d021bbc4 -- src/Media_Command.php features/media-import.feature
printf '%s\n' '--- source around changed lines ---'
nl -ba src/Media_Command.php | sed -n '560,650p'
printf '%s\n' '--- references to attachment path and URL assertions ---'
rg -n -F --glob '*.php' --glob '*.feature' -- '_wp_attached_file' . || test "$?" -eq 1
rg -n -F --glob '*.php' --glob '*.feature' -- 'wp_get_attachment_url' . || test "$?" -eq 1
printf '%s\n' '--- WordPress/path configuration ---'
rg -n -F --glob 'composer.json' --glob 'composer.lock' --glob '*.php' -- 'wp_upload_dir' . || test "$?" -eq 1
rg -n -F --glob '*.php' -- 'skip-copy' src tests features || test "$?" -eq 1Repository: wp-cli/media-command Length of output: 12840 🏁 Script executed: git diff --unified=25 af1ad95295283c1bb6ecf29c5baa57abf544d56f 0baf0ee9ccaeaf4169a0cbb1fdd0f736d021bbc4 -- src/Media_Command.php features/media-import.feature
nl -ba src/Media_Command.php | sed -n '580,635p'
rg -n -F --glob '*.php' --glob '*.feature' -- '_wp_attached_file' . || test "$?" -eq 1
rg -n -F --glob '*.php' --glob '*.feature' -- 'wp_get_attachment_url' . || test "$?" -eq 1
rg -n -F --glob '*.php' -- 'skip-copy' src tests features || test "$?" -eq 1Repository: wp-cli/media-command Length of output: 10545 🏁 Script executed: set -eu
printf '%s\n' '--- import continuation ---'
nl -ba src/Media_Command.php | sed -n '680,755p'
printf '%s\n' '--- import entry and path contract ---'
nl -ba src/Media_Command.php | sed -n '390,435p'
nl -ba src/Media_Command.php | sed -n '1085,1170p'
printf '%s\n' '--- attachment insertion references ---'
rg -n -F --glob '*.php' -- 'wp_insert_attachment' src
rg -n -F --glob '*.php' -- 'tempfile' src/Media_Command.phpRepository: wp-cli/media-command Length of output: 10035 Preserve the uploads-relative path for symlinked imports.
When this occurs, pass the normalized absolute path of the original symlink location, not the 🤖 Prompt for AI Agents |
||||||||||||
| } | ||||||||||||
|
Comment on lines
+611
to
+614
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
| } | ||||||||||||
| $src_basename = Path::basename( $file ); | ||||||||||||
| if ( Utils\get_flag_value( $assoc_args, 'skip-duplicates' ) ) { | ||||||||||||
| $check_basename = $src_basename; | ||||||||||||
|
|
||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This step passes on
maintoo, so it does not test the fix. A check onget_attached_file()fails onmain(false) and passes with this PR: