/** * To log do bfLog::log('something'); * * @param $msg * @param bool $truncate */ public static function log($msg, $truncate = FALSE) { /** * I dont think we actually need to be logging anymore at all - except on crappy webhosts maybe? */ if (_BF_LOG == FALSE) { return; } if (file_exists(dirname(__FILE__) . bfLog::FILE)) { $logSize = number_format(filesize(dirname(__FILE__) . bfLog::FILE) / 1024 / 1024, 2); if ($logSize > 10) { $truncate = TRUE; } } $template = '%s | %s | %s'; $msg = sprintf($template, self::getTimestamp(), self::getTimerStats(), $msg); if (TRUE === $truncate) { bfLog::truncate(); } file_put_contents(dirname(__FILE__) . bfLog::FILE, $msg . PHP_EOL, FILE_APPEND); }
/** * Reset the state of our audit, cleaning files and database */ private function resetState() { bfLog::log('Creating our database tables'); $this->db->setQuery('SHOW TABLES LIKE "bf_files_last"'); if ($this->db->loadResult()) { $this->db->setQuery('DROP TABLE IF EXISTS `bf_files_last`'); $this->db->query(); } $this->db->setQuery('SHOW TABLES LIKE "bf_files"'); if ($this->db->loadResult()) { $this->db->setQuery('RENAME TABLE `bf_files` TO `bf_files_last`'); $this->db->query(); } // Drop and recreate our database tables $sql = file_get_contents('./db/blank.sql'); $sqls = explode(';', $sql); foreach ($sqls as $sql) { if (trim($sql) == '') { continue; } $this->db->setQuery($sql); if (!$this->db->query()) { bfEncrypt::reply(bfReply::ERROR, $this->db->getErrorMsg()); } } // remove any tmp files we might have created @unlink(dirname(__FILE__) . '/tmp/tmp.md5s'); @unlink(dirname(__FILE__) . '/tmp/tmp.pattern'); @unlink(dirname(__FILE__) . '/tmp/tmp.false'); @unlink(dirname(__FILE__) . '/tmp/tmp.log'); @unlink(dirname(__FILE__) . '/tmp/tmp.ob'); @unlink(dirname(__FILE__) . '/tmp/large.sql'); @unlink(dirname(__FILE__) . '/tmp/speedup.sql'); @unlink(dirname(__FILE__) . '/tmp/STATE'); @unlink(dirname(__FILE__) . '/tmp/STATE.php'); @unlink(dirname(__FILE__) . '/tmp/Folders'); @unlink(dirname(__FILE__) . '/tmp/Files'); bfLog::truncate(); }