mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-18 18:46:17 +00:00
- NeatArray::threaded() returns to the repository, it got lost somehow.
- A limit (default: 200 lines) on query log size in DBO. - A fix for Flay's url guessing. - Removed application specific code from /libs/legacy.php - A fix for /libs/model.php - An unfinished /libs/dbo_pear.php; if anyone can help out finishing it, it would be great -- I don't know Pear::DB too well git-svn-id: https://svn.cakephp.org/repo/trunk/cake@218 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
065131205d
commit
85dff45ada
6 changed files with 232 additions and 24 deletions
|
@ -387,6 +387,21 @@ class NeatArray {
|
|||
return $this->value = $out;
|
||||
}
|
||||
|
||||
function threaded ($root=null, $idKey='id', $parentIdKey='parent_id', $childrenKey='children') {
|
||||
$out = array();
|
||||
|
||||
for ($ii=0; $ii<sizeof($this->value); $ii++) {
|
||||
if ($this->value[$ii][$parentIdKey] == $root) {
|
||||
$tmp = $this->value[$ii];
|
||||
$tmp[$childrenKey] = isset($this->value[$ii][$idKey])?
|
||||
$this->threaded($this->value[$ii][$idKey], $idKey, $parentIdKey, $childrenKey):
|
||||
null;
|
||||
$out[] = $tmp;
|
||||
}
|
||||
}
|
||||
|
||||
return $out;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
16
libs/dbo.php
16
libs/dbo.php
|
@ -176,6 +176,17 @@ class DBO extends Object {
|
|||
*/
|
||||
var $_queriesLog=array();
|
||||
|
||||
/**
|
||||
* Maximum number of items in query log, to prevent query log taking over
|
||||
* too much memory on large amounts of queries -- we've had problems at
|
||||
* ~6000 queries.
|
||||
*
|
||||
* @var int Maximum number of queries in the queries log.
|
||||
* @access private
|
||||
*/
|
||||
var $_queriesLogMax=200;
|
||||
|
||||
|
||||
// specific for each database, implemented in db drivers
|
||||
function connect ($config) {
|
||||
die('Please implement DBO::connect() first.');
|
||||
|
@ -408,6 +419,7 @@ class DBO extends Object {
|
|||
function logQuery($sql) {
|
||||
$this->_queriesCnt++;
|
||||
$this->_queriesTime += $this->took;
|
||||
|
||||
$this->_queriesLog[] = array(
|
||||
'query'=>$sql,
|
||||
'error'=>$this->error,
|
||||
|
@ -416,6 +428,10 @@ class DBO extends Object {
|
|||
'took'=>$this->took
|
||||
);
|
||||
|
||||
if (count($this->_queriesLog) > $this->_queriesLogMax) {
|
||||
array_pop($this->_queriesLog);
|
||||
}
|
||||
|
||||
if ($this->error)
|
||||
false; // shouldn't we be logging errors somehow?
|
||||
}
|
||||
|
|
188
libs/dbo_pear.php
Normal file
188
libs/dbo_pear.php
Normal file
|
@ -0,0 +1,188 @@
|
|||
<?PHP
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// + $Id$
|
||||
// +------------------------------------------------------------------+ //
|
||||
// + Cake <https://developers.nextco.com/cake/> + //
|
||||
// + Copyright: (c) 2005 Cake Authors/Developers + //
|
||||
// + + //
|
||||
// + Author(s): Michal Tatarynowicz aka Pies <tatarynowicz@gmail.com> + //
|
||||
// + Larry E. Masters aka PhpNut <nut@phpnut.com> + //
|
||||
// + Kamil Dzielinski aka Brego <brego.dk@gmail.com> + //
|
||||
// + + //
|
||||
// +------------------------------------------------------------------+ //
|
||||
// + Licensed under The MIT License + //
|
||||
// + Redistributions of files must retain the above copyright notice. + //
|
||||
// + You may not use this file except in compliance with the License. + //
|
||||
// + + //
|
||||
// + You may obtain a copy of the License at: + //
|
||||
// + License page: http://www.opensource.org/licenses/mit-license.php + //
|
||||
// +------------------------------------------------------------------+ //
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/*
|
||||
* Name: DBO/Pear
|
||||
* Pear::DB layer for DBO
|
||||
*
|
||||
* @filesource
|
||||
* @author Cake Authors/Developers
|
||||
* @copyright Copyright (c) 2005, Cake Authors/Developers
|
||||
* @link https://developers.nextco.com/cake/wiki/Authors Authors/Developers
|
||||
* @package cake
|
||||
* @subpackage cake.libs
|
||||
* @since Cake v 0.2.9
|
||||
* @version $Revision$
|
||||
* @modifiedby $LastChangedBy$
|
||||
* @lastmodified $Date$
|
||||
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
||||
*/
|
||||
|
||||
/**
|
||||
* Enter description here...
|
||||
*
|
||||
*/
|
||||
|
||||
uses('dbo');
|
||||
/**
|
||||
* Enter description here...
|
||||
*
|
||||
*
|
||||
* @package cake
|
||||
* @subpackage cake.libs
|
||||
* @since Cake v 0.2.9
|
||||
*
|
||||
*/
|
||||
class DBO_Pear extends DBO {
|
||||
|
||||
/**
|
||||
* Enter description here...
|
||||
*
|
||||
* @param unknown_type $config
|
||||
* @return unknown
|
||||
*/
|
||||
function connect ($config) {
|
||||
die('Please implement DBO::connect() first.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Enter description here...
|
||||
*
|
||||
* @return unknown
|
||||
*/
|
||||
function disconnect () {
|
||||
die('Please implement DBO::disconnect() first.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Enter description here...
|
||||
*
|
||||
* @param unknown_type $sql
|
||||
* @return unknown
|
||||
*/
|
||||
function execute ($sql) {
|
||||
return $this->_pear->query($sql);
|
||||
}
|
||||
|
||||
/**
|
||||
* Enter description here...
|
||||
*
|
||||
* @param unknown_type $res
|
||||
* @return unknown
|
||||
*/
|
||||
function fetchRow ($result) {
|
||||
return $result->fetchRow(DB_FETCHMODE_ASSOC);
|
||||
}
|
||||
|
||||
/**
|
||||
* Enter description here...
|
||||
*
|
||||
* @return unknown
|
||||
*/
|
||||
function tables () { // POSTGRESQL ONLY! PEAR:DB DOESN'T SUPPORT LISTING TABLES
|
||||
$sql = "SELECT a.relname AS name
|
||||
FROM pg_class a, pg_user b
|
||||
WHERE ( relkind = 'r') and relname !~ '^pg_' AND relname !~ '^sql_'
|
||||
AND relname !~ '^xin[vx][0-9]+' AND b.usesysid = a.relowner
|
||||
AND NOT (EXISTS (SELECT viewname FROM pg_views WHERE viewname=a.relname));";
|
||||
|
||||
$result = $this->all($sql);
|
||||
|
||||
if (!$result) {
|
||||
trigger_error(ERROR_NO_TABLE_LIST, E_USER_ERROR);
|
||||
exit;
|
||||
}
|
||||
else {
|
||||
$tables = array();
|
||||
foreach ($result as $item) $tables[] = $item['name'];
|
||||
return $tables;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Enter description here...
|
||||
*
|
||||
* @param unknown_type $table_name
|
||||
* @return unknown
|
||||
*/
|
||||
function fields ($table_name) {
|
||||
$data = $this->_pear->tableInfo($table_name);
|
||||
$fields = false;
|
||||
|
||||
foreach ($data as $item)
|
||||
$fields[] = array('name'=>$item['name'], 'type'=>$item['type']);
|
||||
|
||||
return $fields;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enter description here...
|
||||
*
|
||||
* @param unknown_type $data
|
||||
* @return unknown
|
||||
*/
|
||||
function prepare ($data) {
|
||||
return $this->_pear->quoteSmart($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Enter description here...
|
||||
*
|
||||
* @return unknown
|
||||
*/
|
||||
function lastError () {
|
||||
return PEAR::isError($this->_result)? $this->_result->getMessage(): null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enter description here...
|
||||
*
|
||||
* @return unknown
|
||||
*/
|
||||
function lastAffected () {
|
||||
return $this->_pear->affectedRows();
|
||||
}
|
||||
|
||||
/**
|
||||
* Enter description here...
|
||||
*
|
||||
* @return unknown
|
||||
*/
|
||||
function lastNumRows ($result) {
|
||||
if (method_exists($result, 'numRows'))
|
||||
return $result->numRows();
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enter description here...
|
||||
*
|
||||
* @return unknown
|
||||
*/
|
||||
function lastInsertId ($table) {
|
||||
return $this->field('id', "SELECT MAX(id) FROM {$table}");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
?>
|
|
@ -151,9 +151,9 @@ class Flay extends Object {
|
|||
$line = str_replace($url, "<a href=\"{$url}\">{$url}</a>", $line);
|
||||
}
|
||||
}
|
||||
if (preg_match_all("#(www\.[^ ]+)#", $line, $urls)) {
|
||||
if (preg_match_all("#(www\.[^\n\%\ ]+[^\n\%\,\.\ ])#", $line, $urls)) {
|
||||
foreach ($urls[1] as $url) {
|
||||
$line = str_replace($url, "<a href=\"{$url}\">{$url}</a>", $line);
|
||||
$line = str_replace($url, "<a href=\"http://{$url}\">{$url}</a>", $line);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -40,25 +40,6 @@ if (version_compare(phpversion(), '5.0') < 0) {
|
|||
}
|
||||
|
||||
|
||||
// needed for old Plog v2
|
||||
//
|
||||
function old_lib ($name) {
|
||||
old_libs ($name);
|
||||
}
|
||||
|
||||
function old_libs () {
|
||||
if (count($lib_names = func_get_args())) {
|
||||
foreach ($lib_names as $lib_name) {
|
||||
require (OLD_LIBS.$lib_name.'.php');
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace file_get_contents()
|
||||
*
|
||||
|
|
|
@ -150,17 +150,25 @@ class Model extends Object {
|
|||
* Constructor. Binds the Model's database table to the object.
|
||||
*
|
||||
* @param unknown_type $id
|
||||
* @param string $table Database table to use.
|
||||
* @param unknown_type $db Database connection object.
|
||||
*/
|
||||
function __construct ($id=false, $db=null) {
|
||||
function __construct ($id=false, $table=null, $db=null) {
|
||||
global $DB;
|
||||
|
||||
$this->db = $db? $db: &$DB;
|
||||
if ($db)
|
||||
{
|
||||
$this->db = $db;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->db = &$DB;
|
||||
}
|
||||
|
||||
if ($id)
|
||||
$this->id = $id;
|
||||
|
||||
$table_name = $this->use_table? $this->use_table: Inflector::tableize(get_class($this));
|
||||
$table_name = $table? $table: ($this->use_table? $this->use_table: Inflector::tableize(get_class($this)));
|
||||
$this->useTable ($table_name);
|
||||
parent::__construct();
|
||||
$this->createLinks();
|
||||
|
|
Loading…
Add table
Reference in a new issue