Magento PHP File and Database Maintenance


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. <?php
  2. $xml = simplexml_load_file('./app/etc/local.xml', NULL, LIBXML_NOCDATA);
  3.  
  4. $db['host'] = $xml->global->resources->default_setup->connection->host;
  5. $db['name'] = $xml->global->resources->default_setup->connection->dbname;
  6. $db['user'] = $xml->global->resources->default_setup->connection->username;
  7. $db['pass'] = $xml->global->resources->default_setup->connection->password;
  8. $db['pref'] = $xml->global->resources->db->table_prefix;
  9.  
  10. if($_GET['clean'] == 'log') clean_log_tables();
  11. if($_GET['clean'] == 'var') clean_var_directory();
  12.  
  13. function clean_log_tables()
  14. {
  15. global $db;
  16.  
  17. $tables = array(
  18. 'catalogindex_aggregation',
  19. 'catalogindex_aggregation_tag',
  20. 'catalogindex_aggregation_to_tag',
  21. 'dataflow_batch_export',
  22. 'dataflow_batch_import',
  23. 'log_customer',
  24. 'log_quote',
  25. 'log_summary',
  26. 'log_summary_type',
  27. 'log_url',
  28. 'log_url_info',
  29. 'log_visitor',
  30. 'log_visitor_info',
  31. 'log_visitor_online',
  32. 'report_event'
  33. );
  34.  
  35. mysql_connect($db['host'], $db['user'], $db['pass']) or die(mysql_error());
  36. mysql_select_db($db['name']) or die(mysql_error());
  37.  
  38. foreach($tables as $v => $k) {
  39. mysql_query('TRUNCATE `'.$db['pref'].$k.'`') or die(mysql_error());
  40. }
  41. }
  42.  
  43. function clean_var_directory()
  44. {
  45. $dirs = array(
  46. 'downloader/pearlib/cache/*',
  47. 'downloader/pearlib/download/*',
  48. 'var/cache/',
  49. 'var/log/',
  50. 'var/report/',
  51. 'var/session/',
  52. 'var/tmp/'
  53. );
  54.  
  55. foreach($dirs as $v => $k) {
  56. exec('rm -rf '.$k);
  57. }
  58. }
  59. clean_log_tables();
  60. clean_var_directory();
  61. ?>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.