Advertisement
MageComp

Magento Cleanup File

Aug 10th, 2015
3,514
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.92 KB | None | 0 0
  1. <?php
  2. ## Function to set file permissions to 0644 and folder permissions to 0755
  3. function AllDirChmod( $dir = "./", $dirModes = 0755, $fileModes = 0644 ){
  4.    $d = new RecursiveDirectoryIterator( $dir );
  5.    foreach( new RecursiveIteratorIterator( $d, 1 ) as $path ){
  6.       if( $path->isDir() ) chmod( $path, $dirModes );
  7.       else if( is_file( $path ) ) chmod( $path, $fileModes );
  8.   }
  9. }
  10. ## Function to clean out the contents of specified directory
  11. function cleandir($dir) {
  12.     if ($handle = opendir($dir)) {
  13.         while (false !== ($file = readdir($handle))) {
  14.             if ($file != '.' && $file != '..' && is_file($dir.'/'.$file)) {
  15.                 if (unlink($dir.'/'.$file)) { }
  16.                 else { echo $dir . '/' . $file . ' (file) NOT deleted!<br />'; }
  17.             }
  18.             else if ($file != '.' && $file != '..' && is_dir($dir.'/'.$file)) {
  19.                 cleandir($dir.'/'.$file);
  20.                 if (rmdir($dir.'/'.$file)) { }
  21.                 else { echo $dir . '/' . $file . ' (directory) NOT deleted!<br />'; }
  22.             }
  23.         }
  24.         closedir($handle);
  25.     }
  26. }
  27. function isDirEmpty($dir){
  28.      return (($files = @scandir($dir)) && count($files) <= 2);
  29. }
  30. echo "----------------------- CLEANUP START -------------------------<br/>";
  31. $start = (float) array_sum(explode(' ',microtime()));
  32. echo "<br/>*************** SETTING PERMISSIONS ***************<br/>";
  33. echo "Setting all folder permissions to 755<br/>";
  34. echo "Setting all file permissions to 644<br/>";
  35. AllDirChmod( "." );
  36. echo "Setting pear permissions to 550<br/>";
  37. chmod("pear", 550);
  38. echo "<br/>****************** CLEARING CACHE ******************<br/>";
  39. if (file_exists("var/cache")) {
  40.     echo "Clearing var/cache<br/>";
  41.     cleandir("var/cache");
  42. }
  43. if (file_exists("var/session")) {
  44.     echo "Clearing var/session<br/>";
  45.     cleandir("var/session");
  46. }
  47. if (file_exists("var/minifycache")) {
  48.     echo "Clearing var/minifycache<br/>";
  49.     cleandir("var/minifycache");
  50. }
  51. if (file_exists("downloader/pearlib/cache")) {
  52.     echo "Clearing downloader/pearlib/cache<br/>";
  53.     cleandir("downloader/pearlib/cache");
  54. }
  55. if (file_exists("downloader/pearlib/download")) {
  56.     echo "Clearing downloader/pearlib/download<br/>";
  57.     cleandir("downloader/pearlib/download");
  58. }
  59. if (file_exists("downloader/pearlib/pear.ini")) {
  60.     echo "Removing downloader/pearlib/pear.ini<br/>";
  61.     unlink ("downloader/pearlib/pear.ini");
  62. }
  63. echo "<br/>************** CHECKING FOR EXTENSIONS ***********<br/>";
  64. If (!isDirEmpty("app/code/local/")) {
  65.     echo "-= WARNING =- Overrides or extensions exist in the app/code/local folder<br/>";
  66. }
  67. If (!isDirEmpty("app/code/community/")) {
  68.     echo "-= WARNING =- Overrides or extensions exist in the app/code/community folder<br/>";
  69. }
  70. $end = (float) array_sum(explode(' ',microtime()));
  71. echo "<br/>------------------- CLEANUP COMPLETED in:". sprintf("%.4f", ($end-$start))." seconds ------------------<br/>";
  72. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement