/** * Get provider by name * * @param string $name * @return ModelContentProvider|null */ public static function get($name) { $item = Memcache::getInstance()->put('cdn_' . $name, 60 * 60 * 24, function () use($name) { return ModelContentProvider::fetchOne('SELECT * FROM {table} WHERE `name` = %s', $name); }); return $item->hasRow() ? $item : null; }
public function __construct($sourceId) { parent::__construct(); $source = Source::getById($sourceId); if ($source->hasRow()) { // Delete thumbnails $thumbnails = ModelThumbnail::getBySourceId($source->id); if ($thumbnails->hasRows()) { foreach ($thumbnails->getRows() as $thumbnail) { $thumbnail->delete(); } } Memcache::getInstance()->clear('source_' . $source->subdomain); /*$cache = new Cache(getenv('CLOUDFLARE_API_EMAIL'), getenv('CLOUDFLARE_API_KEY')); $cache->purge_files(getenv('CLOUDFLARE_ZONE_ID'), array( 'files' => sprintf('http://%s/*', $source->subdomain) ));*/ $this->setMessage('The cache has been purged', 'success'); redirect(url('controlpanel.source')); } }
public function handle(Request $request) { $domain = env('DEBUG', false) ? 'dscuz' : str_ireplace('.' . Registry::getInstance()->get('host'), '', $request->getHost()); $request->source = Memcache::getInstance()->put('source_' . $domain, 60 * 60, function () use($domain) { return Source::getBySubdomain($domain); }); $this->setParameters($request); if (!$request->source->hasRow()) { throw new \ErrorException('Invalid source.'); } if ($request->source->getOrganisation() !== null && $request->source->getOrganisation()->disabled) { throw new OrganisationDisabledException('Source has been disabled'); } if ($request->source->require_ssl && !$request->getIsSecure()) { redirect('https://' . $request->getHost() . $request->getUri(), 101); } // Check for valid api-token if posting if ($request->getMethod() !== 'get') { $token = request()->getHeader('X-Auth-Token'); if ($token === null || $token !== $request->source->getOrganisation()->api_token) { throw new \InvalidArgumentException('Invalid X-Auth-Token.'); } } }
protected function edit($updateDns) { try { $this->source->update(); Memcache::getInstance()->clear('source_' . $this->subdomain); // Update update DNS if neccesary if ($updateDns && !env('DEBUG', false)) { $cloudflareIdentifiers = $this->updateDns($this->source->getCloudflareIdentifiers(), $this->input('subdomain')); if (count($cloudflareIdentifiers) === 0) { $this->setError('Failed to create subdomain - please contact support'); } else { $this->source->setCloudflareIdentifiers($cloudflareIdentifiers); $this->source->update(); } } if (!$this->hasErrors()) { $this->setMessage('Source has been updated - please wait up to 30 minutes for the cache to get synchronized.', 'success'); } } catch (SourceException $e) { $this->setError($e->getMessage()); response()->refresh(); } redirect(url('controlpanel.source')); }