source: trunk/scripts/textblock-creation-timestamp @ 1184

Revision 852, 1.7 KB checked in by cdleonard@…, 4 years ago (diff)

svn:eol-style native in trunk. Also svn:executable on all scripts

  • Property svn:eol-style set to native
  • Property svn:executable set to *
Line 
1#! /usr/bin/env php
2<?php
3// This script is used to repair all text attachments that weren't in Linux format.
4
5require_once(dirname($argv[0]) . "/utilities.php");
6require_once(IA_ROOT_DIR."common/textblock.php");
7require_once(IA_ROOT_DIR."common/db/textblock.php");
8
9ini_set("memory_limit", "128M");
10
11function 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
24function 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
43db_connect();
44add_datetime_column("ia_textblock", "creation_timestamp", "title");
45add_datetime_column("ia_textblock_revision", "creation_timestamp", "title");
46update_table("ia_textblock");
47update_table("ia_textblock_revision");
48
Note: See TracBrowser for help on using the repository browser.