| 1 | #!/usr/bin/env php |
|---|
| 2 | <?php |
|---|
| 3 | require_once(dirname($argv[0]) . "/utilities.php"); |
|---|
| 4 | require_once(IA_ROOT_DIR . "www/format/format.php"); |
|---|
| 5 | |
|---|
| 6 | db_connect(); |
|---|
| 7 | |
|---|
| 8 | $invalid_security = " |
|---|
| 9 | security NOT IN ('public', 'private', 'protected') AND |
|---|
| 10 | security NOT LIKE 'task: %' AND |
|---|
| 11 | security NOT LIKE 'round: %' |
|---|
| 12 | "; |
|---|
| 13 | $query = " |
|---|
| 14 | SELECT name, timestamp, security FROM ia_textblock_revision WHERE |
|---|
| 15 | ($invalid_security) |
|---|
| 16 | "; |
|---|
| 17 | $textblocks = db_fetch_all($query); |
|---|
| 18 | |
|---|
| 19 | foreach ($textblocks as $textblock) { |
|---|
| 20 | if ($textblock["security"] !== "") { |
|---|
| 21 | log_warn("Invalid textblock security for " . $textblock["name"]); |
|---|
| 22 | continue; |
|---|
| 23 | } |
|---|
| 24 | |
|---|
| 25 | # Fetch the security of the first revision which has security set |
|---|
| 26 | $result = db_fetch(sprintf(" |
|---|
| 27 | SELECT security FROM ia_textblock_revision |
|---|
| 28 | WHERE name = %s AND NOT (%s) |
|---|
| 29 | ORDER BY timestamp ASC LIMIT 1 |
|---|
| 30 | ", db_quote($textblock["name"]), $invalid_security)); |
|---|
| 31 | |
|---|
| 32 | if ($result === NULL) { |
|---|
| 33 | # Fetch the security of the latest revision for the current page |
|---|
| 34 | $result = db_fetch(sprintf( |
|---|
| 35 | "SELECT security FROM ia_textblock WHERE name = %s", |
|---|
| 36 | db_quote($textblock["name"]) |
|---|
| 37 | )); |
|---|
| 38 | $new_security = array_pop($result); |
|---|
| 39 | } else { |
|---|
| 40 | $new_security = array_pop($result); |
|---|
| 41 | } |
|---|
| 42 | |
|---|
| 43 | log_print(sprintf( |
|---|
| 44 | "Changing '%s' revision from '%s' security to '%s'", |
|---|
| 45 | $textblock["name"], format_date($textblock["timestamp"]), |
|---|
| 46 | $new_security |
|---|
| 47 | )); |
|---|
| 48 | |
|---|
| 49 | db_query(sprintf( |
|---|
| 50 | "UPDATE ia_textblock_revision SET security = %s |
|---|
| 51 | WHERE name = %s AND timestamp = %s", |
|---|
| 52 | db_quote($new_security), db_quote($textblock["name"]), |
|---|
| 53 | db_quote($textblock["timestamp"]) |
|---|
| 54 | )); |
|---|
| 55 | } |
|---|
| 56 | |
|---|
| 57 | db_query(" |
|---|
| 58 | ALTER TABLE `ia_textblock` |
|---|
| 59 | MODIFY COLUMN `security` VARCHAR(64) NOT NULL |
|---|
| 60 | "); |
|---|
| 61 | |
|---|
| 62 | db_query(" |
|---|
| 63 | ALTER TABLE `ia_textblock_revision` |
|---|
| 64 | MODIFY COLUMN `name` VARCHAR(64) NOT NULL, |
|---|
| 65 | MODIFY COLUMN `security` VARCHAR(64) NOT NULL |
|---|
| 66 | "); |
|---|
| 67 | ?> |
|---|