function revert_dict($rev_id) { if (!$rev_id) { throw new UnexpectedValueException(); } check_permission(PERM_DICT); $res = sql_pe("SELECT lemma_id, rev_text FROM dict_revisions WHERE rev_id=? LIMIT 1", array($rev_id)); $lemma_id = $res[0]['lemma_id']; $old_rev = sql_pe("SELECT rev_text FROM dict_revisions WHERE lemma_id=? and is_last=1 LIMIT 1", array($lemma_id)); sql_begin(); $new_set_id = create_revset("Отмена правки, возврат к версии d{$rev_id}"); $new_rev_id = new_dict_rev($lemma_id, $res[0]['rev_text'], $new_set_id); // updated forms $pdr = parse_dict_rev($old_rev[0]['rev_text']); enqueue_updated_forms(calculate_updated_forms($pdr, parse_dict_rev($res[0]['rev_text'])), $new_rev_id); sql_commit(); }
function del_lemma($id) { check_permission(PERM_DICT); //delete links (but preserve history) $res = sql_pe("SELECT link_id FROM dict_links WHERE lemma1_id=? OR lemma2_id=?", array($id, $id)); sql_begin(); $revset_id = create_revset("Delete lemma {$id}"); foreach ($res as $r) { del_link($r['link_id'], $revset_id); } // create empty revision sql_pe("UPDATE dict_revisions SET is_last=0 WHERE lemma_id=?", array($id)); sql_pe("INSERT INTO dict_revisions VALUES (NULL, ?, ?, '', 1, 1, 1)", array($revset_id, $id)); $rev_id = sql_insert_id(); //update `updated_forms` $res = sql_pe("SELECT rev_text FROM dict_revisions WHERE lemma_id=? ORDER BY `rev_id` DESC LIMIT 1, 1", array($id)); $pdr = parse_dict_rev($res[0]['rev_text']); $updated_forms = array(); foreach ($pdr['forms'] as $form) { $updated_forms[] = $form['text']; } enqueue_updated_forms($updated_forms, $rev_id); //delete forms from form2lemma sql_pe("DELETE FROM `form2lemma` WHERE lemma_id=?", array($id)); //delete lemma sql_pe("UPDATE dict_lemmata SET deleted=1 WHERE lemma_id=? LIMIT 1", array($id)); sql_commit(); }