utils.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. //for easy install migrations mysql
  3. function installMysqlPart($enable) {
  4. $db = getenv('EV_php_name');
  5. $pass = getenv('EV_php_pass');
  6. //scale all backends hiden mysql scripts
  7. $remove_php_open_key_tmp = 'sed "s/<?php//g" -i $1';
  8. $remove_php_open_multiline_comment_tmp = 'sed "s/\/\*//g" -i $1';
  9. $remove_php_close_multiline_comment_tmp = 'sed "s/\*\///g" -i $1';
  10. $remove_php_close_key_tmp = 'sed "s/?>//g" -i $1';
  11. $remove_first_space_tmp = 'sed "1{/^$/d}" -i $1';
  12. $remove_second_space_tmp = 'sed "1{/^$/d}" -i $1';
  13. $remove_last_space_tmp = 'sed -z "s/.$//" -i $1';
  14. $add_php_multiline_comment = 'sed "1s/^/\/\*\n/" -i $1';
  15. $add_php_open_key_comment = 'sed "1s/^/<?php\n/" -i $1';
  16. $add_php_close_multiline_comment = 'echo "*/" >> $1';
  17. $add_php_close_key = 'echo "?>" >> $1';
  18. $add_last_space = 'sed -z "s/.$//" -i $1';
  19. $cmd = <<<CMD
  20. #!/bin/bash
  21. unblockSqlBackenduery() {
  22. if [ -f \$1 ]
  23. then
  24. $remove_php_open_key_tmp
  25. $remove_php_open_multiline_comment_tmp
  26. $remove_php_close_multiline_comment_tmp
  27. $remove_php_close_key_tmp
  28. $remove_first_space_tmp
  29. $remove_second_space_tmp
  30. $remove_last_space_tmp
  31. fi
  32. }
  33. runBackendnServe() {
  34. if [ -f \$1 ]
  35. then
  36. mysql -uroot -p$pass $db < \$1
  37. fi
  38. }
  39. blockSqlBackenduery() {
  40. if [ -f \$1 ]
  41. then
  42. $add_php_multiline_comment
  43. $add_php_open_key_comment
  44. $add_php_close_multiline_comment
  45. $add_php_close_key
  46. $add_last_space
  47. fi
  48. }
  49. runSteps() {
  50. unblockSqlBackenduery \$1
  51. runBackendnServe \$1 || true
  52. blockSqlBackenduery \$1
  53. }
  54. scaleBackend() {
  55. for backendSql in backend/*/*.sql.php; do runSteps \$backendSql; done
  56. }
  57. scaleBackend 2>&1
  58. CMD;
  59. if ($enable) {
  60. echo '<h3>Database information: </h3>';
  61. echo '<br>';
  62. echo exec($cmd);
  63. }
  64. }
  65. $enable = false;
  66. echo $enable;
  67. installMysqlPart($enable);
  68. ?>