public function test_ensure_file_exists_and_is_writable() { global $wp_filesystem; $file_path = '/test.txt'; // Test creation/exists checks $this->assertFalse($wp_filesystem->exists($file_path)); $this->assertTrue(EEH_File::ensure_file_exists_and_is_writable($file_path)); $this->assertTrue(EEH_File::verify_is_writable($file_path)); $wp_filesystem->chmod($file_path, '000'); try { $this->assertFalse(EEH_File::ensure_file_exists_and_is_writable($file_path)); $this->fail(sprintf(__('An exception SHOULD have been thrown but wasn\'t', 'event_espresso'))); } catch (EE_Error $e) { $this->assertTrue(TRUE); } try { $this->assertFalse(EEH_File::verify_is_writable($file_path)); $this->fail(sprintf(__('An exception SHOULD have been thrown but wasn\'t', 'event_espresso'))); } catch (EE_Error $e) { $this->assertTrue(TRUE); } }
/** * write exception details to log file * * @access public * @ param timestamp $time * @ param object $ex * @ return void */ public function write_to_error_log($time = FALSE, $ex = FALSE, $clear = FALSE) { if (!$ex) { return; } if (!$time) { $time = time(); } $exception_log = '----------------------------------------------------------------------------------------' . PHP_EOL; $exception_log .= '[' . date('Y-m-d H:i:s', $time) . '] Exception Details' . PHP_EOL; $exception_log .= 'Message: ' . $ex['msg'] . PHP_EOL; $exception_log .= 'Code: ' . $ex['code'] . PHP_EOL; $exception_log .= 'File: ' . $ex['file'] . PHP_EOL; $exception_log .= 'Line No: ' . $ex['line'] . PHP_EOL; $exception_log .= 'Stack trace: ' . PHP_EOL; $exception_log .= $ex['string'] . PHP_EOL; $exception_log .= '----------------------------------------------------------------------------------------' . PHP_EOL; EE_Registry::instance()->load_helper('File'); try { EEH_File::ensure_file_exists_and_is_writable(EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . self::$_exception_log_file); EEH_File::add_htaccess_deny_from_all(EVENT_ESPRESSO_UPLOAD_DIR . 'logs'); if (!$clear) { //get existing log file and append new log info $exception_log = EEH_File::get_file_contents(EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . self::$_exception_log_file) . $exception_log; } EEH_File::write_to_file(EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . self::$_exception_log_file, $exception_log); } catch (EE_Error $e) { EE_Error::add_error(sprintf(__('Event Espresso error logging could not be setup because: %s', 'event_espresso'), $e->getMessage())); return; } }
/** * captures plugin activation errors for debugging * * @return void */ public static function ee_plugin_activation_errors() { if (WP_DEBUG) { $activation_errors = ob_get_contents(); if (!empty($activation_errors)) { $activation_errors = date('Y-m-d H:i:s') . "\n" . $activation_errors; } espresso_load_required('EEH_File', EE_HELPERS . 'EEH_File.helper.php'); if (class_exists('EEH_File')) { try { EEH_File::ensure_file_exists_and_is_writable(EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html'); EEH_File::write_to_file(EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html', $activation_errors); } catch (EE_Error $e) { EE_Error::add_error(sprintf(__('The Event Espresso activation errors file could not be setup because: %s', 'event_espresso'), $e->getMessage()), __FILE__, __FUNCTION__, __LINE__); } } else { // old school attempt file_put_contents(EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html', $activation_errors); } $activation_errors = get_option('ee_plugin_activation_errors', '') . $activation_errors; update_option('ee_plugin_activation_errors', $activation_errors); } }
/** * captures plugin activation errors for debugging * * @return void */ public static function ee_plugin_activation_errors() { if (defined('WP_DEBUG') && WP_DEBUG) { $activation_errors = ob_get_contents(); if (class_exists('EE_Registry')) { EE_Registry::instance()->load_helper('File'); } else { include_once EE_HELPERS . 'EEH_File.helper.php'; } if (class_exists('EEH_File')) { try { EEH_File::ensure_folder_exists_and_is_writable(EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS); EEH_File::ensure_file_exists_and_is_writable(EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html'); EEH_File::write_to_file(EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html', $activation_errors); } catch (EE_Error $e) { EE_Error::add_error(sprintf(__('The Event Espresso activation errors file could not be setup because: %s', 'event_espresso'), $e->getMessage())); } } else { // old school attempt file_put_contents(EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html', $activation_errors); } $activation_errors = get_option('ee_plugin_activation_errors', '') . $activation_errors; update_option('ee_plugin_activation_errors', $activation_errors); } }
/** * verify_filesystem * tests that the required files and folders exist and are writable * */ public function verify_filesystem() { try { EE_Registry::instance()->load_helper('File'); EEH_File::ensure_file_exists_and_is_writable($this->_logs_folder . $this->_log_file); EEH_File::ensure_file_exists_and_is_writable($this->_logs_folder . $this->_debug_file); EEH_File::add_htaccess_deny_from_all($this->_logs_folder); } catch (EE_Error $e) { EE_Error::add_error(sprintf(__('Event Espresso logging could not be setup because: %s', 'event_espresso'), ' ' . $e->getMessage()), __FILE__, __FUNCTION__, __LINE__); return; } }
/** * captures plugin activation errors for debugging * * @return void */ public function ee_plugin_activation_errors() { if (WP_DEBUG === TRUE) { $errors = ob_get_contents(); if (include_once EE_HELPERS . 'EEH_File.helper.php') { try { EEH_File::ensure_folder_exists_and_is_writable(EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS); EEH_File::ensure_file_exists_and_is_writable(EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html'); EEH_File::write_to_file(EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html', $errors); } catch (EE_Error $e) { EE_Error::add_error(sprintf(__('The Event Espresso activation errors file could not be setup because: %s', 'event_espresso'), $e->getMessage())); } } else { // old school attempt file_put_contents(EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html', $errors); } update_option('ee_plugin_activation_errors', $errors); } }