PHP Script implements Magento permission setting and cache cleanup

Source: Internet
Author: User
Tags chmod explode pear php script file permissions
The code is as follows Copy Code

<?php

# # Setup file 644, directory 755
function Alldirchmod ($dir = "./", $dirModes = 0755, $fileModes = 0644) {
$d = new Recursivedirectoryiterator ($dir);
foreach (New Recursiveiteratoriterator ($d, 1) as $path) {
if ($path->isdir ()) chmod ($path, $dirModes);
else if (Is_file ($path)) chmod ($path, $fileModes);
}
}

# # Clear Specified directory
function Cleandir ($dir) {
if ($handle = Opendir ($dir)) {
while (false!== ($file = Readdir ($handle))) {
if ($file!= '. ' && $file!= ' ... ' && is_file ($dir. '/'. $file)) {
if (unlink ($dir. '/'. $file)) {}
else {echo $dir. '/' . $file. ' (file) not deleted!<br/> '; }
}
else if ($file!= '. ' && $file!= ' ... ' && is_dir ($dir. '/'. $file)) {
Cleandir ($dir. '/'. $file);
if (RmDir ($dir. '/'. $file)) {}
else {echo $dir. '/' . $file. ' (directory) not deleted!<br/> '; }
}
}
Closedir ($handle);
}
}

# # To determine if the directory is empty
function Isdirempty ($dir) {
Return (($files = @scandir ($dir)) && count ($files) <= 2);
}

echo "-----------------------CLEANUP START-------------------------<br/>";
$start = (float) array_sum (Explode (', microtime ());
echo "<br/>*************** SETTING PERMISSIONS ***************<br/>";
echo "Setting all folder permissions to 755<br/>";
echo "Setting all file permissions to 644<br/>";
Alldirchmod (".");
echo "Setting pear permissions to 550<br/>";
chmod ("pear", 550);

echo "<br/>****************** clearing CACHE ******************<br/>";

if (file_exists ("Var/cache")) {
echo "Clearing var/cache<br/>";
Cleandir ("Var/cache");
}

if (file_exists ("Var/session")) {
echo "Clearing var/session<br/>";
Cleandir ("Var/session");
}

if (file_exists ("Var/minifycache")) {
echo "Clearing var/minifycache<br/>";
Cleandir ("Var/minifycache");
}

if (file_exists ("Downloader/pearlib/cache")) {
echo "Clearing downloader/pearlib/cache<br/>";
Cleandir ("Downloader/pearlib/cache");
}

if (file_exists ("Downloader/pearlib/download")) {
echo "Clearing downloader/pearlib/download<br/>";
Cleandir ("Downloader/pearlib/download");
}

if (file_exists ("Downloader/pearlib/pear.ini")) {
echo "Removing downloader/pearlib/pear.ini<br/>";
Unlink ("Downloader/pearlib/pear.ini");
}

Echo "<br/>************** CHECKING for EXTENSIONS ***********<br/>";
If (!isdirempty ("app/code/local/")) {
    echo "= WARNING =-Overrides or extensions exist in th e app/code/local folder<br/> ";
}
If (!isdirempty ("app/code/community/")) {
    echo "= WARNING =-Overrides or extensions E Xist in the app/code/community folder<br/> ";
}
$end = (float) array_sum (Explode (', microtime ());
Echo <br/>-------------------CLEANUP COMPLETED in: ". sprintf ("%.4f", ($end-$start)). "Seconds------------------<br/>";
?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.