/** * [[@doctodo method_description:test]]. * * @param [[@doctodo param_type:email]] $email [[@doctodo param_description:email]] * @param boolean $hash_email [[@doctodo param_description:hash_email]] [optional] * * @return [[@doctodo return_type:test]] [[@doctodo return_description:test]] */ public function test($email, $hash_email = true) { $original = $this->getDefaultImage(); $this->setDefaultImage(404); $url = htmlspecialchars_decode($this->get($email, $hash_email)); $this->setDefaultImage($original); $cacheKey = ['testGravatar', $url]; $cache = Cacher::get($cacheKey); if ($cache) { return $cache; } $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_HEADER, false); curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 5); $data = curl_exec($curl); $httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE); curl_close($curl); if (!$data || $httpCode !== 200) { $result = false; } else { $result = true; } Cacher::set($cacheKey, $result, 3600); return $result; }
private function checkFailTaken($id, $headId) { $key = __CLASS__ . __FUNCTION__ . $id; $checkResult = Cacher::get($key); if (!empty($checkResult) && $checkResult !== $headId) { return true; } Cacher::set($key, $headId, 60 * 10); return false; }
/** * Get stats. * * @param [[@doctodo param_type:parentObject]] $parentObject [[@doctodo param_description:parentObject]] * @param array $options [[@doctodo param_description:options]] [optional] * * @return [[@doctodo return_type:getStats]] [[@doctodo return_description:getStats]] */ public function getStats($parentObject, $options = []) { $cacheKey = [__CLASS__ . '.' . __FUNCTION__, 'parentObject' => $parentObject->primaryKey, 'options' => $options, 'context' => ['user']]; $stats = Cacher::get($cacheKey); if (!$stats) { $cacheDependency = $this->getCachingDependency($parentObject); $stats = []; $stats['total'] = $this->getTotalHours($parentObject, $options); if ($parentObject->modelAlias !== ':Individual\\ObjectIndividual') { $stats['top_contributors'] = $this->getTopContributors($parentObject, $options); } else { $stats['top_contributions'] = $this->getTopContributions($parentObject, $options); } $stats['month_summary'] = $this->getMonthSummary($parentObject, $options); Cacher::set($cacheKey, $stats, 0, $cacheDependency); } return $stats; }
/** * Get status log. * * @param boolean $checkRecent [[@doctodo param_description:checkRecent]] [optional] * * @return [[@doctodo return_type:getStatusLog]] [[@doctodo return_description:getStatusLog]] */ public function getStatusLog($checkRecent = false) { if (!isset($this->_statusLog)) { $this->_statusLog = Cacher::get([get_called_class(), $this->primaryKey, $this->created]); if (empty($this->_statusLog)) { if (is_null($this->message)) { $this->_statusLog = $this->_startStatus(); } else { $this->_statusLog = unserialize($this->message); } } elseif ($checkRecent) { $testStatusLog = unserialize($this->message); if ($testStatusLog && $testStatusLog->lastUpdate > $this->_statusLog->lastUpdate) { $this->_statusLog = $testStatusLog; } } if (empty($this->_statusLog)) { $this->_statusLog = new Status(); } } $this->_statusLog->log = $this; return $this->_statusLog; }
public function getStatusLog() { if (!isset($this->_statusLog)) { $this->_statusLog = new Status(); $this->_statusLog->saveDatabaseOnMessage = true; $this->_statusLog->lastUpdate = microtime(true); $this->saveCache()->save(); } else { $checkLog = Cacher::get(['Instance__StatusLog', $this->model->primaryKey, $this->model->created]); if (!$checkLog && !isset($this->_statusLog)) { $checkLog = $this->_statusLog = new Status(); $this->_statusLog->saveDatabaseOnMessage = true; $checkLog->lastUpdate = microtime(true); $this->saveCache()->save(); } if ($checkLog && $checkLog->lastUpdate && $this->_statusLog->lastUpdate && $checkLog->lastUpdate > $this->_statusLog->lastUpdate) { $this->_statusLog = $checkLog; } } $this->_statusLog->persistentLog = true; $this->_statusLog->log = $this; return $this->_statusLog; }