Created
October 23, 2018 19:07
-
-
Save hidonet/5a15f680eaa0f2cde13391b9cd8883b7 to your computer and use it in GitHub Desktop.
Magento1 Report File Segmentizer by Date
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Magento Report File Date Segmentor | |
Scans var/report directory and moves all report files to created date named directories. | |
Developer : Hidayet Ok ( [email protected] ) | |
http://www.github.com/hidonet/magento_var_report_segmentor | |
*/ | |
echo date("Y.m.d H:i:s")." -- Report File Segmentor started...\n\n"; | |
$mage_file = dirname(realpath(__FILE__))."/../app/Mage.php"; | |
if (file_exists($mage_file)) | |
{ | |
require($mage_file); | |
} // if sonu | |
else | |
{ | |
die("Mage.php not found..."); | |
} // else sonu | |
Mage::app(); | |
$var_report_dir = Mage::getBaseDir('var')."/report/"; | |
$file_list = glob($var_report_dir."/*"); | |
$cnt_total = 0; | |
$cnt_moved = 0; | |
foreach ($file_list as $file) | |
{ | |
$file = str_replace("//","/",$file); | |
if (is_file($file)) | |
{ | |
$file_date = filemtime($file); | |
$rep_dirname = $var_report_dir.date("Y-m-d",$file_date)."/"; | |
if (!file_exists($rep_dirname)) {mkdir($rep_dirname, 0777, true) or die($rep_dirname." directory can not created. Maybe a permission problem.\n\n");} // if sonu | |
if (!file_exists($rep_dirname)) {die_2("$rep_dirname directory not found.\n\n");} // if sonu | |
$ret = @rename($file,$rep_dirname); | |
$rep_dirname = $var_report_dir."".date("Y-m-d",$file_date)."/"; | |
if ($ret !== true and function_exists('shell_exec')) | |
{ | |
$shell_error = false; | |
$ret = `mv $file $rep_dirname`; | |
} // if sonu | |
if (!file_exists($file) and file_exists($rep_dirname.basename($file))) | |
{ | |
echo " Success : $file moved to ".$rep_dirname.basename($file)."\n "; | |
$cnt_moved++; | |
} // if sonu | |
else | |
{ | |
if (file_exists($file) and file_exists($rep_dirname.basename($file))) | |
{ | |
echo " Error : File not moved ($file). File exists in target with same name (".$rep_dirname.basename($file).")....\n "; | |
} // if sonu | |
elseif (file_exists($file) and !file_exists($rep_dirname.basename($file))) | |
{ | |
echo " Error : File not moved ($file). Unknown error occured...\n "; | |
} // elseif sonu | |
} // else sonu | |
} // if sonu | |
$cnt_all++; | |
} // foreach sonu | |
echo "\n"; | |
echo date("Y.m.d H:i:s")." -- Operation finished..."; | |
echo date("Y.m.d H:i:s")." -- Total $cnt_moved files segmentized...\n\n"; | |
// --------------------------------------------------------------------------------------------------- | |
function die_2($msg) { | |
die($msg); | |
} // function sonu ----------------------------------------------------------------------------------- | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment