| 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 | |
|---|
| 7 | require_once(dirname($argv[0]) . "/utilities.php"); |
|---|
| 8 | require_once(IA_ROOT_DIR."common/db/attachment.php"); |
|---|
| 9 | |
|---|
| 10 | ini_set("memory_limit", "128M"); |
|---|
| 11 | |
|---|
| 12 | function 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 | |
|---|
| 20 | db_connect(); |
|---|
| 21 | $query = "SELECT * FROM ia_file;"; |
|---|
| 22 | $attachments = db_fetch_all($query); |
|---|
| 23 | $fixed = $errors = 0; |
|---|
| 24 | |
|---|
| 25 | log_print("Exista ".count($attachments)." atasamente..."); |
|---|
| 26 | foreach ($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 | } |
|---|
| 42 | log_print("S-au reparat ".$fixed." atasamente!"); |
|---|
| 43 | log_print("Au avut loc ".$errors." erori!"); |
|---|