mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Merging fixes into trunk.
Revision: [2522] renamed Bake class file Revision: [2521] removing old bake scripts Revision: [2520] Adding new Bake script Revision: [2519] Adding fix for Ticket #622 Revision: [2518] Adding fix for Ticket #535 Revision: [2517] Adding fix for Ticket #648, associated records are now post-processed by afterFind() method in associated model Revision: [2516] Adding fix for Ticket #618 Revision: [2515] More error page fixes Revision: [2514] Adding fix for Ticket #690 Revision: [2513] Removing empty method Revision: [2512] Adding fix for Ticket #675 Revision: [2511] More fixes for Ticket #670 Revision: [2510] Adding fix for Ticket #670, and removing pointless part of Helper::output(), since print() *always* returns 1. Revision: [2509] Adding fixes for Tickets #677 and #681 Revision: [2508] Added patch from Ticket #632 Revision: [2502] Adding fix to prevent model ID from getting overwritten when saving HABTM data [TEST ME] - thanks sdevore Revision: [2501] Rewriting foreach loops in queryAssociation() Revision: [2493] Adding fix for Ticket #673 Revision: [2492] Adding reconnect() method, to reconnect to database with different settings Revision: [2491] Adding Microsoft SQL Server driver [EXPERIMENTAL] Revision: [2490] Fixing a bug that occurs when connecting to two different databases on the same server, and enabling cross-database model associations Revision: [2488] Adding fix for Ticket #651 Revision: [2487] Adding fix for Ticket #665 Revision: [2486] Adding fix for Ticket #655 Revision: [2485] Forcing DboMysql to validate disconnect, and adding fix for Ticket #663 git-svn-id: https://svn.cakephp.org/repo/trunk/cake@2528 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
ef9836b402
commit
32f9e1e0e5
23 changed files with 992 additions and 783 deletions
|
@ -6,4 +6,4 @@
|
|||
// +---------------------------------------------------------------------------------------------------+ //
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
1.0.0.2482
|
||||
1.0.0.25285
|
|
@ -92,6 +92,7 @@ class Dispatcher extends Object
|
|||
$missingView = false;
|
||||
$privateAction = false;
|
||||
$this->base = $this->baseUrl();
|
||||
|
||||
if (empty($params['controller']))
|
||||
{
|
||||
$missingController = true;
|
||||
|
@ -113,8 +114,13 @@ class Dispatcher extends Object
|
|||
{
|
||||
if(preg_match('/([\\.]+)/', $ctrlName))
|
||||
{
|
||||
return $this->cakeError('error404',array(array('url' => strtolower($ctrlName),
|
||||
'message' => 'Was not found on this server')));
|
||||
return $this->cakeError('error404', array(
|
||||
array(
|
||||
'url' => strtolower($ctrlName),
|
||||
'message' => 'Was not found on this server',
|
||||
'base' => $this->base
|
||||
)
|
||||
));
|
||||
exit();
|
||||
}
|
||||
else
|
||||
|
@ -167,8 +173,14 @@ class Dispatcher extends Object
|
|||
|
||||
if ($missingController)
|
||||
{
|
||||
return $this->cakeError('missingController',array(array('className' => Inflector::camelize($params['controller']."Controller"),
|
||||
'webroot' => $this->webroot)));
|
||||
return $this->cakeError('missingController', array(
|
||||
array(
|
||||
'className' => Inflector::camelize($params['controller']."Controller"),
|
||||
'webroot' => $this->webroot,
|
||||
'url' => $url,
|
||||
'base' => $this->base
|
||||
)
|
||||
));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -216,31 +228,35 @@ class Dispatcher extends Object
|
|||
$component =& new Component($controller);
|
||||
}
|
||||
|
||||
if((in_array('scaffold', array_keys($classVars))) && ($missingAction === true))
|
||||
{
|
||||
uses(DS.'controller'.DS.'scaffold');
|
||||
return new Scaffold($controller, $params);
|
||||
}
|
||||
|
||||
$controller->constructClasses();
|
||||
|
||||
if ($missingAction)
|
||||
if ($missingAction && !in_array('scaffold', array_keys($classVars)))
|
||||
{
|
||||
return $this->cakeError('missingAction',
|
||||
array(array('className' => Inflector::camelize($params['controller']."Controller"),
|
||||
'action' => $params['action'],
|
||||
'webroot' => $this->webroot)));
|
||||
return $this->cakeError('missingAction', array(
|
||||
array(
|
||||
'className' => Inflector::camelize($params['controller']."Controller"),
|
||||
'action' => $params['action'],
|
||||
'webroot' => $this->webroot,
|
||||
'url' => $url,
|
||||
'base' => $this->base
|
||||
)
|
||||
));
|
||||
}
|
||||
|
||||
if ($privateAction)
|
||||
{
|
||||
return $this->cakeError('privateAction',
|
||||
array(array('className' => Inflector::camelize($params['controller']."Controller"),
|
||||
'action' => $params['action'],
|
||||
'webroot' => $this->webroot)));
|
||||
return $this->cakeError('privateAction', array(
|
||||
array(
|
||||
'className' => Inflector::camelize($params['controller']."Controller"),
|
||||
'action' => $params['action'],
|
||||
'webroot' => $this->webroot,
|
||||
'url' => $url,
|
||||
'base' => $this->base
|
||||
)
|
||||
));
|
||||
}
|
||||
|
||||
return $this->_invoke($controller, $params);
|
||||
return $this->_invoke($controller, $params, $missingAction);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -248,9 +264,10 @@ class Dispatcher extends Object
|
|||
*
|
||||
* @param object $controller
|
||||
* @param array $params
|
||||
* @param boolean $missingAction
|
||||
* @return string
|
||||
*/
|
||||
function _invoke (&$controller, $params)
|
||||
function _invoke (&$controller, $params, $missingAction = false)
|
||||
{
|
||||
if (!empty($controller->beforeFilter))
|
||||
{
|
||||
|
@ -282,7 +299,16 @@ class Dispatcher extends Object
|
|||
}
|
||||
}
|
||||
|
||||
$output = call_user_func_array(array(&$controller, $params['action']), empty($params['pass'])? null: $params['pass']);
|
||||
$classVars = get_object_vars($controller);
|
||||
if ($missingAction && in_array('scaffold', array_keys($classVars)))
|
||||
{
|
||||
uses(DS.'controller'.DS.'scaffold');
|
||||
return new Scaffold($controller, $params);
|
||||
}
|
||||
else
|
||||
{
|
||||
$output = call_user_func_array(array(&$controller, $params['action']), empty($params['pass'])? null: $params['pass']);
|
||||
}
|
||||
if ($controller->autoRender)
|
||||
{
|
||||
$output = $controller->render();
|
||||
|
|
|
@ -1,615 +0,0 @@
|
|||
<?php
|
||||
/* SVN FILE: $Id$ */
|
||||
|
||||
/**
|
||||
* Creates controller, model, view files, and the required directories on demand.
|
||||
* Used by /scripts/bake.php.
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP : Rapid Development Framework <http://www.cakephp.org/>
|
||||
* Copyright (c) 2006, Cake Software Foundation, Inc.
|
||||
* 1785 E. Sahara Avenue, Suite 490-204
|
||||
* Las Vegas, Nevada 89104
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @filesource
|
||||
* @copyright Copyright (c) 2006, Cake Software Foundation, Inc.
|
||||
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project
|
||||
* @package cake
|
||||
* @subpackage cake.cake.libs
|
||||
* @since CakePHP v 0.10.3.1612
|
||||
* @version $Revision$
|
||||
* @modifiedby $LastChangedBy$
|
||||
* @lastmodified $Date$
|
||||
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
||||
*/
|
||||
|
||||
/**
|
||||
* Require needed libraries.
|
||||
*/
|
||||
uses('object', 'inflector');
|
||||
|
||||
/**
|
||||
* Bake class creates files in configured application directories. This is a
|
||||
* base class for /scripts/add.php.
|
||||
*
|
||||
* @package cake
|
||||
* @subpackage cake.cake.libs
|
||||
* @since CakePHP v CakePHP v 0.10.3.1612
|
||||
*/
|
||||
class Bake extends Object
|
||||
{
|
||||
|
||||
/**
|
||||
* Standard input stream (php://stdin).
|
||||
*
|
||||
* @var resource
|
||||
* @access private
|
||||
*/
|
||||
var $stdin = null;
|
||||
|
||||
/**
|
||||
* Standard output stream (php://stdout).
|
||||
*
|
||||
* @var resource
|
||||
* @access private
|
||||
*/
|
||||
var $stdout = null;
|
||||
|
||||
/**
|
||||
* Standard error stream (php://stderr).
|
||||
*
|
||||
* @var resource
|
||||
* @access private
|
||||
*/
|
||||
var $stderr = null;
|
||||
|
||||
/**
|
||||
* Counts actions taken.
|
||||
*
|
||||
* @var integer
|
||||
* @access private
|
||||
*/
|
||||
var $actions = null;
|
||||
|
||||
/**
|
||||
* Decides whether to overwrite existing files without asking.
|
||||
*
|
||||
* @var boolean
|
||||
* @access private
|
||||
*/
|
||||
var $dontAsk = false;
|
||||
|
||||
/**
|
||||
* Returns code template for PHP file generator.
|
||||
*
|
||||
* @param string $type
|
||||
* @return string
|
||||
* @access private
|
||||
*/
|
||||
function template ($type)
|
||||
{
|
||||
switch ($type)
|
||||
{
|
||||
case 'view': return "%s";
|
||||
case 'model': return "<?php\n\nclass %s extends AppModel\n{\n}\n\n?>";
|
||||
case 'action': return "\n\tfunction %s () {\n\t\t\n\t}\n";
|
||||
case 'ctrl': return "<?php\n\nclass %s extends %s\n{\n%s\n}\n\n?>";
|
||||
case 'helper': return "<?php\n\nclass %s extends AppController\n{\n}\n\n?>";
|
||||
case 'test': return '<?php
|
||||
|
||||
class %sTest extends TestCase
|
||||
{
|
||||
var $abc;
|
||||
|
||||
// called before the tests
|
||||
function setUp()
|
||||
{
|
||||
$this->abc = new %s ();
|
||||
}
|
||||
|
||||
// called after the tests
|
||||
function tearDown()
|
||||
{
|
||||
unset($this->abc);
|
||||
}
|
||||
|
||||
/*
|
||||
function testFoo ()
|
||||
{
|
||||
$result = $this->abc->Foo();
|
||||
$expected = \'\';
|
||||
$this->assertEquals($result, $expected);
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
?>';
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Baker's constructor method. Initialises bakery, and starts production.
|
||||
*
|
||||
* @param string $type
|
||||
* @param array $names
|
||||
* @access public
|
||||
* @uses Bake::stdin Opens stream for reading.
|
||||
* @uses Bake::stdout Opens stream for writing.
|
||||
* @uses Bake::stderr Opens stream for writing.
|
||||
* @uses Bake::newModel() Depending on the case, can create a new model.
|
||||
* @uses Bake::newView() Depending on the case, can create a new view.
|
||||
* @uses Bake::newController() Depending on the case, can create a new controller.
|
||||
*/
|
||||
function __construct ($type, $names)
|
||||
{
|
||||
$this->stdin = fopen('php://stdin', 'r');
|
||||
$this->stdout = fopen('php://stdout', 'w');
|
||||
$this->stderr = fopen('php://stderr', 'w');
|
||||
|
||||
// Output directory name
|
||||
fwrite($this->stderr, "\n".substr(ROOT,0,strlen(ROOT)-1).":\n".str_repeat('-',strlen(ROOT)+1)."\n");
|
||||
|
||||
switch ($type)
|
||||
{
|
||||
case 'model':
|
||||
case 'models':
|
||||
foreach ($names as $model_name)
|
||||
{
|
||||
$this->newModel($model_name);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'controller':
|
||||
case 'ctrl':
|
||||
$controller = array_shift($names);
|
||||
|
||||
$add_actions = array();
|
||||
|
||||
$controllerPlural = Inflector::pluralize($controller);
|
||||
|
||||
if ($controllerPlural != $controller)
|
||||
{
|
||||
fwrite($this->stdout, "I use pluralized Controller names. You entered '$controller'. I can inflect it to '$controllerPlural'. Should I? If no, I will use '$controller'. [y/n/q] ");
|
||||
$key = trim(fgets($this->stdin));
|
||||
}
|
||||
else
|
||||
{
|
||||
$key = 'n';
|
||||
}
|
||||
|
||||
if ($key=='q')
|
||||
{
|
||||
fwrite($this->stdout, "Quitting.\n");
|
||||
exit;
|
||||
}
|
||||
elseif ($key=='y')
|
||||
{
|
||||
$controller = $controllerPlural;
|
||||
}
|
||||
|
||||
foreach ($names as $action)
|
||||
{
|
||||
$add_actions[] = $action;
|
||||
$this->newView($controller, $action);
|
||||
}
|
||||
|
||||
$this->newController($controller, $add_actions);
|
||||
break;
|
||||
|
||||
case 'view':
|
||||
case 'views':
|
||||
$r = null;
|
||||
foreach ($names as $model_name)
|
||||
{
|
||||
if (preg_match('/^([a-z0-9_]+(?:\/[a-z0-9_]+)*)\/([a-z0-9_]+)$/i', $model_name, $r))
|
||||
{
|
||||
$this->newView($r[1], $r[2]);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (!$this->actions)
|
||||
{
|
||||
fwrite($this->stderr, "Nothing to do, quitting.\n");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates new view in VIEWS/$controller/ directory.
|
||||
*
|
||||
* @param string $controller
|
||||
* @param string $name
|
||||
* @access private
|
||||
* @uses Inflector::underscore() Underscores directory's name.
|
||||
* @uses Bake::createDir() Creates new directory in views dir, named after the controller.
|
||||
* @uses VIEWS
|
||||
* @uses Bake::createFile() Creates view file.
|
||||
* @uses Bake::template() Collects view template.
|
||||
* @uses Bake::actions Adds one action for each run.
|
||||
*/
|
||||
function newView ($controller, $name)
|
||||
{
|
||||
$dir = Inflector::underscore($controller);
|
||||
$path = $dir.DS.strtolower($name).".thtml";
|
||||
|
||||
$this->createDir(VIEWS.$dir);
|
||||
$fn = VIEWS.$path;
|
||||
$this->createFile($fn, sprintf($this->template('view'), "<p>Edit <b>app".DS."views".DS."{$path}</b> to change this message.</p>"));
|
||||
$this->actions++;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates new controller with defined actions, controller's test and
|
||||
* helper with helper's test.
|
||||
*
|
||||
* @param string $name
|
||||
* @param array $actions
|
||||
* @access private
|
||||
* @uses Inflector::pluralize()
|
||||
* @uses Bake::makeController()
|
||||
* @uses Bake::makeControllerTest()
|
||||
* @uses Bake::makeHelper()
|
||||
* @uses Bake::makeHelperTest()
|
||||
* @uses Bake::actions Adds one action for each run.
|
||||
*/
|
||||
function newController ($name, $actions=array())
|
||||
{
|
||||
$this->makeController($name, $actions);
|
||||
$this->makeControllerTest($name);
|
||||
//$this->makeHelper($name);
|
||||
//$this->makeHelperTest($name);
|
||||
$this->actions++;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates new controller file with defined actions.
|
||||
*
|
||||
* @param string $name
|
||||
* @param array $actions
|
||||
* @return boolean
|
||||
* @access private
|
||||
* @uses Bake::makeControllerName() CamelCase for controller's name.
|
||||
* @uses Bake::makeHelperName() CamelCase for helper's name.
|
||||
* @uses Bake::template() Controller's template.
|
||||
* @uses Bake::getActions() Actions' templates to be included in the controller.
|
||||
* @uses Bake::createFile() Creates controller's file.
|
||||
* @uses Bake::makeControllerFn() Underscored name for controller's filename.
|
||||
*/
|
||||
function makeController ($name, $actions)
|
||||
{
|
||||
$ctrl = $this->makeControllerName($name);
|
||||
$helper = $this->makeHelperName($name);
|
||||
//$body = sprintf($this->template('ctrl'), $ctrl, $helper, join('', $this->getActions($actions)));
|
||||
$body = sprintf($this->template('ctrl'), $ctrl, 'AppController', join('', $this->getActions($actions)));
|
||||
return $this->createFile($this->makeControllerFn($name), $body);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns controller's name in CamelCase.
|
||||
*
|
||||
* @param string $name
|
||||
* @return string
|
||||
* @access private
|
||||
* @uses Inflector::camelize CamelCase for controller name.
|
||||
*/
|
||||
function makeControllerName ($name)
|
||||
{
|
||||
return Inflector::camelize($name).'Controller';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a name for controller's file, underscored.
|
||||
*
|
||||
* @param string $name
|
||||
* @return string
|
||||
* @access private
|
||||
* @uses Inflector::underscore() Underscore for controller's file name.
|
||||
*/
|
||||
function makeControllerFn ($name)
|
||||
{
|
||||
return CONTROLLERS.Inflector::underscore($name).'_controller.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates new test for a controller.
|
||||
*
|
||||
* @param string $name
|
||||
* @return boolean
|
||||
* @access private
|
||||
* @uses CONTROLLER_TESTS
|
||||
* @uses Inflector::underscore()
|
||||
* @uses Bake::getTestBody()
|
||||
* @uses Bake::makeControllerName()
|
||||
* @uses Bake::createFile()
|
||||
*/
|
||||
function makeControllerTest ($name)
|
||||
{
|
||||
$fn = CONTROLLER_TESTS.Inflector::underscore($name).'_controller_test.php';
|
||||
$body = $this->getTestBody($this->makeControllerName($name));
|
||||
|
||||
return true;//$this->createFile($fn, $body);// Disable creating tests till later
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates new helper.
|
||||
*
|
||||
* @param string $name
|
||||
* @return boolean
|
||||
* @access private
|
||||
* @uses Bake::template()
|
||||
* @uses Bake::makeHelperName()
|
||||
* @uses Bake::createFile()
|
||||
* @uses Bake::makeHelperFn()
|
||||
*/
|
||||
function makeHelper ($name)
|
||||
{
|
||||
$body = sprintf($this->template('helper'), $this->makeHelperName($name));
|
||||
|
||||
return $this->createFile($this->makeHelperFn($name), $body);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns CamelCase name for a helper.
|
||||
*
|
||||
* @param string $name
|
||||
* @return string
|
||||
* @access private
|
||||
* @uses Inflector::camelize()
|
||||
*/
|
||||
function makeHelperName ($name)
|
||||
{
|
||||
return Inflector::camelize($name).'Helper';
|
||||
}
|
||||
|
||||
/**
|
||||
* Underscores file name for a helper.
|
||||
*
|
||||
* @param string $name
|
||||
* @return string
|
||||
* @access private
|
||||
* @uses HELPERS
|
||||
* @uses Inflector::underscore()
|
||||
*/
|
||||
function makeHelperFn ($name)
|
||||
{
|
||||
return HELPERS.Inflector::underscore($name).'_helper.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates new test for a helper.
|
||||
*
|
||||
* @param string $name
|
||||
* @return boolean
|
||||
* @access private
|
||||
* @uses HELPER_TESTS
|
||||
* @uses Inflector::underscore()
|
||||
* @uses Bake::getTestBody()
|
||||
* @uses Bake::makeHelperName()
|
||||
* @uses Bake::createFile()
|
||||
*/
|
||||
function makeHelperTest ($name)
|
||||
{
|
||||
$fn = HELPER_TESTS.Inflector::underscore($name).'_helper_test.php';
|
||||
$body = $this->getTestBody($this->makeHelperName($name));
|
||||
|
||||
return $this->createFile($fn, $body);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of actions' templates.
|
||||
*
|
||||
* @param array $as
|
||||
* @return array
|
||||
* @access private
|
||||
* @uses Bake::template()
|
||||
*/
|
||||
function getActions ($as)
|
||||
{
|
||||
$out = array();
|
||||
foreach ($as as $a)
|
||||
{
|
||||
$out[] = sprintf($this->template('action'), $a);
|
||||
}
|
||||
return $out;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a test template for given class.
|
||||
*
|
||||
* @param string $class
|
||||
* @return string
|
||||
* @access private
|
||||
* @uses Bake::template()
|
||||
*/
|
||||
function getTestBody ($class)
|
||||
{
|
||||
return sprintf($this->template('test'), $class, $class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates new model.
|
||||
*
|
||||
* @param string $name
|
||||
* @access private
|
||||
* @uses Bake::createFile()
|
||||
* @uses Bake::getModelFn()
|
||||
* @uses Bake::template()
|
||||
* @uses Bake::getModelName()
|
||||
* @uses Bake::makeModelTest()
|
||||
* @uses Bake::actions
|
||||
*/
|
||||
function newModel ($name)
|
||||
{
|
||||
$nameSingular = Inflector::singularize($name);
|
||||
|
||||
if ($nameSingular != $name)
|
||||
{
|
||||
fwrite($this->stdout, "I use singular Model names. You entered '$name'. I can inflect it to '$nameSingular'. Should I? If no, I will use '$name'. [y/n/q] ");
|
||||
$key = trim(fgets($this->stdin));
|
||||
}
|
||||
else
|
||||
{
|
||||
$key = 'n';
|
||||
}
|
||||
|
||||
if ($key=='q')
|
||||
{
|
||||
fwrite($this->stdout, "Quitting.\n");
|
||||
exit;
|
||||
}
|
||||
elseif ($key=='y')
|
||||
{
|
||||
$name = $nameSingular;
|
||||
}
|
||||
|
||||
$this->createFile($this->getModelFn($name), sprintf($this->template('model'), $this->getModelName($name)));
|
||||
//$this->makeModelTest ($name);
|
||||
// TODO: Add model test back when I'm less lazy
|
||||
$this->actions++;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an underscored filename for a model.
|
||||
*
|
||||
* @param string $name
|
||||
* @return string
|
||||
* @access private
|
||||
* @uses MODELS
|
||||
* @uses Inflector::underscore()
|
||||
*/
|
||||
function getModelFn ($name)
|
||||
{
|
||||
return MODELS.Inflector::underscore($name).'.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a test for a given model.
|
||||
*
|
||||
* @param string $name
|
||||
* @return boolean
|
||||
* @access private
|
||||
* @uses MODEL_TESTS
|
||||
* @uses Inflector::underscore()
|
||||
* @uses Bake::getTestBody()
|
||||
* @uses Bake::getModelName()
|
||||
* @uses Bake::createFile()
|
||||
*/
|
||||
function makeModelTest ($name)
|
||||
{
|
||||
$fn = MODEL_TESTS.Inflector::underscore($name).'_test.php';
|
||||
$body = $this->getTestBody($this->getModelName($name));
|
||||
|
||||
return $this->createFile($fn, $body);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns CamelCased name of a model.
|
||||
*
|
||||
* @param string $name
|
||||
* @return string
|
||||
* @access private
|
||||
* @uses Inflector::camelize()
|
||||
*/
|
||||
function getModelName ($name)
|
||||
{
|
||||
return Inflector::camelize($name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a file with given path and contents.
|
||||
*
|
||||
* @param string $path
|
||||
* @param string $contents
|
||||
* @return boolean
|
||||
* @access private
|
||||
* @uses Bake::dontAsk
|
||||
* @uses Bake::stdin
|
||||
* @uses Bake::stdout
|
||||
* @uses Bake::stderr
|
||||
*/
|
||||
function createFile ($path, $contents)
|
||||
{
|
||||
echo "\nCreating file $path\n";
|
||||
$shortPath = str_replace(ROOT,null,$path);
|
||||
|
||||
if (is_file($path) && !$this->dontAsk)
|
||||
{
|
||||
fwrite($this->stdout, "File {$shortPath} exists, overwrite? (y/n/q):");
|
||||
$key = trim(fgets($this->stdin));
|
||||
|
||||
if ($key=='q')
|
||||
{
|
||||
fwrite($this->stdout, "Quitting.\n");
|
||||
exit;
|
||||
}
|
||||
elseif ($key=='a')
|
||||
{
|
||||
$this->dont_ask = true;
|
||||
}
|
||||
elseif ($key=='y')
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
fwrite($this->stdout, "Skip {$shortPath}\n");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if ($f = fopen($path, 'w'))
|
||||
{
|
||||
fwrite($f, $contents);
|
||||
fclose($f);
|
||||
fwrite($this->stdout, "Wrote {$shortPath}\n");
|
||||
// debug ("Wrote {$path}");
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
fwrite($this->stderr, "Error! Couldn't open {$shortPath} for writing.\n");
|
||||
// debug ("Error! Couldn't open {$path} for writing.");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a directory with given path.
|
||||
*
|
||||
* @param string $path
|
||||
* @return boolean
|
||||
* @access private
|
||||
* @uses Bake::stdin
|
||||
* @uses Bake::stdout
|
||||
*/
|
||||
function createDir ($path)
|
||||
{
|
||||
if (is_dir($path))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
$shortPath = str_replace(ROOT, null, $path);
|
||||
|
||||
if (mkdir($path))
|
||||
{
|
||||
fwrite($this->stdout, "Created {$shortPath}\n");
|
||||
// debug ("Created {$path}");
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
fwrite($this->stderr, "Error! Couldn't create dir {$shortPath}\n");
|
||||
// debug ("Error! Couldn't create dir {$path}");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
|
@ -132,18 +132,26 @@ class Component extends Object
|
|||
}
|
||||
else
|
||||
{
|
||||
return $this->cakeError('missingComponentClass',
|
||||
array(array('className' => $this->controller->name,
|
||||
'component' => $component,
|
||||
'file' => $componentFn)));
|
||||
return $this->cakeError('missingComponentClass', array(
|
||||
array(
|
||||
'className' => $this->controller->name,
|
||||
'component' => $component,
|
||||
'file' => $componentFn,
|
||||
'base' => $this->controller->base
|
||||
)
|
||||
));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return $this->cakeError('missingComponentFile',
|
||||
array(array('className' => $this->controller->name,
|
||||
'component' => $component,
|
||||
'file' => $componentFn)));
|
||||
return $this->cakeError('missingComponentFile', array(
|
||||
array(
|
||||
'className' => $this->controller->name,
|
||||
'component' => $component,
|
||||
'file' => $componentFn,
|
||||
'base' => $this->controller->base
|
||||
)
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -75,7 +75,7 @@ class AclNode extends AppModel
|
|||
|
||||
if($parent_id == null || $parent_id === 0)
|
||||
{
|
||||
$parent = $this->find(null, "MAX(rght)");
|
||||
$parent = $this->find(null, "MAX(rght)", null, null, 0);
|
||||
$parent['lft'] = $parent[0]['MAX(rght)'];
|
||||
|
||||
if($parent[0]['MAX(rght)'] == null)
|
||||
|
@ -86,7 +86,7 @@ class AclNode extends AppModel
|
|||
}
|
||||
else
|
||||
{
|
||||
$parent = $this->find($this->_resolveID($parent_id));
|
||||
$parent = $this->find($this->_resolveID($parent_id), null, null, 0);
|
||||
if($parent == null || count($parent) == 0)
|
||||
{
|
||||
trigger_error("Null parent in {$class}::create()", E_USER_WARNING);
|
||||
|
@ -134,48 +134,61 @@ class AclNode extends AppModel
|
|||
$id = $this->id;
|
||||
}
|
||||
|
||||
$object = $this->find($this->_resolveID($id));
|
||||
$object = $this->find($this->_resolveID($id), null, null, 0);
|
||||
if($object == null || count($object) == 0)
|
||||
{
|
||||
// Couldn't find object
|
||||
// Couldn't find object
|
||||
return false;
|
||||
}
|
||||
$parent = $this->getParent(intval($object[$class][$secondary_id]));
|
||||
$object = $object[$class];
|
||||
$parent = $this->getParent($id);
|
||||
|
||||
// Node is already at root, or new parent == old parent
|
||||
if(($parent == null && $parent_id == null) || ($parent_id == $parent[$class][$secondary_id]) || ($parent_id == $parent[$class]['alias']))
|
||||
// Node is already at root, or new parent == old parent
|
||||
if(($parent == null && $parent_id == null) || ($parent_id == $parent[$class][$secondary_id] && $parent_id != null) || ($parent_id == $parent[$class]['alias'] && $parent_id != null))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if($parent_id != null && $parent[$class]['lft'] <= $object[$class]['lft'] && $parent[$class]['rght'] >= $object[$class]['rght'])
|
||||
{
|
||||
// Can't move object inside self or own child
|
||||
return false;
|
||||
}
|
||||
$this->_syncTable($table_name, 0, $object[$class]['lft'], $object[$class]['lft']);
|
||||
|
||||
if($parent_id == null)
|
||||
{
|
||||
$parent = $this->find(null, "MAX(rght)");
|
||||
$parent['lft'] = $parent[0]['MAX(rght)'];
|
||||
$newParent = $this->find(null, "MAX(rght) as lft", null, 0);
|
||||
$newParent = $newParent[0];
|
||||
$newParent['rght'] = $newParent['lft'];
|
||||
}
|
||||
else
|
||||
{
|
||||
$parent = $this->find($this->_resolveID($parent_id));
|
||||
$parent = $parent[$class];
|
||||
$this->_syncTable($table_name, 1, $parent['lft'], $parent['lft']);
|
||||
$newParent = $this->find($this->_resolveID($parent_id), null, null, 0);
|
||||
$newParent = $newParent[$class];
|
||||
}
|
||||
|
||||
$object[$class]['lft'] = $parent['lft'] + 1;
|
||||
$object[$class]['rght'] = $parent['lft'] + 2;
|
||||
$this->save($object);
|
||||
|
||||
if($parent['lft'] == 0)
|
||||
if($parent_id != null && $newParent['lft'] <= $object['lft'] && $newParent['rght'] >= $object['rght'])
|
||||
{
|
||||
$this->_syncTable($table_name, 2, $parent['lft'], $parent['lft']);
|
||||
// Can't move object inside self or own child
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->_syncTable($table_name, 0, $object['lft'], $object['lft']);
|
||||
|
||||
if ($object['lft'] < $newParent['lft'])
|
||||
{
|
||||
$newParent['lft'] = $newParent['lft'] - 2;
|
||||
$newParent['rght'] = $newParent['rght'] - 2;
|
||||
}
|
||||
|
||||
if ($parent_id != null)
|
||||
{
|
||||
$this->_syncTable($table_name, 1, $newParent['lft'], $newParent['lft']);
|
||||
}
|
||||
|
||||
$object['lft'] = $newParent['lft'] + 1;
|
||||
$object['rght'] = $newParent['lft'] + 2;
|
||||
$this->save(array($class => $object));
|
||||
|
||||
if($newParent['lft'] == 0)
|
||||
{
|
||||
$this->_syncTable($table_name, 2, $newParent['lft'], $newParent['lft']);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
@ -213,12 +226,12 @@ class AclNode extends AppModel
|
|||
}
|
||||
extract($this->__dataVars());
|
||||
|
||||
$item = $this->find($this->_resolveID($id));
|
||||
$item = $this->find($this->_resolveID($id), null, null, 0);
|
||||
if($item == null || count($item) == 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return $this->findAll(array($class.'.lft' => '<= '.$item[$class]['lft'], $class.'.rght' => '>= '.$item[$class]['rght']));
|
||||
return $this->findAll(array($class.'.lft' => '<= '.$item[$class]['lft'], $class.'.rght' => '>= '.$item[$class]['rght']), null, array($class.'.lft' => 'ASC'), null, null, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -236,8 +249,8 @@ class AclNode extends AppModel
|
|||
}
|
||||
extract($this->__dataVars());
|
||||
|
||||
$item = $this->find($this->_resolveID($id));
|
||||
return $this->findAll(array($class.'.lft' => '> '.$item[$class]['lft'], $class.'.rght' => '< '.$item[$class]['rght']));
|
||||
$item = $this->find($this->_resolveID($id), null, null, 0);
|
||||
return $this->findAll(array($class.'.lft' => '> '.$item[$class]['lft'], $class.'.rght' => '< '.$item[$class]['rght']), null, null, null, null, null, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -300,8 +300,13 @@ class Controller extends Object
|
|||
}
|
||||
elseif($this->uses === false)
|
||||
{
|
||||
return $this->cakeError('missingModel',array(array('className' => $this->modelClass,
|
||||
'webroot' => '')));
|
||||
return $this->cakeError('missingModel', array(
|
||||
array(
|
||||
'className' => $this->modelClass,
|
||||
'webroot' => '',
|
||||
'base' => $this->base
|
||||
)
|
||||
));
|
||||
}
|
||||
if ($this->uses)
|
||||
{
|
||||
|
@ -341,8 +346,13 @@ class Controller extends Object
|
|||
}
|
||||
else
|
||||
{
|
||||
return $this->cakeError('missingModel',array(array('className' => $modelClass,
|
||||
'webroot' => '')));
|
||||
return $this->cakeError('missingModel', array(
|
||||
array(
|
||||
'className' => $modelClass,
|
||||
'webroot' => '',
|
||||
'base' => $this->base
|
||||
)
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -473,10 +473,14 @@ class Scaffold extends Object {
|
|||
}
|
||||
else
|
||||
{
|
||||
return $this->cakeError('missingAction',
|
||||
array(array('className' => Inflector::camelize($params['controller']."Controller"),
|
||||
'action' => $params['action'],
|
||||
'webroot' => $this->controllerClass->webroot)));
|
||||
return $this->cakeError('missingAction', array(
|
||||
array(
|
||||
'className' => Inflector::camelize($params['controller']."Controller"),
|
||||
'base' => $this->controllerClass->base,
|
||||
'action' => $params['action'],
|
||||
'webroot' => $this->controllerClass->webroot
|
||||
)
|
||||
));
|
||||
}
|
||||
}
|
||||
else
|
||||
|
|
|
@ -85,6 +85,7 @@ class ErrorHandler extends Object
|
|||
function error ($params)
|
||||
{
|
||||
extract($params);
|
||||
$this->controller->base = $base;
|
||||
$this->controller->webroot = $this->_webroot();
|
||||
$this->controller->viewPath = 'errors';
|
||||
$this->controller->set(array('code'=>$code,
|
||||
|
@ -112,12 +113,17 @@ class ErrorHandler extends Object
|
|||
{
|
||||
$message = '';
|
||||
}
|
||||
if(!isset($base))
|
||||
{
|
||||
$base = '';
|
||||
}
|
||||
|
||||
header("HTTP/1.0 404 Not Found");
|
||||
$this->error(
|
||||
array('code' => '404',
|
||||
'name' => 'Not found',
|
||||
'message' => sprintf(__("The requested address %s was not found on this server.", true), $url, $message)
|
||||
'message' => sprintf(__("The requested address %s was not found on this server.", true), $url, $message),
|
||||
'base' => $base
|
||||
)
|
||||
);
|
||||
exit();
|
||||
|
@ -130,10 +136,12 @@ class ErrorHandler extends Object
|
|||
function missingController($params)
|
||||
{
|
||||
extract($params);
|
||||
$this->controller->base = $base;
|
||||
$this->controller->webroot = $webroot;
|
||||
$this->controller->viewPath = 'errors';
|
||||
$this->controller->set(array('controller' => $className,
|
||||
'title' => 'Missing Controller'));
|
||||
$this->controller->render('../errors/missingController');
|
||||
$this->controller->render('missingController');
|
||||
exit();
|
||||
}
|
||||
|
||||
|
@ -144,11 +152,13 @@ class ErrorHandler extends Object
|
|||
function missingAction($params)
|
||||
{
|
||||
extract($params);
|
||||
$this->controller->base = $base;
|
||||
$this->controller->webroot = $webroot;
|
||||
$this->controller->viewPath = 'errors';
|
||||
$this->controller->set(array('controller' => $className,
|
||||
'action' => $action,
|
||||
'title' => 'Missing Method in Controller'));
|
||||
$this->controller->render('../errors/missingAction');
|
||||
$this->controller->render('missingAction');
|
||||
exit();
|
||||
}
|
||||
|
||||
|
@ -159,11 +169,13 @@ class ErrorHandler extends Object
|
|||
function privateAction($params)
|
||||
{
|
||||
extract($params);
|
||||
$this->controller->base = $base;
|
||||
$this->controller->webroot = $webroot;
|
||||
$this->controller->viewPath = 'errors';
|
||||
$this->controller->set(array('controller' => $className,
|
||||
'action' => $action,
|
||||
'title' => 'Trying to access private method in class'));
|
||||
$this->controller->render('../errors/privateAction');
|
||||
$this->controller->render('privateAction');
|
||||
exit();
|
||||
}
|
||||
|
||||
|
@ -174,11 +186,12 @@ class ErrorHandler extends Object
|
|||
function missingTable($params)
|
||||
{
|
||||
extract($params);
|
||||
$this->controller->viewPath = 'errors';
|
||||
$this->controller->webroot = $this->_webroot();
|
||||
$this->controller->set(array('model' => $className,
|
||||
'table' => $table,
|
||||
'title' => 'Missing Database Table'));
|
||||
$this->controller->render('../errors/missingTable');
|
||||
$this->controller->render('missingTable');
|
||||
exit();
|
||||
}
|
||||
|
||||
|
@ -189,9 +202,10 @@ class ErrorHandler extends Object
|
|||
function missingDatabase($params = array())
|
||||
{
|
||||
extract($params);
|
||||
$this->controller->viewPath = 'errors';
|
||||
$this->controller->webroot = $this->_webroot();
|
||||
$this->controller->set(array('title' => 'Scaffold Missing Database Connection'));
|
||||
$this->controller->render('../errors/missingScaffolddb');
|
||||
$this->controller->render('missingScaffolddb');
|
||||
exit();
|
||||
}
|
||||
|
||||
|
@ -202,12 +216,14 @@ class ErrorHandler extends Object
|
|||
function missingView($params)
|
||||
{
|
||||
extract($params);
|
||||
$this->controller->base = $base;
|
||||
$this->controller->viewPath = 'errors';
|
||||
$this->controller->webroot = $this->_webroot();
|
||||
$this->controller->set(array('controller' => $className,
|
||||
'action' => $action,
|
||||
'file' => $file,
|
||||
'title' => 'Missing View'));
|
||||
$this->controller->render('../errors/missingView');
|
||||
$this->controller->render('missingView');
|
||||
exit();
|
||||
}
|
||||
|
||||
|
@ -218,11 +234,13 @@ class ErrorHandler extends Object
|
|||
function missingLayout($params)
|
||||
{
|
||||
extract($params);
|
||||
$this->controller->base = $base;
|
||||
$this->controller->viewPath = 'errors';
|
||||
$this->controller->webroot = $this->_webroot();
|
||||
$this->controller->layout = 'default';
|
||||
$this->controller->set(array('file' => $file,
|
||||
'title' => 'Missing Layout'));
|
||||
$this->controller->render('../errors/missingLayout');
|
||||
$this->controller->render('missingLayout');
|
||||
exit();
|
||||
}
|
||||
|
||||
|
@ -233,10 +251,11 @@ class ErrorHandler extends Object
|
|||
function missingConnection($params)
|
||||
{
|
||||
extract($params);
|
||||
$this->controller->viewPath = 'errors';
|
||||
$this->controller->webroot = $this->_webroot();
|
||||
$this->controller->set(array('model' => $className,
|
||||
'title' => 'Missing Database Connection'));
|
||||
$this->controller->render('../errors/missingConnection');
|
||||
$this->controller->render('missingConnection');
|
||||
exit();
|
||||
}
|
||||
|
||||
|
@ -248,11 +267,13 @@ class ErrorHandler extends Object
|
|||
function missingHelperFile($params)
|
||||
{
|
||||
extract($params);
|
||||
$this->controller->base = $base;
|
||||
$this->controller->viewPath = 'errors';
|
||||
$this->controller->webroot = $this->_webroot();
|
||||
$this->controller->set(array('helperClass' => Inflector::camelize($helper) . "Helper",
|
||||
'file' => $file,
|
||||
'title' => 'Missing Helper File'));
|
||||
$this->controller->render('../errors/missingHelperFile');
|
||||
$this->controller->render('missingHelperFile');
|
||||
exit();
|
||||
}
|
||||
|
||||
|
@ -263,11 +284,13 @@ class ErrorHandler extends Object
|
|||
function missingHelperClass($params)
|
||||
{
|
||||
extract($params);
|
||||
$this->controller->base = $base;
|
||||
$this->controller->viewPath = 'errors';
|
||||
$this->controller->webroot = $this->_webroot();
|
||||
$this->controller->set(array('helperClass' => Inflector::camelize($helper) . "Helper",
|
||||
'file' => $file,
|
||||
'title' => 'Missing Helper Class'));
|
||||
$this->controller->render('../errors/missingHelperClass');
|
||||
$this->controller->render('missingHelperClass');
|
||||
exit();
|
||||
}
|
||||
|
||||
|
@ -278,12 +301,14 @@ class ErrorHandler extends Object
|
|||
function missingComponentFile($params)
|
||||
{
|
||||
extract($params);
|
||||
$this->controller->base = $base;
|
||||
$this->controller->viewPath = 'errors';
|
||||
$this->controller->webroot = $this->_webroot();
|
||||
$this->controller->set(array('controller' => $className,
|
||||
'component' => $component,
|
||||
'file' => $file,
|
||||
'title' => 'Missing Component File'));
|
||||
$this->controller->render('../errors/missingComponentFile');
|
||||
$this->controller->render('missingComponentFile');
|
||||
exit();
|
||||
}
|
||||
|
||||
|
@ -294,12 +319,14 @@ class ErrorHandler extends Object
|
|||
function missingComponentClass($params)
|
||||
{
|
||||
extract($params);
|
||||
$this->controller->base = $base;
|
||||
$this->controller->viewPath = 'errors';
|
||||
$this->controller->webroot = $this->_webroot();
|
||||
$this->controller->set(array('controller' => $className,
|
||||
'component' => $component,
|
||||
'file' => $file,
|
||||
'title' => 'Missing Component Class'));
|
||||
$this->controller->render('../errors/missingComponentClass');
|
||||
$this->controller->render('missingComponentClass');
|
||||
exit();
|
||||
}
|
||||
|
||||
|
@ -310,10 +337,12 @@ class ErrorHandler extends Object
|
|||
function missingModel($params)
|
||||
{
|
||||
extract($params);
|
||||
$this->controller->base = $base;
|
||||
$this->controller->viewPath = 'errors';
|
||||
$this->controller->webroot = $this->_webroot();
|
||||
$this->controller->set(array('model' => $className,
|
||||
'title' => 'Missing Model'));
|
||||
$this->controller->render('../errors/missingModel');
|
||||
$this->controller->render('missingModel');
|
||||
exit();
|
||||
}
|
||||
|
||||
|
|
|
@ -84,6 +84,22 @@ class DboSource extends DataSource
|
|||
return $this->connect();
|
||||
}
|
||||
|
||||
/**
|
||||
* Reconnects to database server with optional new settings
|
||||
*
|
||||
* @param array $config An array defining the new configuration settings
|
||||
* @return boolean True on success, false on failure
|
||||
*/
|
||||
function reconnect ($config = null)
|
||||
{
|
||||
$this->disconnect();
|
||||
if ($config != null)
|
||||
{
|
||||
$this->config = am($this->config, $config);
|
||||
}
|
||||
return $this->connect();
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepares a value, or an array of values for database queries by quoting and escaping them.
|
||||
*
|
||||
|
@ -95,9 +111,11 @@ class DboSource extends DataSource
|
|||
if (is_array($data))
|
||||
{
|
||||
$out = array();
|
||||
foreach ($data as $key => $item)
|
||||
$keys = array_keys($data);
|
||||
$count = count($data);
|
||||
for ($i = 0; $i < $count; $i++)
|
||||
{
|
||||
$out[$key] = $this->value($item);
|
||||
$out[$keys[$i]] = $this->value($data[$keys[$i]]);
|
||||
}
|
||||
return $out;
|
||||
}
|
||||
|
@ -548,9 +566,12 @@ class DboSource extends DataSource
|
|||
}
|
||||
else
|
||||
{
|
||||
if (true === $this->generateAssociationQuery($model, $linkModel, $type, $assoc, $assocData, $queryData, false, $null))
|
||||
if ($model->useDbConfig == $linkModel->useDbConfig)
|
||||
{
|
||||
$linkedModels[] = $type.'/'.$assoc;
|
||||
if (true === $this->generateAssociationQuery($model, $linkModel, $type, $assoc, $assocData, $queryData, false, $null))
|
||||
{
|
||||
$linkedModels[] = $type.'/'.$assoc;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -560,6 +581,7 @@ class DboSource extends DataSource
|
|||
// Build final query SQL
|
||||
$query = $this->generateAssociationQuery($model, $null, null, null, null, $queryData, false, $null);
|
||||
$resultSet = $this->fetchAll($query, $model->cacheQueries);
|
||||
$filtered = $this->__filterResults($resultSet, $model);
|
||||
|
||||
if ($model->recursive > 0)
|
||||
{
|
||||
|
@ -567,18 +589,36 @@ class DboSource extends DataSource
|
|||
{
|
||||
foreach($model->{$type} as $assoc => $assocData)
|
||||
{
|
||||
$db = null;
|
||||
$linkModel =& $model->{$assocData['className']};
|
||||
if (!in_array($type.'/'.$assoc, $linkedModels))
|
||||
{
|
||||
$this->queryAssociation($model, $linkModel, $type, $assoc, $assocData, $array, true, $resultSet, $model->recursive);
|
||||
if ($model->useDbConfig == $linkModel->useDbConfig)
|
||||
{
|
||||
$db =& $this;
|
||||
}
|
||||
else
|
||||
{
|
||||
$db =& ConnectionManager::getDataSource($linkModel->useDbConfig);
|
||||
}
|
||||
}
|
||||
elseif($model->recursive > 1 && ($type == 'belongsTo' || $type == 'hasOne'))
|
||||
{
|
||||
// Do recursive joins on belongsTo and hasOne relationships
|
||||
$this->queryAssociation($model, $linkModel, $type, $assoc, $assocData, $array, true, $resultSet, $model->recursive);
|
||||
$db =& $this;
|
||||
}
|
||||
else
|
||||
{
|
||||
unset($db);
|
||||
}
|
||||
if (isset($db) && $db != null)
|
||||
{
|
||||
$db->queryAssociation($model, $linkModel, $type, $assoc, $assocData, $array, true, $resultSet, $model->recursive);
|
||||
unset($db);
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->__filterResults($resultSet, $model, $filtered);
|
||||
}
|
||||
|
||||
if(!is_null($recursive))
|
||||
|
@ -588,6 +628,48 @@ class DboSource extends DataSource
|
|||
return $resultSet;
|
||||
}
|
||||
|
||||
/**
|
||||
* Private method
|
||||
*
|
||||
* @param unknown_type $linkModel
|
||||
* @param Model $model
|
||||
* @return array
|
||||
*/
|
||||
function __filterResults(&$results, &$model, $filtered = array())
|
||||
{
|
||||
$filtering = array();
|
||||
$associations = am($model->belongsTo, $model->hasOne, $model->hasMany, $model->hasAndBelongsToMany);
|
||||
|
||||
$count = count($results);
|
||||
for ($i = 0; $i < $count; $i++)
|
||||
{
|
||||
$keys = array_keys($results[$i]);
|
||||
$count2 = count($keys);
|
||||
|
||||
for ($j = 0; $j < $count2; $j++)
|
||||
{
|
||||
$key = $keys[$j];
|
||||
if ($model->name != $key && !in_array($key, $filtered))
|
||||
{
|
||||
if (!in_array($key, $filtering))
|
||||
{
|
||||
$filtering[] = $key;
|
||||
}
|
||||
if (isset($model->{$key}) && is_object($model->{$key}))
|
||||
{
|
||||
$data = $model->{$key}->afterFind(array(array($key => $results[$i][$key])));
|
||||
}
|
||||
else
|
||||
{
|
||||
$data = $model->{$associations[$key]['className']}->afterFind(array(array($key => $results[$i][$key])));
|
||||
}
|
||||
$results[$i][$key] = $data[0][$key];
|
||||
}
|
||||
}
|
||||
}
|
||||
return $filtering;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enter description here...
|
||||
*
|
||||
|
@ -618,14 +700,17 @@ class DboSource extends DataSource
|
|||
}
|
||||
return null;
|
||||
}
|
||||
foreach ($resultSet as $i => $row)
|
||||
|
||||
$count = count($resultSet);
|
||||
for ($i = 0; $i < $count; $i++)
|
||||
{
|
||||
$row =& $resultSet[$i];
|
||||
$q = $this->insertQueryData($query, $resultSet, $association, $assocData, $model, $linkModel, $i);
|
||||
$fetch = $this->fetchAll($q, $model->cacheQueries);
|
||||
|
||||
if (!empty($fetch) && is_array($fetch))
|
||||
{
|
||||
if ($recursive > 0)
|
||||
if ($recursive > 1)
|
||||
{
|
||||
foreach($linkModel->__associations as $type1)
|
||||
{
|
||||
|
@ -713,8 +798,8 @@ class DboSource extends DataSource
|
|||
|
||||
$sql = 'SELECT ' . join(', ', $this->fields($model, $model->name, $queryData['fields'])). ', ';
|
||||
$sql .= join(', ', $this->fields($linkModel, $alias, ''));
|
||||
$sql .= ' FROM '.$model->table.' AS ' . $model->name;
|
||||
$sql .= ' LEFT JOIN '.$linkModel->table.' AS ' . $alias;
|
||||
$sql .= ' FROM '.$this->name($model->table).' AS ' . $this->name($model->name);
|
||||
$sql .= ' LEFT JOIN '.$this->name($linkModel->table).' AS ' . $this->name($alias);
|
||||
$sql .= ' ON ';
|
||||
$sql .= $this->name($model->name).'.'.$this->name($assocData['foreignKey']);
|
||||
$sql .= ' = '.$this->name($alias).'.'.$this->name($linkModel->primaryKey);
|
||||
|
@ -1178,15 +1263,22 @@ class DboSource extends DataSource
|
|||
{
|
||||
if(!preg_match('/^.+\\(.*\\)/', $fields[$i]))
|
||||
{
|
||||
$prepend = '';
|
||||
if (strpos($fields[$i], 'DISTINCT') !== false)
|
||||
{
|
||||
$prepend = 'DISTINCT ';
|
||||
$fields[$i] = trim(r('DISTINCT', '', $fields[$i]));
|
||||
}
|
||||
|
||||
$dot = strrpos($fields[$i], '.');
|
||||
if ($dot === false)
|
||||
{
|
||||
$fields[$i] = $this->name($alias).'.'.$this->name($fields[$i]);
|
||||
$fields[$i] = $prepend.$this->name($alias).'.'.$this->name($fields[$i]);
|
||||
}
|
||||
else
|
||||
{
|
||||
$build = explode('.',$fields[$i]);
|
||||
$fields[$i] = $this->name($build[0]).'.'.$this->name($build[1]);
|
||||
$fields[$i] = $prepend.$this->name($build[0]).'.'.$this->name($build[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1288,7 +1380,7 @@ class DboSource extends DataSource
|
|||
{
|
||||
$data = $this->name($key)." = ''";
|
||||
}
|
||||
elseif (preg_match('/^([a-z]*\\([a-z0-9]*\\)\\x20?|like\\x20?|or\\x20?|between\\x20?|regexp\\x20?|[<>=!]{1,3}\\x20?)?(.*)/i', $value, $match))
|
||||
elseif (preg_match('/^([a-z]*\\([a-z0-9]*\\)\\x20?|(?:like\\x20)|(?:or\\x20)|(?:between\\x20)|(?:regexp\\x20)|[<>=!]{1,3}\\x20?)?(.*)/i', $value, $match))
|
||||
{
|
||||
if (preg_match('/(\\x20[\\w]*\\x20)/', $key, $regs))
|
||||
{
|
||||
|
|
612
cake/libs/model/dbo/dbo_mssql.php
Normal file
612
cake/libs/model/dbo/dbo_mssql.php
Normal file
|
@ -0,0 +1,612 @@
|
|||
<?php
|
||||
/* SVN FILE: $Id$ */
|
||||
|
||||
/**
|
||||
* MS SQL layer for DBO
|
||||
*
|
||||
* Long description for file
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP : Rapid Development Framework <http://www.cakephp.org/>
|
||||
* Copyright (c) 2006, Cake Software Foundation, Inc.
|
||||
* 1785 E. Sahara Avenue, Suite 490-204
|
||||
* Las Vegas, Nevada 89104
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @filesource
|
||||
* @copyright Copyright (c) 2006, Cake Software Foundation, Inc.
|
||||
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project
|
||||
* @package cake
|
||||
* @subpackage cake.cake.libs.model.dbo
|
||||
* @since CakePHP v 0.10.5.1790
|
||||
* @version $Revision$
|
||||
* @modifiedby $LastChangedBy$
|
||||
* @lastmodified $Date$
|
||||
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Include DBO.
|
||||
*/
|
||||
uses('model'.DS.'datasources'.DS.'dbo_source');
|
||||
|
||||
/**
|
||||
* Short description for class.
|
||||
*
|
||||
* Long description for class
|
||||
*
|
||||
* @package cake
|
||||
* @subpackage cake.cake.libs.model.dbo
|
||||
* @since CakePHP v 0.10.5.1790
|
||||
*/
|
||||
class DboMssql extends DboSource
|
||||
{
|
||||
/**
|
||||
* Enter description here...
|
||||
*
|
||||
* @var unknown_type
|
||||
*/
|
||||
var $description = "MS SQL DBO Driver";
|
||||
|
||||
/**
|
||||
* Enter description here...
|
||||
*
|
||||
* @var unknown_type
|
||||
*/
|
||||
var $startQuote = "[";
|
||||
|
||||
/**
|
||||
* Enter description here...
|
||||
*
|
||||
* @var unknown_type
|
||||
*/
|
||||
var $endQuote = "]";
|
||||
|
||||
/**
|
||||
* Base configuration settings for MS SQL driver
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
var $_baseConfig = array('persistent' => true,
|
||||
'host' => 'localhost',
|
||||
'login' => 'root',
|
||||
'password' => '',
|
||||
'database' => 'cake',
|
||||
'port' => '1433',
|
||||
'connect' => 'mssql_pconnect');
|
||||
|
||||
/**
|
||||
* MS SQL column definition
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
var $columns = array('primary_key' => array('name' => 'int(11) DEFAULT NULL auto_increment'),
|
||||
'string' => array('name' => 'varchar', 'limit' => '255'),
|
||||
'text' => array('name' => 'text'),
|
||||
'integer' => array('name' => 'int', 'limit' => '11', 'formatter' => 'intval'),
|
||||
'float' => array('name' => 'float', 'formatter' => 'floatval'),
|
||||
'datetime' => array('name' => 'datetime', 'format' => 'Y-m-d H:i:s', 'formatter' => 'date'),
|
||||
'timestamp' => array('name' => 'timestamp', 'format' => 'Y-m-d H:i:s', 'formatter' => 'date'),
|
||||
'time' => array('name' => 'datetime', 'format' => 'H:i:s', 'formatter' => 'date'),
|
||||
'date' => array('name' => 'datetime', 'format' => 'Y-m-d', 'formatter' => 'date'),
|
||||
'binary' => array('name' => 'image'),
|
||||
'boolean' => array('name' => 'bit'));
|
||||
|
||||
/**
|
||||
* MS SQL DBO driver constructor; sets SQL Server error reporting defaults
|
||||
*
|
||||
* @param array $config Configuration data from app/config/databases.php
|
||||
* @return boolean True if connected successfully, false on error
|
||||
*/
|
||||
function __construct ($config)
|
||||
{
|
||||
mssql_min_message_severity(15);
|
||||
mssql_min_error_severity(2);
|
||||
return parent::__construct($config);
|
||||
}
|
||||
|
||||
/**
|
||||
* Connects to the database using options in the given configuration array.
|
||||
*
|
||||
* @return boolean True if the database could be connected, else false
|
||||
*/
|
||||
function connect ()
|
||||
{
|
||||
$config = $this->config;
|
||||
$connect = $config['connect'];
|
||||
|
||||
$this->connected = false;
|
||||
|
||||
if (is_numeric($config['port']))
|
||||
{
|
||||
$port = ':'.$config['port']; // Port number
|
||||
}
|
||||
else
|
||||
{
|
||||
$port = '\\'.$config['port']; // Named pipe
|
||||
}
|
||||
|
||||
$this->connection = $connect($config['host'].$port, $config['login'], $config['password']);
|
||||
|
||||
if (mssql_select_db($config['database'], $this->connection))
|
||||
{
|
||||
$this->connected = true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Disconnects from database.
|
||||
*
|
||||
* @return boolean True if the database could be disconnected, else false
|
||||
*/
|
||||
function disconnect ()
|
||||
{
|
||||
return @mssql_close($this->connection);
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes given SQL statement.
|
||||
*
|
||||
* @param string $sql SQL statement
|
||||
* @return resource Result resource identifier
|
||||
* @access protected
|
||||
*/
|
||||
function _execute ($sql)
|
||||
{
|
||||
return mssql_query($sql, $this->connection);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a row from given resultset as an array .
|
||||
*
|
||||
* @param bool $assoc Associative array only, or both?
|
||||
* @return array The fetched row as an array
|
||||
*/
|
||||
function fetchRow ($assoc = false)
|
||||
{
|
||||
if(is_resource($this->_result))
|
||||
{
|
||||
$this->resultSet($this->_result);
|
||||
$resultRow = $this->fetchResult();
|
||||
return $resultRow;
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of sources (tables) in the database.
|
||||
*
|
||||
* @return array Array of tablenames in the database
|
||||
*/
|
||||
function listSources ()
|
||||
{
|
||||
$cache = parent::listSources();
|
||||
if ($cache != null)
|
||||
{
|
||||
return $cache;
|
||||
}
|
||||
$result = $this->fetchAll('SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES');
|
||||
|
||||
if (!$result || empty($result))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
else
|
||||
{
|
||||
$tables = array();
|
||||
foreach ($result as $table)
|
||||
{
|
||||
$tables[] = $table[0]['TABLE_NAME'];
|
||||
}
|
||||
parent::listSources($tables);
|
||||
return $tables;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of the fields in given table name.
|
||||
*
|
||||
* @param string $tableName Name of database table to inspect
|
||||
* @return array Fields in table. Keys are name and type
|
||||
*/
|
||||
function describe (&$model)
|
||||
{
|
||||
$cache = parent::describe($model);
|
||||
if ($cache != null)
|
||||
{
|
||||
return $cache;
|
||||
}
|
||||
|
||||
$fields = false;
|
||||
$cols = $this->fetchAll("SELECT COLUMN_NAME as Field, DATA_TYPE as Type, COL_LENGTH('".$model->table."', COLUMN_NAME) as Length, IS_NULLABLE As [Null], COLUMN_DEFAULT as [Default], COLUMNPROPERTY(OBJECT_ID('".$model->table."'), COLUMN_NAME, 'IsIdentity') as [Key], NUMERIC_SCALE as Size FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = '".$model->table."'", false);
|
||||
|
||||
foreach ($cols as $column)
|
||||
{
|
||||
$field = array('name' => $column[0]['Field'], 'type' => $this->column($column[0]['Type'].$column[0]['Length']), 'null' => $column[0]['Null']);
|
||||
$fields[] = $field;
|
||||
}
|
||||
$this->__cacheDescription($model->table, $fields);
|
||||
return $fields;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a quoted name of $data for use in an SQL statement.
|
||||
*
|
||||
* @param string $data Name (table.field) to be prepared for use in an SQL statement
|
||||
* @return string Quoted for MS SQL
|
||||
*/
|
||||
function name ($data)
|
||||
{
|
||||
if ($data == '*')
|
||||
{
|
||||
return '*';
|
||||
}
|
||||
$pos = strpos($data, '[');
|
||||
if ($pos === false)
|
||||
{
|
||||
$data = '['. r('.', '].[', $data) .']';
|
||||
}
|
||||
$data = r(']]', ']', r('[[', '[', $data));
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a quoted and escaped string of $data for use in an SQL statement.
|
||||
*
|
||||
* @param string $data String to be prepared for use in an SQL statement
|
||||
* @param string $column The column into which this data will be inserted
|
||||
* @param boolean $safe Whether or not numeric data should be handled automagically if no column data is provided
|
||||
* @return string Quoted and escaped data
|
||||
*/
|
||||
function value ($data, $column = null, $safe = false)
|
||||
{
|
||||
$parent = parent::value($data, $column, $safe);
|
||||
|
||||
if ($parent != null)
|
||||
{
|
||||
return $parent;
|
||||
}
|
||||
|
||||
if ($data === null)
|
||||
{
|
||||
return 'NULL';
|
||||
}
|
||||
|
||||
if($data == '')
|
||||
{
|
||||
return "''";
|
||||
}
|
||||
|
||||
switch ($column)
|
||||
{
|
||||
case 'boolean':
|
||||
$data = $this->boolean((bool)$data);
|
||||
break;
|
||||
default:
|
||||
if (ini_get('magic_quotes_gpc') == 1)
|
||||
{
|
||||
$data = stripslashes($data);
|
||||
}
|
||||
$data = addslashes($data);
|
||||
}
|
||||
|
||||
return "'" . $data . "'";
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates the fields list of an SQL query.
|
||||
*
|
||||
* @param Model $model
|
||||
* @param string $alias Alias tablename
|
||||
* @param mixed $fields
|
||||
* @return array
|
||||
*/
|
||||
function fields (&$model, $alias, $fields)
|
||||
{
|
||||
if (is_array($fields))
|
||||
{
|
||||
$fields = $fields;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($fields != null)
|
||||
{
|
||||
if (strpos($fields, ','))
|
||||
{
|
||||
$fields = explode(',', $fields);
|
||||
}
|
||||
else
|
||||
{
|
||||
$fields = array($fields);
|
||||
}
|
||||
$fields = array_map('trim', $fields);
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach ($model->_tableInfo->value as $field)
|
||||
{
|
||||
$fields[]= $field['name'];
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
$count = count($fields);
|
||||
if ($count >= 1 && $fields[0] != '*' && strpos($fields[0], 'COUNT(*)') === false)
|
||||
{
|
||||
for ($i = 0; $i < $count; $i++)
|
||||
{
|
||||
$dot = strrpos($fields[$i], '.');
|
||||
if ($dot === false)
|
||||
{
|
||||
$fields[$i] = $this->name($alias).'.'.$this->name($fields[$i]) . ' AS ' . $this->name($alias . '__' . $fields[$i]);
|
||||
}
|
||||
else
|
||||
{
|
||||
$build = explode('.',$fields[$i]);
|
||||
$fields[$i] = $this->name($build[0]).'.'.$this->name($build[1]) . ' AS ' . $this->name($build[0] . '__' . $build[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $fields;
|
||||
}
|
||||
|
||||
/**
|
||||
* Begin a transaction
|
||||
*
|
||||
* @param unknown_type $model
|
||||
* @return boolean True on success, false on fail
|
||||
* (i.e. if the database/model does not support transactions).
|
||||
*/
|
||||
function begin (&$model)
|
||||
{
|
||||
if (parent::begin($model))
|
||||
{
|
||||
if ($this->execute('BEGIN TRANSACTION'))
|
||||
{
|
||||
$this->__transactionStarted = true;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Commit a transaction
|
||||
*
|
||||
* @param unknown_type $model
|
||||
* @return boolean True on success, false on fail
|
||||
* (i.e. if the database/model does not support transactions,
|
||||
* or a transaction has not started).
|
||||
*/
|
||||
function commit (&$model)
|
||||
{
|
||||
if (parent::commit($model))
|
||||
{
|
||||
$this->__transactionStarted;
|
||||
return $this->execute('COMMIT');
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Rollback a transaction
|
||||
*
|
||||
* @param unknown_type $model
|
||||
* @return boolean True on success, false on fail
|
||||
* (i.e. if the database/model does not support transactions,
|
||||
* or a transaction has not started).
|
||||
*/
|
||||
function rollback (&$model)
|
||||
{
|
||||
if (parent::rollback($model))
|
||||
{
|
||||
return $this->execute('ROLLBACK');
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a formatted error message from previous database operation.
|
||||
*
|
||||
* @return string Error message with error number
|
||||
*/
|
||||
function lastError ()
|
||||
{
|
||||
$error = mssql_get_last_message($this->connection);
|
||||
if ($error)
|
||||
{
|
||||
if (strpos('changed database', low($error)) !== false)
|
||||
{
|
||||
return $error;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns number of affected rows in previous database operation. If no previous operation exists,
|
||||
* this returns false.
|
||||
*
|
||||
* @return int Number of affected rows
|
||||
*/
|
||||
function lastAffected ()
|
||||
{
|
||||
if ($this->_result)
|
||||
{
|
||||
return mssql_rows_affected($this->connection);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns number of rows in previous resultset. If no previous resultset exists,
|
||||
* this returns false.
|
||||
*
|
||||
* @return int Number of rows in resultset
|
||||
*/
|
||||
function lastNumRows ()
|
||||
{
|
||||
if ($this->_result)
|
||||
{
|
||||
return @mssql_num_rows($this->_result);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the ID generated from the previous INSERT operation.
|
||||
*
|
||||
* @param unknown_type $source
|
||||
* @return in
|
||||
*/
|
||||
function lastInsertId ($source = null)
|
||||
{
|
||||
$id = $this->fetchAll('SELECT SCOPE_IDENTITY() AS insertID', false);
|
||||
return $id[0]['insertID'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a limit statement in the correct format for the particular database.
|
||||
*
|
||||
* @param int $limit Limit of results returned
|
||||
* @param int $offset Offset from which to start results
|
||||
* @return string SQL limit/offset statement
|
||||
*/
|
||||
function limit ($limit, $offset = null)
|
||||
{
|
||||
if ($limit)
|
||||
{
|
||||
$rt = '';
|
||||
if (!strpos(strtolower($limit), 'limit') || strpos(strtolower($limit), 'limit') === 0)
|
||||
{
|
||||
$rt = ' LIMIT';
|
||||
}
|
||||
if ($offset)
|
||||
{
|
||||
$rt .= ' ' . $offset. ',';
|
||||
}
|
||||
$rt .= ' ' . $limit;
|
||||
return $rt;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts database-layer column types to basic types
|
||||
*
|
||||
* @param string $real Real database-layer column type (i.e. "varchar(255)")
|
||||
* @return string Abstract column type (i.e. "string")
|
||||
*/
|
||||
function column($real)
|
||||
{
|
||||
$col = r(')', '', $real);
|
||||
$limit = null;
|
||||
@list($col, $limit) = explode('(', $col);
|
||||
|
||||
if (in_array($col, array('date', 'time', 'datetime', 'timestamp')))
|
||||
{
|
||||
return $col;
|
||||
}
|
||||
if ($col == 'bit')
|
||||
{
|
||||
return 'boolean';
|
||||
}
|
||||
if (strpos($col, 'int') !== false || $col == 'numeric')
|
||||
{
|
||||
return 'integer';
|
||||
}
|
||||
if (strpos($col, 'char') !== false)
|
||||
{
|
||||
return 'string';
|
||||
}
|
||||
if (strpos($col, 'text') !== false)
|
||||
{
|
||||
return 'text';
|
||||
}
|
||||
if (strpos($col, 'binary') !== false || $col == 'image')
|
||||
{
|
||||
return 'binary';
|
||||
}
|
||||
if (in_array($col, array('float', 'real', 'decimal')))
|
||||
{
|
||||
return 'float';
|
||||
}
|
||||
|
||||
return 'text';
|
||||
}
|
||||
|
||||
/**
|
||||
* Enter description here...
|
||||
*
|
||||
* @param unknown_type $results
|
||||
*/
|
||||
function resultSet(&$results)
|
||||
{
|
||||
$this->results =& $results;
|
||||
$this->map = array();
|
||||
$num_fields = mssql_num_fields($results);
|
||||
$index = 0;
|
||||
$j = 0;
|
||||
|
||||
while ($j < $num_fields)
|
||||
{
|
||||
$column = mssql_fetch_field($results, $j);
|
||||
if (strpos($column->name, '__'))
|
||||
{
|
||||
$this->map[$index++] = explode('__', $column->name);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->map[$index++] = array(0, $column->name);
|
||||
}
|
||||
$j++;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches the next row from the current result set
|
||||
*
|
||||
* @return unknown
|
||||
*/
|
||||
function fetchResult()
|
||||
{
|
||||
if ($row = mssql_fetch_row($this->results))
|
||||
{
|
||||
$resultRow = array();
|
||||
$i = 0;
|
||||
foreach ($row as $index => $field)
|
||||
{
|
||||
list($table, $column) = $this->map[$index];
|
||||
$resultRow[$table][$column] = $row[$index];
|
||||
$i++;
|
||||
}
|
||||
return $resultRow;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function buildSchemaQuery($schema)
|
||||
{
|
||||
$search = array('{AUTOINCREMENT}', '{PRIMARY}', '{UNSIGNED}', '{FULLTEXT}',
|
||||
'{BOOLEAN}', '{UTF_8}');
|
||||
$replace = array('int(11) not null auto_increment', 'primary key', 'unsigned',
|
||||
'FULLTEXT', 'enum (\'true\', \'false\') NOT NULL default \'true\'',
|
||||
'/*!40100 CHARACTER SET utf8 COLLATE utf8_unicode_ci */');
|
||||
$query = trim(r($search, $replace, $schema));
|
||||
return $query;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
|
@ -71,12 +71,13 @@ class DboMysql extends DboSource
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
var $_baseConfig = array('persistent' => true,
|
||||
var $_baseConfig = array('persistent' => true,
|
||||
'host' => 'localhost',
|
||||
'login' => 'root',
|
||||
'login' => 'root',
|
||||
'password' => '',
|
||||
'database' => 'cake',
|
||||
'port' => 3306);
|
||||
'port' => '3306',
|
||||
'connect' => 'mysql_pconnect');
|
||||
|
||||
/**
|
||||
* MySQL column definition
|
||||
|
@ -95,18 +96,6 @@ class DboMysql extends DboSource
|
|||
'binary' => array('name' => 'blob'),
|
||||
'boolean' => array('name' => 'tinyint', 'limit' => '1'));
|
||||
|
||||
/**
|
||||
* Enter description here...
|
||||
*
|
||||
* @param unknown_type $config
|
||||
* @return unknown
|
||||
*/
|
||||
function __construct ($config)
|
||||
{
|
||||
parent::__construct($config);
|
||||
return $this->connect();
|
||||
}
|
||||
|
||||
/**
|
||||
* Connects to the database using options in the given configuration array.
|
||||
*
|
||||
|
@ -118,7 +107,14 @@ class DboMysql extends DboSource
|
|||
$connect = $config['connect'];
|
||||
|
||||
$this->connected = false;
|
||||
$this->connection = $connect($config['host'], $config['login'], $config['password']);
|
||||
if (!$config['persistent'])
|
||||
{
|
||||
$this->connection = mysql_connect($config['host'], $config['login'], $config['password'], true);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->connection = $connect($config['host'], $config['login'], $config['password']);
|
||||
}
|
||||
|
||||
if (mysql_select_db($config['database'], $this->connection))
|
||||
{
|
||||
|
@ -133,7 +129,8 @@ class DboMysql extends DboSource
|
|||
*/
|
||||
function disconnect ()
|
||||
{
|
||||
return @mysql_close($this->connection);
|
||||
$this->connected = !@mysql_close($this->connection);
|
||||
return !$this->connected;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -605,7 +605,7 @@ class Model extends Object
|
|||
{
|
||||
foreach ($v as $x => $y)
|
||||
{
|
||||
if($x == $this->primaryKey)
|
||||
if($x == $this->primaryKey && $n == $this->name)
|
||||
{
|
||||
$this->id = $y;
|
||||
}
|
||||
|
|
|
@ -601,7 +601,7 @@ class Model extends Object
|
|||
{
|
||||
foreach ($v as $x => $y)
|
||||
{
|
||||
if($x == $this->primaryKey)
|
||||
if($x == $this->primaryKey && $n == $this->name)
|
||||
{
|
||||
$this->id = $y;
|
||||
}
|
||||
|
@ -1624,7 +1624,6 @@ class Model extends Object
|
|||
*/
|
||||
function setDataSource($dataSource = null)
|
||||
{
|
||||
$db =& ConnectionManager::getDataSource($this->useDbConfig);
|
||||
if ($dataSource == null)
|
||||
{
|
||||
$dataSource = $this->useDbConfig;
|
||||
|
|
|
@ -587,7 +587,7 @@ class CakeSession extends Object
|
|||
}
|
||||
return $expression;
|
||||
}
|
||||
$this->setError(3, "$name is not a string");
|
||||
$this->__setError(3, "$name is not a string");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -68,16 +68,10 @@ class Helper extends Object
|
|||
*/
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* Parses tag templates into $this->tags.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function Helper()
|
||||
{
|
||||
}
|
||||
|
||||
function loadConfig()
|
||||
{
|
||||
$config = fileExistsInPath(CAKE.'config'.DS.'tags.ini.php');
|
||||
|
@ -109,14 +103,8 @@ class Helper extends Object
|
|||
{
|
||||
if (AUTO_OUTPUT && $return === false)
|
||||
{
|
||||
if (print $str)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
echo $str;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -596,7 +596,7 @@ class AjaxHelper extends Helper
|
|||
*/
|
||||
function __optionsForSortable ($options)
|
||||
{
|
||||
$options = $this->_optionsToString($options, array('handle','tag','constraint','ghosting'));
|
||||
$options = $this->_optionsToString($options, array('handle','tag','constraint','ghosting', 'only'));
|
||||
return $this->_buildOptions($options, $this->sortOptions);
|
||||
}
|
||||
|
||||
|
|
|
@ -412,8 +412,8 @@ class FormHelper extends Helper
|
|||
case "checkbox" :
|
||||
$strFormFields = $strFormFields.$this->generateCheckboxDiv( $field['tagName'], $field['prompt'], $field['required'], $field['errorMsg'], $field['htmlOptions'] );
|
||||
break;
|
||||
case "select";
|
||||
case "selectMultiple";
|
||||
case "select":
|
||||
case "selectMultiple":
|
||||
if( "selectMultiple" == $field['type'] )
|
||||
{
|
||||
$field['selectAttr']['multiple'] = 'multiple';
|
||||
|
@ -441,7 +441,7 @@ class FormHelper extends Helper
|
|||
}
|
||||
$strFormFields = $strFormFields.$this->generateSelectDiv( $field['tagName'], $field['prompt'], $field['options'], $field['selected'], $field['selectAttr'], $field['optionsAttr'], $field['required'], $field['errorMsg'] );
|
||||
break;
|
||||
case "area";
|
||||
case "area":
|
||||
if(!isset( $field['rows']))
|
||||
{
|
||||
$field['rows'] = 10;
|
||||
|
@ -452,7 +452,7 @@ class FormHelper extends Helper
|
|||
}
|
||||
$strFormFields = $strFormFields.$this->generateAreaDiv( $field['tagName'], $field['prompt'], $field['required'], $field['errorMsg'], $field['cols'], $field['rows'], $field['htmlOptions'] );
|
||||
break;
|
||||
case "fieldset";
|
||||
case "fieldset":
|
||||
|
||||
$strFieldsetFields = $this->generateFields( $field['fields'] );
|
||||
$strFieldSet = sprintf( '
|
||||
|
@ -460,7 +460,7 @@ class FormHelper extends Helper
|
|||
$field['legend'], $field['noteHeading'], $field['note'], $strFieldsetFields );
|
||||
$strFormFields = $strFormFields.$strFieldSet;
|
||||
break;
|
||||
case "hidden";
|
||||
case "hidden":
|
||||
$strFormFields = $strFormFields . $this->Html->hiddenTag( $field['tagName']);
|
||||
break;
|
||||
case "date":
|
||||
|
|
|
@ -271,6 +271,18 @@ function url($url = null, $return = false)
|
|||
$htmlAttributes['value'] = $this->tagValue($fieldName);
|
||||
}
|
||||
|
||||
if ($this->tagIsInvalid($this->model, $this->field))
|
||||
{
|
||||
if (isset($htmlAttributes['class']) && trim($htmlAttributes['class']) != "")
|
||||
{
|
||||
$htmlAttributes['class'] .= ' form_error';
|
||||
}
|
||||
else
|
||||
{
|
||||
$htmlAttributes['class'] = 'form_error';
|
||||
}
|
||||
}
|
||||
|
||||
return $this->output(sprintf($this->tags['password'], $this->model, $this->field,
|
||||
$this->_parseAttributes($htmlAttributes, null, ' ', ' ')), $return);
|
||||
}
|
||||
|
@ -350,7 +362,7 @@ function url($url = null, $return = false)
|
|||
$output = $this->hidden($fieldName, array('value' => $notCheckedValue), true);
|
||||
$output .= sprintf($this->tags['checkbox'], $this->model, $this->field,
|
||||
$this->_parseAttributes($htmlAttributes, null, '', ' '));
|
||||
return $output;
|
||||
return $this->output($output, $return);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -546,16 +558,18 @@ function url($url = null, $return = false)
|
|||
* @param array $names Array of tablenames.
|
||||
* @param array $trOptions HTML options for TR elements.
|
||||
* @param array $thOptions HTML options for TH elements.
|
||||
* @param boolean $return Wheter this method should return a value
|
||||
* @return string
|
||||
*/
|
||||
function tableHeaders($names, $trOptions=null, $thOptions=null)
|
||||
function tableHeaders($names, $trOptions=null, $thOptions=null, $return=false)
|
||||
{
|
||||
$out = array();
|
||||
foreach ($names as $arg)
|
||||
{
|
||||
$out[] = sprintf($this->tags['tableheader'], $this->parseHtmlOptions($thOptions), $arg);
|
||||
}
|
||||
return sprintf($this->tags['tablerow'], $this->parseHtmlOptions($trOptions), join(' ', $out));
|
||||
$data = sprintf($this->tags['tablerow'], $this->parseHtmlOptions($trOptions), join(' ', $out));
|
||||
return $this->output($data, $return);
|
||||
}
|
||||
|
||||
|
||||
|
@ -565,9 +579,10 @@ function url($url = null, $return = false)
|
|||
* @param array $data Array of table data
|
||||
* @param array $oddTrOptions HTML options for odd TR elements
|
||||
* @param array $evenTrOptions HTML options for even TR elements
|
||||
* @param boolean $return Wheter this method should return a value
|
||||
* @return string Formatted HTML
|
||||
*/
|
||||
function tableCells($data, $oddTrOptions=null, $evenTrOptions=null)
|
||||
function tableCells($data, $oddTrOptions=null, $evenTrOptions=null, $return=false)
|
||||
{
|
||||
if (empty($data[0]) || !is_array($data[0]))
|
||||
{
|
||||
|
@ -587,8 +602,7 @@ function url($url = null, $return = false)
|
|||
$options = $this->parseHtmlOptions($count%2? $oddTrOptions: $evenTrOptions);
|
||||
$out[] = sprintf($this->tags['tablerow'], $options, join(' ', $cellsOut));
|
||||
}
|
||||
|
||||
return join("\n", $out);
|
||||
return $this->output(join("\n", $out), $return);
|
||||
}
|
||||
|
||||
|
||||
|
@ -1051,9 +1065,10 @@ function url($url = null, $return = false)
|
|||
* @param boolean $show_empty Show/hide the empty select option
|
||||
* @param array $selectAttr Array of HTML options for the opening SELECT element
|
||||
* @param array $optionAttr Array of HTML options for the enclosed OPTION elements
|
||||
* @param boolean $return Wheter this method should return a value
|
||||
* @return string Formatted SELECT element
|
||||
*/
|
||||
function selectTag($fieldName, $optionElements, $selected=null, $selectAttr=null, $optionAttr=null, $showEmpty=true)
|
||||
function selectTag($fieldName, $optionElements, $selected=null, $selectAttr=null, $optionAttr=null, $showEmpty=true, $return=false)
|
||||
{
|
||||
$this->setFormTag($fieldName);
|
||||
if ($this->tagIsInvalid($this->model, $this->field))
|
||||
|
@ -1107,7 +1122,7 @@ function url($url = null, $return = false)
|
|||
|
||||
$select[] = sprintf($this->tags['selectend']);
|
||||
|
||||
return implode("\n", $select);
|
||||
return $this->output(implode("\n", $select), $return);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -179,14 +179,28 @@ class TextHelper extends Helper
|
|||
* @param string $text String to truncate.
|
||||
* @param integer $length Length of returned string, including ellipsis.
|
||||
* @param string $ending Ending to be appended to the trimmed string.
|
||||
* @param boolean $exact If false, $test will not be cut mid-word
|
||||
* @return string Trimmed string.
|
||||
*/
|
||||
function truncate($text, $length, $ending='...')
|
||||
function truncate($text, $length, $ending = '...', $exact = true)
|
||||
{
|
||||
if (strlen($text) <= $length)
|
||||
return $text;
|
||||
{
|
||||
return $text;
|
||||
}
|
||||
else
|
||||
return substr($text, 0, $length - strlen($ending)) . $ending;
|
||||
{
|
||||
$truncate = substr($text, 0, $length - strlen($ending));
|
||||
if (!$exact)
|
||||
{
|
||||
$spacepos = strrpos($truncate, ' ');
|
||||
if (isset($spacepos))
|
||||
{
|
||||
return substr($truncate, 0, $spacepos).$ending;
|
||||
}
|
||||
}
|
||||
return $truncate.$ending;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -359,7 +359,7 @@ class TimeHelper extends Helper
|
|||
else
|
||||
{
|
||||
// seconds only
|
||||
$relative_date .= ($relative_date ? ', ' : '').$seconds.' second'.($seconds > 1 ? 's' : '');
|
||||
$relative_date .= ($relative_date ? ', ' : '').$seconds.' second'.($seconds != 1 ? 's' : '');
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -322,10 +322,14 @@ class View extends Object
|
|||
|
||||
if (strpos($action, 'missingView') === false)
|
||||
{
|
||||
return $this->cakeError('missingView',
|
||||
array(array('className' => $this->controller->name,
|
||||
'action' => $action,
|
||||
'file' => $viewFileName)));
|
||||
return $this->cakeError('missingView', array(
|
||||
array(
|
||||
'className' => $this->controller->name,
|
||||
'action' => $action,
|
||||
'file' => $viewFileName,
|
||||
'base' => $this->base
|
||||
)
|
||||
));
|
||||
|
||||
$isFatal = isset($this->isFatal) ? $this->isFatal : false;
|
||||
if (!$isFatal)
|
||||
|
@ -478,9 +482,13 @@ class View extends Object
|
|||
}
|
||||
else
|
||||
{
|
||||
return $this->cakeError('missingLayout',
|
||||
array(array('layout' => $this->layout,
|
||||
'file' => $layout_fn)));
|
||||
return $this->cakeError('missingLayout', array(
|
||||
array(
|
||||
'layout' => $this->layout,
|
||||
'file' => $layout_fn,
|
||||
'base' => $this->base
|
||||
)
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -727,9 +735,13 @@ class View extends Object
|
|||
}
|
||||
else
|
||||
{
|
||||
return $this->cakeError('missingHelperFile',
|
||||
array(array('helper' => $helper,
|
||||
'file' => Inflector::underscore($helper).'.php')));
|
||||
return $this->cakeError('missingHelperFile', array(
|
||||
array(
|
||||
'helper' => $helper,
|
||||
'file' => Inflector::underscore($helper).'.php',
|
||||
'base' => $this->base
|
||||
)
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -761,9 +773,13 @@ class View extends Object
|
|||
}
|
||||
else
|
||||
{
|
||||
return $this->cakeError('missingHelperClass',
|
||||
array(array('helper' => $helper,
|
||||
'file' => Inflector::underscore($helper).'.php')));
|
||||
return $this->cakeError('missingHelperClass', array(
|
||||
array(
|
||||
'helper' => $helper,
|
||||
'file' => Inflector::underscore($helper).'.php',
|
||||
'base' => $this->base
|
||||
)
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -786,10 +802,14 @@ class View extends Object
|
|||
}
|
||||
else
|
||||
{
|
||||
return $this->cakeError('missingView',
|
||||
array(array('className' => $this->controller->name,
|
||||
'action' => $action,
|
||||
'file' => $viewFileName)));
|
||||
return $this->cakeError('missingView', array(
|
||||
array(
|
||||
'className' => $this->controller->name,
|
||||
'action' => $action,
|
||||
'file' => $viewFileName,
|
||||
'base' => $this->base
|
||||
)
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,2 +0,0 @@
|
|||
#!/bin/bash
|
||||
php -q $0.php $@
|
|
@ -1 +0,0 @@
|
|||
@php -q scripts\bake.php %1 %2 %3 %4 %5 %6 %7 %8 %9
|
Loading…
Reference in a new issue