/** * Implement this method in the task subclass to * execute via the TaskRunner */ public function run($request) { if (!($adminEmail = $this->config()->get('administrator_email'))) { $contenders = $this->extend('feedMeAdminEmail') ?: []; $adminEmail = reset($contenders); } if ($adminEmail) { SS_Log::add_writer(new SS_LogEmailWriter($adminEmail, SS_Log::INFO)); } // anything like a warning or above SS_Log::add_writer(new SS_LogEmailWriter(Security::findAnAdministrator()->Email), SS_Log::WARN); $excludedFeedClasses = $this->config()->get('excluded_feed_class_names'); // for each implementor of the FeedMeFeedInterface check if it's not excluded then for each // instance of that model call feedMeImport on it. $implementors = ClassInfo::implementorsOf('FeedMeFeedModelInterface'); foreach ($implementors as $className) { // chance to disable a feed by setting config.excluded_feed_class_names if (!in_array($className, $excludedFeedClasses)) { /** @var FeedMeFeedModelExtension $feedModel */ foreach ($className::get() as $feedModel) { $feedModel->feedMeImport(); } } } }
public function testLogsError() { $logger = new TestWorkableLogger(); SS_Log::add_writer($logger); $result = Workable::create()->getJobs(['state' => 'fail']); $this->assertNotNull($logger->event); SS_Log::remove_writer($logger); }
function setUp() { parent::setUp(); SS_Log::clear_writers(); // this test will break if existing writers are available! $this->testEmailWriter = new SS_LogEmailWriter('*****@*****.**'); $this->testFileWriter = new SS_LogFileWriter('../test.log'); SS_Log::add_writer($this->testEmailWriter, SS_Log::ERR); SS_Log::add_writer($this->testFileWriter, SS_Log::WARN); }
function testEmailWriter() { $testEmailWriter = new SS_LogEmailWriter('*****@*****.**'); SS_Log::add_writer($testEmailWriter, SS_Log::ERR); SS_Log::log('Email test', SS_LOG::ERR, array('my-string' => 'test', 'my-array' => array('one' => 1))); $this->assertEmailSent('*****@*****.**'); $email = $this->findEmail('*****@*****.**'); $parser = new CSSContentParser($email['htmlContent']); $extras = $parser->getBySelector('table.extras'); $extraRows = $extras[0]->tr; $this->assertContains('my-string', $extraRows[count($extraRows) - 2]->td[0]->asXML(), 'Contains extra data key'); $this->assertContains('test', $extraRows[count($extraRows) - 2]->td[1]->asXML(), 'Contains extra data value'); $this->assertContains('my-array', $extraRows[count($extraRows) - 1]->td[0]->asXML(), 'Contains extra data key'); $this->assertContains("array('one'=>1,)", str_replace(array("\r", "\n", " "), '', $extraRows[count($extraRows) - 1]->td[1]->asXML()), 'Serializes arrays correctly'); }
<?php $raygunAPIKey = Config::inst()->get('RaygunLogWriter', 'api_key'); if (empty($raygunAPIKey) && defined('SS_RAYGUN_APP_KEY')) { $raygunAPIKey = SS_RAYGUN_APP_KEY; } if (!empty($raygunAPIKey)) { $raygun = Injector::inst()->create('RaygunLogWriter', $raygunAPIKey); $levelConfig = Config::inst()->get('RaygunLogWriter', 'level'); $level = defined($levelConfig) ? constant($levelConfig) : SS_Log::WARN; SS_Log::add_writer($raygun, $level, '<='); register_shutdown_function(array($raygun, 'shutdown_function')); } else { if (Director::isLive()) { user_error("SilverStripe RayGun module installed, but SS_RAYGUN_APP_KEY not defined in _ss_environment.php", E_USER_WARNING); } }
<?php global $project; $project = 'mysite'; global $database; $database = 'bitnami_silverstripe'; ini_set('mysqli.default_socket', '/opt/bitnami/mysql/tmp/mysql.sock'); //Use _ss_environment.php file for configuration require_once "conf/ConfigureFromEnv.php"; //Security::setDefaultAdmin('admin','password'); //SSL disabled because Chrome does not like unsigned cert //Director::forceSSL(array('/^registration/', '/^Security/','/^admin/')); SS_Log::add_writer(new SS_LogFileWriter('/home/scarola_gmail_com/logs/silverstripe/ss-notice.log'), SS_Log::NOTICE); SS_Log::add_writer(new SS_LogFileWriter('/home/scarola_gmail_com/logs/silverstripe/ss-error.log'), SS_Log::ERR);
<?php if (!Director::isDev()) { SS_Log::add_writer(new SS_LogSlackWriter(), SS_Log::WARN, '<='); }
<?php global $project; $project = 'mysite'; global $database; $database = 'nexthit'; require_once 'conf/ConfigureFromEnv.php'; // Set the site locale i18n::set_locale('en_US'); // log errors and warnings SS_Log::add_writer(new SS_LogFileWriter('../../' + $database + '-silverstripe-errors-warnings.log'), SS_Log::WARN, '<='); // or just errors SS_Log::add_writer(new SS_LogFileWriter('../../' + $database + '-silverstripe-errors.log'), SS_Log::ERR); // or notices (e.g. for Deprecation Notifications) SS_Log::add_writer(new SS_LogFileWriter('../../' + $database + '-silverstripe-errors-notices.log'), SS_Log::NOTICE);
/** * Run the task, and do the business * * @param SS_HTTPRequest $httpRequest */ function run($httpRequest) { require_once 'Zend/Log/Writer/Stream.php'; SS_Log::add_writer(new Zend_Log_Writer_Stream('php://output'), SS_Log::NOTICE); $db = DB::getConn(); if (method_exists($db, 'supportsLocks') && $db->supportsLocks() && !$db->getLock('ScheduledPublishing')) { $this->log('Publication has already been triggered by a different process'); return; } Cookie::$report_errors = false; if (class_exists('Subsite')) { Subsite::$disable_subsite_filter = true; } if (class_exists('Subsite')) { Subsite::$disable_subsite_filter = true; } $this->log('Looking for changes that need to be published'); $bt = defined('DB::USE_ANSI_SQL') ? "\"" : "`"; $wfRequests = DataObject::get('WorkflowRequest', "{$bt}Status{$bt} = 'Scheduled' AND {$bt}EmbargoDate{$bt} <= '" . SS_Datetime::now()->getValue() . "'"); $this->log(sprintf('Found %d pages', $wfRequests ? count($wfRequests) : 0)); $admin = Security::findAnAdministrator(); $admin->logIn(); if (count($wfRequests)) { foreach ($wfRequests as $request) { // Use a try block to prevent one bad request // taking down the whole queue try { $page = $request->Page(); $this->log(sprintf("Attempting to publish '%s' (URL: %s)", $page->Title, $page->AbsoluteLink())); // We remove the embargo date and republish to trigger this. $request->EmbargoDate = null; $result = $request->publish('Page was embargoed. Automatically published.', WorkflowSystemMember::get(), false); $this->log(sprintf("Published '%s' (URL: %s)", $page->Title, $page->AbsoluteLink())); } catch (Exception $e) { // Log it? $this->log(sprintf("Failed to publish '%s (URL: %s)", $page->Title, $page->AbsoluteLink())); user_error("Error publishing change to Page ID " . $request->PageID . " - " . $request->Page()->Title . " Error: " . $e->getMessage(), E_USER_WARNING); continue; } } } $this->log('Looking for live pages that need to be expired'); $pagesToExpire = Versioned::get_by_stage('SiteTree', 'Live', "\"ExpiryDate\" <= '" . SS_Datetime::now()->getValue() . "'"); $this->log(sprintf('Found %d pages', $pagesToExpire ? count($pagesToExpire) : 0)); if (count($pagesToExpire)) { foreach ($pagesToExpire as $page) { // Use a try block to prevent one bad request // taking down the whole queue try { $this->log(sprintf("Attempting to unpublish '%s' (URL: %s)", $page->Title, $page->AbsoluteLink())); // Close any existing workflows if ($wf = $page->openWorkflowRequest()) { $this->log(sprintf("Closing '%s' workflow request for '%s'", $wf->Status, $page->Title)); $wf->deny('Page automatically expired. Removing from Live site.', $admin); } $page->ExpiryDate = null; $page->write(); $page->doUnpublish(); $this->log(sprintf("Unpublished '%s' (URL: %s)", $page->Title, $page->AbsoluteLink())); } catch (Exception $e) { $this->log(sprintf("Failed to unpublish '%s' (URL: %s)", $page->Title, $page->AbsoluteLink())); user_error("Error unpublishing Page ID " . $page->ID . " - " . $page->Title . " Error: " . $e->getMessage(), E_USER_WARNING); continue; } } } // We don't need to clear the lock on every potential exception, // as the closing of the DB connection will do that for us. if (method_exists($db, 'supportsLocks') && $db->supportsLocks()) { $db->releaseLock('ScheduledPublishing'); } }
/** * Log the given error, if self::$log_errors is set. * Uses the native error_log() funtion in PHP. * * Format: [d-M-Y h:i:s] <type> at <file> line <line>: <errormessage> <url> * * @todo Detect script path for CLI errors * @todo Log detailed errors to full file * @deprecated 2.5 See SS_Log on setting up error file logging */ protected static function log_error_if_necessary($errno, $errstr, $errfile, $errline, $errcontext, $errtype) { Deprecation::notice('2.5', 'Use SS_Log instead. See the class documentation in SS_Log.php for more information.'); $priority = $errtype == 'Error' ? SS_Log::ERR : SS_Log::WARN; $writer = new SS_LogFileWriter('../' . self::$log_errors_to); SS_Log::add_writer($writer, $priority); SS_Log::log(array('errno' => $errno, 'errstr' => $errstr, 'errfile' => $errfile, 'errline' => $errline, 'errcontext' => $errcontext), $priority); SS_Log::remove_writer($writer); }
<?php global $project; $project = 'mysite'; global $database; $database = 'silverstripe_webdevelopment_com'; require_once "conf/ConfigureFromEnv.php"; date_default_timezone_set('Pacific/Auckland'); //set cache to 72 hours SS_Cache::set_cache_lifetime('any', 60 * 60 * 72); if (Director::isLive()) { SS_Log::add_writer(new SS_LogEmailWriter('*****@*****.**'), SS_Log::ERR); } else { //BasicAuth::protect_entire_site(); see config.yml } HtmlEditorConfig::get('cms')->setOption('valid_styles', array('*' => 'color,font-weight,font-style,text-decoration')); HtmlEditorConfig::get('cms')->setOption('paste_as_text', true); HtmlEditorConfig::get('cms')->setOption('paste_text_sticky', true); HtmlEditorConfig::get('cms')->setOption('paste_text_sticky_default', true);
<?php // Get YML comfiguration settings $config = Config::inst(); // use database name from config.yml unless defined in environment if (!defined('SS_DATABASE_NAME')) { define('SS_DATABASE_NAME', $config->get('Database', 'name')); } // include configuration set in _ss_environment.php require_once 'conf/ConfigureFromEnv.php'; FulltextSearchable::enable(array('SiteTree')); if (Director::isDev()) { // Turn on all errors ini_set('display_errors', 1); ini_set("log_errors", 1); // error_reporting(E_ERROR | E_PARSE); // error_reporting(E_ALL && ~E_DEPRECATED); error_reporting(E_ALL | E_STRICT); SS_Log::add_writer(new SS_LogFileWriter(dirname(__FILE__) . '/errors.log')); // SSViewer::flush_template_cache(); // Email::send_all_emails_to('?@platocreative.co.nz'); }
<?php require_once 'conf/ConfigureFromEnv.php'; // Set the site locale i18n::set_locale('en_US'); // Extensions DataObject::add_extension('SiteConfig', 'SiteConfigExtension'); // specify log files $path = BASE_PATH . '/../logs'; SS_Log::add_writer(new SS_LogFileWriter($path . '/info.log'), SS_Log::WARN, '<='); SS_Log::add_writer(new SS_LogFileWriter($path . '/errors.log'), SS_Log::ERR);
<?php global $project; $project = 'mysite'; global $database; $database = 'somepainter'; require_once 'conf/ConfigureFromEnv.php'; // Set timezone date_default_timezone_set('Australia/Melbourne'); // Set the site locale i18n::set_locale('en_AU'); //Log notices if (defined('MY_SS_ERROR_LOG')) { SS_Log::add_writer(new SS_LogFileWriter(MY_SS_ERROR_LOG), SS_Log::NOTICE, '<='); } // Configure Admin CMSMenu::remove_menu_item('ReportAdmin'); CMSMenu::remove_menu_item('CMSPagesController'); CMSMenu::remove_menu_item('AssetAdmin'); CMSMenu::remove_menu_item('SecurityAdmin'); CMSMenu::remove_menu_item('CMSSettingsController'); // Configure cache $liveCacheLife = 60 * 60; // 60 minutes $devCacheLife = -1; // disabled $cacheLife = Director::isDev() ? $devCacheLife : $liveCacheLife; SS_Cache::set_cache_lifetime(EventsController::EVENTS_CACHE_NAME, $cacheLife, 100); SS_Cache::set_cache_lifetime(EventsController::CONFIG_CACHE_NAME, $cacheLife, 100);
<?php define('SS_NR_BASE', basename(dirname(__FILE__))); Config::inst()->update('NewRelicPerformanceReport', 'menu_icon', SS_NR_BASE . '/images/new-relic.png'); //Configure new relic monitoring if (extension_loaded('newrelic')) { //Bind to the controller class Controller::add_extension('NewRelicControllerHook'); //If we have an application name constant ensure New Relic knows what the name is if (defined('SS_NR_APPLICATION_NAME')) { newrelic_set_appname(SS_NR_APPLICATION_NAME); } //If we're in cli make sure New Relic is aware that we are if (Director::is_cli()) { newrelic_background_job(true); } //New Relic error binders if (Director::isLive() || defined('SS_NR_FORCE_ENABLE_LOGGING')) { SS_Log::add_writer(new NewRelicErrorLogger(), SS_Log::NOTICE); SS_Log::add_writer(new NewRelicErrorLogger(), SS_Log::WARN); SS_Log::add_writer(new NewRelicErrorLogger(), SS_Log::ERR); } }
<?php /** * CMS Requirements */ Config::inst()->update('LeftAndMain', 'extra_requirements_javascript', array(basename(__DIR__) . '/javascript/actions.js' => array())); /**********************************/ /* Logging Information and Errors */ /**********************************/ // Clear any default writers SS_Log::clear_writers(); // Logging notices & information SS_Log::add_writer(new SS_LogFileWriter('../assets/' . basename(__DIR__) . '/logs/info.log'), SS_Log::NOTICE, '='); // Logging warnings & errors SS_Log::add_writer(new SS_LogFileWriter('../assets/' . basename(__DIR__) . '/logs/error.log'), SS_Log::WARN, '<=');
// Set the timezone if called for if (defined('SS_DATABASE_TIMEZONE')) { $databaseConfig['timezone'] = SS_DATABASE_TIMEZONE; } // For schema enabled drivers: if (defined('SS_DATABASE_SCHEMA')) { $databaseConfig["schema"] = SS_DATABASE_SCHEMA; } // For SQlite3 memory databases (mainly for testing purposes) if (defined('SS_DATABASE_MEMORY')) { $databaseConfig["memory"] = SS_DATABASE_MEMORY; } } if (defined('SS_SEND_ALL_EMAILS_TO')) { Config::inst()->update("Email", "send_all_emails_to", SS_SEND_ALL_EMAILS_TO); } if (defined('SS_SEND_ALL_EMAILS_FROM')) { Config::inst()->update("Email", "send_all_emails_from", SS_SEND_ALL_EMAILS_FROM); } if (defined('SS_DEFAULT_ADMIN_USERNAME')) { if (!defined('SS_DEFAULT_ADMIN_PASSWORD')) { user_error("SS_DEFAULT_ADMIN_PASSWORD must be defined in your _ss_environment.php," . "if SS_DEFAULT_ADMIN_USERNAME is defined. See " . "http://doc.silverstripe.org/framework/en/topics/environment-management for more information", E_USER_ERROR); } Security::setDefaultAdmin(SS_DEFAULT_ADMIN_USERNAME, SS_DEFAULT_ADMIN_PASSWORD); } if (defined('SS_USE_BASIC_AUTH') && SS_USE_BASIC_AUTH) { Config::inst()->update('BasicAuth', 'entire_site_protected', SS_USE_BASIC_AUTH); } if (defined('SS_ERROR_LOG')) { SS_Log::add_writer(new SS_LogFileWriter(BASE_PATH . '/' . SS_ERROR_LOG), SS_Log::WARN, '<='); }
<?php global $project; $project = 'mysite'; include_once dirname(__FILE__) . '/local.conf.php'; if (!defined('SS_LOG_FILE')) { define('SS_LOG_FILE', '/var/log/silverstripe/' . basename(dirname(dirname(__FILE__))) . '.log'); } SS_Log::add_writer(new SS_LogFileWriter(SS_LOG_FILE), SS_Log::NOTICE, '<='); // Sets up relevant cache settings to prevent permission errors SS_Cache::add_backend('default', 'File', array('cache_dir' => TEMP_FOLDER . DIRECTORY_SEPARATOR . 'cache', 'hashed_directory_umask' => 2775, 'cache_file_umask' => 0660)); require_once 'Zend/Cache.php'; require_once 'Zend/Date.php'; $coreCache = Zend_Cache::factory('Core', 'File', array(), array('hashed_directory_umask' => 2775, 'cache_file_umask' => 0660, 'cache_dir' => TEMP_FOLDER)); Zend_Date::setOptions(array('cache' => $coreCache));
/** * Get the Debug Bar instance * * @global array $databaseConfig * @return DebugBar\StandardDebugBar */ public static function getDebugBar() { if (self::$debugbar !== null) { return self::$debugbar; } if (!Director::isDev() || self::IsDisabled() || self::VendorNotInstalled() || self::NotLocalIp() || Director::is_cli() || self::IsDevUrl() || self::IsAdminUrl() && !self::config()->enabled_in_admin) { self::$debugbar = false; // No need to check again return; } // Add the controller extension programmaticaly because it might not be added properly through yml Controller::add_extension('DebugBarControllerExtension'); // Add a custom logger that logs everything under the Messages tab SS_Log::add_writer(new DebugBarLogWriter(), SS_Log::DEBUG, '<='); self::$debugbar = $debugbar = new DebugBar\DebugBar(); if (isset($_REQUEST['showqueries'])) { self::setShowQueries(true); echo "The queries above have been run before we started DebugBar"; echo '<hr>'; unset($_REQUEST['showqueries']); } $debugbar->addCollector(new DebugBar\DataCollector\PhpInfoCollector()); $debugbar->addCollector(new DebugBar\DataCollector\MessagesCollector()); $debugbar->addCollector(new DebugBar\DataCollector\TimeDataCollector()); $debugbar->addCollector(new DebugBar\DataCollector\MemoryCollector()); // On 3.1, PDO does not exist if (method_exists('DB', 'get_conn')) { if (!DB::get_conn()) { global $databaseConfig; if ($databaseConfig) { DB::connect($databaseConfig); } } $connector = DB::get_connector(); if (!self::config()->force_proxy && $connector instanceof PDOConnector) { // Use a little bit of magic to replace the pdo instance $refObject = new ReflectionObject($connector); $refProperty = $refObject->getProperty('pdoConnection'); $refProperty->setAccessible(true); $traceablePdo = new DebugBar\DataCollector\PDO\TraceablePDO($refProperty->getValue($connector)); $refProperty->setValue($connector, $traceablePdo); $debugbar->addCollector(new DebugBar\DataCollector\PDO\PDOCollector($traceablePdo)); } else { DB::set_conn($db = new DebugBarDatabaseNewProxy(DB::get_conn())); $db->setShowQueries(self::getShowQueries()); $debugbar->addCollector(new DebugBarDatabaseCollector($db)); } } else { if (!DB::getConn()) { global $databaseConfig; if ($databaseConfig) { DB::connect($databaseConfig); } } DB::setConn($db = new DebugBarDatabaseProxy(DB::getConn())); $db->setShowQueries(self::getShowQueries()); $debugbar->addCollector(new DebugBarDatabaseCollector($db)); } // Add some SilverStripe specific infos $debugbar->addCollector(new DebugBarSilverStripeCollector()); if (self::config()->enable_storage) { $debugbar->setStorage(new DebugBar\Storage\FileStorage(TEMP_FOLDER . '/debugbar')); } // Since we buffer everything, why not enable all dev options ? if (self::config()->auto_debug) { $_REQUEST['debug'] = true; $_REQUEST['debug_request'] = true; } if (isset($_REQUEST['debug']) || isset($_REQUEST['debug_request'])) { self::$bufferingEnabled = true; ob_start(); // We buffer everything until we have called an action } return $debugbar; }
function process_ipn_response($request = null) { if (!defined('PAYPAL_DEBUG_MODE')) { define("PAYPAL_DEBUG_MODE", false); } // this prevents some kind of error in the core $_SESSION = null; if (DEBUG_MODE) { SS_Log::add_writer(new SS_LogFileWriter(__DIR__ . "/log/paypal.transactions.txt"), SS_Log::WARN, '>'); } if (DEBUG_MODE) { SS_Log::log("IPN Started!", SS_Log::DEBUG); } // parse post variables, reformat the data to be sent back via socket $data = "cmd=_notify-validate"; foreach ($_POST as $key => $value) { $value = urlencode(stripslashes($value)); $data .= "&" . $key . "=" . $value; } // post back to PayPal system to validate $header = "POST /cgi-bin/webscr HTTP/1.1\r\n"; $header .= "Content-Type: application/x-www-form-urlencoded\r\n"; $header .= "Host: www.paypal.com\r\n"; $header .= "Connection: close\r\n"; $header .= "Content-Length: " . strlen($data) . "\r\n\r\n"; $response = "NONE"; // send back the info $socket_handle = fsockopen("ssl://www.paypal.com", 443, $errno, $errstr, 30); if (DEBUG_MODE) { SS_Log::log("header_debug:\n" . print_r($header, true) . "\n\n", SS_Log::DEBUG); } if (DEBUG_MODE) { SS_Log::log("data_debug:\n" . print_r($data, true) . "\n\n", SS_Log::DEBUG); } if ($socket_handle) { fputs($socket_handle, $header . $data); while (!feof($socket_handle)) { $response = fgets($socket_handle, 1024); $response = trim($response); if (DEBUG_MODE) { SS_Log::log("response_debug:\n" . print_r($response, true) . "\n\n", SS_Log::DEBUG); } if (strcmp($response, "VERIFIED") == 0) { $response = "VERIFIED"; } else { if (strcmp($response, "INVALID") == 0) { $response = "INVALID"; } } } fclose($socket_handle); } if (DEBUG_MODE) { SS_Log::log("paypal response: " . $response, SS_Log::DEBUG); } if (DEBUG_MODE) { SS_Log::log(print_r($_POST, true), SS_Log::DEBUG); } if ($response == "INVALID") { // we only care about completed interactions exit(0); } // SUCCESS - Do something with the data $Payment = new PaypalPayment(); $Payment->PaypalStorePageID = $this->ID; $Payment->Date = SS_Datetime::now(); $Payment->TransactionID = isset($_POST['txn_id']) ? $_POST['txn_id'] : $_POST['ipn_track_id']; $Payment->GatewayResponse = implode("\n", $_POST); $Payment->Amount = isset($_POST['amount3']) ? $_POST['amount3'] : (isset($_POST['payment_gross']) ? $_POST['payment_gross'] : (isset($_POST['mc_gross']) ? $_POST['mc_gross'] : 0)); $Payment->ItemID = isset($_POST['item_number']) ? $_POST['item_number'] : null; $Payment->ItemName = isset($_POST['item_name']) ? $_POST['item_name'] : null; $Payment->Email = isset($_POST['payer_email']) ? $_POST['payer_email'] : null; $Payment->Status = isset($_POST['payment_status']) ? $_POST['payment_status'] : null; $Payment->Name = (isset($_POST['first_name']) ? $_POST['first_name'] : null) . ' ' . (isset($_POST['last_name']) ? $_POST['last_name'] : null); $Payment->Street = isset($_POST['address_street']) ? $_POST['address_street'] : null; $Payment->City = isset($_POST['address_city']) ? $_POST['address_city'] : null; $Payment->State = isset($_POST['address_state']) ? $_POST['address_state'] : null; $Payment->Country = isset($_POST['address_country']) ? $_POST['address_country'] : null; $Payment->Zip = isset($_POST['address_zip']) ? $_POST['address_zip'] : null; $Payment->PayerID = isset($_POST['payer_id']) ? $_POST['payer_id'] : null; $Payment->write(); $Payment->OnSuccessfulPayment(); return $Payment; }
<?php /* * Uncomment lines below to configure username, password and/or "From" mail */ // define('SENDGRIDMAILER_USERNAME', '<username>'); // define('SENDGRIDMAILER_PASSWORD', '<password>'); // define('SENDGRIDMAILER_MAIL', 'Info Test <*****@*****.**>'); // Email::set_mailer(new CustomMailer()); SS_Log::add_writer(new SS_LogFileWriter(BASE_PATH . '/info.log'), SS_Log::INFO);
if (class_exists('DynamicCache')) { DynamicCache::config()->enabled = false; } // See where are included files Config::inst()->update('SSViewer', 'source_file_comments', true); // Fix this issue https://github.com/silverstripe/silverstripe-framework/issues/4146 if (isset($_GET['flush'])) { i18n::get_cache()->clean(Zend_Cache::CLEANING_MODE_ALL); } } else { // In production, sanitize php environment to avoid leaking information ini_set('display_errors', false); // Hide where are included files Config::inst()->update('SSViewer', 'source_file_comments', false); // Warn admin if errors occur SS_Log::add_writer(new SS_LogEmailWriter(Email::config()->admin_email), SS_Log::ERR, '<='); } // Protect website if env = isTest if (Director::isTest()) { // If php runs under cgi, Http auth might not work by default. Don't forget to update htaccess if (!isset($_SERVER['PHP_AUTH_USER'])) { if (isset($_SERVER['HTTP_AUTHORIZATION']) && strlen($_SERVER['HTTP_AUTHORIZATION']) > 0) { list($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']) = explode(':', base64_decode(substr($_SERVER['HTTP_AUTHORIZATION'], 6))); if (strlen($_SERVER['PHP_AUTH_USER']) == 0 || strlen($_SERVER['PHP_AUTH_PW']) == 0) { unset($_SERVER['PHP_AUTH_USER']); unset($_SERVER['PHP_AUTH_PW']); } } } BasicAuth::protect_entire_site(); }
define('PROJECT_THIRDPARTY_PATH', project() . '/' . PROJECT_THIRDPARTY_DIR); FulltextSearchable::enable(array('SiteTree')); /** * it is suggested to set SS_ERROR_LOG in _ss_environment.php to enable logging, * alternatively you can use the line below for your custom logging settings * SS_Log::add_writer(new SS_LogFileWriter('../silverstripe-errors.log'), SS_Log::ERR); */ if (!Director::isLive()) { /** * set settings that should only be in dev and test */ } else { /** * we are in live mode, send errors per email */ SS_Log::add_writer(new SS_LogEmailWriter('*****@*****.**'), SS_Log::ERR); } /** ----------------------------------------- * HTMLEditorField * * Adding styles, and buttons * to the HTMLEditorField * -------------------------------------------*/ $formats = array(array('title' => 'Colour - Primary', 'inline' => 'span', 'classes' => 'colour--primary', 'wrapper' => true, 'merge_siblings' => false), array('title' => 'Colour - Secondary', 'inline' => 'span', 'classes' => 'colour--secondary', 'wrapper' => true, 'merge_siblings' => false), array('title' => 'Button - Default', 'selector' => 'a, button', 'classes' => 'btn--default', 'wrapper' => false), array('title' => 'Button - Bordered', 'selector' => 'a, button', 'classes' => 'btn--bordered', 'wrapper' => false)); HtmlEditorConfig::get('cms')->setOption('style_formats', $formats); HtmlEditorConfig::get('cms')->setOption('theme_advanced_blockformats', 'h1,h2,h3,h4,h5,h6,p'); /** * Remove buttons from TinyMCE * * ====== List of available buttons ====== *
<?php global $project; $project = 'mysite'; global $database; $database = ''; require_once 'conf/ConfigureFromEnv.php'; // Set the site locale i18n::set_locale('en_US'); if (Director::isTest()) { SS_Log::add_writer(new SS_LogFileWriter('../silverstripe-errors-warnings.log'), SS_Log::WARN, '<='); SS_Log::add_writer(new SS_LogFileWriter('../silverstripe-errors.log'), SS_Log::ERR); } if (Director::isLive()) { SS_Log::add_writer(new SS_LogEmailWriter('*****@*****.**'), SS_Log::ERR); }
<?php global $project; $project = 'mysite'; include __DIR__ . '/local.conf.php'; // Set the site locale i18n::set_locale('en_US'); SiteTree::enable_nested_urls(); Security::setDefaultAdmin('admin', 'password'); Director::set_environment_type('dev'); SS_Log::add_writer(new SS_LogFileWriter('../silverstripe-errors.log'), SS_Log::ERR);
<?php /** * SilverStripe Project */ global $project; $project = 'mysite'; /** * _ss_environment.php */ require_once "conf/ConfigureFromEnv.php"; /** * Email errors */ if (!Director::isDev()) { SS_Log::add_writer(new SS_LogEmailWriter(Email::getAdminEmail()), SS_Log::NOTICE, '<='); } /** * Keep the cache clean */ if (isset($_REQUEST['flush'])) { SS_Cache::set_cache_lifetime('any', -1, 100); } /** * Locale */ i18n::set_locale('en_US');
public function testEmailException() { $testEmailWriter = new SS_LogEmailWriter('*****@*****.**'); SS_Log::add_writer($testEmailWriter, SS_Log::ERR); // Trigger exception handling mechanism try { $this->exceptionGenerator(); } catch (Exception $exception) { // Mimics exceptionHandler, but without the exit(1) SS_Log::log(array('errno' => E_USER_ERROR, 'errstr' => "Uncaught " . get_class($exception) . ": " . $exception->getMessage(), 'errfile' => $exception->getFile(), 'errline' => $exception->getLine(), 'errcontext' => $exception->getTrace()), SS_Log::ERR); } // Ensure email is sent $this->assertEmailSent('*****@*****.**'); // Begin parsing of email body $email = $this->findEmail('*****@*****.**'); $parser = new CSSContentParser($email['htmlContent']); // Check that the first three lines of the stacktrace are correct $stacktrace = $parser->getByXpath('//body/div[1]/ul[1]'); $this->assertContains('<b>SS_LogTest->exceptionGeneratorThrower()</b>', $stacktrace[0]->li[0]->asXML()); $this->assertContains('<b>SS_LogTest->exceptionGenerator()</b>', $stacktrace[0]->li[1]->asXML()); $this->assertContains('<b>SS_LogTest->testEmailException()</b>', $stacktrace[0]->li[2]->asXML()); }
/** * Log the given error, if self::$log_errors is set. * Uses the native error_log() funtion in PHP. * * Format: [d-M-Y h:i:s] <type> at <file> line <line>: <errormessage> <url> * * @todo Detect script path for CLI errors * @todo Log detailed errors to full file * @deprecated 2.5 See SS_Log on setting up error file logging */ protected static function log_error_if_necessary($errno, $errstr, $errfile, $errline, $errcontext, $errtype) { user_error('Debug::log_error_if_necessary() and Debug::log_errors_to() are deprecated. Please use SS_Log instead. See the class documentation in SS_Log.php for more information.', E_USER_NOTICE); $priority = $errtype == 'Error' ? SS_Log::ERR : SS_Log::WARN; $writer = new SS_LogFileWriter('../' . self::$log_errors_to); SS_Log::add_writer($writer, $priority); SS_Log::log(array('errno' => $errno, 'errstr' => $errstr, 'errfile' => $errfile, 'errline' => $errline, 'errcontext' => $errcontext), $priority); SS_Log::remove_writer($writer); }
<?php global $project; $project = 'mysite'; global $databaseConfig; $databaseConfig = array("type" => 'MySQLDatabase', "server" => 'localhost', "username" => 'root', "password" => '12345', "database" => 'catalogue', "path" => ''); SS_Log::add_writer(new SS_LogFileWriter('c:/inetpub/catalogue/logs/'), SS_Log::WARN, '<='); //uploads folder location define('POSTERSDIR', 'c:\\inetpub\\catalogue\\assets\\Uploads\\'); define('JSONDIR', 'c:\\inetpub\\catalogue\\assets\\Uploads\\metadata\\'); // Set the site locale i18n::set_locale('en_US'); ini_set("log_errors", "On"); //ini_set("error_log", "c:/inetpub/catalogue/logs/");
<?php global $project; $project = 'mysite'; // use the _ss_environment.php file for configuration require_once 'conf/ConfigureFromEnv.php'; // set default language i18n::set_locale('en_US'); define('PROJECT_THIRDPARTY_DIR', project() . '/thirdparty'); define('PROJECT_THIRDPARTY_PATH', BASE_PATH . '/' . PROJECT_THIRDPARTY_DIR); if (SS_IS_TEST_ENV) { BasicAuth::protect_entire_site(true); } if (Director::isLive()) { if (strpos(Director::absoluteBaseURL(), 'silverstripe-europe.org') !== false || strpos(Director::absoluteBaseURL(), 'www') !== false) { $response = new SS_HTTPResponse(); $response->redirect('https://stripecon.eu', 301); HTTP::add_cache_headers($response); $response->output(); die; } // we are in live mode, send errors per email, set cache and force WWW HTTP::set_cache_age(3600); // HTTP Header for CloudFlare Caching SS_Cache::set_cache_lifetime('any', 10800); // Serverside cache to 3 hours. SS_Log::add_writer(new SS_LogEmailWriter('*****@*****.**'), SS_Log::ERR); } Config::inst()->update('HtmlEditorField', 'use_gzip', false);