source: trunk/scripts/attach-endline-fix @ 1184

Revision 1170, 1.6 KB checked in by bogdan2412, 3 months ago (diff)

Some more fixes from live.

  • Made finfo only return the mime type (no charset information), since most of our code expects this behaviour. Changed check-attachments script so that it optionally checks that the stored mimetypes agree with the stored files. This helped discover a bug in the attach-endline-fix which was skiping files that were small enough that mime was not recognizing them as plain text.
  • Fixed a bug with the textblock edit button not displaying the correct edit link for pages with round or task security.
  • Replaced deprecated functions from mailing code base.
  • Added an 'admin' tab to the top navigation bar.
  • Fixed random unwanted characters in common/round.php
  • Property svn:executable set to *
Line 
1#! /usr/bin/env php
2<?php
3require_once(dirname($argv[0]) . "/utilities.php");
4require_once(IA_ROOT_DIR . "common/attachment.php");
5
6$verbose = getattr($argv, 1, false);
7
8db_connect();
9$files = db_fetch_all("SELECT `id`, `page`, `name`, `mime_type`
10                       FROM `ia_file`");
11if ($verbose) {
12    log_print(count($files) . " rows fetched.");
13}
14
15$nr_notfound = 0;
16$nr_changed = 0;
17
18foreach ($files as $file) {
19    $file_path = attachment_get_filepath($file);
20
21    if (is_file($file_path)) {
22        if (is_grader_testfile($file['name']) &&
23            is_problem_page($file['page'])) {
24            if (!is_textfile($file['mime_type'])) {
25                log_print('Test file ' . $file['name'] . ' on page ' .
26                          $file['page'] . ' of size ' . filesize($file_path) .
27                          ' has an unexpected mime type: ' .
28                          $file['mime_type']);
29                if (read_bool('Do you want to skip file?', true)) {
30                    continue;
31                }
32            }
33
34            if (add_ending_newline($file_path)) {
35                if ($verbose) {
36                    log_print("Added newline to file " . $file_path);
37                }
38                db_query("UPDATE `ia_file`" .
39                         " SET `size` = " . db_quote(filesize($file_path)) .
40                         " WHERE `id` = " . db_quote((int)$file['id']));
41                $nr_changed++;
42            }
43        }
44    } else {
45        $nr_notfound++;
46    }
47}
48
49if ($verbose) {
50    log_print($nr_changed . " grader testfiles updated.");
51    log_print($nr_notfound . " files not found.");
52}
53
54?>
Note: See TracBrowser for help on using the repository browser.