public function nextObject() { //error_log("get next object..."); if (!isset($this->iterator)) { if (isset($this->managed_objects)) { $this->array_iterator_location = 0; $this->managed_object; } else { if (!$this->loaded && $this->canUseMemcache() && EAMemCache::isAvailable()) { $primary_key = $this->get_primary_key(); $sql = $this->select_for_memcache(); if (isset($primary_key) && isset($sql)) { if ($results = $this->db()->query($sql)) { $this->iterator_type = "memcache"; $this->iterator = $results; } } } } if (!isset($this->iterator)) { $sql = $this->select(); // error_log($sql); if (isset($sql)) { if ($result = $this->db()->query($sql)) { $this->iterator_type = "normal"; $this->iterator = $result; } } } //error_log("type: {$this->iterator_type}"); } if (is_array($this->iterator)) { if (!isset($this->iterator[$this->array_iterator_location])) { return $this->iterator[$this->array_iterator_location]; } } else { $obj = $this->iterator->fetch_object(); if (isset($obj)) { if ($this->iterator_type == "memcache") { $primary_key = $this->get_primary_key(); if (isset($primary_key)) { //error_log("create with primary value {$obj->$primary_key}"); return $this->create_managed_object_with_primary_value($obj->{$primary_key}); } } else { //error_log("create managed object..."); return $this->create_managed_object($obj); } } } }
private function error_recently_sent() { Loader::load('utility', "memcache/MemCache"); if (!EAMemCache::isAvailable()) { //error_log("memcache not available for ErrorHandler. no email alert sent"); return true; } $result = EAMemCache::get($this->getMemCacheKey(), time()); if (isset($result) && $result > strtotime("-10 minutes")) { //error_log("error has been emailed in the last X minutes. do not sent email alert. $memCacheKey - $result"); return true; } //error_log("update/set current error. $memCacheKey - $result"); EAMemCache::set($this->getMemCacheKey(), time()); return false; }
private final function loadFromPrimaryKeys($random = null) { $primary_key = $this->get_primary_key(); if (isset($primary_key)) { $primary_keys = $this->getPrimaryKeys(); $managed_objects = array(); foreach ((array) $primary_keys as $key) { //error_log("create with key: $key"); $object = $this->create_managed_object_with_primary_value($key); if ($this->managedObjectAllowsMemcache()) { $managed_objects[$object->getMemcacheKey()] = $object; } else { $managed_objects[] = $object; } } if ($this->managedObjectAllowsMemcache() && count($managed_objects)) { //error_log(print_r($memcache_keys,true)); $memcache_data = EAMemCache::get(array_keys($managed_objects)); //error_log(print_r(array_keys($memcache_data),true)); //error_log("managed object keys: " . print_r(array_keys($managed_objects),true)); foreach ($managed_objects as $key => $managed_object) { if (isset($memcache_data[$key]) && is_object($memcache_data[$key])) { // error_log("load from sql result..."); $managed_object->load_from_sql_result($memcache_data[$key]); } //else // error_log("$key not found"); } } $this->managed_objects = array_values($managed_objects); } //else //error_log("primary key is not defined!"); }