code.fastix.org

Dateiansicht:

Datei:Projekte -> PHP73to74 -> php73to74.sh
md5:9914eeab556b365c34c14167a726fadb
sha1:2cc0b35a5971dac4d3412b6531610c9c4fa07c2f
Download-Link:Download
  1. #!/bin/bash
  2.  
  3. ### Diese Zeile muss angepasst werden!
  4. #phpcli='/usr/bin/php74/bin/php-cli';
  5. phpcli='/usr/bin/php';
  6. ## automatische Ermittlung(nicht empfohlen)
  7. # phpcli=$(readlink -f "$(which php)");
  8. ###
  9.  
  10. ##################
  11. # Dieses Skript versucht Dateien umzuwandeln,
  12. # bei denen in PHP7.4 folgende Fehlermeldung erscheint:
  13. # "Deprecated: Array and string offset access syntax with curly braces is deprecated in php"
  14.  
  15. ## Run with: ###
  16. ## find -name '*.php' -exec /PFAD/ZU/php73to74.sh "{}" 2> php73to74.log \;;
  17. #################
  18.  
  19.  
  20. file="$1";
  21. dir=$(dirname "$1");
  22.  
  23. if [ ! -f "${phpcli}" ] || [ ! -x "${phpcli}" ]; then
  24.         echo "phpcli ('${phpcli}') ist falsch. Exit!" 1>&2;
  25.         exit 1;
  26. fi
  27.  
  28. if [ -z "${file}" ]; then
  29.         echo "Keine Datei angegeben. Exit!" 1>&2;
  30.         exit 2;
  31.  
  32. elif [ -f "${file}]" ]; then
  33.         echo "'${file}' ist keine Datei. Exit!" 1>&2;
  34.         exit 4;
  35.  
  36. elif [ ! -r "${file}" ]; then
  37.         echo "'${file}' ist nicht lesbar. Exit!" 1>&2;
  38.         exit 8;
  39.  
  40. elif [ ! -w "${file}" ]; then
  41.         echo "Keine Schreibrechte an '${file}'. Exit!" 1>&2;
  42.         exit 16;
  43.  
  44. elif [ ! -w "${dir}" ]; then
  45.         echo "Keine Schreibrechte am Verzeichnis '${dir}'. Exit!" 1>&2;
  46.         exit 16;
  47. fi
  48.  
  49. echo "-------------------------------------------------" 1>&2;
  50. echo "Für Syntaxprüfung benutztes PHP:" 1>&2;
  51. echo "   Pfad: ${phpcli}" 1>&2;
  52. echo -n "Version: " 1>&2;
  53. ${phpcli} -v | head -n1 1>&2;
  54. echo "" 1>&2;
  55.  
  56. err=$(${phpcli} -l "${file}" 2>&1);
  57. if [ 0 -ne $? ]; then
  58.         echo "-------------------------------------------------" 1>&2;
  59.         echo "Misserfolg: Die Umwandlung von '${file}' wurde verweigert."  1>&2;
  60.         echo "-------------------------------------------------" 1>&2;
  61.         echo "Grund: '${file}' enthält folgenden Fehler:"  1>&2;
  62.         echo "${err}" 1>&2 ;
  63.         echo "-------------------------------------------------" 1>&2;
  64.         exit 32;
  65. fi
  66.  
  67. tmpfile1=$(mktemp);
  68. tmpfile2=$(mktemp);
  69. backupfile="${file}-$(date +%Y%m%d_%H%M)";
  70.  
  71. sed -E -e 's/\$([a-zA-Z0-9_]+)\{([^\}]*)\}/\$\1[\2]/g' "${file}" > "${tmpfile1}";
  72. ${phpcli} -l "${tmpfile1}" 1>/dev/null 2>/dev/null;
  73. if [ 0 -eq $? ]; then
  74.         t=$(diff "${tmpfile1}" "${file}" | wc -l);
  75.         if [ 0 -ne $t ]; then
  76.                 cp "${file}" "${backupfile}";
  77.                 cp "${tmpfile1}" "${file}";
  78.                 echo "-------------------------------------------------" 1>&2;
  79.                 echo "Erfolg: '${file}' wurde umgewandelt. Backup in '${backupfile}'." 1>&2;
  80.                 echo "-------------------------------------------------" 1>&2;
  81.                 echo "diff:" 1>&2;
  82.                 echo "-------------------------------------------------" 1>&2;
  83.                 diff "${backupfile}" "${file}" 1>&2;
  84.                 echo "-------------------------------------------------" 1>&2;
  85.                 rm -f "${tmpfile1}" "${tmpfile2}";
  86.                 exit 0;
  87.         else
  88.                 echo "Neutral: '${file}' Nichts zu tun."  1>&2;
  89.                 rm -f "${tmpfile1}" "${tmpfile2}";
  90.                 exit 0;
  91.         fi     
  92. else
  93.         sed -E -e 's/\$([a-zA-Z0-9_]+)\{([^\}]*)\}/\$\1[\2]/g' "${tmpfile1}" > "${tmpfile2}";
  94.         ${phpcli} -l "${tmpfile2}" 1>/dev/null 2>/dev/null;
  95.         if [ 0 -eq $? ]; then
  96.                 t=$(diff "${tmpfile2}" "${file}" | wc -l);
  97.                 if [ 0 -ne $t ]; then
  98.                         cp "${file}" "${backupfile}";
  99.                         cp "${tmpfile2}" "${file}";
  100.                         echo "-------------------------------------------------" 1>&2;
  101.                         echo "Erfolg: '${file}' wurde umgewandelt. Backup in '${backupfile}'."  1>&2;
  102.                         echo "-------------------------------------------------" 1>&2;
  103.                         echo "diff:"
  104.                         echo "-------------------------------------------------" 1>&2;
  105.                         diff "${backupfile}" "${file}" 1>&2;
  106.                         echo "-------------------------------------------------" 1>&2;
  107.                         rm -f "${tmpfile1}" "${tmpfile2}";
  108.                         exit 0;
  109.                 else
  110.                         echo "Merkwürdig: '${file}' Nichts umgewandelt'."  1>&2;
  111.                         rm -f "${tmpfile1}" "${tmpfile2}";
  112.                         exit 0;
  113.                 fi             
  114.         fi
  115. fi
  116. echo "-------------------------------------------------" 1>&2;
  117. echo "Misserfolg: '${file}' konnte nicht erfolgreich umgewandelt werden."  1>&2;
  118. echo "-------------------------------------------------" 1>&2;
  119. echo "Grund:";
  120. err=$(${phpcli} -l "${tmpfile1}" 1>&2);
  121. if [ 0 -ne $? ]; then
  122.         echo "Erster Umwandlungsversuch führte zu folgendem Fehler:"  1>&2;
  123.         echo "${err}" 1>&2;
  124.         echo "-------------------------------------------------" 1>&2;
  125.  
  126. fi
  127. err=$(${phpcli} -l "${tmpfile2}" 1>&2);
  128. if [ 0 -ne $? ]; then
  129.         echo "'Zweiter Umwandlungsversuch führte zu folgendem Fehler:"  1>&2;
  130.         echo "${err}" 1>&2;
  131.         echo "-------------------------------------------------" 1>&2;
  132. fi
  133. rm -f "${tmpfile1}" "${tmpfile2}";
  134. exit 64;
  135.