/** * Returns information about file in this repository by reference * {@link repository::get_file_reference()} * {@link repository::get_file()} * * Returns null if file not found or can not be accessed * * @param stdClass $reference file reference db record * @return null|stdClass containing attribute 'filepath' */ public function get_file_by_reference($reference) { $ref = unserialize(base64_decode($reference->reference)); $url = $this->appendtoken($ref->url); if (!$url) { // Occurs when the user isn't known.. return null; } // We use this cache to get the correct file size. $cachedfilepath = cache_file::get($url, array('ttl' => 0)); if ($cachedfilepath === false) { // Cache the file. $path = $this->get_file($url); $cachedfilepath = cache_file::create_from_file($url, $path['path']); } if ($cachedfilepath && is_readable($cachedfilepath)) { return (object)array('filepath' => $cachedfilepath); } return null; }
public function cron() { $fs = get_file_storage(); $files = $fs->get_external_files($this->id); foreach ($files as $file) { $reference = unserialize($file->get_reference()); $cachedfile = cache_file::get($reference); if ($cachedfile === false) { // Re-fetch resource. $this->set_access_key($reference->access_key); $this->set_access_secret($reference->access_secret); $path = $this->get_file($reference->path); cache_file::create_from_file($reference, $path['path']); } } }