Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also .

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also .
base repository: haiku/userguide-translator
Choose a Base Repository
base: 4e5bf34a2613
head repository: haiku/userguide-translator
Choose a Head Repository
compare: 66bf9a966069
  • 2 commits
  • 18 files changed
  • 0 commit comments
  • 1 contributor
Commits on Mar 05, 2018
Was actually not that bad. See MIGRATE.md for how to migrate a
running system.

I tried to test this pretty thoroughly, but some bugs may still remain.
Never really worked and is now pointless.
@@ -5,7 +5,7 @@ Create config file

Install database
----------------
1. Install MySQL.
1. Install PostgreSQL.
2. Create a database and user.
3. Import db_structure.sql into the database.
4. Create a default user with Administrative privileges. Password is SHA1-hashed, no salt.
@@ -15,5 +15,3 @@ Install Git
1. Install Git.
2. mkdir source_docs && cd source_docs
3. git init .

(TODO: need info on svn->git migration.)
@@ -0,0 +1,19 @@
Migration to PostgreSQL
==================================

1. Download and extract the master branch of [this tool](https://github.com/mihailShumilov/mysql2postgresql#mysql2postgresql).
2. Dump the userguide MySQL database: `mysqldump --xml -u USERNAME userguide >userguide_db.xml`
3. Run the tool (`php converter.php`) with arguments `-i userguide_db.xml -o userguide_pg.sql`
4. Create a database called `userguide` on the Postgres server.
5. `psql -d userguide -f userguide_pg.sql`
6. Make sure `userguide` owns all tables, and update `config.php`.
7. Run these commands on the database:
```
ALTER TABLE translate_langs ALTER COLUMN lang_code TYPE varchar(5);
ALTER TABLE translate_users ALTER COLUMN real_name SET DEFAULT '''';
UPDATE translate_langs SET lang_code=trim(both from lang_code);
```
8. Run this query on the database and execute all the commands it outputs:
```
SELECT 'ALTER TABLE translate_strings ALTER COLUMN "' ||column_name|| '" SET DEFAULT '''';' FROM information_schema.columns WHERE table_name='translate_strings' AND column_name LIKE 'translation_%';
```
@@ -8,6 +8,5 @@
• <a href="docs.php">Documents</a>
• <a href="resources.php">Resources</a>
• <a href="export.php">Export</a>
• <a href="logs.php">Logs</a>
EOD;
?>
@@ -16,20 +16,17 @@
and isset($_SESSION['exp_langs'])) {
$lang_code = $_SESSION['exp_cur_lang'];
$lang_name = ($lang_code ? $_SESSION['exp_langs'][$lang_code] : '');
$dirty_column = 'is_dirty' . ($lang_code ? '_' . $lang_code : '');
$dirty_column = '"is_dirty' . ($lang_code ? '_' . $lang_code : '') . '"';
$documents = array();
$doc_ids = '';
if ($lang_code) {
$req = db_query('
SELECT doc_id, path_original, path_translations, strings_count,
count_' . $lang_code . ', count_fuzzy_' . $lang_code . '
$req = db_query('SELECT doc_id, path_original, path_translations, strings_count,
"count_' . $lang_code . '", "count_fuzzy_' . $lang_code . '"
FROM ' . DB_DOCS . "
WHERE is_disabled = 0 AND $dirty_column = 1");
} else {
$req = db_query('
SELECT doc_id, path_original, path_translations
$req = db_query('SELECT doc_id, path_original, path_translations
FROM ' . DB_DOCS . "
WHERE is_disabled = 0 AND $dirty_column = 1");
}
@@ -44,10 +41,10 @@
// Non-English: load the translations
if ($lang_code and $doc_ids) {
$req = db_query('
SELECT doc_id, source_md5, string_id, translation_' . $lang_code . '
$req = db_query('SELECT doc_id, source_md5, string_id, "translation_' . $lang_code . '"
FROM ' . DB_STRINGS . "
WHERE doc_id IN ($doc_ids) AND translation_$lang_code <> '' AND unused_since IS NULL AND is_fuzzy_$lang_code = 0");
WHERE doc_id IN ($doc_ids) AND \"translation_$lang_code\" <> '' AND
unused_since IS NULL AND \"is_fuzzy_$lang_code\" = 0");
$trans_by_md5 = array();
while ($row = db_fetch($req)) {
@@ -97,7 +94,7 @@
// all of their translations.
foreach ($_SESSION['exp_langs_loc'] as $lang => $name) {
$sql .= ", is_dirty_$lang = 1";
$sql .= ", \"is_dirty_$lang\" = 1";
}
}
@@ -15,16 +15,11 @@
WHERE lang_code = ?", array($lang_code));
if (db_num_rows($result) > 0) {
db_query('ALTER TABLE ' . DB_DOCS . "
DROP `count_$lang_code`");
db_query('ALTER TABLE ' . DB_DOCS . "
DROP `count_fuzzy_$lang_code`");
db_query('ALTER TABLE ' . DB_DOCS . "
DROP `is_dirty_$lang_code`");
db_query('ALTER TABLE ' . DB_STRINGS . "
DROP `translation_$lang_code`");
db_query('ALTER TABLE ' . DB_STRINGS . "
DROP `is_fuzzy_$lang_code`");
db_query('ALTER TABLE ' . DB_DOCS . " DROP \"count_$lang_code\"");
db_query('ALTER TABLE ' . DB_DOCS . " DROP \"count_fuzzy_$lang_code\"");
db_query('ALTER TABLE ' . DB_DOCS . " DROP \"is_dirty_$lang_code\"");
db_query('ALTER TABLE ' . DB_STRINGS . " DROP \"translation_$lang_code\"");
db_query('ALTER TABLE ' . DB_STRINGS . " DROP \"is_fuzzy_$lang_code\"");
}
redirect('langs.php');
} else if (isset($_POST['confirm_cancel'])) {
@@ -49,8 +44,7 @@
db_query('UPDATE ' . DB_LANGS . ' SET is_disabled = 0 WHERE TRUE');
if (count($dis_list)) {
db_query('
UPDATE ' . DB_LANGS . '
db_query('UPDATE ' . DB_LANGS . '
SET is_disabled = 1
WHERE lang_code = ' . implode(' OR lang_code = ', $dis_list));
}
@@ -66,29 +60,27 @@
$lang_code = validate_lang($lang_code);
db_query('
INSERT INTO ' . DB_LANGS . '
db_query('INSERT INTO ' . DB_LANGS . '
(lang_code, lang_name, loc_name) ' . "
VALUES (?, ?, ?)", array($lang_code, $lang_name, $lang_loc_name));
db_query('ALTER TABLE ' . DB_DOCS . "
ADD `count_$lang_code` INT UNSIGNED NOT NULL DEFAULT '0'");
ADD \"count_$lang_code\" INT NOT NULL DEFAULT '0'");
db_query('ALTER TABLE ' . DB_DOCS . "
ADD `count_fuzzy_$lang_code` INT UNSIGNED NOT NULL DEFAULT '0'");
ADD \"count_fuzzy_$lang_code\" INT NOT NULL DEFAULT '0'");
db_query('ALTER TABLE ' . DB_DOCS . "
ADD `is_dirty_$lang_code` BOOLEAN NOT NULL DEFAULT '1'");
ADD \"is_dirty_$lang_code\" smallint NOT NULL DEFAULT '1'");
db_query('ALTER TABLE ' . DB_STRINGS . "
ADD `translation_$lang_code` TEXT collate utf8_bin NOT NULL");
ADD \"translation_$lang_code\" TEXT NOT NULL DEFAULT ''");
db_query('ALTER TABLE ' . DB_STRINGS . "
ADD `is_fuzzy_$lang_code` BOOL NOT NULL DEFAULT '0'");
ADD \"is_fuzzy_$lang_code\" smallint NOT NULL DEFAULT '0'");
$lang_code = '';
$lang_name = '';
$lang_loc_name = '';
echo '<div class="box-info">New language added successfully.</div>';
} else {
echo '<div class="box-stop">Adding language failed: Incorrect ' .
'parameters.</div>';
echo '<div class="box-stop">Adding language failed: Incorrect parameters.</div>';
}
}
?>

This file was deleted.

@@ -159,7 +159,7 @@
<th style="width:5%">Edits</th><th style="width:5%">Translations</th><th style="width:10%">Options</th>
</tr>
<?php
$req = db_query('SELECT * FROM ' . DB_USERS . ' ORDER BY UCASE(username)');
$req = db_query('SELECT * FROM ' . DB_USERS . ' ORDER BY username');
while ($row = db_fetch($req)) {
if ($row['user_id'] == $user_id) {
?>
@@ -37,8 +37,7 @@
die("badxml $xml_msg");
// Update the document
$req = db_query('
SELECT path_original, name FROM ' . DB_DOCS . "
$req = db_query('SELECT path_original, name FROM ' . DB_DOCS . "
WHERE doc_id = ?", array($doc_id));
$row = db_fetch($req);
db_free($req);
@@ -51,8 +50,7 @@
// Load all the md5
$blocks_md5 = array();
$req = db_query('
SELECT string_id, source_md5 FROM ' . DB_STRINGS . "
$req = db_query('SELECT string_id, source_md5 FROM ' . DB_STRINGS . "
WHERE doc_id = ?", array($doc_id));
while ($row = db_fetch($req)) {
$blocks_md5[$row['source_md5']] = $row['string_id'];
@@ -75,42 +73,36 @@
replace_block_id($doc, $doc, $string_id, $new_block, $blocks_md5[$md5])
or die("Unable to replace the block #$string_id with #$blocks_md5[$md5] !");
db_query('
UPDATE ' . DB_STRINGS . "
db_query('UPDATE ' . DB_STRINGS . "
SET unused_since = NULL
WHERE string_id = ?", array($blocks_md5[$md5]));
db_query('
UPDATE ' . DB_STRINGS . "
db_query('UPDATE ' . DB_STRINGS . "
SET unused_since = ?
WHERE string_id = ?", array($time, $string_id));
} else {
$r_norm = 'doc_id';
$r_fuzzy = '';
$r_to_fuzzy = '';
$req = db_query('SELECT lang_code FROM ' . DB_LANGS);
while ($row = db_fetch($req)) {
$r_norm .= ', translation_' . $row['lang_code'];
$r_fuzzy .= ($r_fuzzy ? ', ' : '') . 'is_fuzzy_' .
$row['lang_code'];
$r_norm .= ', "translation_' . $row['lang_code'] . '"';
$r_fuzzy .= ($r_fuzzy ? ', ' : '') . '"is_fuzzy_' .
$row['lang_code'] . '"';
$r_to_fuzzy .= ($r_to_fuzzy ? ', ' : '') . '1';
}
$fuzzy = !$_POST['dont_mark_fuzzy'];
$update = 'source_md5' . ($r_norm ? ', ' : '') . $r_norm . (($fuzzy and $r_fuzzy) ? ', ' . $r_fuzzy : '');
$up_to = "'$md5'" . ($r_norm ? ', ' : '') . $r_norm . (($fuzzy and $r_to_fuzzy) ? ', ' . $r_to_fuzzy : '');
db_query('
INSERT INTO ' . DB_STRINGS . "
($update)
SELECT $up_to FROM " . DB_STRINGS . "
WHERE string_id = ?", array($string_id));
db_query('INSERT INTO ' . DB_STRINGS . " ($update)
SELECT $up_to FROM " . DB_STRINGS . "
WHERE string_id = ?", array($string_id));
$new_id = db_insert_id();
replace_block_id($doc, $doc, $string_id, $new_block, $new_id)
or die('unable to replace');
db_query('
UPDATE ' . DB_STRINGS . "
db_query('UPDATE ' . DB_STRINGS . "
SET unused_since = ?
WHERE string_id = ?", array($time, $string_id));
}
@@ -123,20 +115,22 @@
// Log
$delay = $time - 5 * 60;
$result = db_query('
UPDATE ' . DB_LOG . '
SET log_trans_number = log_trans_number + 1' . "
$result = db_query('SELECT log_id FROM ' . DB_LOG . "
WHERE log_user = ? AND log_time > ? AND log_doc = ?
AND log_action = 'ed_block' LIMIT 1", array($user_id, $delay, $doc_id));
if (!db_num_rows($result))
db_query('
INSERT INTO ' . DB_LOG . '
if (!db_num_rows($result)) {
db_query('INSERT INTO ' . DB_LOG . '
(log_user, log_time, log_action, log_doc, log_trans_number) ' . "
VALUES (?, ?, ?, ?, ?)", array($user_id, $time, 'ed_block', $doc_id, 1));
} else {
$row = db_fetch($result);
db_query('UPDATE ' . DB_LOG . '
SET log_trans_number = log_trans_number + 1 WHERE log_id = ?',
array($row['log_id']));
}
db_query('
UPDATE ' . DB_USERS . '
db_query('UPDATE ' . DB_USERS . '
SET num_edits = num_edits + 1 ' . "
WHERE user_id = ?", array($user_id));
@@ -71,9 +71,8 @@
</tr></thead>
<tbody>
<?php
$req = db_query('
SELECT doc_id, name, path_original, path_translations, strings_count, ' . "
count_${sel_lang}, count_fuzzy_${sel_lang} FROM " . DB_DOCS . '
$req = db_query('SELECT doc_id, name, path_original, path_translations, strings_count, ' . "
\"count_${sel_lang}\", \"count_fuzzy_${sel_lang}\" FROM " . DB_DOCS . '
ORDER BY name ASC');
while ($row = db_fetch($req)) {
$doc_id = $row['doc_id'];
@@ -113,7 +112,7 @@
$sql = 'SELECT doc_id, name, strings_count, path_translations';
$count_langs = count($language_names);
foreach($language_names as $code => $name) {
$sql .= ", count_$code, count_fuzzy_$code";
$sql .= ", \"count_$code\", \"count_fuzzy_$code\"";
echo "<th>$name</th>";
}
echo "\n</tr></thead>\n";
@@ -236,25 +236,22 @@
$edited_doc->save($file_path) or die('Unable to save the XML document !');
$req = db_query('
SELECT COUNT(*) FROM ' . DB_STRINGS . "
$req = db_query('SELECT COUNT(*) FROM ' . DB_STRINGS . "
WHERE doc_id = ? AND unused_since IS NULL", array($doc_id));
$row = db_fetch($req);
$count = $row['COUNT(*)'];
$count = $row['count'];
db_free($req);
db_query('UPDATE ' . DB_DOCS . "
SET strings_count = ?, is_dirty = 1 WHERE doc_id = ?", array($count, $doc_id));
// Log
db_query('
INSERT INTO ' . DB_LOG . '
db_query('INSERT INTO ' . DB_LOG . '
(log_user, log_time, log_action, log_doc) ' . "
VALUES (?, ?, ?, ?)", array($user_id, $time, 'mod', $doc_id));
db_query('
UPDATE ' . DB_USERS . '
db_query('UPDATE ' . DB_USERS . '
SET num_edits = num_edits + 1 ' . "
WHERE user_id = ?", array($user_id));

This file was deleted.

@@ -54,7 +54,7 @@
// Connect to the DB
$db_h = null;
try {
$db_h = new PDO("mysql:host=$db_server;dbname=$db_base_name;charset=utf8",
$db_h = new PDO("pgsql:host=$db_server;dbname=$db_base_name;options='--client-encoding=UTF8'",
$db_username, $db_password);
$db_h->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); // TODO: REMOVE!
} catch (PDOException $e) {

No commit comments for this range

You can’t perform that action at this time.