Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/3.2' into 3
Browse files Browse the repository at this point in the history
  • Loading branch information
Damian Mooyman committed Aug 24, 2015
2 parents 1bb6b85 + d0f94b5 commit 4ea344a
Show file tree
Hide file tree
Showing 34 changed files with 1,540 additions and 32 deletions.
14 changes: 14 additions & 0 deletions control/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,20 @@ class Controller extends RequestHandler implements TemplateGlobalProvider {
public function init() {
if($this->basicAuthEnabled) BasicAuth::protect_site_if_necessary();

// Directly access the session variable just in case the Group or Member tables don't yet exist
if(Member::config()->log_last_visited) {
Deprecation::notice(
'4.0',
'Member::$LastVisited is deprecated. From 4.0 onwards you should implement this as a custom extension'
);
if(Session::get('loggedInAs') && Security::database_is_ready() && ($member = Member::currentUser())) {
DB::prepared_query(
sprintf('UPDATE "Member" SET "LastVisited" = %s WHERE "ID" = ?', DB::get_conn()->now()),
array($member->ID)
);
}
}

// This is used to test that subordinate controllers are actually calling parent::init() - a common bug
$this->baseInitCalled = true;
}
Expand Down
25 changes: 25 additions & 0 deletions control/Cookie.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,15 @@ public static function get_all($includeUnsent = true) {
return self::get_inst()->getAll($includeUnsent);
}

/**
* @deprecated
*/
public static function forceExpiry($name, $path = null, $domain = null) {
Deprecation::notice('4.0', 'Use Cookie::force_expiry instead.');

return self::force_expiry($name, $path, $domain);
}

/**
* @param string
* @param string
Expand All @@ -69,4 +78,20 @@ public static function get_all($includeUnsent = true) {
public static function force_expiry($name, $path = null, $domain = null, $secure = false, $httpOnly = true) {
return self::get_inst()->forceExpiry($name, $path, $domain, $secure, $httpOnly);
}

/**
* @deprecated
*/
public static function set_report_errors($reportErrors) {
Deprecation::notice('4.0', 'Use "Cookie.report_errors" config setting instead');
Config::inst()->update('Cookie', 'report_errors', $reportErrors);
}

/**
* @deprecated
*/
public static function report_errors() {
Deprecation::notice('4.0', 'Use "Cookie.report_errors" config setting instead');
return Config::inst()->get('Cookie', 'report_errors');
}
}
54 changes: 53 additions & 1 deletion core/Object.php
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,58 @@ public static function static_lookup($class, $name, $default = null) {
return $default;
}

/**
* @deprecated
*/
public static function get_static($class, $name, $uncached = false) {
Deprecation::notice('4.0', 'Replaced by Config#get');
return Config::inst()->get($class, $name, Config::FIRST_SET);
}

/**
* @deprecated
*/
public static function set_static($class, $name, $value) {
Deprecation::notice('4.0', 'Replaced by Config#update');
Config::inst()->update($class, $name, $value);
}

/**
* @deprecated
*/
public static function uninherited_static($class, $name, $uncached = false) {
Deprecation::notice('4.0', 'Replaced by Config#get');
return Config::inst()->get($class, $name, Config::UNINHERITED);
}

/**
* @deprecated
*/
public static function combined_static($class, $name, $ceiling = false) {
if ($ceiling) throw new Exception('Ceiling argument to combined_static is no longer supported');

Deprecation::notice('4.0', 'Replaced by Config#get');
return Config::inst()->get($class, $name);
}

/**
* @deprecated
*/
public static function addStaticVars($class, $properties, $replace = false) {
Deprecation::notice('4.0', 'Replaced by Config#update');
foreach($properties as $prop => $value) self::add_static_var($class, $prop, $value, $replace);
}

/**
* @deprecated
*/
public static function add_static_var($class, $name, $value, $replace = false) {
Deprecation::notice('4.0', 'Replaced by Config#remove and Config#update');

if ($replace) Config::inst()->remove($class, $name);
Config::inst()->update($class, $name, $value);
}

/**
* Return TRUE if a class has a specified extension.
* This supports backwards-compatible format (static Object::has_extension($requiredExtension))
Expand Down Expand Up @@ -441,7 +493,7 @@ public static function has_extension($classOrExtension, $requiredExtension = nul
* instances, not existing ones (including all instances created through {@link singleton()}).
*
* @see http://doc.silverstripe.org/framework/en/trunk/reference/dataextension
* @param string $class Class that should be extended - has to be a subclass of {@link Object}
* @param string $classOrExtension Class that should be extended - has to be a subclass of {@link Object}
* @param string $extension Subclass of {@link Extension} with optional parameters
* as a string, e.g. "Versioned" or "Translatable('Param')"
*/
Expand Down
239 changes: 239 additions & 0 deletions dev/Profiler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,239 @@
<?php
/********************************************************************************\
* Copyright (C) Carl Taylor ([email protected]) *
* Copyright (C) Torben Nehmer ([email protected]) for Code Cleanup *
* Licensed under the BSD license upon request *
\********************************************************************************/

/// Enable multiple timers to aid profiling of performance over sections of code

/**
* Execution time profiler.
*
* @deprecated 4.0 The Profiler class is deprecated, use third party tools like XHProf instead
*
* @package framework
* @subpackage misc
*/
class Profiler {
var $description;
var $startTime;
var $endTime;
var $initTime;
var $cur_timer;
var $stack;
var $trail;
var $trace;
var $count;
var $running;

protected static $inst;

/**
* Initialise the timer. with the current micro time
*/
public function Profiler( $output_enabled=false, $trace_enabled=false)
{
$this->description = array();
$this->startTime = array();
$this->endTime = array();
$this->initTime = 0;
$this->cur_timer = "";
$this->stack = array();
$this->trail = "";
$this->trace = "";
$this->count = array();
$this->running = array();
$this->initTime = $this->getMicroTime();
$this->output_enabled = $output_enabled;
$this->trace_enabled = $trace_enabled;
$this->startTimer('unprofiled');
}

// Public Methods

public static function init() {
Deprecation::notice('4.0', 'The Profiler class is deprecated, use third party tools like XHProf instead');
if(!self::$inst) self::$inst = new Profiler(true,true);
}

public static function mark($name, $level2 = "", $desc = "") {
if($level2 && $_GET['debug_profile'] > 1) $name .= " $level2";

if(!self::$inst) self::$inst = new Profiler(true,true);

self::$inst->startTimer($name, $desc);
}
public static function unmark($name, $level2 = "", $desc = "") {
if($level2 && $_GET['debug_profile'] > 1) $name .= " $level2";

if(!self::$inst) self::$inst = new Profiler(true,true);

self::$inst->stopTimer($name, $desc);
}
public static function show($showTrace = false) {
if(!self::$inst) self::$inst = new Profiler(true,true);

echo "<div style=\"position: absolute; z-index: 100000; top: 20px; left: 20px; background-color: white;"
. " padding: 20px; border: 1px #AAA solid; height: 80%; overflow: auto;\">";
echo "<p><a href=\"#\" onclick=\"this.parentNode.parentNode.style.display = 'none'; return false;\">"
. "(Click to close)</a></p>";
self::$inst->printTimers();
if($showTrace) self::$inst->printTrace();
echo "</div>";
}

/**
* Start an individual timer
* This will pause the running timer and place it on a stack.
* @param string $name name of the timer
* @param string optional $desc description of the timer
*/
public function startTimer($name, $desc="" ){
$this->trace.="start $name\n";
$n=array_push( $this->stack, $this->cur_timer );
$this->__suspendTimer( $this->stack[$n-1] );
$this->startTime[$name] = $this->getMicroTime();
$this->cur_timer=$name;
$this->description[$name] = $desc;
if (!array_key_exists($name,$this->count))
$this->count[$name] = 1;
else
$this->count[$name]++;
}

/**
* Stop an individual timer
* Restart the timer that was running before this one
* @param string $name name of the timer
*/
public function stopTimer($name){
$this->trace.="stop $name\n";
$this->endTime[$name] = $this->getMicroTime();
if (!array_key_exists($name, $this->running))
$this->running[$name] = $this->elapsedTime($name);
else
$this->running[$name] += $this->elapsedTime($name);
$this->cur_timer=array_pop($this->stack);
$this->__resumeTimer($this->cur_timer);
}

/**
* measure the elapsed time of a timer without stoping the timer if
* it is still running
*/
public function elapsedTime($name){
// This shouldn't happen, but it does once.
if (!array_key_exists($name,$this->startTime))
return 0;

if(array_key_exists($name,$this->endTime)){
return ($this->endTime[$name] - $this->startTime[$name]);
} else {
$now=$this->getMicroTime();
return ($now - $this->startTime[$name]);
}
}//end start_time

/**
* Measure the elapsed time since the profile class was initialised
*
*/
public function elapsedOverall(){
$oaTime = $this->getMicroTime() - $this->initTime;
return($oaTime);
}//end start_time

/**
* print out a log of all the timers that were registered
*
*/
public function printTimers($enabled=false)
{
if($this->output_enabled||$enabled){
$TimedTotal = 0;
$tot_perc = 0;
ksort($this->description);
print("<pre>\n");
$oaTime = $this->getMicroTime() - $this->initTime;
echo"============================================================================\n";
echo " PROFILER OUTPUT\n";
echo"============================================================================\n";
print( "Calls Time Routine\n");
echo"-----------------------------------------------------------------------------\n";
while (list ($key, $val) = each ($this->description)) {
$t = $this->elapsedTime($key);
$total = $this->running[$key];
$count = $this->count[$key];
$TimedTotal += $total;
$perc = ($total/$oaTime)*100;
$tot_perc+=$perc;
// $perc=sprintf("%3.2f", $perc );
$lines[ sprintf( "%3d %3.4f ms (%3.2f %%) %s\n", $count, $total*1000, $perc, $key) ] = $total;
}
arsort($lines);
foreach($lines as $line => $total) {
echo $line;
}

echo "\n";

$missed=$oaTime-$TimedTotal;
$perc = ($missed/$oaTime)*100;
$tot_perc+=$perc;
// $perc=sprintf("%3.2f", $perc );
printf( " %3.4f ms (%3.2f %%) %s\n", $missed*1000,$perc, "Missed");

echo"============================================================================\n";

printf( " %3.4f ms (%3.2f %%) %s\n", $oaTime*1000,$tot_perc, "OVERALL TIME");

echo"============================================================================\n";

print("</pre>");
}
}

public function printTrace( $enabled=false )
{
if($this->trace_enabled||$enabled){
print("<pre>");
print("Trace\n$this->trace\n\n");
print("</pre>");
}
}

/// Internal Use Only Functions

/**
* Get the current time as accuratly as possible
*
*/
public function getMicroTime(){
$tmp=explode(' ', microtime());
$rt=$tmp[0]+$tmp[1];
return $rt;
}

/**
* resume an individual timer
*
*/
public function __resumeTimer($name){
$this->trace.="resume $name\n";
$this->startTime[$name] = $this->getMicroTime();
}

/**
* suspend an individual timer
*
*/
public function __suspendTimer($name){
$this->trace.="suspend $name\n";
$this->endTime[$name] = $this->getMicroTime();
if (!array_key_exists($name, $this->running))
$this->running[$name] = $this->elapsedTime($name);
else
$this->running[$name] += $this->elapsedTime($name);
}
}
1 change: 1 addition & 0 deletions dev/SapphireTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,7 @@ public function loadFixture($fixtureFile) {
* {@link loadFixture()}
*/
public function clearFixtures() {
$this->fixtures = array();
$this->getFixtureFactory()->clear();
}

Expand Down
Loading

0 comments on commit 4ea344a

Please sign in to comment.