Skip to content

Commit

Permalink
Merge pull request #421 from koenpunt/remove-test-db
Browse files Browse the repository at this point in the history
Remove test db
  • Loading branch information
jpfuentes2 committed Jul 16, 2014
2 parents e3f2655 + c7461ce commit dc28449
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Expand Up @@ -2,7 +2,7 @@
.buildpath
.settings
*.log
test/*.db
*.db
*.swp
vendor/*
composer.lock
6 changes: 4 additions & 2 deletions lib/Cache.php
Expand Up @@ -69,7 +69,8 @@ public static function flush()
*/
public static function get($key, $closure, $expire=null)
{
if(is_null($expire)){
if (is_null($expire))
{
$expire = static::$options['expire'];
}

Expand All @@ -89,7 +90,8 @@ public static function set($key, $var, $expire=null)
if (!static::$adapter)
return;

if(is_null($expire)){
if (is_null($expire))
{
$expire = static::$options['expire'];
}

Expand Down
14 changes: 7 additions & 7 deletions lib/Model.php
Expand Up @@ -879,7 +879,7 @@ private function update($validate=true)
static::table()->update($dirty,$pk);
$this->invoke_callback('after_update',false);
$this->update_cache();
}
}

return true;
}
Expand All @@ -894,7 +894,7 @@ protected function update_cache()

protected function cache_key()
{
$table = static::Table();
$table = static::table();
return $table->cache_key_for_model($this->values_for_pk());
}

Expand Down Expand Up @@ -1589,8 +1589,8 @@ public static function find(/* $type, $options */)
// fall thru

case 'first':
$options['limit'] = 1;
$options['offset'] = 0;
$options['limit'] = 1;
$options['offset'] = 0;
break;
}

Expand Down Expand Up @@ -1624,11 +1624,11 @@ protected static function get_models_from_cache(array $pks)

foreach($pks as $pk)
{
$options =array('conditions'=> static::pk_conditions($pk));
$options =array('conditions' => static::pk_conditions($pk));
$models[] = Cache::get($table->cache_key_for_model($pk), function() use ($table, $options)
{
$res = $table->find($options);
return $res?$res[0]:null;
return $res ? $res[0] : null;
}, $table->cache_model_expire);
}
return array_filter($models);
Expand All @@ -1649,7 +1649,7 @@ public static function find_by_pk($values, $options)

if($table->cache_individual_model)
{
$pks=is_array($values)?$values:array($values);
$pks = is_array($values) ? $values : array($values);
$list = static::get_models_from_cache($pks);
}
else
Expand Down
19 changes: 9 additions & 10 deletions lib/Table.php
Expand Up @@ -119,7 +119,6 @@ public function create_joins($joins)
if (!is_array($joins))
return $joins;

$self = $this->table;
$ret = $space = '';

$existing_tables = array();
Expand Down Expand Up @@ -222,11 +221,11 @@ public function find($options)

public function cache_key_for_model($pk)
{
if(!is_array($pk))
if (is_array($pk))
{
$pk = array($pk);
$pk = implode('-', $pk);
}
return $this->class->name."-".implode("-",$pk);
return $this->class->name . '-' . $pk;
}

public function find_by_sql($sql, $values=null, $readonly=false, $includes=null)
Expand All @@ -242,12 +241,12 @@ public function find_by_sql($sql, $values=null, $readonly=false, $includes=null)
{
$cb = function() use ($row, $self)
{
return new $self->class->name($row,false,true,false);
return new $self->class->name($row, false, true, false);
};
if($this->cache_individual_model)
if ($this->cache_individual_model)
{
$key = $this->cache_key_for_model(array_intersect_key($row, array_flip($this->pk)));
$model = Cache::get($key, $cb, $this->cache_model_expire );
$model = Cache::get($key, $cb, $this->cache_model_expire);
}
else
{
Expand Down Expand Up @@ -400,7 +399,7 @@ private function get_meta_data()

$table_name = $this->get_fully_qualified_table_name($quote_name);
$conn = $this->conn;
$this->columns = Cache::get("get_meta_data-$table_name", function() use ($conn, $table_name) { return $conn->columns($table_name); }, Cache::$options['expire']);
$this->columns = Cache::get("get_meta_data-$table_name", function() use ($conn, $table_name) { return $conn->columns($table_name); });
}

/**
Expand Down Expand Up @@ -474,7 +473,7 @@ private function set_table_name()
$this->table = $parts[count($parts)-1];
}

if(($db = $this->class->getStaticPropertyValue('db',null)) || ($db = $this->class->getStaticPropertyValue('db_name',null)))
if (($db = $this->class->getStaticPropertyValue('db',null)) || ($db = $this->class->getStaticPropertyValue('db_name',null)))
$this->db_name = $db;
}

Expand All @@ -485,7 +484,7 @@ private function set_cache()

$model_class_name = $this->class->name;
$this->cache_individual_model = $model_class_name::$cache;
if(property_exists($model_class_name, 'cache_expire') && isset($model_class_name::$cache_expire))
if (property_exists($model_class_name, 'cache_expire') && isset($model_class_name::$cache_expire))
{
$this->cache_model_expire = $model_class_name::$cache_expire;
}
Expand Down
Binary file removed test.db
Binary file not shown.

0 comments on commit dc28449

Please sign in to comment.