Skip to content

Instantly share code, notes, and snippets.

@vkarlsen
Last active March 6, 2022 14:45
Show Gist options
  • Save vkarlsen/e455818c0ba86c3ca8932a74c69cf241 to your computer and use it in GitHub Desktop.
Save vkarlsen/e455818c0ba86c3ca8932a74c69cf241 to your computer and use it in GitHub Desktop.
Checklist for migrating from old Kohana (pre-3.3) to Koseven
# Shamelessly stolen from:
# https://stackoverflow.com/questions/13935621/how-to-upgrade-from-kohana-3-2-to-3-3-implementing-psr-0
# Note that this is merely the start; you should expect to make a number of other changes to your code
# after going through this checklist.
cd application/classes
# Capitalize class filenames and directories:
# NOTE: Use bash for this!
for SRC in `find . -depth`
do DST=`dirname "${SRC}"`/`basename "${SRC}" | gsed -e 's/^./\U&/'`;
if [ "${SRC}" != "${DST}" ]
then
[ ! -e "${DST}" ] && gmv -T "${SRC}" "${DST}" || echo "${SRC} was not renamed"
fi
done
cd ..
# In application/:
# Capitalize all class names inside models and controllers (and helpers):
find ./ -name \*.php -exec gsed -i "s/helper_\([a-zA-Z]\+\)/Helper_\u\1/gI" {} \;
find ./ -name \*.php -exec gsed -i "s/helper_\([a-zA-Z]\+\)_\([a-zA-Z]\+\)/Helper_\u\1_\u\2/gI" {} \;
find ./ -name \*.php -exec gsed -i "s/helper_\([a-zA-Z]\+\)_\([a-zA-Z]\+\)_\([a-zA-Z]\+\)/Helper_\u\1_\u\2_\u\3/gI" {} \;
# Same for classes starting with Model_ and Controller_:
find ./ -name \*.php -exec gsed -i "s/model_\([a-zA-Z]\+\)/Model_\u\1/gI" {} \;
find ./ -name \*.php -exec gsed -i "s/model_\([a-zA-Z]\+\)_\([a-zA-Z]\+\)/Model_\u\1_\u\2/gI" {} \;
find ./ -name \*.php -exec gsed -i "s/model_\([a-zA-Z]\+\)_\([a-zA-Z]\+\)_\([a-zA-Z]\+\)/Model_\u\1_\u\2_\u\3/gI" {} \;
find ./ -name \*.php -exec gsed -i "s/controller_\([a-zA-Z]\+\)/Controller_\u\1/gI" {} \;
find ./ -name \*.php -exec gsed -i "s/controller_\([a-zA-Z]\+\)_\([a-zA-Z]\+\)/Controller_\u\1_\u\2/gI" {} \;
find ./ -name \*.php -exec gsed -i "s/controller_\([a-zA-Z]\+\)_\([a-zA-Z]\+\)_\([a-zA-Z]\+\)/Controller_\u\1_\u\2_\u\3/gI" {} \;
# Now some class names that were used with only 1 capital, are now written in full capitals (Html, Url, Http, UTF8).
# Replace them in your whole application:
find ./ -name \*.php -exec gsed -i "s/Url::/URL::/gI" {} \;
find ./ -name \*.php -exec gsed -i "s/Html::/HTML::/gI" {} \;
find ./ -name \*.php -exec gsed -i "s/Http::/HTTP::/gI" {} \;
find ./ -name \*.php -exec gsed -i "s/Utf8::/UTF8::/gI" {} \;
# When you use the ORM driver, all Orm::factory('some_class') should be upper cased
# and capitalised to ORM::factory('Some_Class'):
find ./ -name \*.php -exec gsed -i "s/orm::factory(\(\"\|'\)\([a-zA-Z_]\+\)\(\"\|'\)\(,[^,]*\)*)/ORM::factory('\u\2'\4)/gI" {} \;
find ./ -name \*.php -exec gsed -i "s/orm::factory(\(\"\|'\)\([a-zA-Z]\+\)_\([a-zA-Z]\+\)\(\"\|'\)\(,[^,]*\)*)/ORM::factory('\u\2_\u\3'\5)/gI" {} \;
find ./ -name \*.php -exec gsed -i "s/orm::factory(\(\"\|'\)\([a-zA-Z]\+\)_\([a-zA-Z]\+\)_\([a-zA-Z]\+\)\(\"\|'\)\(,[^,]*\)*)/ORM::factory('\u\2_\u\3_\u\4'\6)/gI" {} \;
Replace all occurences of:
Request::current()->redirect
with:
HTTP::redirect
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment