Joomla! CMS Issue Tracker item #25835, was opened at 2011-05-08 01:52:57
http://joomlacode.org/gf/project/joomla/tracker/?action=TrackerItemEdit&tracker_id=8103&tracker_item_id=25835
Hello,
The description of the function is:
- Static method to get an instance of a JTable class if it can be found in
- the table include paths.
But this is not working currently in case of multiple tables have the same type: example: User (table will have different "prefix" but same "type")
Explanation:
If you have several includepaths, it's possible to have "user.php" in several includepaths not just in one,
but the current code is using JPath::find to return the fullpath to "user.php", but this function stops looking for user.php on the first path with user.php.
So if the user.php that you want to load is not in the first path of includepaths, the getInstance will returns "false".
Examples:
includepaths:
[0] administrator/components/com_mycomponent/tables/
[1] libraries/joomla/database/table/
these two directories contains user.php.
In getInstance fuction :
if ($path = JPath::find(JTable::addIncludePath(), strtolower($type).'.php')) {
This code will only return path :
administrator/components/com_mycomponent/tables/user.php
so the table JTableUser is no more working !!!!
To fix that:
table.php:
if ($paths = JPath::findAll(JTable::addIncludePath(), strtolower($type).'.php')) {
// Import the class files.
foreach($paths as $path) {
require_once $path;
}
//Call findAll instead of find, so all paths that have user.php will be returned
path.php (new function)
public static function findAll($paths, $file)
{
$fullnames = array();
settype($paths, 'array'); //force to array
// start looping through the path set
foreach ($paths as $path) {
// get the path to the file
$fullname = $path.'/'.$file;
// is the path based on a stream?
if (strpos($path, '://') === false) {
// not a stream, so do a realpath() to avoid directory
// traversal attempts on the local file system.
$path = realpath($path); // needed for substr() later
$fullname = realpath($fullname);
}
// the substr() check added to make sure that the realpath()
// results in a directory registered so that
// non-registered directores are not accessible via directory
// traversal attempts.
if (file_exists($fullname) && substr($fullname, 0, strlen($path)) == $path) {
$fullnames[] = $fullname;
}
}
// could not find the file in the set of paths
if (count($fullnames) == 0) {
return false;
} else {
return $fullnames;
}
}