| 1 | #! /usr/bin/env php |
|---|
| 2 | <?php |
|---|
| 3 | // This script is used to repair all text attachments that weren't in Linux format. |
|---|
| 4 | |
|---|
| 5 | require_once(dirname($argv[0]) . "/utilities.php"); |
|---|
| 6 | require_once(IA_ROOT_DIR."common/textblock.php"); |
|---|
| 7 | require_once(IA_ROOT_DIR."common/db/textblock.php"); |
|---|
| 8 | |
|---|
| 9 | ini_set("memory_limit", "128M"); |
|---|
| 10 | |
|---|
| 11 | function add_datetime_column($table, $column, $after) { |
|---|
| 12 | $query = sprintf("SHOW COLUMNS FROM %s LIKE '%s'", db_escape($table), db_escape($column)); |
|---|
| 13 | if (db_fetch($query) != null) { |
|---|
| 14 | //FIXME: only for testing; remove this before commit |
|---|
| 15 | $query = sprintf("ALTER TABLE %s DROP %s", db_escape($table), db_escape($column)); |
|---|
| 16 | db_query($query); |
|---|
| 17 | log_print(sprintf("Coloana %s exista deja in %s!", $column, $table)); |
|---|
| 18 | } |
|---|
| 19 | $query = sprintf("ALTER TABLE %s ADD %s DATETIME NOT NULL AFTER %s", |
|---|
| 20 | db_escape($table), db_escape($column), db_escape($after)); |
|---|
| 21 | db_query($query); |
|---|
| 22 | } |
|---|
| 23 | |
|---|
| 24 | function update_table($table) { |
|---|
| 25 | $query = sprintf("SELECT * FROM %s", db_escape($table)); |
|---|
| 26 | $textblocks = db_fetch_all($query); |
|---|
| 27 | foreach ($textblocks as $textblock) { |
|---|
| 28 | $name = $textblock['name']; |
|---|
| 29 | |
|---|
| 30 | // ignore junk pages |
|---|
| 31 | if (!is_normal_page_name($name)) { |
|---|
| 32 | continue; |
|---|
| 33 | } |
|---|
| 34 | |
|---|
| 35 | $first_revision = textblock_get_revision($name, 1); |
|---|
| 36 | $query = sprintf("UPDATE %s SET creation_timestamp = '%s' WHERE name = '%s'", |
|---|
| 37 | db_escape($table), db_escape($first_revision['timestamp']), db_escape($name)); |
|---|
| 38 | db_query($query); |
|---|
| 39 | } |
|---|
| 40 | } |
|---|
| 41 | |
|---|
| 42 | |
|---|
| 43 | db_connect(); |
|---|
| 44 | add_datetime_column("ia_textblock", "creation_timestamp", "title"); |
|---|
| 45 | add_datetime_column("ia_textblock_revision", "creation_timestamp", "title"); |
|---|
| 46 | update_table("ia_textblock"); |
|---|
| 47 | update_table("ia_textblock_revision"); |
|---|
| 48 | |
|---|