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

Revision 884, 1.5 KB checked in by bogdanpasoi@…, 4 years ago (diff)

Better rating graph.

  • Property svn:executable set to *
Line 
1#! /usr/bin/env php
2<?php
3// This script is used to repair bad filenames in the IA_ROOT_DIR/attach folder.
4// Previously infoarena lowercased the filename for any attachment making "test" and "Test"
5// having the same file in the attach folder. This script tries to fix this behavior.
6
7require_once(dirname($argv[0]) . "/utilities.php");
8require_once(IA_ROOT_DIR."common/db/attachment.php");
9
10ini_set("memory_limit", "128M");
11
12function attachment_get_bad_filepath($attach) {
13    assert(is_array($attach));
14    return IA_ROOT_DIR.'attach/'.
15            strtolower(preg_replace('/[^a-z0-9\.\-_]/i', '_', $attach['page'])) . '_' .
16            strtolower(preg_replace('/[^a-z0-9\.\-_]/i', '_', $attach['name'])) . '_' .
17            $attach['id'];
18}
19
20db_connect();
21$query = "SELECT * FROM ia_file;";
22$attachments = db_fetch_all($query);
23$fixed = $errors = 0;
24
25log_print("Exista ".count($attachments)." atasamente...");
26foreach ($attachments as $attach) {
27    if ($attach['name'] == strtolower($attach['name'])) {
28        continue;
29    }
30    log_print('Verific '.$attach['page'].'\\'.$attach['name']);
31    $bad_name = attachment_get_bad_filepath($attach);
32    if (file_exists($bad_name)) {
33        log_print('Repar '.$attach['page'].'\\'.$attach['name']);
34        $good_name = attachment_get_filepath($attach);
35        if (!@rename($bad_name, $good_name)) {
36            log_error("Eroare la redenumire!");
37            $errors++;
38        }
39        $fixed++;
40    }
41}
42log_print("S-au reparat ".$fixed." atasamente!");
43log_print("Au avut loc ".$errors." erori!");
Note: See TracBrowser for help on using the repository browser.