Not all instances of this has been fixed, but at least the ones
in the base class of Memcached_DataObject.
Avatar fix (in classes/Profile.php) requires a pkeyGet function
in the Avatar class (or as in this tree, the parent class of
Managed_DataObject)
*/
static function getClassKV($cls, $k, $v=null)
{
*/
static function getClassKV($cls, $k, $v=null)
{
+ if (!is_a($cls, __CLASS__, true)) {
+ throw new Exception('Trying to fetch ' . __CLASS__ . ' into a non-related class');
+ }
if (is_null($v)) {
$v = $k;
$keys = self::pkeyCols($cls);
if (is_null($v)) {
$v = $k;
$keys = self::pkeyCols($cls);
- $i = Memcached_DataObject::getcached($cls, $k, $v);
+ $i = self::getcached($cls, $k, $v);
if ($i === false) { // false == cache miss
if ($i === false) { // false == cache miss
- $i = DB_DataObject::factory($cls);
- if (empty($i)) {
- $i = false;
- return $i;
- }
$result = $i->get($k, $v);
if ($result) {
// Hit!
$result = $i->get($k, $v);
if ($result) {
// Hit!
*/
static function pivotGet($cls, $keyCol, $keyVals, $otherCols = array())
{
*/
static function pivotGet($cls, $keyCol, $keyVals, $otherCols = array())
{
+ if (!is_a($cls, __CLASS__, true)) {
+ throw new Exception('Trying to fetch ' . __CLASS__ . ' into a non-related class');
+ }
if (is_array($keyCol)) {
foreach ($keyVals as $keyVal) {
$result[implode(',', $keyVal)] = null;
if (is_array($keyCol)) {
foreach ($keyVals as $keyVal) {
$result[implode(',', $keyVal)] = null;
}
if (count($toFetch) > 0) {
}
if (count($toFetch) > 0) {
- $i = DB_DataObject::factory($cls);
- if (empty($i)) {
- // TRANS: Exception thrown when a program code class (%s) cannot be instantiated.
- throw new Exception(sprintf(_('Cannot instantiate class %s.'),$cls));
- }
foreach ($otherCols as $otherKeyCol => $otherKeyVal) {
$i->$otherKeyCol = $otherKeyVal;
}
foreach ($otherCols as $otherKeyCol => $otherKeyVal) {
$i->$otherKeyCol = $otherKeyVal;
}
static function pkeyCols($cls)
{
static function pkeyCols($cls)
{
- $i = DB_DataObject::factory($cls);
- if (empty($i)) {
- // TRANS: Exception thrown when a program code class (%s) cannot be instantiated.
- throw new Exception(sprintf(_('Cannot instantiate class %s.'),$cls));
+ if (!is_a($cls, __CLASS__, true)) {
+ throw new Exception('Trying to fetch ' . __CLASS__ . ' into a non-related class');
$types = $i->keyTypes();
ksort($types);
$types = $i->keyTypes();
ksort($types);
static function listGetClass($cls, $keyCol, $keyVals)
{
static function listGetClass($cls, $keyCol, $keyVals)
{
+ if (!is_a($cls, __CLASS__, true)) {
+ throw new Exception('Trying to fetch ' . __CLASS__ . ' into a non-related class');
+ }
$pkeyMap = array_fill_keys($keyVals, array());
$result = array_fill_keys($keyVals, array());
$pkeyMap = array_fill_keys($keyVals, array());
$result = array_fill_keys($keyVals, array());
}
if (count($toFetch) > 0) {
}
if (count($toFetch) > 0) {
- $i = DB_DataObject::factory($cls);
- if (empty($i)) {
- // TRANS: Exception thrown when a program code class (%s) cannot be instantiated.
- throw new Exception(sprintf(_('Cannot instantiate class %s.'),$cls));
- }
$i->whereAddIn($keyCol, $toFetch, $i->columnType($keyCol));
if ($i->find()) {
sprintf(__CLASS__ . "() got {$i->N} results for class $cls key $keyCol");
$i->whereAddIn($keyCol, $toFetch, $i->columnType($keyCol));
if ($i->find()) {
sprintf(__CLASS__ . "() got {$i->N} results for class $cls key $keyCol");
*/
static function pkeyGetClass($cls, $kv)
{
*/
static function pkeyGetClass($cls, $kv)
{
+ if (!is_a($cls, __CLASS__, true)) {
+ throw new Exception('Trying to fetch ' . __CLASS__ . ' into a non-related class');
+ }
$i = Memcached_DataObject::multicache($cls, $kv);
if ($i !== false) { // false == cache miss
return $i;
} else {
$i = Memcached_DataObject::multicache($cls, $kv);
if ($i !== false) { // false == cache miss
return $i;
} else {
- $i = DB_DataObject::factory($cls);
- if (empty($i) || PEAR::isError($i)) {
- return false;
- }
foreach ($kv as $k => $v) {
if (is_null($v)) {
// XXX: possible SQL injection...? Don't
foreach ($kv as $k => $v) {
if (is_null($v)) {
// XXX: possible SQL injection...? Don't
function getOriginalAvatar()
{
function getOriginalAvatar()
{
- $avatar = DB_DataObject::factory('avatar');
- $avatar->profile_id = $this->id;
- $avatar->original = true;
- if ($avatar->find(true)) {
+ $pkey = array('profile_id' => $this->id,
+ 'original' => true);
+ $avatar = Avatar::pkeyGet($pkey);
+ if (!empty($avatar)) {
return $avatar;
} else {
return null;
return $avatar;
} else {
return null;