update-functions.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <?php
  2. // Upgrade the installation
  3. function upgradeInstall($branch = 'v2-master') {
  4. $url = 'https://github.com/causefx/Organizr/archive/'.$branch.'.zip';
  5. $file = "upgrade.zip";
  6. $source = dirname(__DIR__,2).DIRECTORY_SEPARATOR.'upgrade'.DIRECTORY_SEPARATOR.'Organizr-'.str_replace('v2','2',$branch).DIRECTORY_SEPARATOR;
  7. $cleanup = dirname(__DIR__,2) .DIRECTORY_SEPARATOR."upgrade".DIRECTORY_SEPARATOR;
  8. $destination = dirname(__DIR__,2).DIRECTORY_SEPARATOR;
  9. echo 'URL: ',$url, '<br/></br/>FILENAME: ',$file,'<br/></br/>SOURCLEFILE: ', $source,'<br/></br/>DELETE DIR: ', $cleanup,'<br/></br/>OVERWRITE: ', $destination;
  10. //writeLog("success", "starting organizr upgrade process");
  11. if(downloadFile($url, $file)){
  12. echo 'downloaded file';
  13. }else{
  14. echo 'error! download';
  15. }
  16. if(unzipFile($file)){
  17. echo 'unzipped file';
  18. }else{
  19. echo 'error! zip';
  20. }
  21. if(rcopy($source, $destination)){
  22. echo 'copied file';
  23. }else{
  24. echo 'error! copy';
  25. }
  26. if(rrmdir($cleanup)){
  27. echo 'removed file';
  28. }else{
  29. echo 'error! remove';
  30. }
  31. //;
  32. //writeLog("success", "new organizr files copied");
  33. //;
  34. //writeLog("success", "organizr upgrade folder removed");
  35. //writeLog("success", "organizr has been updated");
  36. return true;
  37. }
  38. function downloadFile($url, $path){
  39. ini_set('max_execution_time',0);
  40. $folderPath = "upgrade".DIRECTORY_SEPARATOR;
  41. if(!mkdir($folderPath)){
  42. //writeLog("error", "organizr could not create upgrade folder");
  43. }
  44. $newfname = $folderPath . $path;
  45. $file = fopen ($url, 'rb');
  46. if ($file) {
  47. $newf = fopen ($newfname, 'wb');
  48. if ($newf) {
  49. while(!feof($file)) {
  50. fwrite($newf, fread($file, 1024 * 8), 1024 * 8);
  51. }
  52. }
  53. }else{
  54. //writeLog("error", "organizr could not download $url");
  55. }
  56. if ($file) {
  57. fclose($file);
  58. //writeLog("success", "organizr finished downloading the github zip file");
  59. }else{
  60. //writeLog("error", "organizr could not download the github zip file");
  61. }
  62. if ($newf) {
  63. fclose($newf);
  64. //writeLog("success", "organizr created upgrade zip file from github zip file");
  65. }else{
  66. //writeLog("error", "organizr could not create upgrade zip file from github zip file");
  67. }
  68. return true;
  69. }
  70. function unzipFile($zipFile){
  71. $zip = new ZipArchive;
  72. $extractPath = "upgrade/";
  73. if($zip->open($extractPath . $zipFile) != "true"){
  74. //writeLog("error", "organizr could not unzip upgrade.zip");
  75. }else{
  76. //writeLog("success", "organizr unzipped upgrade.zip");
  77. }
  78. /* Extract Zip File */
  79. $zip->extractTo($extractPath);
  80. $zip->close();
  81. return true;
  82. }
  83. // Function to remove folders and files
  84. function rrmdir($dir) {
  85. if (is_dir($dir)) {
  86. $files = scandir($dir);
  87. foreach ($files as $file)
  88. if ($file != "." && $file != "..") rrmdir("$dir/$file");
  89. rmdir($dir);
  90. }
  91. else if (file_exists($dir)) unlink($dir);
  92. return true;
  93. }
  94. // Function to Copy folders and files
  95. function rcopy($src, $dst) {
  96. if (is_dir ( $src )) {
  97. if (!file_exists($dst)) : mkdir ( $dst ); endif;
  98. $files = scandir ( $src );
  99. foreach ( $files as $file )
  100. if ($file != "." && $file != "..")
  101. rcopy ( "$src/$file", "$dst/$file" );
  102. } else if (file_exists ( $src ))
  103. copy ( $src, $dst );
  104. return true;
  105. }