Skip to content

Commit

Permalink
Synchronizing several improvements from SVN repo (revisions 86 to 90)…
Browse files Browse the repository at this point in the history
… thanks to pablo.ros

Debug performance improvements:
- Don't store debug information in memory when the devel mode is not active in domains.config -> improve memory usage in production environments.
- Add the possibility to deactivate debug in scripts/crons execution. Using 'do' or 'debub_off' when calling the script in command line.
- The debug color changes to red when there are query errors.

PageLink plugging:
- Supports create links with the page number 1, using an special parameter: 'force_first_page'

Database close connection: Allows to close database connection in execution time.

Change in commandLineController: "no debug" parameter name.

Add more information in database error log. Added: current url and referer.
  • Loading branch information
obokaman-com committed Oct 26, 2011
1 parent 7cac4c1 commit 1f42c5b
Show file tree
Hide file tree
Showing 6 changed files with 147 additions and 65 deletions.
Expand Up @@ -97,11 +97,18 @@ abstract class CommandLineController extends Controller
'need_second_param' => false,
'is_required' => false,
),
array(
'short_param_name' => 'nd',
'long_param_name' => 'nodebug',
'help_string' => 'Deactivate the debug mode even if it is active in domains.config.',
'need_second_param' => false,
'is_required' => false,
),
);

abstract function init();

abstract function exec();
abstract function exec();

public function __construct()
{
Expand All @@ -123,9 +130,9 @@ public function __construct()

/**
* Print a message on the console.
*
*
* Usage example:
*
*
* $this->showMessage( 'Example message', self::VERBOSE, array( 'background' => 'red', 'indent' => 4 ) );
*
* @param string $message
Expand Down Expand Up @@ -370,6 +377,11 @@ private function _common_exec()
case "force":
$this->force = true;
break;
case "nd":
case "nodebug":
$this->params['has_debug'] = false;
Domains::getInstance()->setDevModeOff();
break;
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions instances/default/templates/debug.tpl
Expand Up @@ -318,8 +318,8 @@ LoadjQueryUI();
<dd><span>{math equation="y / x * 100" x=$debug.times.total y=$debug.times.db_queries format="%.0f"}%</span>{$debug.times.db_queries|time_format}</dd>
{/if}
{if $debug.queries_errors}
<dt>{t}DB errors{/t}</dt>
<dd>{$debug.queries_errors|@count}</dd>
<dt class="query_error">{t}DB errors{/t}</dt>
<dd class="query_error"><strong>{$debug.queries_errors|@count}</strong></dd>
{/if}
{if $debug.times.search}
<dt>{t}Searches{/t} <small>(<a href="#search_queries">{t 1=$debug.elements.search}%1 searches{/t}</a>)</small></dt>
Expand Down
38 changes: 19 additions & 19 deletions instances/default/templates/manager/findi18n.tpl
Expand Up @@ -2,18 +2,18 @@
<head>
<title>I18N finder and extractor</title>
<meta http-equiv="Content-Type" content="text/html; charset={$charset}" />
<link rel="stylesheet" type="text/css" href="http://static.seoframework.local/css/main.css?id=" /></head>

<link rel="stylesheet" type="text/css" href="http://static.seoframework.local/css/main.css?id=" /></head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.js"></script>
<script type="text/javascript" src="{$url.static}/js/jquery.translate-core.min.js"></script>
<script type="text/javascript" src="{$url.static}/js/jquery.translate-core.min.js"></script>
{literal}
<script type="text/javascript">
$(document).ready( function(){
$('#instance').change( function(){
selected_instance = $(this).val();
$('#locale').html( $('#locale_' + selected_instance).html() );
});

$('a.toggle').unbind('click').click( function() {
dest_el = $(this).attr('rel');
if ( $('#'+dest_el).is(':visible') )
Expand All @@ -22,20 +22,20 @@
$('#'+dest_el).slideDown();
return false;
});

$('#translations p').each( function() {
var original_container = $('span.original',this);
var destination_containter = $('span.translated',this);
var original_text = original_container.html();
original_text = original_text.replace('%1','111');
original_text = original_text.replace('%2','222');
original_text = original_text.replace('%3','333');
original_text = original_text.replace('%4','333');
original_text = original_text.replace(/(<([^>]+)>)/ig,"");
original_text = original_text.replace(/(<([^>]+)>)/ig,"");
var destination_language = '{/literal}{$language}{literal}';
$.translate( original_text, destination_language, {
complete: function(translation){
translation = translation.replace('111','%1');
Expand All @@ -47,7 +47,7 @@
destination_containter.html(translation);
}
});
});
});
});
</script>
<style>
Expand All @@ -74,16 +74,16 @@
<option value="{$i}"{if $instance == $i} selected="selected"{/if}>{$i}</option>
{ /foreach}
</select>

<label for="locale">Compare against:</label>
{ foreach from=$locales key=loc_instance item=loc_files}
<select id="locale_{$loc_instance}" style="display:none">
{ foreach from=$loc_files item=i}
<option value="{$i}"{if $locale == $i} selected="selected"{/if}>{$i}</option>
{ /foreach}
{ /foreach}
</select>
{ /foreach}

<select id="locale" name="locale">
{ foreach from=$locales.$instance item=i}
<option value="{$i}"{if $locale == $i} selected="selected"{/if}>{$i}</option>
Expand All @@ -94,9 +94,9 @@
<option value="utf-8"{if $charset == 'utf-8'} selected="selected"{/if}>utf-8</option>
<option value="iso-8859-1"{if $charset == 'iso-8859-1'} selected="selected"{/if}>iso-8859-1</option>
</select>

<input type="submit" />
</p>
</p>
</form>

{ if isset($literals)}
Expand All @@ -117,16 +117,16 @@ INSERT IGNORE INTO i18n_messages SET message='{$literal|replace:"'":"\'"|escape:
INSERT INTO i18n_messages values ( null, '{$literal|replace:"'":"\'"|escape:'html'}', '{$path}' );
{ /foreach}
</pre>
<h3>Suggested (automatic) translations for missing strings in "messages" (Total {$missing|@count})</h3>

<h3>Suggested (automatic) translations for missing strings in "messages" (Total {$missing|@count})</h3>
<div id="translations">
{ foreach key=literal item=path from=$missing}
<p>
<span class="original">{$literal|replace:"__":""|replace:"'":"\'"}</span>
$translations["<span class="original_visible">{$literal|replace:"__":""|replace:"'":"\'"|escape:'html'}</span>"] =
$translations["<span class="original_visible">{$literal|replace:"__":""|replace:"'":"\'"|escape:'html'}</span>"] =
"<span class="translated">...</span>";
</p>
{ /foreach}
{ /foreach}
</div>
{ /if}
</body>
Expand Down
129 changes: 95 additions & 34 deletions libs/SEOframework/Database.php
@@ -1,15 +1,15 @@
<?php
/**
* LICENSE
*
*
* Copyright 2010 Albert Lombarte
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand Down Expand Up @@ -194,40 +194,13 @@ public function __call($method, $args)//call adodb methods
else
$resultset = $answer;

$query = self::$adodb[self::$destination_type]->_querySQL;
$query_time = Benchmark::getInstance()->timingCurrentToRegistry( 'db_queries' );
$debug_query = array(
"tag" => $tag,
"sql" => in_array( $method, array( 'Affected_Rows', 'Insert_ID' ) ) ? $method : $query,
"type" => ( $read_operation ? 'read' : 'write' ),
"destination" => self::$destination_type,
"host" => self::$adodb[self::$destination_type]->host,
"database" => self::$adodb[self::$destination_type]->database,
"user" => self::$adodb[self::$destination_type]->user,
"controller" => get_class( $this ),
// Show a table with the method name and number (functions: Affected_Rows, Last_InsertID
"resultset" => is_integer( $resultset ) ? array( array( $method => $resultset ) ): $resultset,
"time" => $query_time,
"error" => ( isset( $error ) ? $error : false )
);

if ( $debug_query['type'] == 'read' )
{
$debug_query['rows_num'] = count( $resultset );
}
else
{
$debug_query['rows_num'] = self::$adodb[self::$destination_type]->Affected_Rows();
}

// Log mysql_errors to disk:
if ( isset( $error ) )
{
// Log mysql_errors to disk:
file_put_contents( ROOT_PATH . '/logs/errors_database.log', "================================\nDate: " . date( 'd-m-Y H:i:s') . "\nError:\n". $error . "\n ", FILE_APPEND );
Registry::push( 'queries_errors', $error );
$this->writeDiskLog( $error );
}

Registry::push( 'queries', $debug_query );
$this->queryDebug( $resultset, $tag, $method, $read_operation, isset( $error ) ? $error : null );

// Reset queries in master flag:
self::$launch_in_master = false;
Expand Down Expand Up @@ -272,6 +245,94 @@ public function nextQueryInMaster()
return self::$launch_in_master = true;
}

/**
* Close database connection.
* @return void
*/
protected function closeConnectionDatabase()
{
$this->close();
// Unset current connection. In the next query execution it will reconnect automatically.
unset( self::$adodb[self::$destination_type] );
}

/**
* Set Query Debug. Used in '__call' method. It checks if dev mode is enabled and then stores debug data in registry.
* @param $resultset
* @param $tag
* @param $method
* @param $read_operation
* @param $error
* @return void
*/
protected function queryDebug( $resultset, $tag, $method, $read_operation, $error )
{
if( !Domains::getInstance()->getDevMode() )
{
return false;
}

$query = self::$adodb[self::$destination_type]->_querySQL;
$query_time = Benchmark::getInstance()->timingCurrentToRegistry( 'db_queries' );

$debug_query = array(
"tag" => $tag,
"sql" => in_array( $method, array( 'Affected_Rows', 'Insert_ID' ) ) ? $method : $query,
"type" => ( $read_operation ? 'read' : 'write' ),
"destination" => self::$destination_type,
"host" => self::$adodb[self::$destination_type]->host,
"database" => self::$adodb[self::$destination_type]->database,
"user" => self::$adodb[self::$destination_type]->user,
"controller" => get_class( $this ),
// Show a table with the method name and number (functions: Affected_Rows, Last_InsertID
"resultset" => is_integer( $resultset ) ? array( array( $method => $resultset ) ): $resultset,
"time" => $query_time,
"error" => ( isset( $error ) ? $error : false )
);

if ( $debug_query['type'] == 'read' )
{
$debug_query['rows_num'] = count( $resultset );
}
else
{
$debug_query['rows_num'] = 0;
if ( $method != 'close' )
{
$debug_query['rows_num'] = self::$adodb[self::$destination_type]->Affected_Rows();
}
}

Registry::push( 'queries', $debug_query );
if( isset( $error ) )
{
Registry::push( 'queries_errors', $error );
}
}

/**
* Log mysql_errors to disk:
* @param $error
* @return void
*/
protected function writeDiskLog( $error )
{
$date = date( 'd-m-Y H:i:s');
$referer = FilterServer::getInstance()->getString( 'HTTP_REFERER' );
$current_url = FilterServer::getInstance()->getString( 'SCRIPT_URI' );

// Log mysql_errors to disk:
$message = <<<MESSAGE
================================
Date: $date
URL: $current_url
Referer: $referer
Error: $error
MESSAGE;

file_put_contents( ROOT_PATH . '/logs/errors_database.log', $message, FILE_APPEND );
}
}

class LoadBalancer_ADODB extends LoadBalancer
Expand Down
17 changes: 13 additions & 4 deletions libs/SEOframework/Domains.php
@@ -1,15 +1,15 @@
<?php
/**
* LICENSE
*
*
* Copyright 2010 Albert Lombarte
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand Down Expand Up @@ -253,6 +253,15 @@ public function getDevMode()
return $this->dev_mode;
}

/**
* Deactivate dev mode in order not to use the debug in the excecution even it's dev mode defined in domains.config.
* @return void
*/
public function setDevModeOff()
{
$this->dev_mode = false;
}

/**
* Allows to retrieve any parameter declared in domains.config by Key.
*
Expand Down
4 changes: 2 additions & 2 deletions libs/Smarty-2.6.26/plugins/function.pagelink.php
Expand Up @@ -57,7 +57,7 @@ function smarty_function_pagelink( $params, &$smarty )
}

$_actual_url = implode( $_delimiter, array_reverse( $_actual_url ) );

if ( isset( $params['absolute'] ) )
{
$_actual_url = $_actual_host . $_actual_url;
Expand All @@ -69,7 +69,7 @@ function smarty_function_pagelink( $params, &$smarty )
}
else
{
if ( $params['page'] > 1 )
if ( $params['page'] > 1 || ( isset( $params['force_first_page'] ) && $params['force_first_page'] == true ) )
{
return $_actual_url . $_delimiter . $params['page'];
}
Expand Down

0 comments on commit 1f42c5b

Please sign in to comment.