3 * StatusNet - the distributed open-source microblogging tool
4 * Copyright (C) 2008, 2009, StatusNet, Inc.
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Affero General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Affero General Public License for more details.
16 * You should have received a copy of the GNU Affero General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 if (!defined('GNUSOCIAL')) { exit(1); }
23 * Table Definition for file
25 class File extends Managed_DataObject
27 public $__table = 'file'; // table name
28 public $id; // int(4) primary_key not_null
29 public $urlhash; // varchar(64) unique_key
31 public $filehash; // varchar(64) indexed
32 public $mimetype; // varchar(50)
33 public $size; // int(4)
34 public $title; // text()
35 public $date; // int(4)
36 public $protected; // int(4)
37 public $filename; // text()
38 public $width; // int(4)
39 public $height; // int(4)
40 public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP
42 const URLHASH_ALG = 'sha256';
43 const FILEHASH_ALG = 'sha256';
45 public static function schemaDef()
49 'id' => array('type' => 'serial', 'not null' => true),
50 'urlhash' => array('type' => 'varchar', 'length' => 64, 'not null' => true, 'description' => 'sha256 of destination URL (url field)'),
51 'url' => array('type' => 'text', 'description' => 'destination URL after following possible redirections'),
52 'filehash' => array('type' => 'varchar', 'length' => 64, 'not null' => false, 'description' => 'sha256 of the file contents, only for locally stored files of course'),
53 'mimetype' => array('type' => 'varchar', 'length' => 50, 'description' => 'mime type of resource'),
54 'size' => array('type' => 'int', 'description' => 'size of resource when available'),
55 'title' => array('type' => 'text', 'description' => 'title of resource when available'),
56 'date' => array('type' => 'int', 'description' => 'date of resource according to http query'),
57 'protected' => array('type' => 'int', 'description' => 'true when URL is private (needs login)'),
58 'filename' => array('type' => 'text', 'description' => 'if file is stored locally (too) this is the filename'),
59 'width' => array('type' => 'int', 'description' => 'width in pixels, if it can be described as such and data is available'),
60 'height' => array('type' => 'int', 'description' => 'height in pixels, if it can be described as such and data is available'),
62 'modified' => array('type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'),
64 'primary key' => array('id'),
65 'unique keys' => array(
66 'file_urlhash_key' => array('urlhash'),
69 'file_filehash_idx' => array('filehash'),
74 public static function isProtected($url) {
76 $protected_urls_exps = array(
77 'https://www.facebook.com/login.php',
78 common_path('main/login')
81 foreach ($protected_urls_exps as $protected_url_exp) {
82 if (preg_match('!^'.preg_quote($protected_url_exp).'(.*)$!i', $url) === 1) {
91 * Save a new file record.
93 * @param array $redir_data lookup data eg from File_redirection::where()
94 * @param string $given_url
97 public static function saveNew(array $redir_data, $given_url)
101 // I don't know why we have to keep doing this but we run a last check to avoid
103 $file = File::getByUrl($given_url);
105 } catch (NoResultException $e) {
106 // We don't have the file's URL since before, so let's continue.
109 // if the given url is an local attachment url and the id already exists, don't
110 // save a new file record. This should never happen, but let's make it foolproof
111 // FIXME: how about attachments servers?
112 $u = parse_url($given_url);
113 if (isset($u['host']) && $u['host'] === common_config('site', 'server')) {
115 // Skip the / in the beginning or $r->map won't match
117 $args = $r->map(mb_substr($u['path'], 1));
118 if ($args['action'] === 'attachment') {
120 // $args['attachment'] should always be set if action===attachment, given our routing rules
121 $file = File::getByID($args['attachment']);
123 } catch (EmptyPkeyValueException $e) {
124 // ...but $args['attachment'] can also be 0...
125 } catch (NoResultException $e) {
126 // apparently this link goes to us, but is _not_ an existing attachment (File) ID?
129 } catch (Exception $e) {
130 // Some other exception was thrown from $r->map, likely a
131 // ClientException (404) because of some malformed link to
132 // our own instance. It's still a valid URL however, so we
133 // won't abort anything... I noticed this when linking:
134 // https://social.umeahackerspace.se/mmn/foaf' (notice the
135 // apostrophe in the end, making it unrecognizable for our
137 // That specific issue (the apostrophe being part of a link
138 // is something that may or may not have been fixed since,
139 // in lib/util.php in common_replace_urls_callback().
144 $file->url = $given_url;
145 if (!empty($redir_data['protected'])) $file->protected = $redir_data['protected'];
146 if (!empty($redir_data['title'])) $file->title = $redir_data['title'];
147 if (!empty($redir_data['type'])) $file->mimetype = $redir_data['type'];
148 if (!empty($redir_data['size'])) $file->size = intval($redir_data['size']);
149 if (isset($redir_data['time']) && $redir_data['time'] > 0) $file->date = intval($redir_data['time']);
154 public function saveFile() {
155 $this->urlhash = self::hashurl($this->url);
157 if (!Event::handle('StartFileSaveNew', array(&$this))) {
158 throw new ServerException('File not saved due to an aborted StartFileSaveNew event.');
161 $this->id = $this->insert();
163 if ($this->id === false) {
164 throw new ServerException('File/URL metadata could not be saved to the database.');
167 Event::handle('EndFileSaveNew', array($this));
171 * Go look at a URL and possibly save data about it if it's new:
172 * - follow redirect chains and store them in file_redirection
173 * - if a thumbnail is available, save it in file_thumbnail
174 * - save file record with basic info
175 * - optionally save a file_to_post record
176 * - return the File object with the full reference
178 * @param string $given_url the URL we're looking at
179 * @param Notice $notice (optional)
180 * @param bool $followRedirects defaults to true
182 * @return mixed File on success, -1 on some errors
184 * @throws ServerException on failure
186 public static function processNew($given_url, Notice $notice=null, $followRedirects=true) {
187 if (empty($given_url)) {
188 throw new ServerException('No given URL to process');
191 $given_url = File_redirection::_canonUrl($given_url);
192 if (empty($given_url)) {
193 throw new ServerException('No canonical URL from given URL to process');
196 $redir = File_redirection::where($given_url);
198 $file = $redir->getFile();
199 } catch (EmptyPkeyValueException $e) {
200 common_log(LOG_ERR, 'File_redirection::where gave object with empty file_id for given_url '._ve($given_url));
201 throw new ServerException('URL processing failed without new File object');
202 } catch (NoResultException $e) {
203 // This should not happen
204 common_log(LOG_ERR, 'File_redirection after discovery could still not return a File object.');
205 throw new ServerException('URL processing failed without new File object');
208 if ($notice instanceof Notice) {
209 File_to_post::processNew($file, $notice);
215 public static function respectsQuota(Profile $scoped, $fileSize) {
216 if ($fileSize > common_config('attachments', 'file_quota')) {
217 // TRANS: Message used to be inserted as %2$s in the text "No file may
218 // TRANS: be larger than %1$d byte and the file you sent was %2$s.".
219 // TRANS: %1$d is the number of bytes of an uploaded file.
220 $fileSizeText = sprintf(_m('%1$d byte','%1$d bytes',$fileSize),$fileSize);
222 $fileQuota = common_config('attachments', 'file_quota');
223 // TRANS: Message given if an upload is larger than the configured maximum.
224 // TRANS: %1$d (used for plural) is the byte limit for uploads,
225 // TRANS: %2$s is the proper form of "n bytes". This is the only ways to have
226 // TRANS: gettext support multiple plurals in the same message, unfortunately...
227 throw new ClientException(
228 sprintf(_m('No file may be larger than %1$d byte and the file you sent was %2$s. Try to upload a smaller version.',
229 'No file may be larger than %1$d bytes and the file you sent was %2$s. Try to upload a smaller version.',
231 $fileQuota, $fileSizeText));
236 $query = "select sum(size) as total from file join file_to_post on file_to_post.file_id = file.id join notice on file_to_post.post_id = notice.id where profile_id = {$scoped->id} and file.url like '%/notice/%/file'";
237 $file->query($query);
239 $total = $file->total + $fileSize;
240 if ($total > common_config('attachments', 'user_quota')) {
241 // TRANS: Message given if an upload would exceed user quota.
242 // TRANS: %d (number) is the user quota in bytes and is used for plural.
243 throw new ClientException(
244 sprintf(_m('A file this large would exceed your user quota of %d byte.',
245 'A file this large would exceed your user quota of %d bytes.',
246 common_config('attachments', 'user_quota')),
247 common_config('attachments', 'user_quota')));
249 $query .= ' AND EXTRACT(month FROM file.modified) = EXTRACT(month FROM now()) and EXTRACT(year FROM file.modified) = EXTRACT(year FROM now())';
250 $file->query($query);
252 $total = $file->total + $fileSize;
253 if ($total > common_config('attachments', 'monthly_quota')) {
254 // TRANS: Message given id an upload would exceed a user's monthly quota.
255 // TRANS: $d (number) is the monthly user quota in bytes and is used for plural.
256 throw new ClientException(
257 sprintf(_m('A file this large would exceed your monthly quota of %d byte.',
258 'A file this large would exceed your monthly quota of %d bytes.',
259 common_config('attachments', 'monthly_quota')),
260 common_config('attachments', 'monthly_quota')));
265 public function getFilename()
267 return self::tryFilename($this->filename);
270 public function getSize()
272 return intval($this->size);
275 // where should the file go?
277 static function filename(Profile $profile, $origname, $mimetype)
279 $ext = self::guessMimeExtension($mimetype, $origname);
281 // Normalize and make the original filename more URL friendly.
282 $origname = basename($origname, ".$ext");
283 if (class_exists('Normalizer')) {
284 // http://php.net/manual/en/class.normalizer.php
285 // http://www.unicode.org/reports/tr15/
286 $origname = Normalizer::normalize($origname, Normalizer::FORM_KC);
288 $origname = preg_replace('/[^A-Za-z0-9\.\_]/', '_', $origname);
290 $nickname = $profile->getNickname();
291 $datestamp = strftime('%Y%m%d', time());
293 // generate new random strings until we don't run into a filename collision.
294 $random = strtolower(common_confirmation_code(16));
295 $filename = "$nickname-$datestamp-$origname-$random.$ext";
296 } while (file_exists(self::path($filename)));
301 * @param $mimetype The mimetype we've discovered for this file.
302 * @param $filename An optional filename which we can use on failure.
304 static function guessMimeExtension($mimetype, $filename=null)
307 // first see if we know the extension for our mimetype
308 $ext = common_supported_mime_to_ext($mimetype);
311 } catch (UnknownMimeExtensionException $e) {
312 // We don't know the extension for this mimetype, but let's guess.
314 // If we can't recognize the extension from the MIME, we try
315 // to guess based on filename, if one was supplied.
316 if (!is_null($filename) && preg_match('/^.+\.([A-Za-z0-9]+)$/', $filename, $matches)) {
317 // we matched on a file extension, so let's see if it means something.
318 $ext = mb_strtolower($matches[1]);
320 $blacklist = common_config('attachments', 'extblacklist');
321 // If we got an extension from $filename we want to check if it's in a blacklist
322 // so we avoid people uploading .php files etc.
323 if (array_key_exists($ext, $blacklist)) {
324 if (!is_string($blacklist[$ext])) {
325 // we don't have a safe replacement extension
326 throw new ClientException(_('Blacklisted file extension.'));
328 common_debug('Found replaced extension for filename '._ve($filename).': '._ve($ext));
330 // return a safe replacement extension ('php' => 'phps' for example)
331 return $blacklist[$ext];
333 // the attachment extension based on its filename was not blacklisted so it's ok to use it
336 } catch (Exception $e) {
337 common_log(LOG_INFO, 'Problem when figuring out extension for mimetype: '._ve($e));
340 // If nothing else has given us a result, try to extract it from
341 // the mimetype value (this turns .jpg to .jpeg for example...)
343 // FIXME: try to build a regexp that will get jpeg from image/jpeg as well as json from application/jrd+json
344 if (!preg_match('/\/([a-z0-9]+)/', mb_strtolower($mimetype), $matches)) {
345 throw new Exception('Malformed mimetype: '.$mimetype);
347 return mb_strtolower($matches[1]);
351 * Validation for as-saved base filenames
353 static function validFilename($filename)
355 return preg_match('/^[A-Za-z0-9._-]+$/', $filename);
358 static function tryFilename($filename)
360 if (!self::validFilename($filename))
362 throw new InvalidFilenameException($filename);
364 // if successful, return the filename for easy if-statementing
369 * @throws ClientException on invalid filename
371 static function path($filename)
373 self::tryFilename($filename);
375 $dir = common_config('attachments', 'dir');
377 if (!in_array($dir[mb_strlen($dir)-1], ['/', '\\'])) {
378 $dir .= DIRECTORY_SEPARATOR;
381 return $dir . $filename;
384 static function url($filename)
386 self::tryFilename($filename);
388 if (common_config('site','private')) {
390 return common_local_url('getfile',
391 array('filename' => $filename));
395 if (GNUsocial::useHTTPS()) {
397 $sslserver = common_config('attachments', 'sslserver');
399 if (empty($sslserver)) {
400 // XXX: this assumes that background dir == site dir + /file/
401 // not true if there's another server
402 if (is_string(common_config('site', 'sslserver')) &&
403 mb_strlen(common_config('site', 'sslserver')) > 0) {
404 $server = common_config('site', 'sslserver');
405 } else if (common_config('site', 'server')) {
406 $server = common_config('site', 'server');
408 $path = common_config('site', 'path') . '/file/';
410 $server = $sslserver;
411 $path = common_config('attachments', 'sslpath');
413 $path = common_config('attachments', 'path');
419 $path = common_config('attachments', 'path');
420 $server = common_config('attachments', 'server');
422 if (empty($server)) {
423 $server = common_config('site', 'server');
426 $ssl = common_config('attachments', 'ssl');
428 $protocol = ($ssl) ? 'https' : 'http';
431 if ($path[strlen($path)-1] != '/') {
435 if ($path[0] != '/') {
439 return $protocol.'://'.$server.$path.$filename;
442 static $_enclosures = array();
444 function getEnclosure(){
445 if (isset(self::$_enclosures[$this->getID()])) {
446 return self::$_enclosures[$this->getID()];
449 $enclosure = (object) array();
450 foreach (array('title', 'url', 'date', 'modified', 'size', 'mimetype', 'width', 'height') as $key) {
451 if ($this->$key !== '') {
452 $enclosure->$key = $this->$key;
456 $needMoreMetadataMimetypes = array(null, 'application/xhtml+xml', 'text/html');
458 if (!isset($this->filename) && in_array(common_bare_mime($enclosure->mimetype), $needMoreMetadataMimetypes)) {
459 // This fetches enclosure metadata for non-local links with unset/HTML mimetypes,
460 // which may be enriched through oEmbed or similar (implemented as plugins)
461 Event::handle('FileEnclosureMetadata', array($this, &$enclosure));
463 if (empty($enclosure->mimetype)) {
464 // This means we either don't know what it is, so it can't
465 // be shown as an enclosure, or it is an HTML link which
466 // does not link to a resource with further metadata.
467 throw new ServerException('Unknown enclosure mimetype, not enough metadata');
470 self::$_enclosures[$this->getID()] = $enclosure;
474 public function hasThumbnail()
477 $this->getThumbnail();
478 } catch (Exception $e) {
485 * Get the attachment's thumbnail record, if any.
486 * Make sure you supply proper 'int' typed variables (or null).
488 * @param $width int Max width of thumbnail in pixels. (if null, use common_config values)
489 * @param $height int Max height of thumbnail in pixels. (if null, square-crop to $width)
490 * @param $crop bool Crop to the max-values' aspect ratio
491 * @param $force_still bool Don't allow fallback to showing original (such as animated GIF)
492 * @param $upscale mixed Whether or not to scale smaller images up to larger thumbnail sizes. (null = site default)
494 * @return File_thumbnail
496 * @throws UseFileAsThumbnailException if the file is considered an image itself and should be itself as thumbnail
497 * @throws UnsupportedMediaException if, despite trying, we can't understand how to make a thumbnail for this format
498 * @throws ServerException on various other errors
500 public function getThumbnail($width=null, $height=null, $crop=false, $force_still=true, $upscale=null)
502 // Get some more information about this file through our ImageFile class
503 $image = ImageFile::fromFileObject($this);
504 if ($image->animated && !common_config('thumbnail', 'animated')) {
505 // null means "always use file as thumbnail"
506 // false means you get choice between frozen frame or original when calling getThumbnail
507 if (is_null(common_config('thumbnail', 'animated')) || !$force_still) {
509 // remote files with animated GIFs as thumbnails will match this
510 return File_thumbnail::byFile($this);
511 } catch (NoResultException $e) {
512 // and if it's not a remote file, it'll be safe to use the locally stored File
513 throw new UseFileAsThumbnailException($this);
518 return $image->getFileThumbnail($width, $height, $crop,
519 !is_null($upscale) ? $upscale : common_config('thumbnail', 'upscale'));
522 public function getPath()
524 $filepath = self::path($this->filename);
525 if (!file_exists($filepath)) {
526 throw new FileNotFoundException($filepath);
531 public function getAttachmentUrl()
533 return common_local_url('attachment', array('attachment'=>$this->getID()));
537 * @param mixed $use_local true means require local, null means prefer local, false means use whatever is stored
539 public function getUrl($use_local=null)
541 if ($use_local !== false) {
542 if (is_string($this->filename) || !empty($this->filename)) {
543 // A locally stored file, so let's generate a URL for our instance.
544 return self::url($this->getFilename());
547 // if the file wasn't stored locally (has filename) and we require a local URL
548 throw new FileNotStoredLocallyException($this);
553 // No local filename available, return the URL we have stored
557 static public function getByUrl($url)
560 $file->urlhash = self::hashurl($url);
561 if (!$file->find(true)) {
562 throw new NoResultException($file);
568 * @param string $hashstr String of (preferrably lower case) hexadecimal characters, same as result of 'hash_file(...)'
570 static public function getByHash($hashstr)
573 $file->filehash = strtolower($hashstr);
574 if (!$file->find(true)) {
575 throw new NoResultException($file);
580 public function updateUrl($url)
582 $file = File::getKV('urlhash', self::hashurl($url));
583 if ($file instanceof File) {
584 throw new ServerException('URL already exists in DB');
586 $sql = 'UPDATE %1$s SET urlhash=%2$s, url=%3$s WHERE urlhash=%4$s;';
587 $result = $this->query(sprintf($sql, $this->tableName(),
588 $this->_quote((string)self::hashurl($url)),
589 $this->_quote((string)$url),
590 $this->_quote((string)$this->urlhash)));
591 if ($result === false) {
592 common_log_db_error($this, 'UPDATE', __FILE__);
593 throw new ServerException("Could not UPDATE {$this->tableName()}.url");
600 * Blow the cache of notices that link to this URL
602 * @param boolean $last Whether to blow the "last" cache too
607 function blowCache($last=false)
609 self::blow('file:notice-ids:%s', $this->id);
611 self::blow('file:notice-ids:%s;last', $this->id);
613 self::blow('file:notice-count:%d', $this->id);
617 * Stream of notices linking to this URL
619 * @param integer $offset Offset to show; default is 0
620 * @param integer $limit Limit of notices to show
621 * @param integer $since_id Since this notice
622 * @param integer $max_id Before this notice
624 * @return array ids of notices that link to this file
627 function stream($offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $max_id=0)
629 // FIXME: Try to get the Profile::current() here in some other way to avoid mixing
630 // the current session user with possibly background/queue processing.
631 $stream = new FileNoticeStream($this, Profile::current());
632 return $stream->getNotices($offset, $limit, $since_id, $max_id);
635 function noticeCount()
637 $cacheKey = sprintf('file:notice-count:%d', $this->id);
639 $count = self::cacheGet($cacheKey);
641 if ($count === false) {
643 $f2p = new File_to_post();
645 $f2p->file_id = $this->id;
647 $count = $f2p->count();
649 self::cacheSet($cacheKey, $count);
655 public function isLocal()
657 return !empty($this->filename);
660 public function delete($useWhere=false)
662 // Delete the file, if it exists locally
663 if (!empty($this->filename) && file_exists(self::path($this->filename))) {
664 $deleted = @unlink(self::path($this->filename));
666 common_log(LOG_ERR, sprintf('Could not unlink existing file: "%s"', self::path($this->filename)));
670 // Clear out related things in the database and filesystem, such as thumbnails
671 if (Event::handle('FileDeleteRelated', array($this))) {
672 $thumbs = new File_thumbnail();
673 $thumbs->file_id = $this->id;
674 if ($thumbs->find()) {
675 while ($thumbs->fetch()) {
680 $f2p = new File_to_post();
681 $f2p->file_id = $this->id;
683 while ($f2p->fetch()) {
689 // And finally remove the entry from the database
690 return parent::delete($useWhere);
693 public function getTitle()
695 $title = $this->title ?: $this->filename;
697 return $title ?: null;
700 public function setTitle($title)
702 $orig = clone($this);
703 $this->title = mb_strlen($title) > 0 ? $title : null;
704 return $this->update($orig);
707 static public function hashurl($url)
710 throw new Exception('No URL provided to hash algorithm.');
712 return hash(self::URLHASH_ALG, $url);
715 static public function beforeSchemaUpdate()
717 $table = strtolower(get_called_class());
718 $schema = Schema::get();
719 $schemadef = $schema->getTableDef($table);
721 // 2015-02-19 We have to upgrade our table definitions to have the urlhash field populated
722 if (isset($schemadef['fields']['urlhash']) && isset($schemadef['unique keys']['file_urlhash_key'])) {
723 // We already have the urlhash field, so no need to migrate it.
726 echo "\nFound old $table table, upgrading it to contain 'urlhash' field...";
729 $file->query(sprintf('SELECT id, LEFT(url, 191) AS shortenedurl, COUNT(*) AS c FROM %1$s WHERE LENGTH(url)>191 GROUP BY shortenedurl HAVING c > 1', $schema->quoteIdentifier($table)));
730 print "\nFound {$file->N} URLs with too long entries in file table\n";
731 while ($file->fetch()) {
732 // We've got a URL that is too long for our future file table
733 // so we'll cut it. We could save the original URL, but there is
734 // no guarantee it is complete anyway since the previous max was 255 chars.
735 $dupfile = new File();
736 // First we find file entries that would be duplicates of this when shortened
737 // ... and we'll just throw the dupes out the window for now! It's already so borken.
738 $dupfile->query(sprintf('SELECT * FROM file WHERE LEFT(url, 191) = %1$s', $dupfile->_quote($file->shortenedurl)));
739 // Leave one of the URLs in the database by using ->find(true) (fetches first entry)
740 if ($dupfile->find(true)) {
741 print "\nShortening url entry for $table id: {$file->id} [";
742 $orig = clone($dupfile);
743 $origurl = $dupfile->url; // save for logging purposes
744 $dupfile->url = $file->shortenedurl; // make sure it's only 191 chars from now on
745 $dupfile->update($orig);
746 print "\nDeleting duplicate entries of too long URL on $table id: {$file->id} [";
747 // only start deleting with this fetch.
748 while($dupfile->fetch()) {
749 common_log(LOG_INFO, sprintf('Deleting duplicate File entry of %1$d: %2$d (original URL: %3$s collides with these first 191 characters: %4$s', $dupfile->id, $file->id, $origurl, $file->shortenedurl));
755 print "\nWarning! URL suddenly disappeared from database: {$file->url}\n";
758 echo "...and now all the non-duplicates which are longer than 191 characters...\n";
759 $file->query('UPDATE file SET url=LEFT(url, 191) WHERE LENGTH(url)>191');
761 echo "\n...now running hacky pre-schemaupdate change for $table:";
762 // We have to create a urlhash that is _not_ the primary key,
763 // transfer data and THEN run checkSchema
764 $schemadef['fields']['urlhash'] = array (
767 'not null' => false, // this is because when adding column, all entries will _be_ NULL!
768 'description' => 'sha256 of destination URL (url field)',
770 $schemadef['fields']['url'] = array (
772 'description' => 'destination URL after following possible redirections',
774 unset($schemadef['unique keys']);
775 $schema->ensureTable($table, $schemadef);
778 $classname = ucfirst($table);
779 $tablefix = new $classname;
780 // urlhash is hash('sha256', $url) in the File table
781 echo "Updating urlhash fields in $table table...";
782 // Maybe very MySQL specific :(
783 $tablefix->query(sprintf('UPDATE %1$s SET %2$s=%3$s;',
784 $schema->quoteIdentifier($table),
786 // The line below is "result of sha256 on column `url`"
789 echo "Resuming core schema upgrade...";