Tuesday, 15 February 2011

Migrating a legacy PHP Project from Windows to Linux (inconsistent case disaster) -



Migrating a legacy PHP Project from Windows to Linux (inconsistent case disaster) -

i have problem low-quality php project (i didnt write :)) , migration towards linux file system, is, in contrast windows' case sensitive. includes , image-names inconsistent real filenames need kind of automatic solution.

so thought script, parses project directory recursively for php, js, jpg , gif files , replaces occurrencies of wrong case filename real filename in project's php files.

the algorithm like:

foreach (php,js,jpg,png,gif..) $found in dir: find php in dir : replace ignorecase($found) $found

i tried write perl , file::find, im stuck :/

you can command line using find , gnu-sed gsed.

#!/bin/sh # replace filenames found in code , create backup of original find . -type f \( -name "*.php" -or -name "*.jpg" \) -exec bash -c 'gsed -i.bak "s/\(\w\)`basename {}`\(\w\)/\1`basename {}`\2/ig" /src/ *' \; ######################## # explanation # find # . : recursively current directory, # -type f : files - not folders, # f\(..\) : extensions, # -ecec : execute command, # base of operations -c : , execute in bash after {} replacement # sed # -i : replace text in actual file, # .bak : backup file *.bak, # s/ : search for; # \w : origin # non word dont match test.img # othertest.img, still match "test.img" # `basename {}` : file name placeholder provided find # \w : not end in word dont match # test.htm against test.html # /`basename {}`/ : replace string search # string of actual filename # g : global search, match more first instance # : case insensitive search # /src/* : total path files sed work on

php linux windows perl migration

No comments:

Post a Comment