File modules/cms/action/migrate.sh

Last commit: Tue Nov 17 23:51:00 2020 +0100	Jan Dankert	Refactoring: Every Actionmethod has now its own class.
1 #!/bin/bash 2 3 4 function read_section { 5 local id=$1 6 while IFS= read -r p ; do 7 if [[ "$p" == *"function $id"* ]] ; then 8 # Read data here 9 while IFS= read -r p ; do 10 # Check for end of section - empty line 11 if [ "$p" = " }" -o "$p" = $'\t}' ] ; then 12 break 13 fi 14 # Do something with '$p' 15 echo "$p" 16 done 17 # Indicate section was found 18 return 19 fi 20 done 21 # Indicate section not found 22 return 23 } 24 25 26 for act in `ls -1 *Action.class.php|grep -o '^[A-Z][a-z]*'`; do 27 mkdir -v ${act,,} 28 29 for mth in `grep "function " ${act}Action.class.php|grep -E -o '[A-Z]*[a-z]*(View|Post)'|grep -o '^[a-z]*'|uniq`; do 30 31 out=${act,,}/$act${mth^}Action.class.php 32 touch $out 33 34 echo "act: $act method: $mth" 35 36 echo "<?php" > $out 37 echo "namespace cms\\action\\${act,,};" >> $out 38 echo "use cms\\action\\${act}Action;" >> $out 39 echo "use cms\\action\\Method;" >> $out 40 echo "class ${act}${mth^}Action extends ${act}Action implements Method {" >> $out 41 echo " public function view() {" >> $out 42 read_section "${mth}View" >> $out < ${act}Action.class.php 43 44 echo " }" >> $out 45 echo " public function post() {" >> $out 46 read_section "${mth}Post" >> $out < ${act}Action.class.php 47 echo " }" >> $out 48 echo "}" >> $out 49 done 50 done
Download modules/cms/action/migrate.sh
History Tue, 17 Nov 2020 23:51:00 +0100 Jan Dankert Refactoring: Every Actionmethod has now its own class.