Skip to content

Commit

Permalink
Fix: use call_user_func with object instead of class when method is n…
Browse files Browse the repository at this point in the history
…ot static.

git-svn-id: http://voip.null.ro/svn/ansql/trunk@124 dbfed7de-b0aa-0410-b6a1-c7e608b77fc9
  • Loading branch information
monica committed Nov 26, 2014
1 parent 6d902e6 commit 897abb5
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions framework.php
Original file line number Diff line number Diff line change
Expand Up @@ -565,10 +565,11 @@ public static function createTable($table,$vars)
$query.= " WITH OIDS";
elseif ($db_type == "mysql") {
if (substr($table,0,6)!="_temp_")
$class = get_class(Model::getObject($table));
$obj = Model::getObject($table);
else
$class = get_class(TemporaryModel::getObject(substr($table,6)));
$engine = call_user_func(array($class,"getDbEngine"));
$obj = TemporaryModel::getObject(substr($table,6));
$engine = call_user_func(array($obj,"getDbEngine"));

if ($engine)
$query.= "ENGINE $engine";
}
Expand Down Expand Up @@ -2387,11 +2388,13 @@ static function init()
if (get_parent_class($class) == "Model" || get_parent_class(get_parent_class($class)) == "Model")
{
$vars = null;
$vars = @call_user_func(array($class,"variables"));
if (!method_exists($class,"variables"))
continue;
$vars = call_user_func(array($class,"variables"));
if (!$vars)
continue;

$identifier = @call_user_func(array($class,"getDbIdentifier"));
//$identifier = @call_user_func(array($class,"getDbIdentifier"));
// if object doesn't have identifier and current identier if different than the default => skip
// if object has identifier but current identier is not in the object identifiers => skip

Expand Down Expand Up @@ -2483,7 +2486,9 @@ static function updateAll()

foreach (self::$_models as $class => $vars)
{
$identifier = @call_user_func(array($class,"getDbIdentifier"));
$object = new $class;

$identifier = call_user_func(array($object,"getDbIdentifier"));
// if object doesn't have identifier and current identier if different than the default => skip
// if object has identifier but current identier is not in the object identifiers => skip
// even if classes are loaded, they won't be updated
Expand All @@ -2492,8 +2497,6 @@ static function updateAll()
if ( (!in_array($db_identifier, $identifier) && count($identifier)) || ($default_identifier!=$db_identifier && !count($identifier)) )
continue;

$object = new $class;

$table = $object->getTableName();
if (!Database::updateTable($table,$vars))
{
Expand All @@ -2506,7 +2509,7 @@ static function updateAll()

if (!method_exists($object,"index"))
continue;
if ($index = call_user_func(array($class,"index")))
if ($index = call_user_func(array($object,"index")))
Database::createIndex($table,$index);
}

Expand All @@ -2517,10 +2520,12 @@ static function updateAll()

if(self::$_modified)
foreach(self::$_models as $class => $vars) {
$identifier = @call_user_func(array($class,"getDbIdentifier"));
$object = new $class;

$identifier = (method_exists($object,"getDbIdentifier")) ? call_user_func(array($object,"getDbIdentifier")) : null;

if ( (!in_array($db_identifier, $identifier) && count($identifier)) || ($default_identifier!=$db_identifier && !count($identifier)))
continue;
$object = new $class;
if(method_exists($object, "defaultObject"))
$res = call_user_func(array($object,"defaultObject"));
}
Expand Down

0 comments on commit 897abb5

Please sign in to comment.